Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PaperSuccessContext> edit) {
+ return new InteractionResult.Success(this.swingSource, this.itemContext, edit.apply(this.paperSuccessContext));
+ public InteractionResult.Success configurePaper(final java.util.function.UnaryOperator<PaperSuccessContext> context) {
+ return new InteractionResult.Success(this.swingSource, this.itemContext, context.apply(this.paperSuccessContext));
+ }
+
+ public Success(final InteractionResult.SwingSource swingSource, final InteractionResult.ItemContext itemContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InteractionResult.PaperSuccessContext> 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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading