Skip to content

Commit

Permalink
fix a bug which can make entropy manipulator still consumes energy wh…
Browse files Browse the repository at this point in the history
…en it is prevented from melting a block.
  • Loading branch information
xsun2001 committed Feb 18, 2018
1 parent d65c652 commit 27feccc
Showing 1 changed file with 56 additions and 47 deletions.
103 changes: 56 additions & 47 deletions src/main/java/appeng/items/tools/powered/ToolEntropyManipulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,51 +84,28 @@ 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()
{
super.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 ) );
Expand All @@ -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() );
Expand All @@ -160,16 +136,18 @@ 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 )
{
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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
}

}

0 comments on commit 27feccc

Please sign in to comment.