From 2ccd460e09179aadf3ad083bf5fcb52e6e42e8dd Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 22 Jul 2021 09:53:26 +1000 Subject: [PATCH] SPIGOT-6663: Chicken Jockeys chickens don't despawn By: md_5 --- .../net/minecraft/world/entity/Entity.patch | 2 +- .../world/entity/EntityInsentient.patch | 52 ++++++++++++------- .../world/entity/animal/EntityAnimal.patch | 2 +- .../world/entity/animal/EntityChicken.patch | 2 +- .../world/entity/animal/EntityFish.patch | 2 +- .../world/entity/animal/axolotl/Axolotl.patch | 2 +- .../entity/monster/EntityZombieVillager.patch | 2 +- .../craftbukkit/entity/CraftLivingEntity.java | 4 +- .../entity/CraftVillagerZombie.java | 2 +- .../craftbukkit/event/CraftEventFactory.java | 2 +- 10 files changed, 43 insertions(+), 29 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch index daed97996d..5eb8a09090 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch @@ -322,7 +322,7 @@ + // Reset the persistence for tamed animals + if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) { + EntityInsentient entityinsentient = (EntityInsentient) entity; -+ entityinsentient.persistenceRequired = !entityinsentient.isTypeNotPersistent(0); ++ entityinsentient.setPersistenceRequired(!entityinsentient.isTypeNotPersistent(0)); + } + } + this.persist = !nbttagcompound.hasKey("Bukkit.persist") || nbttagcompound.getBoolean("Bukkit.persist"); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch index 982d5e95c4..2c20ff4d21 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch @@ -20,6 +20,15 @@ public abstract class EntityInsentient extends EntityLiving { private static final DataWatcherObject DATA_MOB_FLAGS_ID = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.BYTE); +@@ -101,7 +114,7 @@ + private final NonNullList armorItems; + public final float[] armorDropChances; + private boolean canPickUpLoot; +- public boolean persistenceRequired; ++ private boolean persistenceRequired; + private final Map pathfindingMalus; + public MinecraftKey lootTable; + public long lootTableSeed; @@ -113,6 +126,8 @@ private BlockPosition restrictCenter; private float restrictRadius; @@ -29,17 +38,22 @@ protected EntityInsentient(EntityTypes entitytypes, World world) { super(entitytypes, world); this.handItems = NonNullList.a(2, ItemStack.EMPTY); -@@ -136,6 +151,9 @@ +@@ -136,7 +151,14 @@ this.initPathfinder(); } + // CraftBukkit start - default persistance to type's persistance value + this.persistenceRequired = !isTypeNotPersistent(0); -+ // CraftBukkit end ++ } ++ ++ public void setPersistenceRequired(boolean persistenceRequired) { ++ this.persistenceRequired = persistenceRequired; } ++ // CraftBukkit end protected void initPathfinder() {} -@@ -216,7 +234,38 @@ + +@@ -216,7 +238,38 @@ } public void setGoalTarget(@Nullable EntityLiving entityliving) { @@ -78,7 +92,7 @@ } @Override -@@ -443,16 +492,26 @@ +@@ -443,16 +496,26 @@ nbttagcompound.setBoolean("NoAI", this.isNoAI()); } @@ -107,7 +121,7 @@ NBTTagList nbttaglist; int i; -@@ -499,6 +558,11 @@ +@@ -499,6 +562,11 @@ } this.setNoAI(nbttagcompound.getBoolean("NoAI")); @@ -119,7 +133,7 @@ } @Override -@@ -562,7 +626,7 @@ +@@ -562,7 +630,7 @@ protected void b(EntityItem entityitem) { ItemStack itemstack = entityitem.getItemStack(); @@ -128,7 +142,7 @@ this.a(entityitem); this.receive(entityitem, itemstack.getCount()); entityitem.die(); -@@ -571,15 +635,29 @@ +@@ -571,15 +639,29 @@ } public boolean j(ItemStack itemstack) { @@ -159,7 +173,7 @@ } this.b(enumitemslot, itemstack); -@@ -692,18 +770,18 @@ +@@ -692,18 +774,18 @@ EntityHuman entityhuman = this.level.findNearbyPlayer(this, -1.0D); if (entityhuman != null) { @@ -181,7 +195,7 @@ this.die(); } else if (d0 < (double) l) { this.noActionTime = 0; -@@ -718,6 +796,7 @@ +@@ -718,6 +800,7 @@ @Override protected final void doTick() { ++this.noActionTime; @@ -189,7 +203,7 @@ this.level.getMethodProfiler().enter("sensing"); this.sensing.a(); this.level.getMethodProfiler().exit(); -@@ -1101,6 +1180,12 @@ +@@ -1101,6 +1184,12 @@ if (!this.isAlive()) { return EnumInteractionResult.PASS; } else if (this.getLeashHolder() == entityhuman) { @@ -202,7 +216,7 @@ this.unleash(true, !entityhuman.getAbilities().instabuild); return EnumInteractionResult.a(this.level.isClientSide); } else { -@@ -1119,6 +1204,12 @@ +@@ -1119,6 +1208,12 @@ ItemStack itemstack = entityhuman.b(enumhand); if (itemstack.a(Items.LEAD) && this.a(entityhuman)) { @@ -215,7 +229,7 @@ this.setLeashHolder(entityhuman, true); itemstack.subtract(1); return EnumInteractionResult.a(this.level.isClientSide); -@@ -1134,7 +1225,7 @@ +@@ -1134,7 +1229,7 @@ if (itemstack.getItem() instanceof ItemMonsterEgg) { if (this.level instanceof WorldServer) { ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem(); @@ -224,7 +238,7 @@ optional.ifPresent((entityinsentient) -> { this.a(entityhuman, entityinsentient); -@@ -1184,12 +1275,19 @@ +@@ -1184,12 +1279,19 @@ return this.restrictRadius != -1.0F; } @@ -245,7 +259,7 @@ t0.s(this); t0.setBaby(this.isBaby()); -@@ -1221,7 +1319,12 @@ +@@ -1221,7 +1323,12 @@ } } @@ -259,7 +273,7 @@ if (this.isPassenger()) { Entity entity = this.getVehicle(); -@@ -1241,6 +1344,7 @@ +@@ -1241,6 +1348,7 @@ if (this.leashHolder != null) { if (!this.isAlive() || !this.leashHolder.isAlive()) { @@ -267,7 +281,7 @@ this.unleash(true, true); } -@@ -1252,7 +1356,9 @@ +@@ -1252,7 +1360,9 @@ this.leashHolder = null; this.leashInfoTag = null; if (!this.level.isClientSide && flag1) { @@ -277,7 +291,7 @@ } if (!this.level.isClientSide && flag && this.level instanceof WorldServer) { -@@ -1302,6 +1408,7 @@ +@@ -1302,6 +1412,7 @@ boolean flag1 = super.a(entity, flag); if (flag1 && this.isLeashed()) { @@ -285,7 +299,7 @@ this.unleash(true, true); } -@@ -1397,7 +1504,14 @@ +@@ -1397,7 +1508,14 @@ int i = EnchantmentManager.getFireAspectEnchantmentLevel(this); if (i > 0) { @@ -301,7 +315,7 @@ } boolean flag = entity.damageEntity(DamageSource.mobAttack(this), f); -@@ -1465,9 +1579,10 @@ +@@ -1465,9 +1583,10 @@ @Override protected void cc() { super.cc(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch index d875689912..3336d8b12b 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch @@ -62,7 +62,7 @@ if (entityageable != null) { + // CraftBukkit start - set persistence for tame animals + if (entityageable instanceof EntityTameableAnimal && ((EntityTameableAnimal) entityageable).isTamed()) { -+ entityageable.persistenceRequired = true; ++ entityageable.setPersistenceRequired(true); + } + // CraftBukkit end EntityPlayer entityplayer = this.getBreedCause(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch index 330b0d9693..8d8d84606a 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch @@ -6,7 +6,7 @@ public void movementTick() { + // CraftBukkit start + if (this.isChickenJockey()) { -+ this.persistenceRequired = !this.isTypeNotPersistent(0); ++ this.setPersistenceRequired(!this.isTypeNotPersistent(0)); + } + // CraftBukkit end super.movementTick(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFish.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFish.patch index 7a7fc9d3ea..d2555c4831 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFish.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFish.patch @@ -13,7 +13,7 @@ @Override public void setFromBucket(boolean flag) { this.entityData.set(EntityFish.FROM_BUCKET, flag); -+ this.persistenceRequired = this.isPersistent(); // CraftBukkit - SPIGOT-4106 update persistence ++ this.setPersistenceRequired(this.isPersistent()); // CraftBukkit - SPIGOT-4106 update persistence } @Override diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch index dfafa20885..bc24c4c133 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch @@ -14,7 +14,7 @@ @Override public void setFromBucket(boolean flag) { this.entityData.set(Axolotl.FROM_BUCKET, flag); -+ this.persistenceRequired = this.isPersistent(); // CraftBukkit - SPIGOT-4106 update persistence ++ this.setPersistenceRequired(this.isPersistent()); // CraftBukkit - SPIGOT-4106 update persistence } @Nullable diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch index 388773aa53..ef79f7d969 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch @@ -57,7 +57,7 @@ - this.removeEffect(MobEffects.WEAKNESS); - this.addEffect(new MobEffect(MobEffects.DAMAGE_BOOST, i, Math.min(this.level.getDifficulty().a() - 1, 0))); + // CraftBukkit start -+ this.persistenceRequired = true; // CraftBukkit - SPIGOT-4684 update persistence ++ this.setPersistenceRequired(true); // CraftBukkit - SPIGOT-4684 update persistence + this.removeEffect(MobEffects.WEAKNESS, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION); + this.addEffect(new MobEffect(MobEffects.DAMAGE_BOOST, i, Math.min(this.level.getDifficulty().a() - 1, 0)), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION); + // CraftBukkit end diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index fdf6fbd896..987173e860 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -491,13 +491,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public boolean getRemoveWhenFarAway() { - return getHandle() instanceof EntityInsentient && !((EntityInsentient) getHandle()).persistenceRequired; + return getHandle() instanceof EntityInsentient && !((EntityInsentient) getHandle()).isPersistent(); } @Override public void setRemoveWhenFarAway(boolean remove) { if (getHandle() instanceof EntityInsentient) { - ((EntityInsentient) getHandle()).persistenceRequired = !remove; + ((EntityInsentient) getHandle()).setPersistenceRequired(!remove); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java index ce4d95b72d..fe7cc3b9dc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillagerZombie.java @@ -76,7 +76,7 @@ public class CraftVillagerZombie extends CraftZombie implements ZombieVillager { if (time < 0) { getHandle().villagerConversionTime = -1; getHandle().getDataWatcher().set(EntityZombieVillager.DATA_CONVERTING_ID, false); - getHandle().persistenceRequired = false; // CraftBukkit - SPIGOT-4684 update persistence + getHandle().setPersistenceRequired(false); // CraftBukkit - SPIGOT-4684 update persistence getHandle().conversionStarter = null; getHandle().removeEffect(MobEffects.DAMAGE_BOOST, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.CONVERSION); } else { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 1be8babf3c..e7b4689367 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -661,7 +661,7 @@ public class CraftEventFactory { org.bukkit.entity.AnimalTamer bukkitTamer = (tamer != null ? tamer.getBukkitEntity() : null); CraftServer craftServer = (CraftServer) bukkitEntity.getServer(); - entity.persistenceRequired = true; + entity.setPersistenceRequired(true); EntityTameEvent event = new EntityTameEvent((LivingEntity) bukkitEntity, bukkitTamer); craftServer.getPluginManager().callEvent(event);