Merge branch 'master' of https://bitbucket.org/calclavia/resonant-induction
This commit is contained in:
commit
db4af58b2b
3 changed files with 257 additions and 248 deletions
|
@ -21,141 +21,148 @@ import calclavia.lib.utility.LanguageUtility;
|
|||
@UniversalClass
|
||||
public class ItemBlockBattery extends ItemBlock implements IEnergyItem, IVoltageItem
|
||||
{
|
||||
public ItemBlockBattery(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(100);
|
||||
this.setNoRepair();
|
||||
}
|
||||
public ItemBlockBattery(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(100);
|
||||
this.setNoRepair();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
|
||||
{
|
||||
String color = "";
|
||||
long joules = this.getEnergy(itemStack);
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
|
||||
{
|
||||
String color = "";
|
||||
long joules = this.getEnergy(itemStack);
|
||||
|
||||
if (joules <= this.getEnergyCapacity(itemStack) / 3)
|
||||
{
|
||||
color = "\u00a74";
|
||||
}
|
||||
else if (joules > this.getEnergyCapacity(itemStack) * 2 / 3)
|
||||
{
|
||||
color = "\u00a72";
|
||||
}
|
||||
else
|
||||
{
|
||||
color = "\u00a76";
|
||||
}
|
||||
if (joules <= this.getEnergyCapacity(itemStack) / 3)
|
||||
{
|
||||
color = "\u00a74";
|
||||
}
|
||||
else if (joules > this.getEnergyCapacity(itemStack) * 2 / 3)
|
||||
{
|
||||
color = "\u00a72";
|
||||
}
|
||||
else
|
||||
{
|
||||
color = "\u00a76";
|
||||
}
|
||||
itemStack.getItemDamageForDisplay();
|
||||
list.add(LanguageUtility.getLocal("tooltip.battery.energy").replace("%0", color).replace("%1", EnumColor.GREY.toString()).replace("%v0", UnitDisplay.getDisplayShort(joules, Unit.JOULES)).replace("%v1", UnitDisplay.getDisplayShort(this.getEnergyCapacity(itemStack), Unit.JOULES)));
|
||||
}
|
||||
|
||||
list.add(LanguageUtility.getLocal("tooltip.battery.energy").replace("%0", color).replace("%1", EnumColor.GREY.toString()).replace("%v0", UnitDisplay.getDisplayShort(joules, Unit.JOULES)).replace("%v1", UnitDisplay.getDisplayShort(this.getEnergyCapacity(itemStack), Unit.JOULES)));
|
||||
}
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
||||
{
|
||||
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
||||
{
|
||||
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
|
||||
if (place)
|
||||
{
|
||||
TileBattery tileEntity = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
tileEntity.setEnergy(null, this.getEnergy(stack));
|
||||
}
|
||||
|
||||
if (place)
|
||||
{
|
||||
TileBattery tileEntity = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
tileEntity.setEnergy(null, this.getEnergy(stack));
|
||||
}
|
||||
return place;
|
||||
}
|
||||
|
||||
return place;
|
||||
}
|
||||
/** Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
|
||||
* not want this to happen! */
|
||||
@Override
|
||||
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
this.setEnergy(itemStack, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
|
||||
* not want this to happen!
|
||||
*/
|
||||
@Override
|
||||
public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
|
||||
{
|
||||
this.setEnergy(itemStack, 0);
|
||||
}
|
||||
@Override
|
||||
public long recharge(ItemStack itemStack, long energy, boolean doReceive)
|
||||
{
|
||||
long rejectedElectricity = Math.max((this.getEnergy(itemStack) + energy) - this.getEnergyCapacity(itemStack), 0);
|
||||
long energyToReceive = Math.min(energy - rejectedElectricity, getTransferRate(itemStack));
|
||||
|
||||
@Override
|
||||
public long recharge(ItemStack itemStack, long energy, boolean doReceive)
|
||||
{
|
||||
long rejectedElectricity = Math.max((this.getEnergy(itemStack) + energy) - this.getEnergyCapacity(itemStack), 0);
|
||||
long energyToReceive = Math.min(energy - rejectedElectricity, getTransferRate(itemStack));
|
||||
if (doReceive)
|
||||
{
|
||||
this.setEnergy(itemStack, this.getEnergy(itemStack) + energyToReceive);
|
||||
}
|
||||
|
||||
if (doReceive)
|
||||
{
|
||||
this.setEnergy(itemStack, this.getEnergy(itemStack) + energyToReceive);
|
||||
}
|
||||
return energyToReceive;
|
||||
}
|
||||
|
||||
return energyToReceive;
|
||||
}
|
||||
@Override
|
||||
public long discharge(ItemStack itemStack, long energy, boolean doTransfer)
|
||||
{
|
||||
long energyToExtract = Math.min(Math.min(this.getEnergy(itemStack), energy), getTransferRate(itemStack));
|
||||
|
||||
@Override
|
||||
public long discharge(ItemStack itemStack, long energy, boolean doTransfer)
|
||||
{
|
||||
long energyToExtract = Math.min(Math.min(this.getEnergy(itemStack), energy), getTransferRate(itemStack));
|
||||
if (doTransfer)
|
||||
{
|
||||
this.setEnergy(itemStack, this.getEnergy(itemStack) - energyToExtract);
|
||||
}
|
||||
|
||||
if (doTransfer)
|
||||
{
|
||||
this.setEnergy(itemStack, this.getEnergy(itemStack) - energyToExtract);
|
||||
}
|
||||
return energyToExtract;
|
||||
}
|
||||
|
||||
return energyToExtract;
|
||||
}
|
||||
@Override
|
||||
public long getVoltage(ItemStack itemStack)
|
||||
{
|
||||
return UniversalElectricity.DEFAULT_VOLTAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVoltage(ItemStack itemStack)
|
||||
{
|
||||
return UniversalElectricity.DEFAULT_VOLTAGE;
|
||||
}
|
||||
@Override
|
||||
public void setEnergy(ItemStack itemStack, long joules)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(ItemStack itemStack, long joules)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
long electricityStored = Math.max(Math.min(joules, this.getEnergyCapacity(itemStack)), 0);
|
||||
itemStack.getTagCompound().setLong("electricity", electricityStored);
|
||||
}
|
||||
|
||||
long electricityStored = Math.max(Math.min(joules, this.getEnergyCapacity(itemStack)), 0);
|
||||
itemStack.getTagCompound().setLong("electricity", electricityStored);
|
||||
itemStack.setItemDamage((int) (100 - ((double) electricityStored / (double) getEnergyCapacity(itemStack)) * 100));
|
||||
}
|
||||
public long getTransfer(ItemStack itemStack)
|
||||
{
|
||||
return this.getEnergyCapacity(itemStack) - this.getEnergy(itemStack);
|
||||
}
|
||||
|
||||
public long getTransfer(ItemStack itemStack)
|
||||
{
|
||||
return this.getEnergyCapacity(itemStack) - this.getEnergy(itemStack);
|
||||
}
|
||||
/** Gets the energy stored in the item. Energy is stored using item NBT */
|
||||
@Override
|
||||
public long getEnergy(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
/** Gets the energy stored in the item. Energy is stored using item NBT */
|
||||
@Override
|
||||
public long getEnergy(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
long energyStored = itemStack.getTagCompound().getLong("electricity");
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
long energyStored = itemStack.getTagCompound().getLong("electricity");
|
||||
itemStack.setItemDamage((int) (100 - ((double) energyStored / (double) getEnergyCapacity(itemStack)) * 100));
|
||||
return energyStored;
|
||||
}
|
||||
@Override
|
||||
public int getDisplayDamage(ItemStack stack)
|
||||
{
|
||||
return (int) (100 - ((double) this.getEnergy(stack) / (double) getEnergyCapacity(stack)) * 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyCapacity(ItemStack theItem)
|
||||
{
|
||||
return TileBattery.getEnergyForTier(theItem.getItemDamage());
|
||||
}
|
||||
@Override
|
||||
public long getEnergyCapacity(ItemStack theItem)
|
||||
{
|
||||
return TileBattery.getEnergyForTier(theItem.getItemDamage() + 1);
|
||||
}
|
||||
|
||||
public long getTransferRate(ItemStack itemStack)
|
||||
{
|
||||
return this.getEnergyCapacity(itemStack) / 100;
|
||||
}
|
||||
public long getTransferRate(ItemStack itemStack)
|
||||
{
|
||||
return this.getEnergyCapacity(itemStack) / 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this), 0));
|
||||
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this), this.getEnergyCapacity(new ItemStack(this))));
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||
{
|
||||
par3List.add(new ItemStack(this, 1, 0));
|
||||
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this, 1, 0), this.getEnergyCapacity(new ItemStack(this, 1, 0))));
|
||||
par3List.add(new ItemStack(this, 1, 1));
|
||||
par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this, 1, 1), this.getEnergyCapacity(new ItemStack(this, 1, 1))));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,169 +24,171 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
|
||||
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
|
||||
{
|
||||
/** The transfer rate **/
|
||||
public static final long DEFAULT_WATTAGE = (long) (getEnergyForTier(1) * 0.01);
|
||||
/** The transfer rate **/
|
||||
public static final long DEFAULT_WATTAGE = getEnergyForTier(1);
|
||||
|
||||
/** Voltage increases as series connection increases */
|
||||
public static final long DEFAULT_VOLTAGE = UniversalElectricity.DEFAULT_VOLTAGE;
|
||||
/** Voltage increases as series connection increases */
|
||||
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 int clientCells;
|
||||
public float clientMaxEnergy;
|
||||
public float clientEnergy;
|
||||
public int clientCells;
|
||||
public float clientMaxEnergy;
|
||||
|
||||
public TileBattery()
|
||||
{
|
||||
this.energy = new EnergyStorageHandler(getEnergyForTier(1));
|
||||
this.saveIOMap = true;
|
||||
}
|
||||
public TileBattery()
|
||||
{
|
||||
this.energy = new EnergyStorageHandler(getEnergyForTier(1));
|
||||
this.saveIOMap = true;
|
||||
}
|
||||
|
||||
public static long getEnergyForTier(int tier)
|
||||
{
|
||||
return (long) Math.pow(1000000, tier);
|
||||
}
|
||||
public static long getEnergyForTier(int tier)
|
||||
{
|
||||
if (tier <= 0)
|
||||
{
|
||||
tier = 1;
|
||||
}
|
||||
return (long) Math.pow(1000000, tier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
this.updateStructure();
|
||||
}
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
this.updateStructure();
|
||||
}
|
||||
|
||||
public void updateStructure()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||
public void updateStructure()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||
|
||||
if (tile instanceof TileBattery)
|
||||
{
|
||||
this.getNetwork().merge(((TileBattery) tile).getNetwork());
|
||||
}
|
||||
}
|
||||
if (tile instanceof TileBattery)
|
||||
{
|
||||
this.getNetwork().merge(((TileBattery) tile).getNetwork());
|
||||
}
|
||||
}
|
||||
|
||||
this.energy.setMaxTransfer(DEFAULT_WATTAGE * this.getNetwork().get().size());
|
||||
this.getNetwork().redistribute();
|
||||
}
|
||||
}
|
||||
this.energy.setMaxTransfer(DEFAULT_WATTAGE * this.getNetwork().get().size());
|
||||
this.getNetwork().redistribute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (this.produce() > 0)
|
||||
{
|
||||
this.getNetwork().redistribute();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (this.produce() > 0)
|
||||
{
|
||||
this.getNetwork().redistribute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
||||
{
|
||||
long returnValue = super.onReceiveEnergy(from, receive, doReceive);
|
||||
this.getNetwork().redistribute();
|
||||
return returnValue;
|
||||
}
|
||||
@Override
|
||||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
||||
{
|
||||
long returnValue = super.onReceiveEnergy(from, receive, doReceive);
|
||||
this.getNetwork().redistribute();
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
|
||||
{
|
||||
long returnValue = super.onExtractEnergy(from, extract, doExtract);
|
||||
this.getNetwork().redistribute();
|
||||
return returnValue;
|
||||
}
|
||||
@Override
|
||||
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
|
||||
{
|
||||
long returnValue = super.onExtractEnergy(from, extract, doExtract);
|
||||
this.getNetwork().redistribute();
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public void updateClient()
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
|
||||
}
|
||||
public void updateClient()
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllPlayers(ResonantInduction.PACKET_TILE.getPacket(this, getPacketData(0).toArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList getPacketData(int type)
|
||||
{
|
||||
ArrayList data = new ArrayList();
|
||||
return data;
|
||||
}
|
||||
@Override
|
||||
public ArrayList getPacketData(int type)
|
||||
{
|
||||
ArrayList data = new ArrayList();
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryStructure getNetwork()
|
||||
{
|
||||
if (this.structure == null)
|
||||
{
|
||||
this.structure = new BatteryStructure();
|
||||
this.structure.add(this);
|
||||
}
|
||||
@Override
|
||||
public BatteryStructure getNetwork()
|
||||
{
|
||||
if (this.structure == null)
|
||||
{
|
||||
this.structure = new BatteryStructure();
|
||||
this.structure.add(this);
|
||||
}
|
||||
|
||||
return this.structure;
|
||||
}
|
||||
return this.structure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(BatteryStructure structure)
|
||||
{
|
||||
this.structure = structure;
|
||||
}
|
||||
@Override
|
||||
public void setNetwork(BatteryStructure structure)
|
||||
{
|
||||
this.structure = structure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
Object[] connections = new Object[6];
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
Object[] connections = new Object[6];
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||
|
||||
if (tile instanceof TileBattery)
|
||||
{
|
||||
connections[dir.ordinal()] = tile;
|
||||
}
|
||||
}
|
||||
if (tile instanceof TileBattery)
|
||||
{
|
||||
connections[dir.ordinal()] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
return connections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.getNetwork().redistribute(this);
|
||||
this.getNetwork().split(this);
|
||||
super.invalidate();
|
||||
}
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.getNetwork().redistribute(this);
|
||||
this.getNetwork().split(this);
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVoltageOutput(ForgeDirection side)
|
||||
{
|
||||
return DEFAULT_VOLTAGE;
|
||||
}
|
||||
@Override
|
||||
public long getVoltageOutput(ForgeDirection side)
|
||||
{
|
||||
return DEFAULT_VOLTAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVoltageInput(ForgeDirection direction)
|
||||
{
|
||||
return DEFAULT_VOLTAGE;
|
||||
}
|
||||
@Override
|
||||
public long getVoltageInput(ForgeDirection direction)
|
||||
{
|
||||
return DEFAULT_VOLTAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrongVoltage(ForgeDirection direction, long voltage)
|
||||
{
|
||||
@Override
|
||||
public void onWrongVoltage(ForgeDirection direction, long voltage)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class TileSolarPanel extends TileElectrical
|
|||
{
|
||||
if (!(this.worldObj.isThundering() || this.worldObj.isRaining()))
|
||||
{
|
||||
this.energy.receiveEnergy(1, true);
|
||||
this.energy.receiveEnergy(5, true);
|
||||
this.produce();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue