Added set energy options

This commit is contained in:
Calclavia 2013-08-03 22:29:56 -04:00
parent f6ab9e1f9b
commit 4e4d6d2d18
2 changed files with 40 additions and 2 deletions

View file

@ -3,13 +3,23 @@
*/ */
package resonantinduction.api; package resonantinduction.api;
import net.minecraft.item.ItemStack;
/** /**
* TODO: Use UE interface after ModJAm
*
* @author Calclavia * @author Calclavia
* *
*/ */
public interface IBattery public interface IBattery
{ {
public float getEnergyStored(); public float getEnergyStored(ItemStack itemStack);
public float getMaxEnergyStored(); public float getMaxEnergyStored();
/**
* @param itemStack
* @param amount
*/
public void setEnergyStored(ItemStack itemStack, float amount);
} }

View file

@ -3,6 +3,9 @@
*/ */
package resonantinduction.battery; package resonantinduction.battery;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import resonantinduction.api.IBattery;
import resonantinduction.base.ItemBase; import resonantinduction.base.ItemBase;
/** /**
@ -11,7 +14,7 @@ import resonantinduction.base.ItemBase;
* @author Calclavia * @author Calclavia
* *
*/ */
public class ItemCapacitor extends ItemBase public class ItemCapacitor extends ItemBase implements IBattery
{ {
public ItemCapacitor(int id) public ItemCapacitor(int id)
{ {
@ -20,4 +23,29 @@ public class ItemCapacitor extends ItemBase
this.setMaxDamage(1000); this.setMaxDamage(1000);
} }
@Override
public void setEnergyStored(ItemStack itemStack, float amount)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
itemStack.getTagCompound().setFloat("energyStored", amount);
}
@Override
public float getEnergyStored(ItemStack itemStack)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
return itemStack.getTagCompound().getFloat("energyStored");
}
@Override
public float getMaxEnergyStored()
{
return 100;
}
} }