Fixed BatteryBox charge cap tiering
This commit is contained in:
parent
3c36d162e0
commit
85136fb62c
1 changed files with 135 additions and 133 deletions
|
@ -24,169 +24,171 @@ import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
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
|
public class TileBattery extends TileElectrical implements IConnector<BatteryStructure>, IVoltageInput, IVoltageOutput, IPacketSender, IPacketReceiver, IEnergyInterface, IEnergyContainer
|
||||||
{
|
{
|
||||||
/** The transfer rate **/
|
/** The transfer rate **/
|
||||||
public static final long DEFAULT_WATTAGE = (long) (getEnergyForTier(1) * 0.01);
|
public static final long DEFAULT_WATTAGE = getEnergyForTier(1);
|
||||||
|
|
||||||
/** Voltage increases as series connection increases */
|
/** Voltage increases as series connection increases */
|
||||||
public static final long DEFAULT_VOLTAGE = UniversalElectricity.DEFAULT_VOLTAGE;
|
public static final long DEFAULT_VOLTAGE = UniversalElectricity.DEFAULT_VOLTAGE;
|
||||||
|
|
||||||
private BatteryStructure structure;
|
private BatteryStructure structure;
|
||||||
|
|
||||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||||
|
|
||||||
public float clientEnergy;
|
public float clientEnergy;
|
||||||
public int clientCells;
|
public int clientCells;
|
||||||
public float clientMaxEnergy;
|
public float clientMaxEnergy;
|
||||||
|
|
||||||
public TileBattery()
|
public TileBattery()
|
||||||
{
|
{
|
||||||
this.energy = new EnergyStorageHandler(getEnergyForTier(1));
|
this.energy = new EnergyStorageHandler(getEnergyForTier(1));
|
||||||
this.saveIOMap = true;
|
this.saveIOMap = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getEnergyForTier(int tier)
|
public static long getEnergyForTier(int tier)
|
||||||
{
|
{
|
||||||
return (long) Math.pow(1000000, tier);
|
if (tier <= 0)
|
||||||
}
|
{
|
||||||
|
tier = 1;
|
||||||
|
}
|
||||||
|
return (long) Math.pow(1000000, tier);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initiate()
|
public void initiate()
|
||||||
{
|
{
|
||||||
this.updateStructure();
|
this.updateStructure();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStructure()
|
public void updateStructure()
|
||||||
{
|
{
|
||||||
if (!this.worldObj.isRemote)
|
if (!this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||||
|
|
||||||
if (tile instanceof TileBattery)
|
if (tile instanceof TileBattery)
|
||||||
{
|
{
|
||||||
this.getNetwork().merge(((TileBattery) tile).getNetwork());
|
this.getNetwork().merge(((TileBattery) tile).getNetwork());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.energy.setMaxTransfer(DEFAULT_WATTAGE * this.getNetwork().get().size());
|
this.energy.setMaxTransfer(DEFAULT_WATTAGE * this.getNetwork().get().size());
|
||||||
this.getNetwork().redistribute();
|
this.getNetwork().redistribute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if (!this.worldObj.isRemote)
|
if (!this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
if (this.produce() > 0)
|
if (this.produce() > 0)
|
||||||
{
|
{
|
||||||
this.getNetwork().redistribute();
|
this.getNetwork().redistribute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
||||||
{
|
{
|
||||||
long returnValue = super.onReceiveEnergy(from, receive, doReceive);
|
long returnValue = super.onReceiveEnergy(from, receive, doReceive);
|
||||||
this.getNetwork().redistribute();
|
this.getNetwork().redistribute();
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
|
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
|
||||||
{
|
{
|
||||||
long returnValue = super.onExtractEnergy(from, extract, doExtract);
|
long returnValue = super.onExtractEnergy(from, extract, doExtract);
|
||||||
this.getNetwork().redistribute();
|
this.getNetwork().redistribute();
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateClient()
|
public void updateClient()
|
||||||
{
|
{
|
||||||
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
|
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArrayList getPacketData(int type)
|
public ArrayList getPacketData(int type)
|
||||||
{
|
{
|
||||||
ArrayList data = new ArrayList();
|
ArrayList data = new ArrayList();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BatteryStructure getNetwork()
|
public BatteryStructure getNetwork()
|
||||||
{
|
{
|
||||||
if (this.structure == null)
|
if (this.structure == null)
|
||||||
{
|
{
|
||||||
this.structure = new BatteryStructure();
|
this.structure = new BatteryStructure();
|
||||||
this.structure.add(this);
|
this.structure.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.structure;
|
return this.structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNetwork(BatteryStructure structure)
|
public void setNetwork(BatteryStructure structure)
|
||||||
{
|
{
|
||||||
this.structure = structure;
|
this.structure = structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getConnections()
|
public Object[] getConnections()
|
||||||
{
|
{
|
||||||
Object[] connections = new Object[6];
|
Object[] connections = new Object[6];
|
||||||
|
|
||||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||||
|
|
||||||
if (tile instanceof TileBattery)
|
if (tile instanceof TileBattery)
|
||||||
{
|
{
|
||||||
connections[dir.ordinal()] = tile;
|
connections[dir.ordinal()] = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate()
|
public void invalidate()
|
||||||
{
|
{
|
||||||
this.getNetwork().redistribute(this);
|
this.getNetwork().redistribute(this);
|
||||||
this.getNetwork().split(this);
|
this.getNetwork().split(this);
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getVoltageOutput(ForgeDirection side)
|
public long getVoltageOutput(ForgeDirection side)
|
||||||
{
|
{
|
||||||
return DEFAULT_VOLTAGE;
|
return DEFAULT_VOLTAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getVoltageInput(ForgeDirection direction)
|
public long getVoltageInput(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
return DEFAULT_VOLTAGE;
|
return DEFAULT_VOLTAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWrongVoltage(ForgeDirection direction, long voltage)
|
public void onWrongVoltage(ForgeDirection direction, long voltage)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue