Skip to content

Commit 3ea224d

Browse files
committed
Reset placed blocks on exceptions
1 parent 87d8ef9 commit 3ea224d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Nassim Jahnke <jahnke.nassim@gmail.com>
3+
Date: Fri, 7 Jan 2022 11:45:15 +0100
4+
Subject: [PATCH] Reset placed block on exception
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
8+
index 8175bb6331727440da2232998bdad068a1c47ae8..893d5bf448ddbccb30db0ee751c7f4a4e83634b9 100644
9+
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
10+
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
11+
@@ -78,6 +78,7 @@ public class BlockItem extends Item {
12+
if (this instanceof WaterLilyBlockItem || this instanceof SolidBucketItem) {
13+
blockstate = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos());
14+
}
15+
+ final org.bukkit.block.BlockState oldBlockstate = blockstate != null ? blockstate : org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos()); // Paper
16+
// CraftBukkit end
17+
18+
if (iblockdata == null) {
19+
@@ -93,7 +94,19 @@ public class BlockItem extends Item {
20+
21+
if (iblockdata1.is(iblockdata.getBlock())) {
22+
iblockdata1 = this.updateBlockStateFromTag(blockposition, world, itemstack, iblockdata1);
23+
+ // Paper start - reset block on exception
24+
+ try {
25+
this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1);
26+
+ } catch (Exception e) {
27+
+ oldBlockstate.update(true, false);
28+
+ if (entityhuman instanceof ServerPlayer player) {
29+
+ org.apache.logging.log4j.LogManager.getLogger().error("Player {} tried placing invalid block", player.getScoreboardName(), e);
30+
+ player.getBukkitEntity().kickPlayer("Packet processing error");
31+
+ return InteractionResult.FAIL;
32+
+ }
33+
+ throw e; // Rethrow exception if not placed by a player
34+
+ }
35+
+ // Paper end
36+
iblockdata1.getBlock().setPlacedBy(world, blockposition, iblockdata1, entityhuman, itemstack);
37+
// CraftBukkit start
38+
if (blockstate != null) {

0 commit comments

Comments
 (0)