From 27fecccec4aa7331f2369886c092e72685a4a04e Mon Sep 17 00:00:00 2001 From: xsun2001 <1563770452@qq.com> Date: Sun, 18 Feb 2018 20:20:36 +0800 Subject: [PATCH] fix a bug which can make entropy manipulator still consumes energy when it is prevented from melting a block. --- .../tools/powered/ToolEntropyManipulator.java | 103 ++++++++++-------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java b/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java index 0a565973c2a..40ac625c195 100644 --- a/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java +++ b/src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java @@ -84,6 +84,13 @@ public ToolEntropyManipulator() this.heatUp.put( new InWorldToolOperationIngredient( Blocks.snow, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.flowing_water ) ) ); } + private static final boolean breakBlockWithCheck( final World w, final EntityPlayer p, final int x, final int y, final int z ) + { + BlockEvent.BreakEvent event = new BlockEvent.BreakEvent( x, y, z, w, w.getBlock( x, y, z ), w.getBlockMetadata( x, y, z ), p ); + MinecraftForge.EVENT_BUS.post( event ); + return !event.isCanceled() && w.setBlockToAir( x, y, z ); + } + @Override public void postInit() { @@ -91,44 +98,14 @@ public void postInit() BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() ); } - private static class InWorldToolOperationIngredient + private boolean heat( final Block blockID, final EntityPlayer p, final int metadata, final World w, final int x, final int y, final int z ) { - private final Block blockID; - private final int metadata; - - public InWorldToolOperationIngredient( final Block blockID, final int metadata ) - { - this.blockID = blockID; - this.metadata = metadata; - } - - @Override - public int hashCode() - { - return this.blockID.hashCode() ^ this.metadata; - } - - @Override - public boolean equals( final Object obj ) - { - if( obj == null ) - { - return false; - } - if( this.getClass() != obj.getClass() ) - { - return false; - } - final InWorldToolOperationIngredient other = (InWorldToolOperationIngredient) obj; - return this.blockID == other.blockID && this.metadata == other.metadata; - } - } + if( !breakBlockWithCheck( w, p, x, y, z ) ) + return false; - private boolean heat( final Block blockID,final EntityPlayer p,final int metadata, final World w, final int x, final int y, final int z ) - { InWorldToolOperationResult r = this.heatUp.get( new InWorldToolOperationIngredient( blockID, metadata ) ); - if(!breakBlockWithCheck( w,p,x,y,z ))return false; + if( r == null ) { r = this.heatUp.get( new InWorldToolOperationIngredient( blockID, OreDictionary.WILDCARD_VALUE ) ); @@ -139,7 +116,6 @@ private boolean heat( final Block blockID,final EntityPlayer p,final int metadat w.setBlock( x, y, z, Block.getBlockFromItem( r.getBlockItem().getItem() ), r.getBlockItem().getItemDamage(), 3 ); } - if( r.getDrops() != null ) { Platform.spawnDrops( w, x, y, z, r.getDrops() ); @@ -160,8 +136,11 @@ private boolean canHeat( final Block blockID, final int metadata ) return r != null; } - private boolean cool( final Block blockID,final EntityPlayer p, final int metadata, final World w, final int x, final int y, final int z ) + private boolean cool( final Block blockID, final EntityPlayer p, final int metadata, final World w, final int x, final int y, final int z ) { + if( !breakBlockWithCheck( w, p, x, y, z ) ) + return false; + InWorldToolOperationResult r = this.coolDown.get( new InWorldToolOperationIngredient( blockID, metadata ) ); if( r == null ) @@ -169,7 +148,6 @@ private boolean cool( final Block blockID,final EntityPlayer p, final int metada r = this.coolDown.get( new InWorldToolOperationIngredient( blockID, OreDictionary.WILDCARD_VALUE ) ); } - if(!breakBlockWithCheck( w,p,x,y,z ))return false; if( r.getBlockItem() != null ) { w.setBlock( x, y, z, Block.getBlockFromItem( r.getBlockItem().getItem() ), r.getBlockItem().getItemDamage(), 3 ); @@ -252,13 +230,14 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl if( blockID == null || ForgeEventFactory.onPlayerInteract( p, blockID.isAir( w, x, y, z ) ? PlayerInteractEvent.Action.RIGHT_CLICK_AIR : PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK, - x, y, z, side, w ).isCanceled() ) return false; + x, y, z, side, w ).isCanceled() ) + return false; if( p.isSneaking() ) { if( this.canCool( blockID, metadata ) ) { - if(this.cool( blockID, p, metadata, w, x, y, z )) + if( this.cool( blockID, p, metadata, w, x, y, z ) ) { this.extractAEPower( item, 1600 ); return true; @@ -270,21 +249,23 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl { if( blockID instanceof BlockTNT ) { - if(!breakBlockWithCheck( w,p,x,y,z )) return false; + if( !breakBlockWithCheck( w, p, x, y, z ) ) + return false; ( (BlockTNT) blockID ).func_150114_a( w, x, y, z, 1, p ); return true; } if( blockID instanceof BlockTinyTNT ) { - if(!breakBlockWithCheck( w,p,x,y,z )) return false; + if( !breakBlockWithCheck( w, p, x, y, z ) ) + return false; ( (BlockTinyTNT) blockID ).startFuse( w, x, y, z, p ); return true; } if( this.canHeat( blockID, metadata ) ) { - if(this.heat( blockID, p, metadata, w, x, y, z )) + if( this.heat( blockID, p, metadata, w, x, y, z ) ) { this.extractAEPower( item, 1600 ); return true; @@ -322,11 +303,13 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl if( hasFurnaceable && canFurnaceable ) { + if( !breakBlockWithCheck( w, p, x, y, z ) ) + return false; + this.extractAEPower( item, 1600 ); final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) ); w.playSoundEffect( x + 0.5D, y + 0.5D, z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F ); - if(!breakBlockWithCheck( w,p,x,y,z )) return false; if( or.getBlockItem() != null ) { w.setBlock( x, y, z, Block.getBlockFromItem( or.getBlockItem().getItem() ), or.getBlockItem().getItemDamage(), 3 ); @@ -366,11 +349,37 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl return false; } - private static final boolean breakBlockWithCheck(final World w,final EntityPlayer p,final int x,final int y,final int z) + private static class InWorldToolOperationIngredient { - BlockEvent.BreakEvent event = new BlockEvent.BreakEvent( x, y, z, w, w.getBlock( x, y, z ), w.getBlockMetadata( x, y, z ), p ); - MinecraftForge.EVENT_BUS.post( event ); - return !event.isCanceled() && w.setBlockToAir( x, y, z ); + private final Block blockID; + private final int metadata; + + public InWorldToolOperationIngredient( final Block blockID, final int metadata ) + { + this.blockID = blockID; + this.metadata = metadata; + } + + @Override + public int hashCode() + { + return this.blockID.hashCode() ^ this.metadata; + } + + @Override + public boolean equals( final Object obj ) + { + if( obj == null ) + { + return false; + } + if( this.getClass() != obj.getClass() ) + { + return false; + } + final InWorldToolOperationIngredient other = (InWorldToolOperationIngredient) obj; + return this.blockID == other.blockID && this.metadata == other.metadata; + } } }