Paper/Spigot-Server-Patches/0284-Allow-disabling-armour-stand-ticking.patch

284 lines
12 KiB
Diff
Raw Normal View History

From 2a3338308eecbeca3e916817a22e9abb19452f88 Mon Sep 17 00:00:00 2001
2018-08-15 10:26:51 +02:00
From: kashike <kashike@vq.lc>
Date: Wed, 15 Aug 2018 01:26:09 -0700
Subject: [PATCH] Allow disabling armour stand ticking
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 721685704..9ee27f638 100644
2018-08-15 10:26:51 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -391,4 +391,10 @@ public class PaperWorldConfig {
2019-05-05 04:23:25 +02:00
log("Bed Search Radius: " + bedSearchRadius);
}
2018-08-15 10:26:51 +02:00
}
+
+ public boolean armorStandTick = true;
+ private void armorStandTick() {
+ this.armorStandTick = this.getBoolean("armor-stands-tick", this.armorStandTick);
+ log("ArmorStand ticking is " + (this.armorStandTick ? "enabled" : "disabled") + " by default");
+ }
}
diff --git a/src/main/java/net/minecraft/server/EntityArmorStand.java b/src/main/java/net/minecraft/server/EntityArmorStand.java
index d8497fa5e..85fc48371 100644
2018-08-15 10:26:51 +02:00
--- a/src/main/java/net/minecraft/server/EntityArmorStand.java
+++ b/src/main/java/net/minecraft/server/EntityArmorStand.java
@@ -44,6 +44,12 @@ public class EntityArmorStand extends EntityLiving {
2018-08-15 10:26:51 +02:00
public Vector3f leftLegPose;
public Vector3f rightLegPose;
public boolean canMove = true; // Paper
+ // Paper start - Allow ArmorStands not to tick
+ public boolean canTick = true;
+ public boolean canTickSetByAPI = false;
+ private boolean noTickPoseDirty = false;
+ private boolean noTickEquipmentDirty = false;
+ // Paper end
2018-08-15 10:26:51 +02:00
2019-05-05 04:23:25 +02:00
public EntityArmorStand(EntityTypes<? extends EntityArmorStand> entitytypes, World world) {
super(entitytypes, world);
@@ -55,6 +61,7 @@ public class EntityArmorStand extends EntityLiving {
2019-05-05 04:23:25 +02:00
this.rightArmPose = EntityArmorStand.bx;
this.leftLegPose = EntityArmorStand.by;
this.rightLegPose = EntityArmorStand.bz;
2018-08-15 10:26:51 +02:00
+ if (world != null) this.canTick = world.paperConfig.armorStandTick; // Paper - armour stand ticking
2019-05-05 04:23:25 +02:00
this.K = 0.0F;
2018-08-15 10:26:51 +02:00
}
2019-05-05 04:23:25 +02:00
@@ -135,6 +142,7 @@ public class EntityArmorStand extends EntityLiving {
2019-05-28 01:01:45 +02:00
this.armorItems.set(enumitemslot.b(), itemstack);
}
+ this.noTickEquipmentDirty = true; // Paper - Allow equipment to be updated even when tick disabled
}
2019-05-05 04:23:25 +02:00
@Override
@@ -215,6 +223,7 @@ public class EntityArmorStand extends EntityLiving {
}
2019-05-05 04:23:25 +02:00
nbttagcompound.set("Pose", this.B());
+ if (this.canTickSetByAPI) nbttagcompound.setBoolean("Paper.CanTickOverride", this.canTick); // Paper - persist no tick setting
}
2019-05-05 04:23:25 +02:00
@Override
@@ -246,6 +255,12 @@ public class EntityArmorStand extends EntityLiving {
2019-05-05 04:23:25 +02:00
this.setBasePlate(nbttagcompound.getBoolean("NoBasePlate"));
this.setMarker(nbttagcompound.getBoolean("Marker"));
2019-05-05 04:23:25 +02:00
this.noclip = !this.A();
+ // Paper start - persist no tick
+ if (nbttagcompound.hasKey("Paper.CanTickOverride")) {
+ this.canTick = nbttagcompound.getBoolean("Paper.CanTickOverride");
+ this.canTickSetByAPI = true;
+ }
+ // Paper end
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("Pose");
this.g(nbttagcompound1);
@@ -589,7 +604,29 @@ public class EntityArmorStand extends EntityLiving {
2018-08-15 10:26:51 +02:00
2019-05-05 04:23:25 +02:00
@Override
public void tick() {
+ // Paper start
+ if (!this.canTick) {
+ if (this.noTickPoseDirty) {
+ this.noTickPoseDirty = false;
+ this.updatePose();
+ }
+
+ if (this.noTickEquipmentDirty) {
+ this.noTickEquipmentDirty = false;
+ this.updateEntityEquipment();
+ }
+
+ return;
+ }
+ // Paper end
+
super.tick();
+ // Paper start - Split into separate method
+ updatePose();
+ }
+
+ public void updatePose() {
+ // Paper end
2019-05-05 04:23:25 +02:00
Vector3f vector3f = (Vector3f) this.datawatcher.get(EntityArmorStand.c);
2018-08-15 10:26:51 +02:00
if (!this.headPose.equals(vector3f)) {
@@ -712,31 +749,37 @@ public class EntityArmorStand extends EntityLiving {
public void setHeadPose(Vector3f vector3f) {
this.headPose = vector3f;
2019-05-05 04:23:25 +02:00
this.datawatcher.set(EntityArmorStand.c, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setBodyPose(Vector3f vector3f) {
this.bodyPose = vector3f;
2019-05-05 04:23:25 +02:00
this.datawatcher.set(EntityArmorStand.d, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setLeftArmPose(Vector3f vector3f) {
this.leftArmPose = vector3f;
2019-05-05 04:23:25 +02:00
this.datawatcher.set(EntityArmorStand.e, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setRightArmPose(Vector3f vector3f) {
this.rightArmPose = vector3f;
2019-05-05 04:23:25 +02:00
this.datawatcher.set(EntityArmorStand.f, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setLeftLegPose(Vector3f vector3f) {
this.leftLegPose = vector3f;
2019-05-05 04:23:25 +02:00
this.datawatcher.set(EntityArmorStand.g, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setRightLegPose(Vector3f vector3f) {
this.rightLegPose = vector3f;
2019-05-05 04:23:25 +02:00
this.datawatcher.set(EntityArmorStand.bs, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public Vector3f r() {
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index e1972f793..dbf42f882 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#2415) * fixup patch and rebuild * Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: bde198c9 SPIGOT-5246: PlayerQuitEvent.get/setQuitMessage() is incorrectly marked as NotNull 24ad5a79 SPIGOT-5240: Vector.angle not valid for angles very close to each other a143db9a SPIGOT-5231: ShotAtAngle API for Fireworks 10db5c3d SPIGOT-5226: Update Javadoc of PlayerDeathEvent CraftBukkit Changes: 1ec1b05e SPIGOT-5245: Unneeded cast to WorldNBTStorage in CraftWorld#getWorldFolder e5e8eec2 SPIGOT-5241: setAttributeModifiers does not work on untouched stack 803eaa31 SPIGOT-5231: ShotAtAngle API for Fireworks 7881d2ae SPIGOT-5237: Horses, pigs do not drop their inventory 06efc9ec Don't accept connections until all plugins have enabled da62a66a SPIGOT-5225: World handle isn't closed if world is unloaded without saving 104b3831 SPIGOT-5222: Cannot get Long values from Entity memory f0b3fe43 SPIGOT-5220: Server CPU usage reaches 100% when stdin is null Spigot Changes: e5b1b5db SPIGOT-5235: Destroy expired area effect clouds / fireworks that are inactive cbcc8e87 Make region files more reliable to write to 8887c5f4 Remove redundant late-bind option dac29063 Rebuild patches * Preserve old flush on save flag for reliable regionfiles Originally this patch was in paper * Fix some issues with the death event - Entities potentially entering a glitched state to the client where they appear to be falling over - Donkeys losing their chest if the event was cancelled (only an issue since the upstream merge) - Some wither death logic running for an entity killed by a wither
2019-08-05 18:35:40 +02:00
@@ -2266,52 +2266,7 @@ public abstract class EntityLiving extends Entity {
}
}
- EnumItemSlot[] aenumitemslot = EnumItemSlot.values();
- int j = aenumitemslot.length;
-
- for (int k = 0; k < j; ++k) {
- EnumItemSlot enumitemslot = aenumitemslot[k];
- ItemStack itemstack;
-
- switch (enumitemslot.a()) {
2019-05-28 01:01:45 +02:00
- case HAND:
- itemstack = (ItemStack) this.bw.get(enumitemslot.b());
- break;
- case ARMOR:
- itemstack = (ItemStack) this.bx.get(enumitemslot.b());
- break;
- default:
- continue;
- }
-
- ItemStack itemstack1 = this.getEquipment(enumitemslot);
-
- if (!ItemStack.matches(itemstack1, itemstack)) {
- // Paper start - PlayerArmorChangeEvent
- if (this instanceof EntityPlayer && enumitemslot.getType() == EnumItemSlot.Function.ARMOR) {
- final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(itemstack);
- final org.bukkit.inventory.ItemStack newItem = CraftItemStack.asBukkitCopy(itemstack1);
- new PlayerArmorChangeEvent((Player) this.getBukkitEntity(), PlayerArmorChangeEvent.SlotType.valueOf(enumitemslot.name()), oldItem, newItem).callEvent();
- }
- // Paper end
2019-05-05 04:23:25 +02:00
- ((WorldServer) this.world).getChunkProvider().broadcast(this, new PacketPlayOutEntityEquipment(this.getId(), enumitemslot, itemstack1));
- if (!itemstack.isEmpty()) {
- this.getAttributeMap().a(itemstack.a(enumitemslot));
- }
-
- if (!itemstack1.isEmpty()) {
- this.getAttributeMap().b(itemstack1.a(enumitemslot));
- }
-
- switch (enumitemslot.a()) {
2019-05-28 01:01:45 +02:00
- case HAND:
- this.bw.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
- break;
- case ARMOR:
- this.bx.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
- }
- }
- }
+ updateEntityEquipment(); // Paper - split into own method
if (this.ticksLived % 20 == 0) {
this.getCombatTracker().g();
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#2415) * fixup patch and rebuild * Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: bde198c9 SPIGOT-5246: PlayerQuitEvent.get/setQuitMessage() is incorrectly marked as NotNull 24ad5a79 SPIGOT-5240: Vector.angle not valid for angles very close to each other a143db9a SPIGOT-5231: ShotAtAngle API for Fireworks 10db5c3d SPIGOT-5226: Update Javadoc of PlayerDeathEvent CraftBukkit Changes: 1ec1b05e SPIGOT-5245: Unneeded cast to WorldNBTStorage in CraftWorld#getWorldFolder e5e8eec2 SPIGOT-5241: setAttributeModifiers does not work on untouched stack 803eaa31 SPIGOT-5231: ShotAtAngle API for Fireworks 7881d2ae SPIGOT-5237: Horses, pigs do not drop their inventory 06efc9ec Don't accept connections until all plugins have enabled da62a66a SPIGOT-5225: World handle isn't closed if world is unloaded without saving 104b3831 SPIGOT-5222: Cannot get Long values from Entity memory f0b3fe43 SPIGOT-5220: Server CPU usage reaches 100% when stdin is null Spigot Changes: e5b1b5db SPIGOT-5235: Destroy expired area effect clouds / fireworks that are inactive cbcc8e87 Make region files more reliable to write to 8887c5f4 Remove redundant late-bind option dac29063 Rebuild patches * Preserve old flush on save flag for reliable regionfiles Originally this patch was in paper * Fix some issues with the death event - Entities potentially entering a glitched state to the client where they appear to be falling over - Donkeys losing their chest if the event was cancelled (only an issue since the upstream merge) - Some wither death logic running for an entity killed by a wither
2019-08-05 18:35:40 +02:00
@@ -2412,6 +2367,57 @@ public abstract class EntityLiving extends Entity {
}
}
+ // Paper start - split into own method from above
+ public void updateEntityEquipment() {
+ EnumItemSlot[] aenumitemslot = EnumItemSlot.values();
+ int j = aenumitemslot.length;
+
+ for (int k = 0; k < j; ++k) {
+ EnumItemSlot enumitemslot = aenumitemslot[k];
+ ItemStack itemstack;
+
+ switch (enumitemslot.a()) {
+ case HAND:
2019-05-05 04:23:25 +02:00
+ itemstack = (ItemStack) this.bw.get(enumitemslot.b());
+ break;
+ case ARMOR:
2019-05-05 04:23:25 +02:00
+ itemstack = (ItemStack) this.bx.get(enumitemslot.b());
+ break;
+ default:
+ continue;
+ }
+
+ ItemStack itemstack1 = this.getEquipment(enumitemslot);
+
+ if (!ItemStack.matches(itemstack1, itemstack)) {
+ // Paper start - PlayerArmorChangeEvent
+ if (this instanceof EntityPlayer && enumitemslot.getType() == EnumItemSlot.Function.ARMOR) {
+ final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(itemstack);
+ final org.bukkit.inventory.ItemStack newItem = CraftItemStack.asBukkitCopy(itemstack1);
+ new PlayerArmorChangeEvent((Player) this.getBukkitEntity(), PlayerArmorChangeEvent.SlotType.valueOf(enumitemslot.name()), oldItem, newItem).callEvent();
+ }
+ // Paper end
2019-05-05 04:23:25 +02:00
+ ((WorldServer) this.world).getChunkProvider().broadcast(this, new PacketPlayOutEntityEquipment(this.getId(), enumitemslot, itemstack1));
+ if (!itemstack.isEmpty()) {
+ this.getAttributeMap().a(itemstack.a(enumitemslot));
+ }
+
+ if (!itemstack1.isEmpty()) {
+ this.getAttributeMap().b(itemstack1.a(enumitemslot));
+ }
+
+ switch (enumitemslot.a()) {
+ case HAND:
2019-05-05 04:23:25 +02:00
+ this.bw.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
+ break;
+ case ARMOR:
2019-05-05 04:23:25 +02:00
+ this.bx.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
+ }
+ }
+ }
+ }
+ // Paper end
+
protected float e(float f, float f1) {
2019-05-05 04:23:25 +02:00
float f2 = MathHelper.g(f - this.aK);
2018-08-15 10:26:51 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
index 9f5c3b92e..73714d71a 100644
2018-08-15 10:26:51 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
@@ -297,5 +297,16 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
public boolean isSlotDisabled(org.bukkit.inventory.EquipmentSlot slot) {
return getHandle().isSlotDisabled(org.bukkit.craftbukkit.CraftEquipmentSlot.getNMS(slot));
2018-08-15 10:26:51 +02:00
}
+
+ @Override
+ public boolean canTick() {
+ return this.getHandle().canTick;
+ }
+
+ @Override
+ public void setCanTick(final boolean tick) {
+ this.getHandle().canTick = tick;
+ this.getHandle().canTickSetByAPI = true;
2018-08-15 10:26:51 +02:00
+ }
// Paper end
2018-08-15 10:26:51 +02:00
}
--
2.23.0
2018-08-15 10:26:51 +02:00