Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PlaceOnWaterBlockItem block updates #9650

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -0,0 +1,57 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <[email protected]>
Date: Wed, 23 Aug 2023 13:22:09 -0700
Subject: [PATCH] Fix PlaceOnWaterBlockItem inv desync and block updates


diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
index 65c69432da4bc042cd975e01fcf62b09843cf202..e483186a5292b3b53bfb1af4d56f55fcc1a6106c 100644
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
@@ -116,7 +116,7 @@ public class BlockItem extends Item {
if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) {
blockstate.update(true, false);

- if (this instanceof SolidBucketItem) {
+ if (true) { // Paper - if the event is called here, the inventory should be updated
((ServerPlayer) entityhuman).connection.send(new net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket(world, blockposition.below())); // Paper - update block below
((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
}
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 879cc823d56625867eb73bb621db6a13f40ad81c..49d194f460c3712ce35bcc7c0146c69832c1658f 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -542,6 +542,33 @@ public final class ItemStack {
}

public InteractionResultHolder<ItemStack> use(Level world, net.minecraft.world.entity.player.Player user, InteractionHand hand) {
+ // Paper start - capture block changes here for PlaceOnWaterBlockItem
+ if (this.getItem() instanceof PlaceOnWaterBlockItem) {
+ world.captureBlockStates = true;
+ final InteractionResultHolder<ItemStack> result;
+ try {
+ result = this.getItem().use(world, user, hand);
+ } finally {
+ world.captureBlockStates = false;
+ }
+ if (result.getResult().shouldAwardStats()) {
+ final List<CraftBlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
+ for (CraftBlockState blockstate : blocks) {
+ int updateFlag = blockstate.getFlag();
+ net.minecraft.world.level.block.state.BlockState oldBlock = blockstate.getHandle();
+ BlockPos newblockposition = blockstate.getPosition();
+ net.minecraft.world.level.block.state.BlockState block = world.getBlockState(newblockposition);
+
+ if (!(block.getBlock() instanceof BaseEntityBlock)) { // Containers get placed automatically
+ block.onPlace(world, newblockposition, oldBlock, true);
+ }
+
+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
+ }
+ }
+ return result;
+ }
+ // Paper end - capture block changes here for PlaceOnWaterBlockItem
return this.getItem().use(world, user, hand);
}

19 changes: 0 additions & 19 deletions patches/server/1026-Fix-inventory-desync.patch

This file was deleted.

Loading