2014-01-08 02:55:50 +01:00
|
|
|
package mekanism.common.tile;
|
2012-10-28 23:18:23 +01:00
|
|
|
|
2015-03-03 17:41:46 +01:00
|
|
|
import ic2.api.energy.EnergyNet;
|
|
|
|
import ic2.api.energy.event.EnergyTileLoadEvent;
|
|
|
|
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
|
|
|
import ic2.api.energy.tile.IEnergyConductor;
|
|
|
|
import ic2.api.energy.tile.IEnergySink;
|
|
|
|
import ic2.api.energy.tile.IEnergySource;
|
|
|
|
import ic2.api.energy.tile.IEnergyTile;
|
|
|
|
import ic2.api.tile.IEnergyStorage;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-02-27 02:21:30 +01:00
|
|
|
import java.util.ArrayList;
|
2013-03-18 17:23:57 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2013-12-20 22:09:09 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2014-08-01 01:58:12 +02:00
|
|
|
import mekanism.api.MekanismConfig.general;
|
2013-11-27 19:24:13 +01:00
|
|
|
import mekanism.api.energy.ICableOutputter;
|
|
|
|
import mekanism.api.energy.IStrictEnergyAcceptor;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.api.energy.IStrictEnergyStorage;
|
2014-01-05 08:24:06 +01:00
|
|
|
import mekanism.api.transmitters.IGridTransmitter;
|
2013-11-06 02:07:38 +01:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
2013-04-13 16:33:37 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-11-27 19:24:13 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2013-04-13 16:33:37 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2014-06-02 16:52:13 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2015-03-03 17:41:46 +01:00
|
|
|
import cofh.api.energy.IEnergyHandler;
|
2014-10-17 18:00:39 +02:00
|
|
|
import cpw.mods.fml.common.Optional.Interface;
|
|
|
|
import cpw.mods.fml.common.Optional.InterfaceList;
|
|
|
|
import cpw.mods.fml.common.Optional.Method;
|
|
|
|
|
2014-06-26 02:10:53 +02:00
|
|
|
@InterfaceList({
|
2014-09-30 23:08:40 +02:00
|
|
|
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
|
2014-11-11 13:50:48 +01:00
|
|
|
@Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = "IC2"),
|
2014-09-30 23:08:40 +02:00
|
|
|
@Interface(iface = "ic2.api.tile.IEnergyStorage", modid = "IC2"),
|
2014-06-26 02:10:53 +02:00
|
|
|
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
|
|
|
|
})
|
2015-03-03 17:41:46 +01:00
|
|
|
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter
|
2012-10-28 23:18:23 +01:00
|
|
|
{
|
|
|
|
/** How much energy is stored in this block. */
|
2012-11-25 16:45:00 +01:00
|
|
|
public double electricityStored;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2012-10-28 23:18:23 +01:00
|
|
|
/** Maximum amount of energy this machine can hold. */
|
2014-09-06 22:14:49 +02:00
|
|
|
public double BASE_MAX_ENERGY;
|
|
|
|
|
|
|
|
/** Actual maximum energy storage, including upgrades */
|
|
|
|
public double maxEnergy;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-30 23:14:16 +02:00
|
|
|
/** Is this registered with IC2 */
|
|
|
|
public boolean ic2Registered = false;
|
|
|
|
|
2012-10-28 23:18:23 +01:00
|
|
|
/**
|
|
|
|
* The base of all blocks that deal with electricity. It has a facing state, initialized state,
|
|
|
|
* and a current amount of stored energy.
|
|
|
|
* @param name - full name of this block
|
2014-09-06 22:14:49 +02:00
|
|
|
* @param baseMaxEnergy - how much energy this block can store
|
2012-10-28 23:18:23 +01:00
|
|
|
*/
|
2014-09-06 22:14:49 +02:00
|
|
|
public TileEntityElectricBlock(String name, double baseMaxEnergy)
|
2012-10-28 23:18:23 +01:00
|
|
|
{
|
2012-11-21 16:14:35 +01:00
|
|
|
super(name);
|
2014-09-06 22:14:49 +02:00
|
|
|
BASE_MAX_ENERGY = baseMaxEnergy;
|
|
|
|
maxEnergy = BASE_MAX_ENERGY;
|
2012-10-28 23:18:23 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2013-11-03 22:54:33 +01:00
|
|
|
public void register()
|
2012-12-19 21:23:55 +01:00
|
|
|
{
|
2014-06-26 19:16:33 +02:00
|
|
|
if(!worldObj.isRemote)
|
2012-12-19 21:23:55 +01:00
|
|
|
{
|
2014-09-30 23:14:16 +02:00
|
|
|
TileEntity registered = EnergyNet.instance.getTileEntity(worldObj, xCoord, yCoord, zCoord);
|
2014-10-17 18:00:39 +02:00
|
|
|
|
2014-09-30 23:14:16 +02:00
|
|
|
if(registered != this)
|
2013-10-09 00:06:25 +02:00
|
|
|
{
|
2014-09-30 23:14:16 +02:00
|
|
|
if(registered instanceof IEnergyTile)
|
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)registered));
|
|
|
|
}
|
|
|
|
else if(registered == null)
|
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
|
|
|
ic2Registered = true;
|
|
|
|
}
|
2013-10-09 00:06:25 +02:00
|
|
|
}
|
2013-11-03 22:54:33 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-26 19:16:33 +02:00
|
|
|
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-03-08 04:00:35 +01:00
|
|
|
public void deregister()
|
|
|
|
{
|
2014-06-26 19:16:33 +02:00
|
|
|
if(!worldObj.isRemote)
|
2014-03-08 04:00:35 +01:00
|
|
|
{
|
2014-09-30 23:14:16 +02:00
|
|
|
TileEntity registered = EnergyNet.instance.getTileEntity(worldObj, xCoord, yCoord, zCoord);
|
2014-10-17 18:00:39 +02:00
|
|
|
|
2014-09-30 23:14:16 +02:00
|
|
|
if(registered instanceof IEnergyTile)
|
2014-03-08 04:00:35 +01:00
|
|
|
{
|
2014-09-30 23:14:16 +02:00
|
|
|
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)registered));
|
2014-03-08 04:00:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-03 22:54:33 +01:00
|
|
|
@Override
|
2013-12-03 17:10:14 +01:00
|
|
|
public void onUpdate()
|
|
|
|
{
|
2014-09-30 23:14:16 +02:00
|
|
|
if(!ic2Registered && MekanismUtils.useIC2())
|
2014-10-17 18:00:39 +02:00
|
|
|
{
|
2014-09-30 23:14:16 +02:00
|
|
|
register();
|
2014-10-17 18:00:39 +02:00
|
|
|
}
|
2013-12-03 17:10:14 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-29 23:17:01 +01:00
|
|
|
public EnumSet<ForgeDirection> getOutputtingSides()
|
2013-11-02 17:00:29 +01:00
|
|
|
{
|
2013-11-30 06:28:02 +01:00
|
|
|
return EnumSet.noneOf(ForgeDirection.class);
|
2013-11-02 17:00:29 +01:00
|
|
|
}
|
2013-03-18 17:23:57 +01:00
|
|
|
|
|
|
|
protected EnumSet<ForgeDirection> getConsumingSides()
|
|
|
|
{
|
2013-11-30 18:29:49 +01:00
|
|
|
EnumSet set = EnumSet.allOf(ForgeDirection.class);
|
|
|
|
set.remove(ForgeDirection.UNKNOWN);
|
|
|
|
return set;
|
2013-03-18 17:23:57 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-02 17:00:29 +01:00
|
|
|
public double getMaxOutput()
|
2013-03-18 17:23:57 +01:00
|
|
|
{
|
2013-11-02 17:00:29 +01:00
|
|
|
return 0;
|
2013-03-18 17:23:57 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-03-18 17:23:57 +01:00
|
|
|
@Override
|
2013-04-19 21:43:00 +02:00
|
|
|
public double getEnergy()
|
|
|
|
{
|
|
|
|
return electricityStored;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-19 21:43:00 +02:00
|
|
|
@Override
|
|
|
|
public void setEnergy(double energy)
|
|
|
|
{
|
|
|
|
electricityStored = Math.max(Math.min(energy, getMaxEnergy()), 0);
|
2013-11-11 20:37:56 +01:00
|
|
|
MekanismUtils.saveChunk(this);
|
2013-04-19 21:43:00 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-19 21:43:00 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxEnergy()
|
2013-03-18 17:23:57 +01:00
|
|
|
{
|
2014-09-06 22:14:49 +02:00
|
|
|
return maxEnergy;
|
2013-03-18 17:23:57 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-02-27 02:21:30 +01:00
|
|
|
@Override
|
2014-06-02 16:52:13 +02:00
|
|
|
public void handlePacketData(ByteBuf dataStream)
|
2013-02-27 02:21:30 +01:00
|
|
|
{
|
|
|
|
super.handlePacketData(dataStream);
|
2013-08-22 17:36:31 +02:00
|
|
|
setEnergy(dataStream.readDouble());
|
2013-02-27 02:21:30 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-02-27 02:21:30 +01:00
|
|
|
@Override
|
|
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
|
|
{
|
|
|
|
super.getNetworkedData(data);
|
2013-08-22 17:36:31 +02:00
|
|
|
data.add(getEnergy());
|
2013-02-27 02:21:30 +01:00
|
|
|
return data;
|
|
|
|
}
|
2014-08-01 06:55:24 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded()
|
|
|
|
{
|
|
|
|
super.onAdded();
|
|
|
|
|
|
|
|
if(MekanismUtils.useIC2())
|
|
|
|
{
|
|
|
|
register();
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2012-12-19 21:23:55 +01:00
|
|
|
@Override
|
2013-11-03 22:54:33 +01:00
|
|
|
public void onChunkUnload()
|
2012-12-19 21:23:55 +01:00
|
|
|
{
|
2014-06-26 19:16:33 +02:00
|
|
|
if(MekanismUtils.useIC2())
|
2014-08-01 06:55:24 +02:00
|
|
|
{
|
2014-06-26 20:28:40 +02:00
|
|
|
deregister();
|
2014-08-01 06:55:24 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-03 22:54:33 +01:00
|
|
|
super.onChunkUnload();
|
2012-12-19 21:23:55 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-15 23:10:13 +01:00
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
super.invalidate();
|
2014-06-26 19:16:33 +02:00
|
|
|
|
|
|
|
if(MekanismUtils.useIC2())
|
2014-08-01 06:55:24 +02:00
|
|
|
{
|
2014-06-26 20:28:40 +02:00
|
|
|
deregister();
|
2014-08-01 06:55:24 +02:00
|
|
|
}
|
2014-02-15 23:10:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbtTags);
|
2012-11-02 02:30:40 +01:00
|
|
|
|
2014-03-08 02:00:25 +01:00
|
|
|
electricityStored = nbtTags.getDouble("electricityStored");
|
|
|
|
}
|
2012-11-02 02:30:40 +01:00
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbtTags);
|
|
|
|
|
|
|
|
nbtTags.setDouble("electricityStored", getEnergy());
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:36:31 +02:00
|
|
|
/**
|
|
|
|
* Gets the scaled energy level for the GUI.
|
|
|
|
* @param i - multiplier
|
|
|
|
* @return scaled energy
|
|
|
|
*/
|
|
|
|
public int getScaledEnergyLevel(int i)
|
|
|
|
{
|
|
|
|
return (int)(getEnergy()*i / getMaxEnergy());
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-15 18:06:03 +01:00
|
|
|
@Override
|
2014-06-26 02:10:53 +02:00
|
|
|
@Method(modid = "CoFHAPI|energy")
|
2013-11-15 18:06:03 +01:00
|
|
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
|
|
|
{
|
|
|
|
if(getConsumingSides().contains(from))
|
|
|
|
{
|
2014-08-01 01:58:12 +02:00
|
|
|
double toAdd = (int)Math.min(getMaxEnergy()-getEnergy(), maxReceive* general.FROM_TE);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-15 18:06:03 +01:00
|
|
|
if(!simulate)
|
|
|
|
{
|
|
|
|
setEnergy(getEnergy() + toAdd);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-08-01 01:58:12 +02:00
|
|
|
return (int)Math.round(toAdd* general.TO_TE);
|
2013-11-15 18:06:03 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-15 18:06:03 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-26 02:10:53 +02:00
|
|
|
@Method(modid = "CoFHAPI|energy")
|
2013-11-15 18:06:03 +01:00
|
|
|
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
|
|
|
{
|
2013-11-29 23:17:01 +01:00
|
|
|
if(getOutputtingSides().contains(from))
|
2013-11-15 18:06:03 +01:00
|
|
|
{
|
2014-08-01 01:58:12 +02:00
|
|
|
double toSend = Math.min(getEnergy(), Math.min(getMaxOutput(), maxExtract* general.FROM_TE));
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-15 18:06:03 +01:00
|
|
|
if(!simulate)
|
|
|
|
{
|
|
|
|
setEnergy(getEnergy() - toSend);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-08-01 01:58:12 +02:00
|
|
|
return (int)Math.round(toSend* general.TO_TE);
|
2013-11-15 18:06:03 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-15 18:06:03 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-26 02:10:53 +02:00
|
|
|
@Method(modid = "CoFHAPI|energy")
|
2014-06-15 13:35:51 +02:00
|
|
|
public boolean canConnectEnergy(ForgeDirection from)
|
2013-11-15 18:06:03 +01:00
|
|
|
{
|
2013-12-21 18:51:55 +01:00
|
|
|
return getConsumingSides().contains(from) || getOutputtingSides().contains(from);
|
2013-11-15 18:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-26 02:10:53 +02:00
|
|
|
@Method(modid = "CoFHAPI|energy")
|
2013-11-15 18:06:03 +01:00
|
|
|
public int getEnergyStored(ForgeDirection from)
|
|
|
|
{
|
2014-08-01 01:58:12 +02:00
|
|
|
return (int)Math.round(getEnergy()* general.TO_TE);
|
2013-11-15 18:06:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-26 02:10:53 +02:00
|
|
|
@Method(modid = "CoFHAPI|energy")
|
2014-03-08 02:00:25 +01:00
|
|
|
public int getMaxEnergyStored(ForgeDirection from)
|
2013-11-15 18:06:03 +01:00
|
|
|
{
|
2014-08-01 01:58:12 +02:00
|
|
|
return (int)Math.round(getMaxEnergy()* general.TO_TE);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-27 19:24:13 +01:00
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-07-08 03:48:18 +02:00
|
|
|
public int getSinkTier()
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-07-08 03:48:18 +02:00
|
|
|
return 4;
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-10-02 19:13:19 +02:00
|
|
|
@Method(modid = "IC2")
|
|
|
|
public int getSourceTier()
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2013-11-27 19:24:13 +01:00
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2013-11-27 19:24:13 +01:00
|
|
|
public void setStored(int energy)
|
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
setEnergy(energy*general.FROM_IC2);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2013-11-27 19:24:13 +01:00
|
|
|
public int addEnergy(int amount)
|
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
setEnergy(getEnergy() + amount*general.FROM_IC2);
|
|
|
|
return (int)Math.round(getEnergy()*general.TO_IC2);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-03-08 02:00:25 +01:00
|
|
|
public boolean isTeleporterCompatible(ForgeDirection side)
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2013-11-29 23:17:01 +01:00
|
|
|
return getOutputtingSides().contains(side);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-27 19:24:13 +01:00
|
|
|
@Override
|
|
|
|
public boolean canOutputTo(ForgeDirection side)
|
|
|
|
{
|
2013-11-29 23:17:01 +01:00
|
|
|
return getOutputtingSides().contains(side);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-27 19:24:13 +01:00
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2013-11-27 19:24:13 +01:00
|
|
|
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
|
|
|
{
|
2014-10-02 19:13:19 +02:00
|
|
|
return getConsumingSides().contains(direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Method(modid = "IC2")
|
|
|
|
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
|
|
|
{
|
2014-10-02 19:42:04 +02:00
|
|
|
return getOutputtingSides().contains(direction) && receiver instanceof IEnergyConductor;
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-03-08 02:00:25 +01:00
|
|
|
public int getStored()
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
return (int)Math.round(getEnergy()*general.TO_IC2);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-03-08 02:00:25 +01:00
|
|
|
public int getCapacity()
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
return (int)Math.round(getMaxEnergy()*general.TO_IC2);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-03-08 02:00:25 +01:00
|
|
|
public int getOutput()
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
return (int)Math.round(getMaxOutput()*general.TO_IC2);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-07-08 03:48:18 +02:00
|
|
|
public double getDemandedEnergy()
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
return (getMaxEnergy() - getEnergy())*general.TO_IC2;
|
2014-10-02 19:13:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Method(modid = "IC2")
|
|
|
|
public double getOfferedEnergy()
|
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
return Math.min(getEnergy(), getMaxOutput())*general.TO_IC2;
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-27 19:24:13 +01:00
|
|
|
@Override
|
|
|
|
public boolean canReceiveEnergy(ForgeDirection side)
|
|
|
|
{
|
2013-12-28 04:34:05 +01:00
|
|
|
return getConsumingSides().contains(side);
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2013-11-27 19:24:13 +01:00
|
|
|
public double getOutputEnergyUnitsPerTick()
|
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
return getMaxOutput()*general.TO_IC2;
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-30 23:08:40 +02:00
|
|
|
@Method(modid = "IC2")
|
2014-10-02 19:13:19 +02:00
|
|
|
public double injectEnergy(ForgeDirection direction, double amount, double voltage)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2014-01-05 08:24:06 +01:00
|
|
|
if(Coord4D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof IGridTransmitter)
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-10-02 19:13:19 +02:00
|
|
|
return amount;
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-10-17 18:00:39 +02:00
|
|
|
return amount-transferEnergyToAcceptor(direction, amount*general.FROM_IC2)*general.TO_IC2;
|
2014-10-02 19:13:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Method(modid = "IC2")
|
|
|
|
public void drawEnergy(double amount)
|
|
|
|
{
|
2014-10-17 18:00:39 +02:00
|
|
|
setEnergy(Math.max(getEnergy() - (amount*general.FROM_IC2), 0));
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
2013-11-27 19:24:13 +01:00
|
|
|
@Override
|
|
|
|
public double transferEnergyToAcceptor(ForgeDirection side, double amount)
|
|
|
|
{
|
2014-04-11 00:45:59 +02:00
|
|
|
if(!(getConsumingSides().contains(side) || side == ForgeDirection.UNKNOWN))
|
2013-11-27 19:24:13 +01:00
|
|
|
{
|
2014-01-09 00:28:17 +01:00
|
|
|
return 0;
|
2013-11-27 19:24:13 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
double toUse = Math.min(getMaxEnergy()-getEnergy(), amount);
|
|
|
|
setEnergy(getEnergy() + toUse);
|
|
|
|
|
|
|
|
return toUse;
|
2013-11-15 18:06:03 +01:00
|
|
|
}
|
2012-10-28 23:18:23 +01:00
|
|
|
}
|