From c2cbdc5ab41fe4f77a5a28f01d8b79098b1bb392 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 27 Aug 2018 18:27:59 +1000 Subject: [PATCH] SPIGOT-4316: Do even less processing when block placement without physics requested --- nms-patches/Chunk.patch | 34 ++++++++++++++----- nms-patches/World.patch | 3 +- .../bukkit/craftbukkit/block/CraftBlock.java | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/nms-patches/Chunk.patch b/nms-patches/Chunk.patch index 41edc035e3..321b2b3821 100644 --- a/nms-patches/Chunk.patch +++ b/nms-patches/Chunk.patch @@ -80,17 +80,33 @@ } public Set t() { -@@ -473,7 +513,8 @@ +@@ -412,8 +452,15 @@ + } + } + ++ // CraftBukkit start + @Nullable + public IBlockData a(BlockPosition blockposition, IBlockData iblockdata, boolean flag) { ++ return this.a(blockposition, iblockdata, flag, true); ++ } ++ ++ @Nullable ++ public IBlockData a(BlockPosition blockposition, IBlockData iblockdata, boolean flag, boolean doPlace) { ++ // CraftBukkit end + int i = blockposition.getX() & 15; + int j = blockposition.getY(); + int k = blockposition.getZ() & 15; +@@ -473,7 +520,8 @@ } } - if (!this.world.isClientSide) { + // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled. -+ if (!this.world.isClientSide && (!this.world.captureBlockStates || block instanceof BlockTileEntity)) { ++ if (!this.world.isClientSide && doPlace && (!this.world.captureBlockStates || block instanceof BlockTileEntity)) { iblockdata.onPlace(this.world, blockposition, iblockdata1); } -@@ -653,7 +694,12 @@ +@@ -653,7 +701,12 @@ @Nullable public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) { @@ -104,7 +120,7 @@ if (tileentity == null) { if (chunk_enumtileentitystate == Chunk.EnumTileEntityState.IMMEDIATE) { -@@ -688,6 +734,13 @@ +@@ -688,6 +741,13 @@ tileentity.z(); this.tileEntities.put(blockposition, tileentity); @@ -118,7 +134,7 @@ } } -@@ -720,6 +773,17 @@ +@@ -720,6 +780,17 @@ })); } @@ -136,7 +152,7 @@ } public void removeEntities() { -@@ -736,9 +800,21 @@ +@@ -736,9 +807,21 @@ int i = aentityslice.length; for (int j = 0; j < i; ++j) { @@ -160,7 +176,7 @@ } } -@@ -800,8 +876,8 @@ +@@ -800,8 +883,8 @@ while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); @@ -171,7 +187,7 @@ } } } -@@ -1007,13 +1083,13 @@ +@@ -1007,13 +1090,13 @@ @Nullable public LongSet b(String s) { @@ -187,7 +203,7 @@ return new LongOpenHashSet(); })).add(i); } -@@ -1061,14 +1137,14 @@ +@@ -1061,14 +1144,14 @@ } if (this.s instanceof ProtoChunkTickList) { diff --git a/nms-patches/World.patch b/nms-patches/World.patch index 1e96e1705b..78569d8c16 100644 --- a/nms-patches/World.patch +++ b/nms-patches/World.patch @@ -146,6 +146,7 @@ } else { Chunk chunk = this.getChunkAtWorldCoords(blockposition); Block block = iblockdata.getBlock(); +- IBlockData iblockdata1 = chunk.a(blockposition, iblockdata, (i & 64) != 0); + + // CraftBukkit start - capture blockstates + CraftBlockState blockstate = null; @@ -155,7 +156,7 @@ + } + // CraftBukkit end + - IBlockData iblockdata1 = chunk.a(blockposition, iblockdata, (i & 64) != 0); ++ IBlockData iblockdata1 = chunk.a(blockposition, iblockdata, (i & 64) != 0, (i & 1024) == 0); // CraftBukkit custom NO_PLACE flag if (iblockdata1 == null) { + // CraftBukkit start - remove blockstate if failed diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 370a222f83..922266441d 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -157,7 +157,7 @@ public class CraftBlock implements Block { return world.setTypeAndData(position, blockData, 3); } else { IBlockData old = world.getType(position); - boolean success = world.setTypeAndData(position, blockData, 18); // NOTIFY | NO_OBSERVER + boolean success = world.setTypeAndData(position, blockData, 2 | 16 | 1024); // NOTIFY | NO_OBSERVER | NO_PLACE (custom) if (success) { world.getMinecraftWorld().notify( position,