Added ability to left/right click capacitors into battery
This commit is contained in:
parent
fd8806ffee
commit
19208dd01a
2 changed files with 57 additions and 30 deletions
|
@ -14,6 +14,7 @@ import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.ResonantInduction;
|
import resonantinduction.ResonantInduction;
|
||||||
import resonantinduction.api.IBattery;
|
import resonantinduction.api.IBattery;
|
||||||
import resonantinduction.base.BlockBase;
|
import resonantinduction.base.BlockBase;
|
||||||
|
import resonantinduction.base.ListUtil;
|
||||||
import resonantinduction.render.BlockRenderingHandler;
|
import resonantinduction.render.BlockRenderingHandler;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
@ -32,6 +33,21 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
this.func_111022_d(ResonantInduction.PREFIX + "machine");
|
this.func_111022_d(ResonantInduction.PREFIX + "machine");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer entityPlayer)
|
||||||
|
{
|
||||||
|
if (!entityPlayer.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
ItemStack itemStack = ListUtil.getTop(tileEntity.structure.inventory);
|
||||||
|
|
||||||
|
if (tileEntity.structure.inventory.remove(itemStack))
|
||||||
|
{
|
||||||
|
entityPlayer.dropPlayerItem(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick)
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float xClick, float yClick, float zClick)
|
||||||
{
|
{
|
||||||
|
@ -47,8 +63,18 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
if (side != 0 && side != 1)
|
if (side != 0 && side != 1)
|
||||||
{
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
|
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
tileEntity.structure.inventory.add(entityPlayer.getCurrentEquippedItem());
|
||||||
|
tileEntity.structure.sortInventory();
|
||||||
|
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Place cells into block. 2 Dimensional Click Zone
|
* Place cells into block. 2 Dimensional Click Zone.
|
||||||
|
*
|
||||||
|
* TODO: In the future.
|
||||||
*/
|
*/
|
||||||
float xHit = 0;
|
float xHit = 0;
|
||||||
float yHit = yClick;
|
float yHit = yClick;
|
||||||
|
@ -93,12 +119,13 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z);
|
entityPlayer.openGui(ResonantInduction.INSTNACE, 0, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
@ -143,31 +170,31 @@ public class BlockBattery extends BlockBase implements ITileEntityProvider
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z)
|
public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if(!world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
|
if (!world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
|
||||||
{
|
{
|
||||||
TileEntityBattery tileEntity = (TileEntityBattery)world.getBlockTileEntity(x, y, z);
|
TileEntityBattery tileEntity = (TileEntityBattery) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
if(!tileEntity.structure.isMultiblock)
|
if (!tileEntity.structure.isMultiblock)
|
||||||
{
|
{
|
||||||
for(ItemStack itemStack : tileEntity.structure.inventory)
|
for (ItemStack itemStack : tileEntity.structure.inventory)
|
||||||
{
|
{
|
||||||
float motion = 0.7F;
|
float motion = 0.7F;
|
||||||
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||||
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||||
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||||
|
|
||||||
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, itemStack);
|
EntityItem entityItem = new EntityItem(world, x + motionX, y + motionY, z + motionZ, itemStack);
|
||||||
|
|
||||||
world.spawnEntityInWorld(entityItem);
|
world.spawnEntityInWorld(entityItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.removeBlockByPlayer(world, player, x, y, z);
|
return super.removeBlockByPlayer(world, player, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class BlockMultimeter extends BlockBase implements ITileEntityProvider
|
||||||
{
|
{
|
||||||
int metadata = par1World.getBlockMetadata(par2, par3, par4) & 7;
|
int metadata = par1World.getBlockMetadata(par2, par3, par4) & 7;
|
||||||
float thickness = 0.15f;
|
float thickness = 0.15f;
|
||||||
System.out.println(metadata);
|
|
||||||
if (metadata == 0)
|
if (metadata == 0)
|
||||||
{
|
{
|
||||||
this.setBlockBounds(0, 0, 0, 1, thickness, 1);
|
this.setBlockBounds(0, 0, 0, 1, thickness, 1);
|
||||||
|
|
Loading…
Reference in a new issue