Fixed battery tiers

This commit is contained in:
Calclavia 2014-01-19 20:19:58 +08:00
parent 06a9c10788
commit a3122c7e0f
2 changed files with 280 additions and 255 deletions

View file

@ -55,7 +55,7 @@ public class ItemBlockBattery extends ItemBlock implements IEnergyItem, IVoltage
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, getTier(stack));
if (place)
{
@ -66,8 +66,10 @@ public class ItemBlockBattery extends ItemBlock implements IEnergyItem, IVoltage
return place;
}
/** Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
* not want this to happen! */
/**
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
* not want this to happen!
*/
@Override
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
{
@ -137,6 +139,26 @@ public class ItemBlockBattery extends ItemBlock implements IEnergyItem, IVoltage
return energyStored;
}
public ItemStack setTier(ItemStack itemStack, byte tier)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.getTagCompound().setByte("tier", tier);
return itemStack;
}
public byte getTier(ItemStack itemStack)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
return itemStack.getTagCompound().getByte("tier");
}
@Override
public int getDisplayDamage(ItemStack stack)
{
@ -158,11 +180,11 @@ public class ItemBlockBattery extends ItemBlock implements IEnergyItem, IVoltage
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this, 1, 0));
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this, 1, 0), this.getEnergyCapacity(new ItemStack(this, 1, 0))));
par3List.add(new ItemStack(this, 1, 1));
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this, 1, 1), this.getEnergyCapacity(new ItemStack(this, 1, 1))));
for (byte tier = 0; tier < 3; tier++)
{
par3List.add(setTier(new ItemStack(this, 1), tier));
par3List.add(setTier(CompatibilityModule.getItemWithCharge(new ItemStack(this, 1, 0), this.getEnergyCapacity(new ItemStack(this, 1, 0))), tier));
}
}
}

View file

@ -24,9 +24,11 @@ import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
/** A modular battery.
/**
* A modular battery.
*
* @author Calclavia */
* @author Calclavia
*/
public class TileBattery extends TileElectrical implements IConnector<BatteryStructure>, IVoltageInput, IVoltageOutput, IPacketSender, IPacketReceiver, IEnergyInterface, IEnergyContainer
{
/** The transfer rate **/
@ -49,13 +51,13 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryStr
this.saveIOMap = true;
}
/**
* @param tier - 0, 1, 2
* @return
*/
public static long getEnergyForTier(int tier)
{
if (tier <= 0)
{
tier = 1;
}
return (long) Math.pow(1000000, tier);
return (long) Math.pow(1000000, tier + 1);
}
@Override
@ -68,6 +70,7 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryStr
{
if (!this.worldObj.isRemote)
{
energy.setCapacity(getEnergyForTier(getBlockMetadata()));
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);