From 2f18108123a33312a073906cd2a5fe2da18dc049 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 7 Jul 2020 09:35:47 +1000 Subject: [PATCH] Improve physics code --- nms-patches/ItemStack.patch | 2 +- nms-patches/World.patch | 18 +++++++++--------- .../org/bukkit/craftbukkit/CraftWorld.java | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nms-patches/ItemStack.patch b/nms-patches/ItemStack.patch index 4b5825947d..bc0fdfe2ae 100644 --- a/nms-patches/ItemStack.patch +++ b/nms-patches/ItemStack.patch @@ -191,7 +191,7 @@ + block.getBlock().onPlace(block, world, newblockposition, oldBlock, true); + } + -+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getType(newblockposition), updateFlag); // send null chunk as chunk.k() returns false by this point ++ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getType(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point + } + + // Special case juke boxes as they update their tile entity. Copied from ItemRecord. diff --git a/nms-patches/World.patch b/nms-patches/World.patch index b1e282122b..b9d8f56632 100644 --- a/nms-patches/World.patch +++ b/nms-patches/World.patch @@ -173,7 +173,7 @@ + // CraftBukkit start + if (!this.captureBlockStates) { // Don't notify clients or update physics while capturing blockstates + // Modularize client and physic updates -+ notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, iblockdata2, i); ++ notifyAndUpdatePhysics(blockposition, chunk, iblockdata1, iblockdata, iblockdata2, i, j); + } + // CraftBukkit end @@ -183,7 +183,7 @@ } + // CraftBukkit start - Split off from above in order to directly send client and physic updates -+ public void notifyAndUpdatePhysics(BlockPosition blockposition, Chunk chunk, IBlockData oldBlock, IBlockData newBlock, IBlockData actualBlock, int i) { ++ public void notifyAndUpdatePhysics(BlockPosition blockposition, Chunk chunk, IBlockData oldBlock, IBlockData newBlock, IBlockData actualBlock, int i, int j) { + IBlockData iblockdata = newBlock; + IBlockData iblockdata1 = oldBlock; + IBlockData iblockdata2 = actualBlock; @@ -196,18 +196,18 @@ + this.notify(blockposition, iblockdata1, iblockdata, i); + } + -+ if (!this.isClientSide && (i & 1) != 0) { ++ if ((i & 1) != 0) { + this.update(blockposition, iblockdata1.getBlock()); -+ if (iblockdata.isComplexRedstone()) { ++ if (!this.isClientSide && iblockdata.isComplexRedstone()) { + this.updateAdjacentComparators(blockposition, newBlock.getBlock()); + } + } + -+ if ((i & 16) == 0) { -+ int j = i & -2; ++ if ((i & 16) == 0 && j > 0) { ++ int k = i & -34; + + // CraftBukkit start -+ iblockdata1.b(this, blockposition, j); // Don't call an event for the old block to limit event spam ++ iblockdata1.b(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam + CraftWorld world = ((WorldServer) this).getWorld(); + if (world != null) { + BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata)); @@ -218,8 +218,8 @@ + } + } + // CraftBukkit end -+ iblockdata.a(this, blockposition, j); -+ iblockdata.b(this, blockposition, j); ++ iblockdata.a((GeneratorAccess) this, blockposition, k, j - 1); ++ iblockdata.b(this, blockposition, k, j - 1); + } + + this.a(blockposition, iblockdata1, iblockdata2); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index a0db0cfcbb..a7569471c4 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -762,7 +762,7 @@ public class CraftWorld implements World { int flag = ((CraftBlockState) blockstate).getFlag(); delegate.setBlockData(blockstate.getX(), blockstate.getY(), blockstate.getZ(), blockstate.getBlockData()); net.minecraft.server.IBlockData newBlock = world.getType(position); - world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag); + world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, newBlock, flag, 512); } world.capturedBlockStates.clear(); return true;