From e1adb82073ea7cf2469ad0c879edef864d90d110 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sat, 22 Jul 2023 17:00:50 -0400
Subject: [PATCH] Remove sign ticking (#9478)

Minecraft now ticks signs in order to validate the playerWhoMayEdit field. This is a horrible idea, as this means that even waxed signs are ticked for essentially no reason. This moves the logic lazily onto the getter.
---
 patches/server/Don-t-tick-signs.patch | 63 +++++++++++++++++++++++++++
 patches/server/MC-Dev-fixes.patch     | 34 +++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 patches/server/Don-t-tick-signs.patch

diff --git a/patches/server/Don-t-tick-signs.patch b/patches/server/Don-t-tick-signs.patch
new file mode 100644
index 0000000000..450b2434cd
--- /dev/null
+++ b/patches/server/Don-t-tick-signs.patch
@@ -0,0 +1,63 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
+Date: Wed, 12 Jul 2023 17:38:26 -0400
+Subject: [PATCH] Don't tick signs
+
+Minecraft now ticks signs in order to validate the playerWhoMayEdit field. This is a horrible idea, as this means that even waxed signs are ticked for essentially no reason. This moves the logic lazily onto the getter.
+
+== AT ==
+private net.minecraft.world.level.block.entity.SignBlockEntity playerWhoMayEdit
+
+diff --git a/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java b/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java
+@@ -0,0 +0,0 @@ public class CeilingHangingSignBlock extends SignBlock {
+     @Nullable
+     @Override
+     public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state, BlockEntityType<T> type) {
+-        return createTickerHelper(type, BlockEntityType.HANGING_SIGN, SignBlockEntity::tick);
++        return null; // Paper
+     }
+ }
+diff --git a/src/main/java/net/minecraft/world/level/block/SignBlock.java b/src/main/java/net/minecraft/world/level/block/SignBlock.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/level/block/SignBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/SignBlock.java
+@@ -0,0 +0,0 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
+     @Nullable
+     @Override
+     public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state, BlockEntityType<T> type) {
+-        return createTickerHelper(type, BlockEntityType.SIGN, SignBlockEntity::tick);
++        return null; // Paper
+     }
+ }
+diff --git a/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java b/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java
+@@ -0,0 +0,0 @@ public class WallHangingSignBlock extends SignBlock {
+     @Nullable
+     @Override
+     public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level world, BlockState state, BlockEntityType<T> type) {
+-        return createTickerHelper(type, BlockEntityType.HANGING_SIGN, SignBlockEntity::tick);
++        return null; // Paper
+     }
+ }
+diff --git a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
++++ b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+@@ -0,0 +0,0 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
+ 
+     @Nullable
+     public UUID getPlayerWhoMayEdit() {
++        // Paper start
++        if (this.hasLevel() && this.playerWhoMayEdit != null) {
++            // Manually invalidate the value lazily.
++            this.clearInvalidPlayerWhoMayEdit(this, this.getLevel(), this.playerWhoMayEdit);
++        }
++        // Paper end
+         return this.playerWhoMayEdit;
+     }
+ 
diff --git a/patches/server/MC-Dev-fixes.patch b/patches/server/MC-Dev-fixes.patch
index d6d85b5332..dc176e1953 100644
--- a/patches/server/MC-Dev-fixes.patch
+++ b/patches/server/MC-Dev-fixes.patch
@@ -184,6 +184,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          }));
          this.byName = Maps.newHashMap(builder.build()); // CraftBukkit
          RecipeManager.LOGGER.info("Loaded {} recipes", map1.size());
+diff --git a/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java b/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/CeilingHangingSignBlock.java
+@@ -0,0 +0,0 @@ public class CeilingHangingSignBlock extends SignBlock {
+     public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+         BlockEntity itemStack = world.getBlockEntity(pos);
+         if (itemStack instanceof SignBlockEntity signBlockEntity) {
+-            ItemStack itemStack = player.getItemInHand(hand);
+-            if (this.shouldTryToChainAnotherHangingSign(player, hit, signBlockEntity, itemStack)) {
++            // Paper start - decompile fixes
++            ItemStack itemStack0 = player.getItemInHand(hand);
++            if (this.shouldTryToChainAnotherHangingSign(player, hit, signBlockEntity, itemStack0)) {
++            // Paper end - decompile fixes
+                 return InteractionResult.PASS;
+             }
+         }
 diff --git a/src/main/java/net/minecraft/world/level/block/SignBlock.java b/src/main/java/net/minecraft/world/level/block/SignBlock.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/level/block/SignBlock.java
@@ -209,6 +226,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              if (!world.isClientSide) {
                  boolean bl2 = signBlockEntity.isFacingFrontText(player);
                  SignText signText = signBlockEntity.getText(bl2);
+diff --git a/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java b/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java
++++ b/src/main/java/net/minecraft/world/level/block/WallHangingSignBlock.java
+@@ -0,0 +0,0 @@ public class WallHangingSignBlock extends SignBlock {
+     public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+         BlockEntity itemStack = world.getBlockEntity(pos);
+         if (itemStack instanceof SignBlockEntity signBlockEntity) {
+-            ItemStack itemStack = player.getItemInHand(hand);
+-            if (this.shouldTryToChainAnotherHangingSign(state, player, hit, signBlockEntity, itemStack)) {
++            // Paper start - decompile fixes
++            ItemStack itemStack0 = player.getItemInHand(hand);
++            if (this.shouldTryToChainAnotherHangingSign(state, player, hit, signBlockEntity, itemStack0)) {
++            // Paper end
+                 return InteractionResult.PASS;
+             }
+         }
 diff --git a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java