2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.api.energy;
|
2013-04-23 21:36:43 +02:00
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
public class EnergizedItemManager
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Discharges an IEnergizedItem with the defined amount of energy.
|
|
|
|
* @param itemStack - ItemStack to discharge
|
|
|
|
* @param amount - amount of energy to discharge from the item, usually the total amount of energy needed in a TileEntity
|
|
|
|
* @return amount of energy discharged
|
|
|
|
*/
|
|
|
|
public static double discharge(ItemStack itemStack, double amount)
|
|
|
|
{
|
|
|
|
if(itemStack != null)
|
|
|
|
{
|
|
|
|
if(itemStack.getItem() instanceof IEnergizedItem)
|
|
|
|
{
|
|
|
|
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
if(energizedItem.canSend(itemStack))
|
|
|
|
{
|
|
|
|
double energyToUse = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getEnergy(itemStack), amount));
|
|
|
|
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToUse);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
return energyToUse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
/**
|
|
|
|
* Charges an IEnergizedItem with the defined amount of energy.
|
|
|
|
* @param itemStack - ItemStack to charge
|
|
|
|
* @param amount - amount of energy to charge the item with, usually the total amount of energy stored in a TileEntity
|
|
|
|
* @return amount of energy charged
|
|
|
|
*/
|
|
|
|
public static double charge(ItemStack itemStack, double amount)
|
|
|
|
{
|
|
|
|
if(itemStack != null)
|
|
|
|
{
|
|
|
|
if(itemStack.getItem() instanceof IEnergizedItem)
|
|
|
|
{
|
|
|
|
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
if(energizedItem.canReceive(itemStack))
|
|
|
|
{
|
|
|
|
double energyToSend = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getMaxEnergy(itemStack) - energizedItem.getEnergy(itemStack), amount));
|
|
|
|
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToSend);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
return energyToSend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-23 21:36:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|