From c3cbec2dac54b188c30930c86de012cc2700423b Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Sat, 25 Jun 2016 23:55:56 -0500 Subject: [PATCH] Don't try and fix TileEntities as they are removed Currently, CraftBukkit tries to fix TEs that do not match the present block at the location. This is normally good, however, this same fixer runs when the TE removal functions go through to remove a TE after its block has been changed. So a block will be changed, the server will attempt to remove the TE present, but will then get caught up in CB's overzealous TE fixer. That fixer checks the block against the TE present, and throws a fit because it doesn't match. Which is why we're removing it in the first place. The 'fix' to this issue is to skip the fixer entirely when we're removing the TE, as it shouldn't ever need to run then anyway, we're removing it. diff --git a/src/main/java/net/minecraft/server/BlockChest.java b/src/main/java/net/minecraft/server/BlockChest.java index a5f2fc0..ef525ea 100644 --- a/src/main/java/net/minecraft/server/BlockChest.java +++ b/src/main/java/net/minecraft/server/BlockChest.java @@ -288,7 +288,7 @@ public class BlockChest extends BlockTileEntity { } public void remove(World world, BlockPosition blockposition, IBlockData iblockdata) { - TileEntity tileentity = world.getTileEntity(blockposition); + TileEntity tileentity = world.getTileEntity(blockposition, true); // Paper - This is being removed, don't fix if (tileentity instanceof IInventory) { InventoryUtils.dropInventory(world, blockposition, (IInventory) tileentity); diff --git a/src/main/java/net/minecraft/server/BlockDispenser.java b/src/main/java/net/minecraft/server/BlockDispenser.java index 024ce36..c423663 100644 --- a/src/main/java/net/minecraft/server/BlockDispenser.java +++ b/src/main/java/net/minecraft/server/BlockDispenser.java @@ -144,7 +144,7 @@ public class BlockDispenser extends BlockTileEntity { } public void remove(World world, BlockPosition blockposition, IBlockData iblockdata) { - TileEntity tileentity = world.getTileEntity(blockposition); + TileEntity tileentity = world.getTileEntity(blockposition, true); // Paper - This is being removed, don't fix if (tileentity instanceof TileEntityDispenser) { InventoryUtils.dropInventory(world, blockposition, (TileEntityDispenser) tileentity); diff --git a/src/main/java/net/minecraft/server/BlockFurnace.java b/src/main/java/net/minecraft/server/BlockFurnace.java index 25f7b4b..898be91 100644 --- a/src/main/java/net/minecraft/server/BlockFurnace.java +++ b/src/main/java/net/minecraft/server/BlockFurnace.java @@ -109,7 +109,7 @@ public class BlockFurnace extends BlockTileEntity { public void remove(World world, BlockPosition blockposition, IBlockData iblockdata) { if (!BlockFurnace.c) { - TileEntity tileentity = world.getTileEntity(blockposition); + TileEntity tileentity = world.getTileEntity(blockposition, true); // Paper - This is being removed, don't fix if (tileentity instanceof TileEntityFurnace) { InventoryUtils.dropInventory(world, blockposition, (TileEntityFurnace) tileentity); diff --git a/src/main/java/net/minecraft/server/BlockSkull.java b/src/main/java/net/minecraft/server/BlockSkull.java index 404793a..0d4d29b 100644 --- a/src/main/java/net/minecraft/server/BlockSkull.java +++ b/src/main/java/net/minecraft/server/BlockSkull.java @@ -122,7 +122,7 @@ public class BlockSkull extends BlockTileEntity { // if (!((Boolean) iblockdata.get(BlockSkull.NODROP)).booleanValue()) { if (false) { // CraftBukkit end - TileEntity tileentity = world.getTileEntity(blockposition); + TileEntity tileentity = world.getTileEntity(blockposition, true); // Paper - This is being removed, don't fix if (tileentity instanceof TileEntitySkull) { TileEntitySkull tileentityskull = (TileEntitySkull) tileentity; diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index f7d9a7c..383eef2 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -2071,8 +2071,14 @@ public abstract class World implements IBlockAccess { } public Map capturedTileEntities = Maps.newHashMap(); + // Paper start - Add additional param so we can ignore fixing on removals @Nullable public TileEntity getTileEntity(BlockPosition blockposition) { + return getTileEntity(blockposition, false); + } + + public TileEntity getTileEntity(BlockPosition blockposition, boolean isRemoving) { + // Paper end if (blockposition.isInvalidYLocation()) { // Paper return null; } else { @@ -2149,7 +2155,7 @@ public abstract class World implements IBlockAccess { } public void s(BlockPosition blockposition) { - TileEntity tileentity = this.getTileEntity(blockposition); + TileEntity tileentity = this.getTileEntity(blockposition, true); // Paper - This is being removed, don't fix if (tileentity != null && this.M) { tileentity.y(); diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index d448277..bd43075 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -123,8 +123,16 @@ public class WorldServer extends World implements IAsyncTaskHandler { // CraftBukkit start @Override + // Paper start - Add additional param so we can ignore fixing on removals public TileEntity getTileEntity(BlockPosition pos) { - TileEntity result = super.getTileEntity(pos); + return getTileEntity(pos, false); + } + + @Override + public TileEntity getTileEntity(BlockPosition pos, boolean isRemoving) { + TileEntity result = super.getTileEntity(pos, isRemoving); + if (isRemoving) return result; + // Paper end Block type = getType(pos).getBlock(); if (type == Blocks.CHEST || type == Blocks.TRAPPED_CHEST) { // Spigot -- 2.9.0