Update armorstand pose and equipment w/ no tick option

This change allows ArmorStands with ticking disabled to visually update
their equipment and pose properly.

Given the wide range of usage of ArmorStands, I have not changed
their tick loop when their tick is enabled as usual. Doing so may
likely gains in the future, though additional testing would be
needed to ensure nothing breaks.

Fixes GH-1593
This commit is contained in:
Zach Brown 2018-11-07 20:48:22 -05:00
parent 335ab110bc
commit db6d9b0522
No known key found for this signature in database
GPG key ID: CC9DA35FC5450B76
4 changed files with 217 additions and 26 deletions

View file

@ -1,11 +1,11 @@
From acfd71d693f42e32e09b2035fc1d78bdff690938 Mon Sep 17 00:00:00 2001
From 760436fa248f9b01dc2e29c950cab68d49ceffb7 Mon Sep 17 00:00:00 2001
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 a2656abaf0..95fc2d8ed8 100644
index a2656abaf..95fc2d8ed 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -493,4 +493,10 @@ public class PaperWorldConfig {
@ -20,18 +20,22 @@ index a2656abaf0..95fc2d8ed8 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/EntityArmorStand.java b/src/main/java/net/minecraft/server/EntityArmorStand.java
index 7647311dfd..35afffedef 100644
index 7647311df..d8939420c 100644
--- a/src/main/java/net/minecraft/server/EntityArmorStand.java
+++ b/src/main/java/net/minecraft/server/EntityArmorStand.java
@@ -45,6 +45,7 @@ public class EntityArmorStand extends EntityLiving {
@@ -45,6 +45,11 @@ public class EntityArmorStand extends EntityLiving {
public Vector3f leftLegPose;
public Vector3f rightLegPose;
public boolean canMove = true; // Paper
+ public boolean canTick = true; // Paper - armour stand ticking
+ // Paper start - Allow ArmorStands not to tick
+ public boolean canTick = true;
+ private boolean noTickPoseDirty = false;
+ private boolean noTickEquipmentDirty = false;
+ // Paper end
public EntityArmorStand(World world) {
super(EntityTypes.ARMOR_STAND, world);
@@ -57,6 +58,7 @@ public class EntityArmorStand extends EntityLiving {
@@ -57,6 +62,7 @@ public class EntityArmorStand extends EntityLiving {
this.leftLegPose = EntityArmorStand.bB;
this.rightLegPose = EntityArmorStand.bC;
this.noclip = this.isNoGravity();
@ -39,16 +43,203 @@ index 7647311dfd..35afffedef 100644
this.setSize(0.5F, 1.975F);
this.Q = 0.0F;
}
@@ -556,6 +558,7 @@ public class EntityArmorStand extends EntityLiving {
@@ -131,6 +137,7 @@ public class EntityArmorStand extends EntityLiving {
this.bF.set(enumitemslot.b(), itemstack);
}
+ this.noTickEquipmentDirty = true; // Paper - Allow equipment to be updated even when tick disabled
}
public boolean c(int i, ItemStack itemstack) {
@@ -556,7 +563,30 @@ public class EntityArmorStand extends EntityLiving {
}
public void tick() {
+ if (!this.canTick) return;// Paper
+ // Paper start
+ if (!this.canTick) {
+ if (this.noTickPoseDirty) {
+ this.noTickEquipmentDirty = 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
Vector3f vector3f = (Vector3f) this.datawatcher.get(EntityArmorStand.b);
if (!this.headPose.equals(vector3f)) {
@@ -685,31 +715,37 @@ public class EntityArmorStand extends EntityLiving {
public void setHeadPose(Vector3f vector3f) {
this.headPose = vector3f;
this.datawatcher.set(EntityArmorStand.b, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setBodyPose(Vector3f vector3f) {
this.bodyPose = vector3f;
this.datawatcher.set(EntityArmorStand.c, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setLeftArmPose(Vector3f vector3f) {
this.leftArmPose = vector3f;
this.datawatcher.set(EntityArmorStand.d, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setRightArmPose(Vector3f vector3f) {
this.rightArmPose = vector3f;
this.datawatcher.set(EntityArmorStand.e, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setLeftLegPose(Vector3f vector3f) {
this.leftLegPose = vector3f;
this.datawatcher.set(EntityArmorStand.f, vector3f);
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
public void setRightLegPose(Vector3f vector3f) {
this.rightLegPose = vector3f;
this.datawatcher.set(EntityArmorStand.g, 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 a8103ff68..21d32178c 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2082,55 +2082,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()) {
- case HAND:
- itemstack = (ItemStack) this.bB.get(enumitemslot.b());
- break;
-
- case ARMOR:
- itemstack = (ItemStack) this.bC.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 && !itemstack.getItem().equals(itemstack1.getItem())) {
- 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
- ((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (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:
- this.bB.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
- break;
-
- case ARMOR:
- this.bC.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
- }
- }
- }
+ updateEntityEquipment(); // Paper - split into own method
if (this.ticksLived % 20 == 0) {
this.getCombatTracker().g();
@@ -2223,6 +2175,56 @@ public abstract class EntityLiving extends Entity {
}
}
+ // Paper start - split into own method from above
+ public void updateEntityEquipment() {
+ for (EnumItemSlot enumitemslot : EnumItemSlot.values()) {
+ ItemStack itemstack;
+
+ switch (enumitemslot.a()) {
+ case HAND:
+ itemstack = (ItemStack) this.bB.get(enumitemslot.b());
+ break;
+
+ case ARMOR:
+ itemstack = (ItemStack) this.bC.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 && !itemstack.getItem().equals(itemstack1.getItem())) {
+ 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
+ ((WorldServer) this.world).getTracker().a((Entity) this, (Packet) (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:
+ this.bB.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
+ break;
+
+ case ARMOR:
+ this.bC.set(enumitemslot.b(), itemstack1.isEmpty() ? ItemStack.a : itemstack1.cloneItemStack());
+ }
+ }
+ }
+ }
+ // Paper end
+
protected float e(float f, float f1) {
float f2 = MathHelper.g(f - this.aQ);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
index 9f5c3b92e3..07ce93f17c 100644
index 9f5c3b92e..07ce93f17 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
@@ -297,5 +297,15 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
@ -68,5 +259,5 @@ index 9f5c3b92e3..07ce93f17c 100644
// Paper end
}
--
2.19.0
2.19.1

View file

@ -1,14 +1,14 @@
From 0cc71e0200f90df7b6c4177dc44298298eb63b76 Mon Sep 17 00:00:00 2001
From 46984ce90bf3c3a444595575bfc6ca250977c1cc Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Mon, 3 Sep 2018 18:20:03 -0500
Subject: [PATCH] Add ray tracing methods to LivingEntity
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index a8103ff68..3a70fa381 100644
index 21d32178c..2aedfa808 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -2813,6 +2813,22 @@ public abstract class EntityLiving extends Entity {
@@ -2815,6 +2815,22 @@ public abstract class EntityLiving extends Entity {
}
// Paper start

View file

@ -1,4 +1,4 @@
From e3311a5221d039ca87f85192018cc4949b9e1f33 Mon Sep 17 00:00:00 2001
From 5e82f4f46a56b6fe2e0d835e64fc2161eb6881ae Mon Sep 17 00:00:00 2001
From: Phoenix616 <mail@moep.tv>
Date: Tue, 21 Aug 2018 01:39:35 +0100
Subject: [PATCH] Improve death events
@ -15,7 +15,7 @@ items and experience which is otherwise only properly possible by using
internal code.
diff --git a/src/main/java/net/minecraft/server/CombatTracker.java b/src/main/java/net/minecraft/server/CombatTracker.java
index 9a74601b05..6e60d15ccb 100644
index 9a74601b0..6e60d15cc 100644
--- a/src/main/java/net/minecraft/server/CombatTracker.java
+++ b/src/main/java/net/minecraft/server/CombatTracker.java
@@ -163,6 +163,7 @@ public class CombatTracker {
@ -27,7 +27,7 @@ index 9a74601b05..6e60d15ccb 100644
int i = this.f ? 300 : 100;
if (this.g && (!this.b.isAlive() || this.b.ticksLived - this.c > i)) {
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 665c85ca47..8abd71dfc7 100644
index 665c85ca4..8abd71dfc 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1539,6 +1539,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@ -55,10 +55,10 @@ index 665c85ca47..8abd71dfc7 100644
return SoundCategory.NEUTRAL;
}
diff --git a/src/main/java/net/minecraft/server/EntityArmorStand.java b/src/main/java/net/minecraft/server/EntityArmorStand.java
index 35afffedef..e8e7413748 100644
index d8939420c..3a77a112f 100644
--- a/src/main/java/net/minecraft/server/EntityArmorStand.java
+++ b/src/main/java/net/minecraft/server/EntityArmorStand.java
@@ -629,7 +629,8 @@ public class EntityArmorStand extends EntityLiving {
@@ -656,7 +656,8 @@ public class EntityArmorStand extends EntityLiving {
}
public void killEntity() {
@ -69,7 +69,7 @@ index 35afffedef..e8e7413748 100644
}
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 3a70fa381f..c27807ea2a 100644
index 2aedfa808..83d648fff 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -76,14 +76,14 @@ public abstract class EntityLiving extends Entity {
@ -207,7 +207,7 @@ index 3a70fa381f..c27807ea2a 100644
return this.isBaby() ? (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.5F : (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F;
}
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 9dcf29609a..720eb9184f 100644
index 9dcf29609..720eb9184 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -75,6 +75,10 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@ -258,7 +258,7 @@ index 9dcf29609a..720eb9184f 100644
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftSound.java b/src/main/java/org/bukkit/craftbukkit/CraftSound.java
index 17fab031b4..ee8219e3ba 100644
index 17fab031b..ee8219e3b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftSound.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftSound.java
@@ -674,6 +674,22 @@ public enum CraftSound {
@ -285,7 +285,7 @@ index 17fab031b4..ee8219e3ba 100644
this.minecraftKey = minecraftKey;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 8be0a47bae..f56ef6f710 100644
index 8be0a47ba..f56ef6f71 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1711,7 +1711,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@ -306,7 +306,7 @@ index 8be0a47bae..f56ef6f710 100644
public void injectScaledMaxHealth(Collection<AttributeInstance> collection, boolean force) {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 396a37f69b..11ff21fcf0 100644
index 396a37f69..11ff21fcf 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -485,9 +485,16 @@ public class CraftEventFactory {

View file

@ -1,4 +1,4 @@
From 4e76f0d704ff2f74911023600819ad3a3fac2a7f Mon Sep 17 00:00:00 2001
From e43e19ddbebb2d46b4c2a09a850c958beba89093 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Sat, 22 Sep 2018 00:33:08 -0500
Subject: [PATCH] Add LivingEntity#getTargetEntity
@ -71,7 +71,7 @@ index dd96b09e6..d60dab95f 100644
return this.d(this.pitch, this.yaw);
}
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index c27807ea2..923bc0cc7 100644
index 83d648fff..a845856af 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -3,6 +3,8 @@ package net.minecraft.server;
@ -92,7 +92,7 @@ index c27807ea2..923bc0cc7 100644
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.bukkit.Location;
@@ -2859,6 +2863,36 @@ public abstract class EntityLiving extends Entity {
@@ -2861,6 +2865,36 @@ public abstract class EntityLiving extends Entity {
return world.rayTrace(start, end, fluidCollisionOption);
}