Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attribute spam for bats #744

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 68 additions & 12 deletions patches/server/0007-Ridables.patch
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ index bb0f7c631b4889e95a87214fbc0537a0e420d87f..0a076780868ed1bd15c36dd88de85a0d

this.profiler.push(() -> {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index ce146c771b8e38eb24e9372058f238920ec88882..1f10746e79373c269a904d23046003af6c3f6352 100644
index 1ae7a10df7460f223413c38ac6bd85dba15fb347..2a7e46b4f65dd4d90dbfa6fdf608b5496fa743c7 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -200,6 +200,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
Expand Down Expand Up @@ -86,7 +86,7 @@ index f6f12392e119a4742591d8043a0a51fc35a719c5..94fa47af7f3fe98cac637190e533102c
if ((entity instanceof AbstractFish && origItem != null && origItem.asItem() == Items.WATER_BUCKET) && (event.isCancelled() || ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null || ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem() != origItem)) {
ServerGamePacketListenerImpl.this.send(new ClientboundAddMobPacket((AbstractFish) entity));
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 7a954d7495636a27149a55b58436183e18e028dd..643f0c878352fd205f928aaa083cde59c911f926 100644
index 9d7d40a693dca5d732010da3b5e71d30929aaad3..01ddf9955cbff75bb02ac0e6d150f7b2ea9bca1a 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -230,7 +230,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
Expand Down Expand Up @@ -201,7 +201,7 @@ index 94f7f8238c01d203d28640c56e35deab2bf17bbc..f0c30ab5e32e78850d402aa4bc7d4266
protected ParticleOptions getInkParticle() {
return ParticleTypes.GLOW_SQUID_INK;
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 71fefe3956c1e4458dd4b441f90902a3ed0cdf24..15421740e66f61a818348f57f0d68db69d3577ce 100644
index 71fefe3956c1e4458dd4b441f90902a3ed0cdf24..62303c6aef57f92fc5d8c3e3f19558b1e2f2cd29 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -219,9 +219,9 @@ public abstract class LivingEntity extends Entity {
Expand All @@ -217,7 +217,24 @@ index 71fefe3956c1e4458dd4b441f90902a3ed0cdf24..15421740e66f61a818348f57f0d68db6
protected int lerpSteps;
protected double lerpX;
protected double lerpY;
@@ -2585,7 +2585,7 @@ public abstract class LivingEntity extends Entity {
@@ -286,7 +286,7 @@ public abstract class LivingEntity extends Entity {
this.effectsDirty = true;
this.useItem = ItemStack.EMPTY;
this.lastClimbablePos = Optional.empty();
- this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type));
+ this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type), this); // Purpur
this.craftAttributes = new CraftAttributeMap(this.attributes); // CraftBukkit
// CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
this.entityData.set(LivingEntity.DATA_HEALTH_ID, (float) this.getAttribute(Attributes.MAX_HEALTH).getValue());
@@ -337,6 +337,7 @@ public abstract class LivingEntity extends Entity {
public static AttributeSupplier.Builder createLivingAttributes() {
return AttributeSupplier.builder().add(Attributes.MAX_HEALTH).add(Attributes.KNOCKBACK_RESISTANCE).add(Attributes.MOVEMENT_SPEED).add(Attributes.ARMOR).add(Attributes.ARMOR_TOUGHNESS);
}
+ public boolean shouldSendAttribute(Attribute attribute) { return true; } // Purpur

@Override
protected void checkFallDamage(double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
@@ -2585,7 +2586,7 @@ public abstract class LivingEntity extends Entity {
}

protected long lastJumpTime = 0L; // Paper - add critical damage API
Expand All @@ -226,7 +243,7 @@ index 71fefe3956c1e4458dd4b441f90902a3ed0cdf24..15421740e66f61a818348f57f0d68db6
double d0 = (double) this.getJumpPower() + this.getJumpBoostPower();
Vec3 vec3d = this.getDeltaMovement();
// Paper start - add critical damage API
@@ -3250,8 +3250,10 @@ public abstract class LivingEntity extends Entity {
@@ -3250,8 +3251,10 @@ public abstract class LivingEntity extends Entity {
this.pushEntities();
this.level.getProfiler().pop();
// Paper start
Expand All @@ -239,7 +256,7 @@ index 71fefe3956c1e4458dd4b441f90902a3ed0cdf24..15421740e66f61a818348f57f0d68db6
Location from = new Location(this.level.getWorld(), this.xo, this.yo, this.zo, this.yRotO, this.xRotO);
Location to = new Location (this.level.getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
io.papermc.paper.event.entity.EntityMoveEvent event = new io.papermc.paper.event.entity.EntityMoveEvent(this.getBukkitLivingEntity(), from, to.clone());
@@ -3261,6 +3263,21 @@ public abstract class LivingEntity extends Entity {
@@ -3261,6 +3264,21 @@ public abstract class LivingEntity extends Entity {
absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
Expand Down Expand Up @@ -336,6 +353,42 @@ index 6051fd771dd989f2903b854b6564252a847a74e3..6106274009fcd8b43373e2fa9080183d
+ }
+ // Purpur end
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
index d3e97858dacc850012e5585ac44a1aeafc82b8f4..85e22acaf64c29e624a7f5b234cd8d88db1a4d2a 100644
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
+++ b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
@@ -23,14 +23,21 @@ public class AttributeMap {
private final Set<AttributeInstance> dirtyAttributes = Sets.newHashSet();
private final AttributeSupplier supplier;
private final java.util.function.Function<Attribute, AttributeInstance> createInstance; // Airplane
+ private final net.minecraft.world.entity.LivingEntity entity; // Purpur

public AttributeMap(AttributeSupplier defaultAttributes) {
+ // Purpur start
+ this(defaultAttributes, null);
+ }
+ public AttributeMap(AttributeSupplier defaultAttributes, net.minecraft.world.entity.LivingEntity entity) {
+ this.entity = entity;
+ // Purpur end
this.supplier = defaultAttributes;
this.createInstance = attribute -> this.supplier.createInstance(this::onAttributeModified, attribute); // Airplane
}

private void onAttributeModified(AttributeInstance instance) {
- if (instance.getAttribute().isClientSyncable()) {
+ if (instance.getAttribute().isClientSyncable() && (entity == null || entity.shouldSendAttribute(instance.getAttribute()))) { // Purpur
this.dirtyAttributes.add(instance);
}

@@ -42,7 +49,7 @@ public class AttributeMap {

public Collection<AttributeInstance> getSyncableAttributes() {
return this.attributes.values().stream().filter((attribute) -> {
- return attribute.getAttribute().isClientSyncable();
+ return attribute.getAttribute().isClientSyncable() && (entity == null || entity.shouldSendAttribute(attribute.getAttribute())); // Purpur
}).collect(Collectors.toList());
}

diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java b/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java
index b1e00093ad2b42a1e0a399d261539e06f2a505b9..53d43442ddc711d39ede5f33c3754e0a2097c2bc 100644
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/DefaultAttributes.java
Expand Down Expand Up @@ -488,7 +541,7 @@ index ffc87d14cdc7edc22a7e2ac642d0e37037c52487..f2957d7f4c377a67ee486a9d0f7ae173
}

diff --git a/src/main/java/net/minecraft/world/entity/ambient/Bat.java b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
index cda441f5cf64f061dc145fbeba175874c31cebe4..02eb039e4c17d21649610b0d475bbecfc8574809 100644
index cda441f5cf64f061dc145fbeba175874c31cebe4..62dfbd1afbfe5f8ecfa4ea1a6ba0918ffad5d1c0 100644
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
@@ -20,6 +20,7 @@ import net.minecraft.world.entity.EntityType;
Expand All @@ -499,7 +552,7 @@ index cda441f5cf64f061dc145fbeba175874c31cebe4..02eb039e4c17d21649610b0d475bbecf
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
@@ -42,9 +43,48 @@ public class Bat extends AmbientCreature {
@@ -42,9 +43,51 @@ public class Bat extends AmbientCreature {

public Bat(EntityType<? extends Bat> type, Level world) {
super(type, world);
Expand All @@ -509,6 +562,9 @@ index cda441f5cf64f061dc145fbeba175874c31cebe4..02eb039e4c17d21649610b0d475bbecf

+ // Purpur start
+ @Override
+ public boolean shouldSendAttribute(net.minecraft.world.entity.ai.attributes.Attribute attribute) { return attribute != Attributes.FLYING_SPEED; } // Fixes log spam on clients
+
+ @Override
+ public boolean isRidable() {
+ return level.purpurConfig.batRidable;
+ }
Expand Down Expand Up @@ -548,7 +604,7 @@ index cda441f5cf64f061dc145fbeba175874c31cebe4..02eb039e4c17d21649610b0d475bbecf
@Override
public boolean isFlapping() {
return !this.isResting() && this.tickCount % Bat.TICKS_PER_FLAP == 0;
@@ -94,7 +134,7 @@ public class Bat extends AmbientCreature {
@@ -94,7 +137,7 @@ public class Bat extends AmbientCreature {
protected void pushEntities() {}

public static AttributeSupplier.Builder createAttributes() {
Expand All @@ -557,7 +613,7 @@ index cda441f5cf64f061dc145fbeba175874c31cebe4..02eb039e4c17d21649610b0d475bbecf
}

public boolean isResting() {
@@ -126,6 +166,14 @@ public class Bat extends AmbientCreature {
@@ -126,6 +169,14 @@ public class Bat extends AmbientCreature {

@Override
protected void customServerAiStep() {
Expand Down Expand Up @@ -1433,7 +1489,7 @@ index ae21d260b2d4673eb4aa56a82e1043d20507adb2..3950dd170edee24f4a2effc1946e17b3
this.goalSelector.addGoal(2, new SitWhenOrderedToGoal(this));
this.goalSelector.addGoal(2, new FollowOwnerGoal(this, 1.0D, 5.0F, 1.0F, true));
diff --git a/src/main/java/net/minecraft/world/entity/animal/Pig.java b/src/main/java/net/minecraft/world/entity/animal/Pig.java
index 53eaafad559cd6413bb1e10d07374da0ab907ec6..2afacf7a5d15f821e42d98f542dae41c025386d3 100644
index e4d811025a000f6d12ab8587de293e929c8fd970..812d188cea9059f0ce5dd25b2649f30a5dfcea85 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Pig.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Pig.java
@@ -65,9 +65,22 @@ public class Pig extends Animal implements ItemSteerable, Saddleable {
Expand Down Expand Up @@ -5717,7 +5773,7 @@ index 0000000000000000000000000000000000000000..8eefb7b7eb33aecf48ac206d3f0139e0
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 2712aa554383a3b2b742c945e2f0be7ee96eea69..f8811514c155f743f6e93c9a88721903fdb1bddd 100644
index 986f045a2e6a040c6e2aab7420c8cb2d4ac3a726..c1ffaa53ccb1bf2224738a76200d4bcfbe70261f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1264,4 +1264,27 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
Expand Down
12 changes: 6 additions & 6 deletions patches/server/0008-Configurable-entity-base-attributes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Configurable entity base attributes


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 643f0c878352fd205f928aaa083cde59c911f926..1ab4456b67b1b439b3b0e96f85de0fe104a5b2f8 100644
index 01ddf9955cbff75bb02ac0e6d150f7b2ea9bca1a..5e8bf4d98a79f517b3970e7db50a5814a54b3431 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -150,7 +150,7 @@ import org.bukkit.plugin.PluginManager;
Expand Down Expand Up @@ -34,13 +34,13 @@ index f0c30ab5e32e78850d402aa4bc7d42667610dbf0..8c76074289954aae933dd41184f1f0d3

@Override
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 15421740e66f61a818348f57f0d68db69d3577ce..633d8d5cdbd757e56fe5e40937887a027280b08f 100644
index 62303c6aef57f92fc5d8c3e3f19558b1e2f2cd29..846b40dde025f03e3936503b6345547922d6d4d2 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -287,6 +287,7 @@ public abstract class LivingEntity extends Entity {
this.useItem = ItemStack.EMPTY;
this.lastClimbablePos = Optional.empty();
this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type));
this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type), this); // Purpur
+ this.initAttributes(); // Purpur
this.craftAttributes = new CraftAttributeMap(this.attributes); // CraftBukkit
// CraftBukkit - setHealth(getMaxHealth()) inlined and simplified to skip the instanceof check for EntityPlayer, as getBukkitEntity() is not initialized in constructor
Expand All @@ -55,10 +55,10 @@ index 15421740e66f61a818348f57f0d68db69d3577ce..633d8d5cdbd757e56fe5e40937887a02
return this.brain;
}
diff --git a/src/main/java/net/minecraft/world/entity/ambient/Bat.java b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
index 02eb039e4c17d21649610b0d475bbecfc8574809..1894b630673d399b0f5b65d534fb4ac0bd72b751 100644
index 62dfbd1afbfe5f8ecfa4ea1a6ba0918ffad5d1c0..f8ac91c845360e0654f8b855483e412fb004f194 100644
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
@@ -83,6 +83,18 @@ public class Bat extends AmbientCreature {
@@ -86,6 +86,18 @@ public class Bat extends AmbientCreature {
setDeltaMovement(mot.scale(0.9D));
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ index 3950dd170edee24f4a2effc1946e17b3b5f0c792..19caa59e11879b1269196fb0997b899e

@Nullable
diff --git a/src/main/java/net/minecraft/world/entity/animal/Pig.java b/src/main/java/net/minecraft/world/entity/animal/Pig.java
index 2afacf7a5d15f821e42d98f542dae41c025386d3..ebfeeab7b8aceeb7f0de09200c13647eae5bc32f 100644
index 812d188cea9059f0ce5dd25b2649f30a5dfcea85..6842ed6eeeaf2785efd7518d1143c75de3240114 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Pig.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Pig.java
@@ -75,6 +75,11 @@ public class Pig extends Animal implements ItemSteerable, Saddleable {
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0015-LivingEntity-safeFallDistance.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] LivingEntity safeFallDistance


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 633d8d5cdbd757e56fe5e40937887a027280b08f..bdab5361e6fb42a30380ad76a08dd4d1fda92520 100644
index 846b40dde025f03e3936503b6345547922d6d4d2..c81d5711526075503754a840ac783cab6415231b 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -254,6 +254,7 @@ public abstract class LivingEntity extends Entity {
Expand All @@ -16,7 +16,7 @@ index 633d8d5cdbd757e56fe5e40937887a027280b08f..bdab5361e6fb42a30380ad76a08dd4d1
public boolean forceDrops;
public ArrayList<org.bukkit.inventory.ItemStack> drops = new ArrayList<org.bukkit.inventory.ItemStack>();
public final org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes;
@@ -352,8 +353,8 @@ public abstract class LivingEntity extends Entity {
@@ -353,8 +354,8 @@ public abstract class LivingEntity extends Entity {
this.tryAddSoulSpeed();
}

Expand All @@ -27,7 +27,7 @@ index 633d8d5cdbd757e56fe5e40937887a027280b08f..bdab5361e6fb42a30380ad76a08dd4d1

if (!landedState.isAir()) {
double d1 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
@@ -1904,7 +1905,7 @@ public abstract class LivingEntity extends Entity {
@@ -1905,7 +1906,7 @@ public abstract class LivingEntity extends Entity {
MobEffectInstance mobeffect = this.getEffect(MobEffects.JUMP);
float f2 = mobeffect == null ? 0.0F : (float) (mobeffect.getAmplifier() + 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Disable loot drops on death by cramming


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index bdab5361e6fb42a30380ad76a08dd4d1fda92520..7b93c9799ea16f1ae91819e1c7c76fea7d9f0fe2 100644
index c81d5711526075503754a840ac783cab6415231b..6150d1cadfe5f410b1564953a30a0c092da039e0 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1708,8 +1708,10 @@ public abstract class LivingEntity extends Entity {
@@ -1709,8 +1709,10 @@ public abstract class LivingEntity extends Entity {

this.dropEquipment(); // CraftBukkit - from below
if (this.shouldDropLoot() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0052-Fix-the-dead-lagging-the-server.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Fix the dead lagging the server


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 1ab4456b67b1b439b3b0e96f85de0fe104a5b2f8..082f8ede1d1839da7682a9cbb1ce16540f06b8ad 100644
index 5e8bf4d98a79f517b3970e7db50a5814a54b3431..720f8c1c66fd8b85eb5cada47f36d3fed41690ab 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1772,6 +1772,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
Expand All @@ -17,10 +17,10 @@ index 1ab4456b67b1b439b3b0e96f85de0fe104a5b2f8..082f8ede1d1839da7682a9cbb1ce1654

public void absMoveTo(double x, double y, double z) {
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 7b93c9799ea16f1ae91819e1c7c76fea7d9f0fe2..e60c2fe4f81c3660e009e3156e9ad3b5f3581dd0 100644
index 6150d1cadfe5f410b1564953a30a0c092da039e0..68119dbc9a7e7312db8ac6d914678a49a684dc60 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -2909,7 +2909,7 @@ public abstract class LivingEntity extends Entity {
@@ -2910,7 +2910,7 @@ public abstract class LivingEntity extends Entity {
}
}

Expand Down
Loading