Added capacitor charge to creative

This commit is contained in:
Calclavia 2013-08-05 00:58:59 -04:00
parent 6537a7b7ae
commit aef0e8f44e

View file

@ -3,6 +3,10 @@
*/ */
package resonantinduction.battery; package resonantinduction.battery;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import resonantinduction.api.IBattery; import resonantinduction.api.IBattery;
@ -23,6 +27,13 @@ public class ItemCapacitor extends ItemBase implements IBattery
this.setMaxDamage(1000); this.setMaxDamage(1000);
} }
@Override
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
double energyStored = this.getEnergyStored(itemStack);
par3List.add("Energy: " + energyStored + " J");
}
@Override @Override
public void setEnergyStored(ItemStack itemStack, float amount) public void setEnergyStored(ItemStack itemStack, float amount)
{ {
@ -31,6 +42,7 @@ public class ItemCapacitor extends ItemBase implements IBattery
itemStack.setTagCompound(new NBTTagCompound()); itemStack.setTagCompound(new NBTTagCompound());
} }
itemStack.getTagCompound().setFloat("energyStored", amount); itemStack.getTagCompound().setFloat("energyStored", amount);
itemStack.setItemDamage((int) (amount / this.getMaxEnergyStored()));
} }
@Override @Override
@ -48,4 +60,16 @@ public class ItemCapacitor extends ItemBase implements IBattery
{ {
return 100; return 100;
} }
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
ItemStack chargedStack = new ItemStack(par1, 1, 0);
this.setEnergyStored(chargedStack, this.getMaxEnergyStored());
par3List.add(chargedStack);
ItemStack unchargedStack = new ItemStack(par1, 1, 0);
this.setEnergyStored(unchargedStack, 0);
par3List.add(unchargedStack);
}
} }