Paper/patches/server/0218-Allow-disabling-armor-stand-ticking.patch

146 lines
5.9 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 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 armor stand ticking
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
2024-06-13 21:04:27 +02:00
index 1057679ceec86898a3e62bd183c6944f561aa7fd..ee3902cbada46ffb78c42dbf6f00c859546c76e1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
+++ b/src/main/java/net/minecraft/world/entity/decoration/ArmorStand.java
2024-06-13 21:04:27 +02:00
@@ -96,9 +96,16 @@ public class ArmorStand extends LivingEntity {
2021-06-11 14:02:28 +02:00
public Rotations leftLegPose;
public Rotations 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 - Allow ArmorStands not to tick
2021-06-11 14:02:28 +02:00
public ArmorStand(EntityType<? extends ArmorStand> type, Level world) {
super(type, world);
+ if (world != null) this.canTick = world.paperConfig().entities.armorStands.tick; // Paper - Allow ArmorStands not to tick
2021-06-13 01:45:00 +02:00
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
this.armorItems = NonNullList.withSize(4, ItemStack.EMPTY);
2021-06-11 14:02:28 +02:00
this.headPose = ArmorStand.DEFAULT_HEAD_POSE;
2024-06-13 21:04:27 +02:00
@@ -201,6 +208,7 @@ public class ArmorStand extends LivingEntity {
2022-06-07 23:45:11 +02:00
this.onEquipItem(enumitemslot, (ItemStack) this.armorItems.set(enumitemslot.getIndex(), itemstack), itemstack, silent); // CraftBukkit
2021-06-11 14:02:28 +02:00
}
+ this.noTickEquipmentDirty = true; // Paper - Allow ArmorStands not to tick; Still update equipment
2021-06-11 14:02:28 +02:00
}
@Override
2024-06-13 21:04:27 +02:00
@@ -243,6 +251,7 @@ public class ArmorStand extends LivingEntity {
2021-06-11 14:02:28 +02:00
}
2021-06-13 01:45:00 +02:00
nbt.put("Pose", this.writePose());
+ if (this.canTickSetByAPI) nbt.putBoolean("Paper.CanTickOverride", this.canTick); // Paper - Allow ArmorStands not to tick
2021-06-11 14:02:28 +02:00
}
@Override
2024-06-13 21:04:27 +02:00
@@ -277,6 +286,12 @@ public class ArmorStand extends LivingEntity {
2021-06-13 01:45:00 +02:00
this.setNoBasePlate(nbt.getBoolean("NoBasePlate"));
this.setMarker(nbt.getBoolean("Marker"));
2021-06-11 14:02:28 +02:00
this.noPhysics = !this.hasPhysics();
+ // Paper start - Allow ArmorStands not to tick
2021-06-13 01:45:00 +02:00
+ if (nbt.contains("Paper.CanTickOverride")) {
+ this.canTick = nbt.getBoolean("Paper.CanTickOverride");
2021-06-11 14:02:28 +02:00
+ this.canTickSetByAPI = true;
+ }
+ // Paper end - Allow ArmorStands not to tick
2024-04-24 04:46:06 +02:00
CompoundTag nbttagcompound2 = nbt.getCompound("Pose");
2021-06-11 14:02:28 +02:00
2024-04-24 04:46:06 +02:00
this.readPose(nbttagcompound2);
2024-06-13 21:04:27 +02:00
@@ -664,7 +679,29 @@ public class ArmorStand extends LivingEntity {
2021-06-11 14:02:28 +02:00
@Override
public void tick() {
+ // Paper start - Allow ArmorStands not to tick
2021-06-11 14:02:28 +02:00
+ if (!this.canTick) {
+ if (this.noTickPoseDirty) {
+ this.noTickPoseDirty = false;
+ this.updatePose();
+ }
+
+ if (this.noTickEquipmentDirty) {
+ this.noTickEquipmentDirty = false;
+ this.detectEquipmentUpdatesPublic();
2021-06-11 14:02:28 +02:00
+ }
+
+ return;
+ }
+ // Paper end - Allow ArmorStands not to tick
2021-06-11 14:02:28 +02:00
+
super.tick();
+ // Paper start - Allow ArmorStands not to tick
2021-06-11 14:02:28 +02:00
+ updatePose();
+ }
+
+ public void updatePose() {
+ // Paper end - Allow ArmorStands not to tick
2021-06-11 14:02:28 +02:00
Rotations vector3f = (Rotations) this.entityData.get(ArmorStand.DATA_HEAD_POSE);
if (!this.headPose.equals(vector3f)) {
2024-06-13 21:04:27 +02:00
@@ -799,31 +836,37 @@ public class ArmorStand extends LivingEntity {
2021-06-13 01:45:00 +02:00
public void setHeadPose(Rotations angle) {
this.headPose = angle;
this.entityData.set(ArmorStand.DATA_HEAD_POSE, angle);
2021-06-11 14:02:28 +02:00
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
2021-06-13 01:45:00 +02:00
public void setBodyPose(Rotations angle) {
this.bodyPose = angle;
this.entityData.set(ArmorStand.DATA_BODY_POSE, angle);
2021-06-11 14:02:28 +02:00
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
2021-06-13 01:45:00 +02:00
public void setLeftArmPose(Rotations angle) {
this.leftArmPose = angle;
this.entityData.set(ArmorStand.DATA_LEFT_ARM_POSE, angle);
2021-06-11 14:02:28 +02:00
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
2021-06-13 01:45:00 +02:00
public void setRightArmPose(Rotations angle) {
this.rightArmPose = angle;
this.entityData.set(ArmorStand.DATA_RIGHT_ARM_POSE, angle);
2021-06-11 14:02:28 +02:00
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
2021-06-13 01:45:00 +02:00
public void setLeftLegPose(Rotations angle) {
this.leftLegPose = angle;
this.entityData.set(ArmorStand.DATA_LEFT_LEG_POSE, angle);
2021-06-11 14:02:28 +02:00
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
2021-06-13 01:45:00 +02:00
public void setRightLegPose(Rotations angle) {
this.rightLegPose = angle;
this.entityData.set(ArmorStand.DATA_RIGHT_LEG_POSE, angle);
2021-06-11 14:02:28 +02:00
+ this.noTickPoseDirty = true; // Paper - Allow updates when not ticking
}
2021-06-13 01:45:00 +02:00
public Rotations getHeadPose() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
2023-12-05 18:20:55 +01:00
index 52ffc401bbb9fa768534a4b871f9cc7dbebb8b20..9923cea74ba39a774d6b16a225bc3e455e54c418 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java
@@ -232,5 +232,16 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand {
2021-06-13 01:45:00 +02:00
public void setCanMove(boolean move) {
getHandle().canMove = move;
2021-06-11 14:02:28 +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;
+ }
// Paper end
}