aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1017-Fix-InventoryOpenEvent-cancellation.patch
blob: 2ac771df859e8cc20969e9d34ada5272e91c224d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tamion <70228790+notTamion@users.noreply.github.com>
Date: Mon, 19 Aug 2024 18:05:26 +0200
Subject: [PATCH] Fix InventoryOpenEvent cancellation


diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index b6b8687fc79c060cd65e04dc67c855c775ab7684..e2527f3e2b96df539c765ae23c83a09d3298d430 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -1942,6 +1942,10 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
                     } else if (factory instanceof ChestBlock.DoubleInventory) {
                         // SPIGOT-5355 - double chests too :(
                         ((ChestBlock.DoubleInventory) factory).inventorylargechest.stopOpen(this);
+                        // Paper start - Fix InventoryOpenEvent cancellation
+                    } else if (!this.enderChestInventory.isActiveChest(null)) {
+                        this.enderChestInventory.stopOpen(this);
+                        // Paper end - Fix InventoryOpenEvent cancellation
                     }
                     return OptionalInt.empty();
                 }
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index 5d189ba60d40f5c42b2dacc339594ed067418e95..504c996220b278c194c93e001a3b326d549868ec 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -572,8 +572,7 @@ public class ServerPlayerGameMode {
         } else if (this.gameModeForPlayer == GameType.SPECTATOR) {
             MenuProvider itileinventory = iblockdata.getMenuProvider(world, blockposition);
 
-            if (itileinventory != null) {
-                player.openMenu(itileinventory);
+            if (itileinventory != null && player.openMenu(itileinventory).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
                 return InteractionResult.CONSUME;
             } else {
                 return InteractionResult.PASS;
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractChestBoat.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractChestBoat.java
index 8033abfd77bcc20326b992a9d81e2faa9582fb83..1f4cc08e84a23213bb9786ea09ad77caeec2d336 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractChestBoat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractChestBoat.java
@@ -125,10 +125,10 @@ public abstract class AbstractChestBoat extends AbstractBoat implements HasCusto
 
     @Override
     public void openCustomInventoryScreen(Player player) {
-        player.openMenu(this);
+        // Paper - fix inventory open cancel - moved into below if
         Level world = player.level();
 
-        if (world instanceof ServerLevel worldserver) {
+        if (world instanceof ServerLevel worldserver && player.openMenu(this).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             this.gameEvent(GameEvent.CONTAINER_OPEN, player);
             PiglinAi.angerNearbyPiglins(worldserver, player, true);
         }
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/ContainerEntity.java b/src/main/java/net/minecraft/world/entity/vehicle/ContainerEntity.java
index cc7826a10f22e3307231d887db2fee98063b1f46..45f6191cc8e2ecdacbc2df0ddb5ea7cc6a546812 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/ContainerEntity.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/ContainerEntity.java
@@ -95,7 +95,11 @@ public interface ContainerEntity extends Container, MenuProvider {
     }
 
     default InteractionResult interactWithContainerVehicle(Player player) {
-        player.openMenu(this);
+        // Paper start - Fix InventoryOpenEvent cancellation
+        if (player.openMenu(this).isEmpty()) {
+            return InteractionResult.PASS;
+        }
+        // Paper end - Fix InventoryOpenEvent cancellation
         return InteractionResult.SUCCESS;
     }
 
diff --git a/src/main/java/net/minecraft/world/level/block/AnvilBlock.java b/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
index f50135ddd1e3699b0e3390b316d82f3884bab719..50c907c962f936d2035bb7550750cdbd220b29c2 100644
--- a/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/AnvilBlock.java
@@ -62,8 +62,9 @@ public class AnvilBlock extends FallingBlock {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_ANVIL);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/level/block/BarrelBlock.java b/src/main/java/net/minecraft/world/level/block/BarrelBlock.java
index 85fbba41ca0b6aded476043d280c746a8f5bacb9..2338b94158e3b685dc1ea8394ff271d85b5f7a7e 100644
--- a/src/main/java/net/minecraft/world/level/block/BarrelBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BarrelBlock.java
@@ -41,8 +41,7 @@ public class BarrelBlock extends BaseEntityBlock {
 
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
-        if (world instanceof ServerLevel serverLevel && world.getBlockEntity(pos) instanceof BarrelBlockEntity barrelBlockEntity) {
-            player.openMenu(barrelBlockEntity);
+        if (world instanceof ServerLevel serverLevel && world.getBlockEntity(pos) instanceof BarrelBlockEntity barrelBlockEntity && player.openMenu(barrelBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.OPEN_BARREL);
             PiglinAi.angerNearbyPiglins(serverLevel, player, true);
         }
diff --git a/src/main/java/net/minecraft/world/level/block/BeaconBlock.java b/src/main/java/net/minecraft/world/level/block/BeaconBlock.java
index 5e61dfa142dd108dd4b35de47c6ff424b1b28c02..debe8dbf1d5f3e58774903c5fcdcea672274ea61 100644
--- a/src/main/java/net/minecraft/world/level/block/BeaconBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BeaconBlock.java
@@ -46,8 +46,7 @@ public class BeaconBlock extends BaseEntityBlock implements BeaconBeamBlock {
 
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
-        if (!world.isClientSide && world.getBlockEntity(pos) instanceof BeaconBlockEntity beaconBlockEntity) {
-            player.openMenu(beaconBlockEntity);
+        if (!world.isClientSide && world.getBlockEntity(pos) instanceof BeaconBlockEntity beaconBlockEntity && player.openMenu(beaconBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_BEACON);
         }
 
diff --git a/src/main/java/net/minecraft/world/level/block/BlastFurnaceBlock.java b/src/main/java/net/minecraft/world/level/block/BlastFurnaceBlock.java
index b491cc959d4ce65a7ba16b64a7e1a56e77d0052c..03fed46291ff2236da619c941f864b8c78408450 100644
--- a/src/main/java/net/minecraft/world/level/block/BlastFurnaceBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BlastFurnaceBlock.java
@@ -45,8 +45,7 @@ public class BlastFurnaceBlock extends AbstractFurnaceBlock {
     @Override
     protected void openContainer(Level world, BlockPos pos, Player player) {
         BlockEntity blockEntity = world.getBlockEntity(pos);
-        if (blockEntity instanceof BlastFurnaceBlockEntity) {
-            player.openMenu((MenuProvider)blockEntity);
+        if (blockEntity instanceof BlastFurnaceBlockEntity && player.openMenu((MenuProvider)blockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_BLAST_FURNACE);
         }
     }
diff --git a/src/main/java/net/minecraft/world/level/block/BrewingStandBlock.java b/src/main/java/net/minecraft/world/level/block/BrewingStandBlock.java
index 4109e4965f65bdd81fa956f9e0882cb7877bd2aa..cbaa6fc04eb8d765e0dd8238f2b82eed196d13c7 100644
--- a/src/main/java/net/minecraft/world/level/block/BrewingStandBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BrewingStandBlock.java
@@ -73,8 +73,7 @@ public class BrewingStandBlock extends BaseEntityBlock {
 
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
-        if (!world.isClientSide && world.getBlockEntity(pos) instanceof BrewingStandBlockEntity brewingStandBlockEntity) {
-            player.openMenu(brewingStandBlockEntity);
+        if (!world.isClientSide && world.getBlockEntity(pos) instanceof BrewingStandBlockEntity brewingStandBlockEntity && player.openMenu(brewingStandBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_BREWINGSTAND);
         }
 
diff --git a/src/main/java/net/minecraft/world/level/block/CartographyTableBlock.java b/src/main/java/net/minecraft/world/level/block/CartographyTableBlock.java
index 20feecb9c7f5537e00788a30969b002dceda605f..9e7066ec9fa5a0a852f6e38052887a47be98cb55 100644
--- a/src/main/java/net/minecraft/world/level/block/CartographyTableBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CartographyTableBlock.java
@@ -32,8 +32,9 @@ public class CartographyTableBlock extends Block {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_CARTOGRAPHY_TABLE);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/level/block/ChestBlock.java b/src/main/java/net/minecraft/world/level/block/ChestBlock.java
index 590837cb242eda62dca3c937a26b8ba26c41850c..edef8fc62f8dba1b57214d8d7d805ff0d83f4114 100644
--- a/src/main/java/net/minecraft/world/level/block/ChestBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ChestBlock.java
@@ -252,8 +252,7 @@ public class ChestBlock extends AbstractChestBlock<ChestBlockEntity> implements
         if (world instanceof ServerLevel worldserver) {
             MenuProvider itileinventory = this.getMenuProvider(state, world, pos);
 
-            if (itileinventory != null) {
-                player.openMenu(itileinventory);
+            if (itileinventory != null && player.openMenu(itileinventory).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
                 player.awardStat(this.getOpenChestStat());
                 PiglinAi.angerNearbyPiglins(worldserver, player, true);
             }
diff --git a/src/main/java/net/minecraft/world/level/block/CraftingTableBlock.java b/src/main/java/net/minecraft/world/level/block/CraftingTableBlock.java
index 673a92d383db463b5c4e2ac3a4ecbd7e97c15c6d..6a2123cd808fa79f3cdb1cb56632d29bfe99058d 100644
--- a/src/main/java/net/minecraft/world/level/block/CraftingTableBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/CraftingTableBlock.java
@@ -31,8 +31,9 @@ public class CraftingTableBlock extends Block {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
index 500c56c4ef0878434582a50d6dba2ccca9773275..5a6c153fa2873aecba0d0d02be2cc2a514f445e3 100644
--- a/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/DispenserBlock.java
@@ -80,8 +80,9 @@ public class DispenserBlock extends BaseEntityBlock {
             if (tileentity instanceof DispenserBlockEntity) {
                 DispenserBlockEntity tileentitydispenser = (DispenserBlockEntity) tileentity;
 
-                player.openMenu(tileentitydispenser);
+                if (player.openMenu(tileentitydispenser).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
                 player.awardStat(tileentitydispenser instanceof DropperBlockEntity ? Stats.INSPECT_DROPPER : Stats.INSPECT_DISPENSER);
+                } // Paper - Fix InventoryOpenEvent cancellation
             }
         }
 
diff --git a/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java b/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java
index ef0d469176ee74b6bb5f9e9cc508735145fda5b8..ebb9baca7a65173f7c9fdf9bf47a8db876719625 100644
--- a/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java
@@ -86,11 +86,13 @@ public class EnderChestBlock extends AbstractChestBlock<EnderChestBlockEntity> i
             if (world.getBlockState(blockPos).isRedstoneConductor(world, blockPos)) { // Paper - diff on change; make sure that EnderChest#isBlocked uses the same logic
                 return InteractionResult.SUCCESS;
             } else {
-                if (world instanceof ServerLevel serverLevel) {
+                // Paper start - Fix InventoryOpenEvent cancellation - moved up;
+                if (world instanceof ServerLevel serverLevel && player.openMenu(
+                    new SimpleMenuProvider((i, inventory, playerx) -> ChestMenu.threeRows(i, inventory, playerEnderChestContainer), CONTAINER_TITLE)
+                ).isPresent()) {
+                // Paper end - Fix InventoryOpenEvent cancellation - moved up;
                     playerEnderChestContainer.setActiveChest(enderChestBlockEntity);
-                    player.openMenu(
-                        new SimpleMenuProvider((i, inventory, playerx) -> ChestMenu.threeRows(i, inventory, playerEnderChestContainer), CONTAINER_TITLE)
-                    );
+                    // Paper - Fix InventoryOpenEvent cancellation - moved up;
                     player.awardStat(Stats.OPEN_ENDERCHEST);
                     PiglinAi.angerNearbyPiglins(serverLevel, player, true);
                 }
diff --git a/src/main/java/net/minecraft/world/level/block/FurnaceBlock.java b/src/main/java/net/minecraft/world/level/block/FurnaceBlock.java
index 72a3002c291181e7d874a149a22b8004ee2a0b18..618b566f067d53f32351e13b692095ebf6402925 100644
--- a/src/main/java/net/minecraft/world/level/block/FurnaceBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/FurnaceBlock.java
@@ -45,8 +45,7 @@ public class FurnaceBlock extends AbstractFurnaceBlock {
     @Override
     protected void openContainer(Level world, BlockPos pos, Player player) {
         BlockEntity blockEntity = world.getBlockEntity(pos);
-        if (blockEntity instanceof FurnaceBlockEntity) {
-            player.openMenu((MenuProvider)blockEntity);
+        if (blockEntity instanceof FurnaceBlockEntity && player.openMenu((MenuProvider)blockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_FURNACE);
         }
     }
diff --git a/src/main/java/net/minecraft/world/level/block/GrindstoneBlock.java b/src/main/java/net/minecraft/world/level/block/GrindstoneBlock.java
index 15fb9e8f63d1db1125680aced7f9b477d4ebf43a..59c000612bbf7beb7208af48001d3b1e5111ebd4 100644
--- a/src/main/java/net/minecraft/world/level/block/GrindstoneBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/GrindstoneBlock.java
@@ -157,8 +157,9 @@ public class GrindstoneBlock extends FaceAttachedHorizontalDirectionalBlock {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_GRINDSTONE);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/level/block/HopperBlock.java b/src/main/java/net/minecraft/world/level/block/HopperBlock.java
index b61324fe162f32817b87e4adb80df57b9433259f..005a2a66a6e8a492acfa7ba91117884cda08562d 100644
--- a/src/main/java/net/minecraft/world/level/block/HopperBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/HopperBlock.java
@@ -125,8 +125,7 @@ public class HopperBlock extends BaseEntityBlock {
 
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
-        if (!world.isClientSide && world.getBlockEntity(pos) instanceof HopperBlockEntity hopperBlockEntity) {
-            player.openMenu(hopperBlockEntity);
+        if (!world.isClientSide && world.getBlockEntity(pos) instanceof HopperBlockEntity hopperBlockEntity && player.openMenu(hopperBlockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INSPECT_HOPPER);
         }
 
diff --git a/src/main/java/net/minecraft/world/level/block/LecternBlock.java b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
index 2864d0dec66980736f7434bff3031c05cff64592..d7e14ee2c11f34703b63fcd2e2ad5257003e14c8 100644
--- a/src/main/java/net/minecraft/world/level/block/LecternBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/LecternBlock.java
@@ -298,8 +298,7 @@ public class LecternBlock extends BaseEntityBlock {
     private void openScreen(Level world, BlockPos pos, Player player) {
         BlockEntity tileentity = world.getBlockEntity(pos);
 
-        if (tileentity instanceof LecternBlockEntity) {
-            player.openMenu((LecternBlockEntity) tileentity);
+        if (tileentity instanceof LecternBlockEntity && player.openMenu((LecternBlockEntity) tileentity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_LECTERN);
         }
 
diff --git a/src/main/java/net/minecraft/world/level/block/LoomBlock.java b/src/main/java/net/minecraft/world/level/block/LoomBlock.java
index 2806ca5b0e3c73a3704a514dba2038072947d9ae..1b57f8cf3f4f27f6a76fec82a542ec1c582470c9 100644
--- a/src/main/java/net/minecraft/world/level/block/LoomBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/LoomBlock.java
@@ -33,8 +33,9 @@ public class LoomBlock extends HorizontalDirectionalBlock {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_LOOM);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java b/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
index a0607cb6c6f74285363dfbd49033a8bde5ca6ae3..155c7240b1112729333e6968122568c707d8f66b 100644
--- a/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
@@ -104,8 +104,8 @@ public class ShulkerBoxBlock extends BaseEntityBlock {
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (world instanceof ServerLevel serverLevel
             && world.getBlockEntity(pos) instanceof ShulkerBoxBlockEntity shulkerBoxBlockEntity
-            && canOpen(state, world, pos, shulkerBoxBlockEntity)) {
-            player.openMenu(shulkerBoxBlockEntity);
+            && canOpen(state, world, pos, shulkerBoxBlockEntity) // Paper - Fix InventoryOpenEvent cancellation - expand if for belows check
+            && player.openMenu(shulkerBoxBlockEntity).isPresent()) {  // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.OPEN_SHULKER_BOX);
             PiglinAi.angerNearbyPiglins(serverLevel, player, true);
         }
diff --git a/src/main/java/net/minecraft/world/level/block/SmithingTableBlock.java b/src/main/java/net/minecraft/world/level/block/SmithingTableBlock.java
index 6b316b8829f542023c20293d664a2d0716fb6c4c..43dc3d2c419a8b4a76de49a1e625076741a98c73 100644
--- a/src/main/java/net/minecraft/world/level/block/SmithingTableBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SmithingTableBlock.java
@@ -38,8 +38,9 @@ public class SmithingTableBlock extends CraftingTableBlock {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_SMITHING_TABLE);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;
diff --git a/src/main/java/net/minecraft/world/level/block/SmokerBlock.java b/src/main/java/net/minecraft/world/level/block/SmokerBlock.java
index b0929942ca06ee14d2ba4f2ec2ee93743ee6233e..83669dfbfec46d319aec82ea2beaa90c9f6b81c3 100644
--- a/src/main/java/net/minecraft/world/level/block/SmokerBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SmokerBlock.java
@@ -44,8 +44,7 @@ public class SmokerBlock extends AbstractFurnaceBlock {
     @Override
     protected void openContainer(Level world, BlockPos pos, Player player) {
         BlockEntity blockEntity = world.getBlockEntity(pos);
-        if (blockEntity instanceof SmokerBlockEntity) {
-            player.openMenu((MenuProvider)blockEntity);
+        if (blockEntity instanceof SmokerBlockEntity && player.openMenu((MenuProvider)blockEntity).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_SMOKER);
         }
     }
diff --git a/src/main/java/net/minecraft/world/level/block/StonecutterBlock.java b/src/main/java/net/minecraft/world/level/block/StonecutterBlock.java
index 3a879d1a469a8f597bfba861d41abd75a5743ab8..e61644241f24b42bb4f702d3eef5b590b4d107c8 100644
--- a/src/main/java/net/minecraft/world/level/block/StonecutterBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/StonecutterBlock.java
@@ -48,8 +48,9 @@ public class StonecutterBlock extends Block {
     @Override
     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
         if (!world.isClientSide) {
-            player.openMenu(state.getMenuProvider(world, pos));
+            if (player.openMenu(state.getMenuProvider(world, pos)).isPresent()) { // Paper - Fix InventoryOpenEvent cancellation
             player.awardStat(Stats.INTERACT_WITH_STONECUTTER);
+            } // Paper - Fix InventoryOpenEvent cancellation
         }
 
         return InteractionResult.SUCCESS;