Skip to content

Commit 81399e4

Browse files
committed
Fix block placement causing physics when cancelled
1 parent 22410ee commit 81399e4

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Samsuik <[email protected]>
3+
Date: Tue, 14 May 2024 19:26:58 +0100
4+
Subject: [PATCH] Fix block placement causing physics when cancelled
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
8+
index 1ad126d992d95062a3db08374db7a927f23a0cac..bf4a5a35272ad0efc0fb26652ea63561ee0cd64d 100644
9+
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
10+
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
11+
@@ -452,9 +452,16 @@ public final class ItemStack {
12+
world.capturedTileEntities.clear(); // Paper - Allow chests to be placed with NBT data; clear out block entities as chests and such will pop loot
13+
// revert back all captured blocks
14+
world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710
15+
+ // Sakura start - fix placement causing physics when event is cancelled
16+
+ world.preventNeighborUpdates = true;
17+
+ try {
18+
for (BlockState blockstate : blocks) {
19+
blockstate.update(true, false);
20+
}
21+
+ } finally {
22+
+ world.preventNeighborUpdates = false;
23+
+ }
24+
+ // Sakura end - fix placement causing physics when event is cancelled
25+
world.preventPoiUpdated = false;
26+
27+
// Brute force all possible updates
28+
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
29+
index 0572cf39080e549354b5adf437afc7dc3e8e824c..c2c0d80adb6fa8cb74fa5fe3ce5bc7ac0609abba 100644
30+
--- a/src/main/java/net/minecraft/world/level/Level.java
31+
+++ b/src/main/java/net/minecraft/world/level/Level.java
32+
@@ -150,6 +150,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
33+
public boolean keepSpawnInMemory = true;
34+
public org.bukkit.generator.ChunkGenerator generator;
35+
36+
+ public boolean preventNeighborUpdates = false; // Sakura - fix placement causing physics when event is cancelled
37+
public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
38+
public boolean captureBlockStates = false;
39+
public boolean captureTreeGeneration = false;
40+
diff --git a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
41+
index 9d8c0d2b5a1d5a23966b49f8fefbb3d379a07364..034f9788550802b4f1e85892a5055ee72a60454e 100644
42+
--- a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
43+
+++ b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
44+
@@ -499,7 +499,7 @@ public class RedStoneWireBlock extends Block {
45+
46+
@Override
47+
public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) {
48+
- if (!moved && !state.is(newState.getBlock())) {
49+
+ if (!moved && !state.is(newState.getBlock()) && !world.preventNeighborUpdates) { // Sakura - fix placement causing physics when event is cancelled
50+
super.onRemove(state, world, pos, newState, moved);
51+
if (!world.isClientSide) {
52+
Direction[] aenumdirection = Direction.values();
53+
diff --git a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
54+
index 19faa8f5f891c1ffbed0af8391dee8202433c447..2f07e1c8fc769a28f235858e1529ab154e0d2247 100644
55+
--- a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
56+
+++ b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
57+
@@ -52,6 +52,7 @@ public interface NeighborUpdater {
58+
59+
static void executeUpdate(Level world, BlockState state, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
60+
try {
61+
+ if (world.preventNeighborUpdates) { return; } // Sakura - fix placement causing physics when event is cancelled
62+
// CraftBukkit start
63+
CraftWorld cworld = ((ServerLevel) world).getWorld();
64+
if (cworld != null) {

0 commit comments

Comments
 (0)