fix a bug which can make entropy manipulator still consumes energy when it is prevented from melting a block.

This commit is contained in:
xsun2001 2018-02-18 20:20:36 +08:00
parent d65c652c7d
commit 27fecccec4
1 changed files with 56 additions and 47 deletions

View File

@ -84,6 +84,13 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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 class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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;
if( !breakBlockWithCheck( w, p, x, y, z ) )
return false;
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;
}
}
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 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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 @@ public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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 class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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 class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
{
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 class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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 class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockT
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;
}
}
}