From f1a6f453530b63c9d0cd693a712721ff5825d21e Mon Sep 17 00:00:00 2001 From: Eloraam Date: Mon, 31 Oct 2011 20:07:31 +0000 Subject: [PATCH] New block destruction hook. Deprecated IOverrideReplace. --- .../minecraft/src/forge/IOverrideReplace.java | 1 + .../net/minecraft/src/Block.java.patch | 12 +++++++++- .../minecraft/src/PlayerController.java.patch | 20 +++++++++++++++- .../net/minecraft/src/Block.java.patch | 12 +++++++++- .../src/ItemInWorldManager.java.patch | 24 +++++++++++++++---- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java b/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java index 69b2820eb..fbfcf8a17 100644 --- a/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java +++ b/forge/forge_common/net/minecraft/src/forge/IOverrideReplace.java @@ -13,6 +13,7 @@ import net.minecraft.src.World; * to control how it can be replaced * * @see Block + * @deprecated. This functionality will be removed soon. */ public interface IOverrideReplace { diff --git a/forge/patches/minecraft/net/minecraft/src/Block.java.patch b/forge/patches/minecraft/net/minecraft/src/Block.java.patch index b0233712d..4ba1a622d 100644 --- a/forge/patches/minecraft/net/minecraft/src/Block.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/Block.java.patch @@ -101,7 +101,7 @@ } protected void dropBlockAsItem_do(World world, int i, int j, int k, ItemStack itemstack) -@@ -618,6 +629,86 @@ +@@ -618,6 +629,96 @@ return iblockaccess.isBlockNormalCube(i, j, k) ? 0.2F : 1.0F; } @@ -184,6 +184,16 @@ + public boolean canHarvestBlock(EntityPlayer player, int md) { + return ForgeHooks.canHarvestBlock(this,player,md); + } ++ ++ /* FORGE: Called when a player removes a block. This is responsible for ++ * actually destroying the block, and the block is intact at time of call. ++ * This is called regardless of whether the player can harvest the block or ++ * not. Return true if the block is actually destroyed. ++ */ ++ public boolean removeBlockByPlayer(World world, EntityPlayer player, ++ int i, int j, int k) { ++ return world.setBlockWithNotify(i, j, k, 0); ++ } + static Class _mthclass$(String s) { diff --git a/forge/patches/minecraft/net/minecraft/src/PlayerController.java.patch b/forge/patches/minecraft/net/minecraft/src/PlayerController.java.patch index 7509b615f..508e56f21 100644 --- a/forge/patches/minecraft/net/minecraft/src/PlayerController.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/PlayerController.java.patch @@ -8,7 +8,25 @@ import net.minecraft.client.Minecraft; -@@ -64,6 +65,7 @@ +@@ -36,12 +37,11 @@ + } + world.playAuxSFX(2001, i, j, k, block.blockID + world.getBlockMetadata(i, j, k) * 256); + int i1 = world.getBlockMetadata(i, j, k); +- boolean flag = world.setBlockWithNotify(i, j, k, 0); +- if(block != null && flag) +- { +- block.onBlockDestroyedByPlayer(world, i, j, k, i1); +- } +- return flag; ++ ++ if(block==null) return false; ++ boolean flag = block.removeBlockByPlayer(world,mc.thePlayer,i,j,k); ++ if(flag) block.onBlockDestroyedByPlayer(world, i, j, k, i1); ++ return flag; + } + + public abstract void sendBlockRemoving(int i, int j, int k, int l); +@@ -64,6 +64,7 @@ if(itemstack1.stackSize == 0) { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; diff --git a/forge/patches/minecraft_server/net/minecraft/src/Block.java.patch b/forge/patches/minecraft_server/net/minecraft/src/Block.java.patch index eb70c99a1..e9bf71902 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/Block.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/Block.java.patch @@ -84,7 +84,7 @@ } protected void dropBlockAsItem_do(World world, int i, int j, int k, ItemStack itemstack) -@@ -529,6 +538,86 @@ +@@ -529,6 +538,96 @@ return blockMaterial.getMaterialMobility(); } @@ -167,6 +167,16 @@ + public boolean canHarvestBlock(EntityPlayer player, int md) { + return ForgeHooks.canHarvestBlock(this,player,md); + } ++ ++ /* FORGE: Called when a player removes a block. This is responsible for ++ * actually destroying the block, and the block is intact at time of call. ++ * This is called regardless of whether the player can harvest the block or ++ * not. Return true if the block is actually destroyed. ++ */ ++ public boolean removeBlockByPlayer(World world, EntityPlayer player, ++ int i, int j, int k) { ++ return world.setBlockWithNotify(i, j, k, 0); ++ } + static Class _mthclass$(String s) { diff --git a/forge/patches/minecraft_server/net/minecraft/src/ItemInWorldManager.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ItemInWorldManager.java.patch index fd72220c4..42658b8f9 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/ItemInWorldManager.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/ItemInWorldManager.java.patch @@ -38,7 +38,23 @@ if(f >= 0.7F) { blockHarvessted(i, j, k); -@@ -164,7 +166,7 @@ +@@ -135,11 +137,10 @@ + { + Block block = Block.blocksList[thisWorld.getBlockId(i, j, k)]; + int l = thisWorld.getBlockMetadata(i, j, k); +- boolean flag = thisWorld.setBlockWithNotify(i, j, k, 0); +- if(block != null && flag) +- { +- block.onBlockDestroyedByPlayer(thisWorld, i, j, k, l); +- } ++ ++ if(block==null) return false; ++ boolean flag = block.removeBlockByPlayer(thisWorld,thisPlayer,i,j,k); ++ if(flag) block.onBlockDestroyedByPlayer(thisWorld, i, j, k, l); + return flag; + } + +@@ -164,7 +165,7 @@ thisPlayer.destroyCurrentEquippedItem(); } } @@ -47,7 +63,7 @@ { Block.blocksList[l].harvestBlock(thisWorld, thisPlayer, i, j, k, i1); } -@@ -188,6 +190,7 @@ +@@ -188,6 +189,7 @@ if(itemstack1.stackSize == 0) { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; @@ -55,7 +71,7 @@ } return true; } else -@@ -198,6 +201,11 @@ +@@ -198,6 +200,11 @@ public boolean activeBlockOrUseItem(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l) { @@ -67,7 +83,7 @@ int i1 = world.getBlockId(i, j, k); if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer)) { -@@ -217,7 +225,11 @@ +@@ -217,7 +224,11 @@ return flag; } else {