From fcc0a736828cefe06ab3912e966dd2c8d6614c96 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Wed, 1 Jul 2026 15:51:24 +0200 Subject: [PATCH] Fix sign placement --- .../patches/features/0031-Optimize-Hoppers.patch | 2 +- .../minecraft/world/InteractionResult.java.patch | 16 ++++++++++------ .../minecraft/world/item/BlockItem.java.patch | 14 ++++++++++---- .../minecraft/world/item/ItemStack.java.patch | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/paper-server/patches/features/0031-Optimize-Hoppers.patch b/paper-server/patches/features/0031-Optimize-Hoppers.patch index 4e2090b12657..cfad64948f79 100644 --- a/paper-server/patches/features/0031-Optimize-Hoppers.patch +++ b/paper-server/patches/features/0031-Optimize-Hoppers.patch @@ -60,7 +60,7 @@ index b71f2e181334ad8646afb48c704c30b6f4a33ffd..68151ce05e7009f28dda0470c744920c profiler.push("tick"); diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java -index 35ec36e8f2ab8d2c9272f1614eefa8b8cfa4f4d7..f1e6e876460e62cee24c4ca4adcf047fb96b1909 100644 +index a8da0c5b2f9b75216d6b93addabff744c6b10431..44a7590558fa73fb570f76ba7a4e7db1415d08f7 100644 --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java @@ -779,11 +779,17 @@ public final class ItemStack implements DataComponentHolder, ItemInstance { diff --git a/paper-server/patches/sources/net/minecraft/world/InteractionResult.java.patch b/paper-server/patches/sources/net/minecraft/world/InteractionResult.java.patch index d5f39ad87c76..06d8b46e6d2f 100644 --- a/paper-server/patches/sources/net/minecraft/world/InteractionResult.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/InteractionResult.java.patch @@ -1,21 +1,25 @@ --- a/net/minecraft/world/InteractionResult.java +++ b/net/minecraft/world/InteractionResult.java -@@ -30,18 +_,34 @@ +@@ -30,18 +_,38 @@ record Pass() implements InteractionResult { } - record Success(InteractionResult.SwingSource swingSource, InteractionResult.ItemContext itemContext) implements InteractionResult { + // Paper start - track more context in interaction result -+ record PaperSuccessContext(net.minecraft.core.@Nullable BlockPos placedPos) { -+ static PaperSuccessContext DEFAULT = new PaperSuccessContext(null); ++ record PaperSuccessContext(net.minecraft.core.@Nullable BlockPos placedPos, boolean updatedBlockEntity) { ++ static PaperSuccessContext DEFAULT = new PaperSuccessContext(null, false); + + public PaperSuccessContext placedBlockAt(final net.minecraft.core.BlockPos pos) { -+ return new PaperSuccessContext(pos); ++ return new PaperSuccessContext(pos, this.updatedBlockEntity); ++ } ++ ++ public PaperSuccessContext updatedBlockEntity(final boolean updatedBlockEntity) { ++ return new PaperSuccessContext(this.placedPos, updatedBlockEntity); + } + } + record Success(InteractionResult.SwingSource swingSource, InteractionResult.ItemContext itemContext, PaperSuccessContext paperSuccessContext) implements InteractionResult { -+ public InteractionResult.Success configurePaper(final java.util.function.UnaryOperator edit) { -+ return new InteractionResult.Success(this.swingSource, this.itemContext, edit.apply(this.paperSuccessContext)); ++ public InteractionResult.Success configurePaper(final java.util.function.UnaryOperator context) { ++ return new InteractionResult.Success(this.swingSource, this.itemContext, context.apply(this.paperSuccessContext)); + } + + public Success(final InteractionResult.SwingSource swingSource, final InteractionResult.ItemContext itemContext) { diff --git a/paper-server/patches/sources/net/minecraft/world/item/BlockItem.java.patch b/paper-server/patches/sources/net/minecraft/world/item/BlockItem.java.patch index ba51373fab3e..1eca2bfbe6a8 100644 --- a/paper-server/patches/sources/net/minecraft/world/item/BlockItem.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/BlockItem.java.patch @@ -8,14 +8,20 @@ if (placementState == null) { return InteractionResult.FAIL; } -@@ -75,19 +_,43 @@ +@@ -73,21 +_,47 @@ + Player player = updatedPlaceContext.getPlayer(); + ItemStack itemStack = updatedPlaceContext.getItemInHand(); BlockState placedState = level.getBlockState(pos); ++ java.util.function.UnaryOperator context = c -> c.placedBlockAt(pos.immutable()); // Paper - track placed block position from block item if (placedState.is(placementState.getBlock())) { placedState = this.updateBlockStateFromTag(pos, level, itemStack, placedState); +- this.updateCustomBlockEntityTag(pos, level, player, itemStack, placedState); +- updateBlockEntityComponents(level, pos, itemStack); + // Paper start - Reset placed block on exception + try { - this.updateCustomBlockEntityTag(pos, level, player, itemStack, placedState); - updateBlockEntityComponents(level, pos, itemStack); ++ boolean updatedBlockEntity = this.updateCustomBlockEntityTag(pos, level, player, itemStack, placedState); ++ context = context.andThen(c -> c.updatedBlockEntity(updatedBlockEntity))::apply; // track whether the block entity got updated or not ++ updateBlockEntityComponents(level, pos, itemStack); + } catch (Exception ex) { + ((org.bukkit.craftbukkit.block.CraftBlockState) previousState).revertPlace(false); + if (player instanceof ServerPlayer serverPlayer) { @@ -49,7 +55,7 @@ level.gameEvent(GameEvent.BLOCK_PLACE, pos, GameEvent.Context.of(player, placedState)); itemStack.consume(1, player); - return InteractionResult.SUCCESS; -+ return InteractionResult.SUCCESS.configurePaper(e -> e.placedBlockAt(pos.immutable())); // Paper - track placed block position from block item ++ return InteractionResult.SUCCESS.configurePaper(context); // Paper } protected SoundEvent getPlaceSound(final BlockState blockState) { diff --git a/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch b/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch index 0e3171b6949c..776ebf432a5b 100644 --- a/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/ItemStack.java.patch @@ -147,7 +147,7 @@ + } + + // SPIGOT-4678 -+ if (usedItem instanceof SignItem && placedPos != null) { ++ if (usedItem instanceof SignItem && placedPos != null && !success.paperSuccessContext().updatedBlockEntity()) { + if (level.getBlockEntity(placedPos) instanceof net.minecraft.world.level.block.entity.SignBlockEntity signEntity) { + if (level.getBlockState(placedPos).getBlock() instanceof net.minecraft.world.level.block.SignBlock sign) { + sign.openTextEdit(player, signEntity, true, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause.PLACE); // CraftBukkit // Paper - Add PlayerOpenSignEvent