2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.common;
|
2012-10-28 23:18:23 +01:00
|
|
|
|
|
|
|
import ic2.api.IWrenchable;
|
2012-12-20 22:53:39 +01:00
|
|
|
import ic2.api.energy.event.EnergyTileLoadEvent;
|
|
|
|
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
|
|
|
import ic2.api.energy.tile.IEnergyTile;
|
2012-11-05 20:29:04 +01:00
|
|
|
import mekanism.api.ITileNetwork;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2012-10-28 23:18:23 +01:00
|
|
|
import net.minecraftforge.common.ISidedInventory;
|
2012-12-19 21:23:55 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2012-12-20 22:53:39 +01:00
|
|
|
import buildcraft.api.power.IPowerProvider;
|
|
|
|
import buildcraft.api.power.IPowerReceptor;
|
|
|
|
import buildcraft.api.power.PowerFramework;
|
2012-10-28 23:18:23 +01:00
|
|
|
|
2012-12-19 21:23:55 +01:00
|
|
|
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IWrenchable, ISidedInventory, IInventory, ITileNetwork, IPowerReceptor, IEnergyTile
|
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;
|
2012-10-28 23:18:23 +01:00
|
|
|
|
|
|
|
/** Maximum amount of energy this machine can hold. */
|
2012-11-25 16:45:00 +01:00
|
|
|
public double MAX_ELECTRICITY;
|
2012-10-28 23:18:23 +01:00
|
|
|
|
2012-11-15 21:04:12 +01:00
|
|
|
/** BuildCraft power provider. */
|
|
|
|
public IPowerProvider powerProvider;
|
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
|
|
|
|
* @param maxEnergy - how much energy this block can store
|
|
|
|
*/
|
|
|
|
public TileEntityElectricBlock(String name, int maxEnergy)
|
|
|
|
{
|
2012-11-21 16:14:35 +01:00
|
|
|
super(name);
|
2012-11-25 16:45:00 +01:00
|
|
|
MAX_ELECTRICITY = maxEnergy;
|
2012-12-21 14:30:40 +01:00
|
|
|
|
2012-11-15 21:04:12 +01:00
|
|
|
if(PowerFramework.currentFramework != null)
|
2012-10-28 23:18:23 +01:00
|
|
|
{
|
2012-11-15 21:04:12 +01:00
|
|
|
powerProvider = PowerFramework.currentFramework.createPowerProvider();
|
|
|
|
powerProvider.configure(5, 2, 10, 1, maxEnergy/10);
|
2012-10-28 23:18:23 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-19 21:23:55 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
if(!initialized && worldObj != null)
|
|
|
|
{
|
|
|
|
if(Mekanism.hooks.IC2Loaded)
|
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
super.invalidate();
|
|
|
|
|
|
|
|
if(initialized)
|
|
|
|
{
|
|
|
|
if(Mekanism.hooks.IC2Loaded)
|
|
|
|
{
|
|
|
|
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-28 23:18:23 +01:00
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-02 02:30:40 +01:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbtTags);
|
|
|
|
|
2012-11-15 21:04:12 +01:00
|
|
|
if(PowerFramework.currentFramework != null)
|
|
|
|
{
|
|
|
|
PowerFramework.currentFramework.loadPowerProvider(this, nbtTags);
|
|
|
|
}
|
2012-11-02 02:30:40 +01:00
|
|
|
|
2012-11-25 16:45:00 +01:00
|
|
|
electricityStored = nbtTags.getDouble("electricityStored");
|
2012-11-02 02:30:40 +01:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-11-02 02:30:40 +01:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbtTags);
|
|
|
|
|
2012-11-15 21:04:12 +01:00
|
|
|
if(PowerFramework.currentFramework != null)
|
|
|
|
{
|
|
|
|
PowerFramework.currentFramework.savePowerProvider(this, nbtTags);
|
|
|
|
}
|
|
|
|
|
2012-11-25 16:45:00 +01:00
|
|
|
nbtTags.setDouble("electricityStored", electricityStored);
|
2012-11-02 02:30:40 +01:00
|
|
|
}
|
2012-10-28 23:18:23 +01:00
|
|
|
|
2012-12-23 20:46:11 +01:00
|
|
|
@Override
|
2012-10-28 23:18:23 +01:00
|
|
|
public boolean isAddedToEnergyNet()
|
|
|
|
{
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
2012-11-15 21:04:12 +01:00
|
|
|
@Override
|
|
|
|
public void setPowerProvider(IPowerProvider provider)
|
|
|
|
{
|
|
|
|
powerProvider = provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPowerProvider getPowerProvider()
|
|
|
|
{
|
|
|
|
return powerProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int powerRequest()
|
|
|
|
{
|
|
|
|
return getPowerProvider().getMaxEnergyReceived();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doWork() {}
|
2012-10-28 23:18:23 +01:00
|
|
|
}
|