Fixed shift + click battery with wrench
This commit is contained in:
parent
fabbf289b0
commit
da2bd6f54b
1 changed files with 106 additions and 118 deletions
|
@ -18,144 +18,132 @@ import universalelectricity.api.CompatibilityModule;
|
|||
import universalelectricity.api.UniversalElectricity;
|
||||
import calclavia.lib.prefab.block.BlockSidedIO;
|
||||
import calclavia.lib.render.block.BlockRenderingHandler;
|
||||
import calclavia.lib.utility.inventory.InventoryUtility;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* A block that detects power.
|
||||
/** A block that detects power.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
* @author Calclavia */
|
||||
public class BlockBattery extends BlockSidedIO implements ITileEntityProvider
|
||||
{
|
||||
public BlockBattery(int id)
|
||||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
setTextureName(Reference.PREFIX + "material_metal_side");
|
||||
}
|
||||
public BlockBattery(int id)
|
||||
{
|
||||
super(id, UniversalElectricity.machine);
|
||||
setTextureName(Reference.PREFIX + "material_metal_side");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileEnergyDistribution distribution = (TileEnergyDistribution) world.getBlockTileEntity(x, y, z);
|
||||
distribution.updateStructure();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileEnergyDistribution distribution = (TileEnergyDistribution) world.getBlockTileEntity(x, y, z);
|
||||
distribution.updateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (!world.isRemote && tileEntity instanceof TileEnergyDistribution)
|
||||
{
|
||||
TileEnergyDistribution distribution = (TileEnergyDistribution) tileEntity;
|
||||
distribution.updateStructure();
|
||||
}
|
||||
}
|
||||
if (!world.isRemote && tileEntity instanceof TileEnergyDistribution)
|
||||
{
|
||||
TileEnergyDistribution distribution = (TileEnergyDistribution) tileEntity;
|
||||
distribution.updateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemStack)
|
||||
{
|
||||
if (!world.isRemote && itemStack.getItem() instanceof ItemBlockBattery)
|
||||
{
|
||||
ItemBlockBattery itemBlock = (ItemBlockBattery) itemStack.getItem();
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
battery.energy.setCapacity(TileBattery.getEnergyForTier(ItemBlockBattery.getTier(itemStack)));
|
||||
battery.energy.setEnergy(itemBlock.getEnergy(itemStack));
|
||||
battery.updateStructure();
|
||||
world.setBlockMetadataWithNotify(x, y, z, ItemBlockBattery.getTier(itemStack), 3);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemStack)
|
||||
{
|
||||
if (!world.isRemote && itemStack.getItem() instanceof ItemBlockBattery)
|
||||
{
|
||||
ItemBlockBattery itemBlock = (ItemBlockBattery) itemStack.getItem();
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
battery.energy.setCapacity(TileBattery.getEnergyForTier(ItemBlockBattery.getTier(itemStack)));
|
||||
battery.energy.setEnergy(itemBlock.getEnergy(itemStack));
|
||||
battery.updateStructure();
|
||||
world.setBlockMetadataWithNotify(x, y, z, ItemBlockBattery.getTier(itemStack), 3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
|
||||
world.setBlock(x, y, z, 0);
|
||||
}
|
||||
@Override
|
||||
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
InventoryUtility.dropBlockAsItem(world, x, y, z, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily "cheat" var for dropping with damage.
|
||||
*/
|
||||
ItemStack dropStack = null;
|
||||
@Override
|
||||
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
|
||||
{
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileBattery)
|
||||
{
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
ItemBlockBattery itemBlock = (ItemBlockBattery) itemStack.getItem();
|
||||
ItemBlockBattery.setTier(itemStack, (byte) world.getBlockMetadata(x, y, z));
|
||||
itemBlock.setEnergy(itemStack, battery.energy.getEnergy());
|
||||
}
|
||||
ret.add(itemStack);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileBattery)
|
||||
{
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
ItemBlockBattery itemBlock = (ItemBlockBattery) itemStack.getItem();
|
||||
ItemBlockBattery.setTier(itemStack, (byte) world.getBlockMetadata(x, y, z));
|
||||
itemBlock.setEnergy(itemStack, battery.energy.getEnergy());
|
||||
}
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dropStack = itemStack;
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
}
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
|
||||
{
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
ret.add(dropStack);
|
||||
return ret;
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getRenderType()
|
||||
{
|
||||
return BlockRenderingHandler.INSTANCE.getRenderId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world)
|
||||
{
|
||||
return new TileBattery();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
|
||||
{
|
||||
int id = idPicked(world, x, y, z);
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getRenderType()
|
||||
{
|
||||
return BlockRenderingHandler.INSTANCE.getRenderId();
|
||||
}
|
||||
if (id == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world)
|
||||
{
|
||||
return new TileBattery();
|
||||
}
|
||||
Item item = Item.itemsList[id];
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
|
||||
{
|
||||
int id = idPicked(world, x, y, z);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Item item = Item.itemsList[id];
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
return CompatibilityModule.getItemWithCharge(ItemBlockBattery.setTier(new ItemStack(id, 1, 0), (byte) world.getBlockMetadata(x, y, z)), battery.energy.getEnergy());
|
||||
}
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
return CompatibilityModule.getItemWithCharge(ItemBlockBattery.setTier(new ItemStack(id, 1, 0), (byte) world.getBlockMetadata(x, y, z)), battery.energy.getEnergy());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue