2013-12-27 23:59:59 +01:00
|
|
|
package appeng.items.tools.powered;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
2014-02-27 08:10:45 +01:00
|
|
|
import net.minecraft.block.BlockDispenser;
|
2014-02-15 04:16:44 +01:00
|
|
|
import net.minecraft.block.BlockTNT;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.FurnaceRecipes;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2014-02-15 04:16:44 +01:00
|
|
|
import appeng.block.misc.BlockTinyTNT;
|
2014-02-09 06:08:27 +01:00
|
|
|
import appeng.core.AEConfig;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.features.AEFeature;
|
2014-05-26 10:26:37 +02:00
|
|
|
import appeng.hooks.DispenserBlockTool;
|
|
|
|
import appeng.hooks.IBlockTool;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.items.tools.powered.powersink.AEBasePoweredItem;
|
|
|
|
import appeng.util.InWorldToolOperationResult;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2014-05-26 10:26:37 +02:00
|
|
|
public class ToolEntropyManipulator extends AEBasePoweredItem implements IBlockTool
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
static class Combo
|
|
|
|
{
|
|
|
|
|
|
|
|
final public Block blk;
|
|
|
|
final public int meta;
|
|
|
|
|
|
|
|
public Combo(Block b, int m) {
|
|
|
|
blk = b;
|
|
|
|
meta = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
return blk.hashCode() ^ meta;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj)
|
|
|
|
{
|
|
|
|
return blk == ((Combo) obj).blk && meta == ((Combo) obj).meta;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static private Hashtable<Combo, InWorldToolOperationResult> heatUp;
|
|
|
|
static private Hashtable<Combo, InWorldToolOperationResult> coolDown;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
static public void heat(Block BlockID, int Metadata, World w, int x, int y, int z)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( r == null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( r.BlockItem != null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( r.Drops != null )
|
|
|
|
{
|
|
|
|
Platform.spawnDrops( w, x, y, z, r.Drops );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
static public boolean canHeat(Block BlockID, int Metadata)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
InWorldToolOperationResult r = heatUp.get( new Combo( BlockID, Metadata ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( r == null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
r = heatUp.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return r != null;
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
static public void cool(Block BlockID, int Metadata, World w, int x, int y, int z)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( r == null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( r.BlockItem != null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Block.getBlockFromItem( r.BlockItem.getItem() ), r.BlockItem.getItemDamage(), 3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( r.Drops != null )
|
|
|
|
{
|
|
|
|
Platform.spawnDrops( w, x, y, z, r.Drops );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
static public boolean canCool(Block BlockID, int Metadata)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
InWorldToolOperationResult r = coolDown.get( new Combo( BlockID, Metadata ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( r == null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
r = coolDown.get( new Combo( BlockID, OreDictionary.WILDCARD_VALUE ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return r != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ToolEntropyManipulator() {
|
|
|
|
super( ToolEntropyManipulator.class, null );
|
|
|
|
setfeature( EnumSet.of( AEFeature.EntropyManipulator, AEFeature.PoweredTools ) );
|
2014-02-09 06:08:27 +01:00
|
|
|
maxStoredPower = AEConfig.instance.manipulator_battery;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
coolDown = new Hashtable<Combo, InWorldToolOperationResult>();
|
|
|
|
coolDown.put( new Combo( Blocks.stone, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.cobblestone ) ) );
|
|
|
|
coolDown.put( new Combo( Blocks.stonebrick, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.stonebrick, 1, 2 ) ) );
|
|
|
|
coolDown.put( new Combo( Blocks.lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
|
|
|
|
coolDown.put( new Combo( Blocks.flowing_lava, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.obsidian ) ) );
|
|
|
|
coolDown.put( new Combo( Blocks.grass, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.dirt ) ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
List<ItemStack> snowBalls = new ArrayList();
|
2014-02-09 02:34:52 +01:00
|
|
|
snowBalls.add( new ItemStack( Items.snowball ) );
|
|
|
|
coolDown.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( null, snowBalls ) );
|
|
|
|
coolDown.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.ice ) ) );
|
|
|
|
|
|
|
|
heatUp = new Hashtable<Combo, InWorldToolOperationResult>();
|
|
|
|
heatUp.put( new Combo( Blocks.ice, 0 ), new InWorldToolOperationResult( new ItemStack( Blocks.water ) ) );
|
|
|
|
heatUp.put( new Combo( Blocks.flowing_water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
|
|
|
|
heatUp.put( new Combo( Blocks.water, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult() );
|
|
|
|
heatUp.put( new Combo( Blocks.snow, OreDictionary.WILDCARD_VALUE ), new InWorldToolOperationResult( new ItemStack( Blocks.flowing_water ) ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-02-27 08:10:45 +01:00
|
|
|
@Override
|
|
|
|
public void postInit()
|
|
|
|
{
|
|
|
|
super.postInit();
|
2014-05-26 10:26:37 +02:00
|
|
|
BlockDispenser.dispenseBehaviorRegistry.putObject( this, new DispenserBlockTool() );
|
2014-02-27 08:10:45 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public boolean hitEntity(ItemStack item, EntityLivingBase target, EntityLivingBase hitter)
|
|
|
|
{
|
|
|
|
if ( this.getAECurrentPower( item ) > 1600 )
|
|
|
|
{
|
|
|
|
extractAEPower( item, 1600 );
|
|
|
|
target.setFire( 8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack item, World w, EntityPlayer p)
|
|
|
|
{
|
|
|
|
MovingObjectPosition target = this.getMovingObjectPositionFromPlayer( w, p, true );
|
|
|
|
|
|
|
|
if ( target == null )
|
|
|
|
return item;
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( target.typeOfHit == MovingObjectType.BLOCK )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int x = target.blockX;
|
|
|
|
int y = target.blockY;
|
|
|
|
int z = target.blockZ;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
if ( w.getBlock( x, y, z ).getMaterial() == Material.lava || w.getBlock( x, y, z ).getMaterial() == Material.water )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( w.canMineBlock( p, x, y, z ) )
|
|
|
|
{
|
|
|
|
onItemUse( item, p, w, x, y, z, 0, 0.0F, 0.0F, 0.0F );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack item, EntityPlayer p, World w, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
|
|
|
if ( this.getAECurrentPower( item ) > 1600 )
|
|
|
|
{
|
|
|
|
if ( !p.canPlayerEdit( x, y, z, side, item ) )
|
|
|
|
return false;
|
|
|
|
|
2014-02-15 04:16:44 +01:00
|
|
|
Block Blk = w.getBlock( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
int Metadata = w.getBlockMetadata( x, y, z );
|
|
|
|
|
|
|
|
if ( p.isSneaking() )
|
|
|
|
{
|
2014-02-15 04:16:44 +01:00
|
|
|
if ( canCool( Blk, Metadata ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
extractAEPower( item, 1600 );
|
2014-02-15 04:16:44 +01:00
|
|
|
cool( Blk, Metadata, w, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-15 04:16:44 +01:00
|
|
|
if ( Blk instanceof BlockTNT )
|
|
|
|
{
|
|
|
|
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
|
|
|
((BlockTNT) Blk).func_150114_a( w, x, y, z, 1, p );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Blk instanceof BlockTinyTNT )
|
|
|
|
{
|
|
|
|
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
|
|
|
((BlockTinyTNT) Blk).startFuse( w, x, y, z, p );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( canHeat( Blk, Metadata ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
extractAEPower( item, 1600 );
|
2014-02-15 04:16:44 +01:00
|
|
|
heat( Blk, Metadata, w, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack[] stack = Platform.getBlockDrops( w, x, y, z );
|
|
|
|
List<ItemStack> out = new ArrayList<ItemStack>();
|
|
|
|
boolean hasFurnaceable = false;
|
|
|
|
boolean canFurnaceable = true;
|
|
|
|
|
|
|
|
for (ItemStack i : stack)
|
|
|
|
{
|
|
|
|
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult( i );
|
|
|
|
|
|
|
|
if ( result != null )
|
|
|
|
{
|
|
|
|
if ( result.getItem() instanceof ItemBlock )
|
|
|
|
{
|
2014-02-15 04:16:44 +01:00
|
|
|
if ( Block.getBlockFromItem( (ItemBlock) result.getItem() ) == Blk && result.getItem().getDamage( result ) == Metadata )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
canFurnaceable = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hasFurnaceable = true;
|
|
|
|
out.add( result );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
canFurnaceable = false;
|
|
|
|
out.add( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasFurnaceable && canFurnaceable )
|
|
|
|
{
|
|
|
|
extractAEPower( item, 1600 );
|
|
|
|
InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
|
|
|
|
w.playSoundEffect( (double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
|
|
|
|
|
|
|
|
if ( or.BlockItem == null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Block.getBlockFromItem( or.BlockItem.getItem() ), or.BlockItem.getItemDamage(), 3 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( or.Drops != null )
|
|
|
|
{
|
|
|
|
Platform.spawnDrops( w, x, y, z, or.Drops );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ForgeDirection dir = ForgeDirection.getOrientation( side );
|
|
|
|
x += dir.offsetX;
|
|
|
|
y += dir.offsetY;
|
|
|
|
z += dir.offsetZ;
|
|
|
|
|
|
|
|
if ( !p.canPlayerEdit( x, y, z, side, item ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( w.isAirBlock( x, y, z ) )
|
|
|
|
{
|
2014-01-30 19:50:49 +01:00
|
|
|
extractAEPower( item, 1600 );
|
2013-12-27 23:59:59 +01:00
|
|
|
w.playSoundEffect( (double) x + 0.5D, (double) y + 0.5D, (double) z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );
|
2014-02-09 02:34:52 +01:00
|
|
|
w.setBlock( x, y, z, Blocks.fire );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|