From a9e1137c3034796c6632121badf5d813cb3b7ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=81=AA=E8=81=AA?= <178666380@qq.com> Date: Sun, 25 Jun 2017 19:10:06 +0800 Subject: [PATCH] fix block snapshot restore bug,add entity restore --- .../common/ForgeHooks.java.patch | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/patches/net/minecraftforge/common/ForgeHooks.java.patch b/patches/net/minecraftforge/common/ForgeHooks.java.patch index f078637..317b1b6 100644 --- a/patches/net/minecraftforge/common/ForgeHooks.java.patch +++ b/patches/net/minecraftforge/common/ForgeHooks.java.patch @@ -65,7 +65,7 @@ { // Let the client know the block still exists entityPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); -@@ -500,81 +514,137 @@ +@@ -500,81 +514,144 @@ if (!(itemstack.getItem() instanceof ItemBucket)) // if not bucket { world.captureBlockSnapshots = true; @@ -169,6 +169,8 @@ + List blockSnapshots = (List) world.capturedBlockSnapshots + .clone(); + world.capturedBlockSnapshots.clear(); ++ List tDropItemSnapshots=(List)world.capturedItems.clone(); ++ world.capturedItems.clear(); + + // make sure to set pre-placement item data for event + itemstack.setItemDamage(meta); @@ -202,13 +204,14 @@ - if (newBlock != null && !(newBlock.hasTileEntity(metadata))) // Containers get placed automatically + flag = false; // cancel placement + // revert back all captured blocks -+ for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots) - { -- newBlock.onBlockAdded(world, blockX, blockY, blockZ); -+ world.restoringBlockSnapshots = true; -+ blocksnapshot.restore(true, false); -+ world.restoringBlockSnapshots = false; - } ++ for(int i=blockSnapshots.size();i>0;){ ++ world.restoringBlockSnapshots=true; ++ blockSnapshots.get(--i).restore(true,false); ++ world.restoringBlockSnapshots=false; ++ } ++ for(net.minecraftforge.common.util.EntitySnapshot sEntityItem : tDropItemSnapshots){ ++ sEntityItem.cancel(); ++ } + } + else + { @@ -216,9 +219,10 @@ + itemstack.setItemDamage(newMeta); + itemstack.stackSize = newSize; + if (nbt != null) -+ { + { +- newBlock.onBlockAdded(world, blockX, blockY, blockZ); + itemstack.setTagCompound(newNBT); -+ } + } - world.markAndNotifyBlock(blockX, blockY, blockZ, null, oldBlock, newBlock, updateFlag); + for (net.minecraftforge.common.util.BlockSnapshot blocksnapshot : blockSnapshots) @@ -240,6 +244,9 @@ + + world.markAndNotifyBlock(blockX, blockY, blockZ, null, oldBlock, newBlock, updateFlag); + } ++ for(net.minecraftforge.common.util.EntitySnapshot sEntityItem : tDropItemSnapshots){ ++ sEntityItem.apply(); ++ } + player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1); } - player.addStat(StatList.objectUseStats[Item.getIdFromItem(itemstack.getItem())], 1);