Battery now charges/discharges items, fixed capacitor energy bar
This commit is contained in:
parent
bb9c3b6c32
commit
32a346633f
4 changed files with 33 additions and 1 deletions
Binary file not shown.
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.7 KiB |
|
@ -16,6 +16,8 @@ public interface IBattery
|
|||
public float getEnergyStored(ItemStack itemStack);
|
||||
|
||||
public float getMaxEnergyStored(ItemStack itemStack);
|
||||
|
||||
public float getTransfer(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* @param itemStack
|
||||
|
|
|
@ -24,7 +24,7 @@ public class ItemCapacitor extends ItemBase implements IBattery
|
|||
{
|
||||
super("capacitor", id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(1000);
|
||||
this.setMaxDamage(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,6 +59,12 @@ public class ItemCapacitor extends ItemBase implements IBattery
|
|||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTransfer(ItemStack itemStack)
|
||||
{
|
||||
return getMaxEnergyStored(itemStack)*0.05F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack itemStack)
|
||||
|
|
|
@ -69,6 +69,30 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
}
|
||||
}
|
||||
|
||||
if(structure.visibleInventory[1] != null)
|
||||
{
|
||||
ItemStack itemStack = structure.visibleInventory[1];
|
||||
IBattery battery = (IBattery)itemStack.getItem();
|
||||
|
||||
float energyStored = getMaxEnergyStored();
|
||||
float batteryNeeded = battery.getMaxEnergyStored(itemStack)-battery.getEnergyStored(itemStack);
|
||||
float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded));
|
||||
|
||||
battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) + removeEnergy(toGive, true));
|
||||
}
|
||||
|
||||
if(structure.visibleInventory[2] != null)
|
||||
{
|
||||
ItemStack itemStack = structure.visibleInventory[2];
|
||||
IBattery battery = (IBattery)itemStack.getItem();
|
||||
|
||||
float energyNeeded = getMaxEnergyStored()-getEnergyStored();
|
||||
float batteryStored = battery.getEnergyStored(itemStack);
|
||||
float toReceive = Math.min(energyNeeded, Math.min(battery.getTransfer(itemStack), batteryStored));
|
||||
|
||||
battery.setEnergyStored(itemStack, battery.getEnergyStored(itemStack) - addEnergy(toReceive, true));
|
||||
}
|
||||
|
||||
if(prevStructure != structure)
|
||||
{
|
||||
for(EntityPlayer player : playersUsing)
|
||||
|
|
Loading…
Add table
Reference in a new issue