Do not perform neighbour updates when using debug stick (Fixes #2134)

CB blindly drops any update flags when recording block modifications,
this causes the debug stick to blindly update neighbouring blocks on usage
in order to control this, we will special case this item, however, this
ideally should be fixed by recording the actual update flags used,
but will induce ABI breaks...

This patch also maintains the behavior of the BlockPlaceEvent, this
behavior will NOT be guaranteed in the future, however.
This commit is contained in:
Shane Freeder 2020-12-22 22:45:10 +00:00
parent 855cb5a9b5
commit 08f196719f
3 changed files with 71 additions and 1 deletions

View file

@ -38,9 +38,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@Override
public void a(PacketPlayInBEdit packetplayinbedit) {
+ // Paper start
+ ItemStack testStack = packetplayinbedit.b(); // TODO(Proximyst): Add obfhelper here
+ ItemStack testStack = packetplayinbedit.getBook();
+ if (!server.isPrimaryThread() && !testStack.isEmpty() && testStack.getTag() != null) {
+ NBTTagList pageList = testStack.getTag().getList("pages", 8);
+ if (pageList.size() > 50) {
+ PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send a book with too many pages");
+ minecraftServer.scheduleOnMain(() -> this.disconnect("Book too large!"));
+ return;
+ }
+ long byteTotal = 0;
+ int maxBookPageSize = com.destroystokyo.paper.PaperConfig.maxBookPageSize;
+ double multiplier = Math.max(0.3D, Math.min(1D, com.destroystokyo.paper.PaperConfig.maxBookTotalSizeMultiplier));
@ -48,6 +53,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ for (int i = 0; i < pageList.size(); ++i) {
+ String testString = pageList.getString(i);
+ int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
+ if (byteLength > 256 * 4) {
+ PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send a book with with a page too large!");
+ minecraftServer.scheduleOnMain(() -> this.disconnect("Book too large!"));
+ return;
+ }
+ byteTotal += byteLength;
+ int length = testString.length();
+ int multibytes = 0;

View file

@ -0,0 +1,47 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Tue, 22 Dec 2020 22:41:12 +0000
Subject: [PATCH] Do not perform neighbour updates when using debug stick
CB blindly drops any update flags when recording block modifications,
this causes the debug stick to blindly update neighbouring blocks on usage
in order to control this, we will special case this item, however, this
ideally should be fixed by recording the actual update flags used,
but will induce ABI breaks...
This patch also maintains the behavior of the BlockPlaceEvent, this
behavior will NOT be guaranteed in the future, however.
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
@@ -0,0 +0,0 @@ public final class ItemStack {
}
public EnumInteractionResult placeItem(ItemActionContext itemactioncontext, EnumHand enumhand) { // CraftBukkit - add hand
+ boolean doPhysicsUpdate = true; // Paper
EntityHuman entityhuman = itemactioncontext.getEntity();
BlockPosition blockposition = itemactioncontext.getClickPosition();
ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false);
@@ -0,0 +0,0 @@ public final class ItemStack {
// special case bonemeal
if (this.getItem() == Items.BONE_MEAL) {
world.captureTreeGeneration = true;
+ // Paper start
+ } else if (this.getItem() instanceof ItemDebugStick) {
+ doPhysicsUpdate = false;
}
+ // Paper end
}
Item item = this.getItem();
EnumInteractionResult enuminteractionresult = item.a(itemactioncontext);
@@ -0,0 +0,0 @@ public final class ItemStack {
block.getBlock().onPlace(block, world, newblockposition, oldBlock, true, itemactioncontext); // Paper - pass itemactioncontext
}
- world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getType(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getType(newblockposition), updateFlag, 512 ^ (doPhysicsUpdate ? 0 : 16)); // send null chunk as chunk.k() returns false by this point // Paper
}
// Special case juke boxes as they update their tile entity. Copied from ItemRecord.

View file

@ -3907,6 +3907,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (packet.a()) {
throw new SkipEncodeException(throwable);
} else {
diff --git a/src/main/java/net/minecraft/server/PacketPlayInBEdit.java b/src/main/java/net/minecraft/server/PacketPlayInBEdit.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/PacketPlayInBEdit.java
+++ b/src/main/java/net/minecraft/server/PacketPlayInBEdit.java
@@ -0,0 +0,0 @@ import java.io.IOException;
public class PacketPlayInBEdit implements Packet<PacketListenerPlayIn> {
- private ItemStack a;
+ private ItemStack a; public ItemStack getBook() { return a; } // Paper - OBFHELPER
private boolean b;
private int c;
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java