2015-05-20 22:39:43 +02:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
|
|
|
import cofh.api.energy.EnergyStorage;
|
2015-05-29 18:17:28 +02:00
|
|
|
import cofh.api.energy.IEnergyProvider;
|
2015-05-20 22:39:43 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-07-02 04:21:21 +02:00
|
|
|
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
|
|
|
|
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
|
2015-05-20 22:39:43 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntityFurnace;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
2015-07-02 04:21:21 +02:00
|
|
|
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements IEnergyProvider, IPacketSyncerToClient{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public EnergyStorage storage = new EnergyStorage(60000);
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastEnergy;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public static int energyProducedPerTick = ConfigIntValues.COAL_GEN_ENERGY_PRODUCED.getValue();
|
|
|
|
|
|
|
|
public int maxBurnTime;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastBurnTime;
|
2015-05-20 22:39:43 +02:00
|
|
|
public int currentBurnTime;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastCurrentBurnTime;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public TileEntityCoalGenerator(){
|
|
|
|
super(1, "coalGenerator");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void updateEntity(){
|
|
|
|
if(!worldObj.isRemote){
|
2015-06-21 02:28:49 +02:00
|
|
|
boolean flag = this.currentBurnTime > 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
if(this.currentBurnTime > 0){
|
|
|
|
this.currentBurnTime--;
|
|
|
|
this.storage.receiveEnergy(energyProducedPerTick, false);
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
if(this.currentBurnTime <= 0 && this.slots[0] != null && TileEntityFurnace.getItemBurnTime(this.slots[0]) > 0){
|
|
|
|
int burnTime = TileEntityFurnace.getItemBurnTime(this.slots[0]);
|
|
|
|
if(energyProducedPerTick*burnTime <= this.getMaxEnergyStored(ForgeDirection.UNKNOWN)-this.getEnergyStored(ForgeDirection.UNKNOWN)){
|
|
|
|
this.maxBurnTime = burnTime;
|
|
|
|
this.currentBurnTime = burnTime;
|
2015-05-20 22:39:43 +02:00
|
|
|
this.slots[0].stackSize--;
|
|
|
|
if(this.slots[0].stackSize == 0) this.slots[0] = this.slots[0].getItem().getContainerItem(this.slots[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.getEnergyStored(ForgeDirection.UNKNOWN) > 0){
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.UP, storage);
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, storage);
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, storage);
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, storage);
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, storage);
|
|
|
|
WorldUtil.pushEnergy(worldObj, xCoord, yCoord, zCoord, ForgeDirection.WEST, storage);
|
|
|
|
}
|
2015-06-21 02:28:49 +02:00
|
|
|
|
|
|
|
if(flag != this.currentBurnTime > 0){
|
2015-07-02 00:35:38 +02:00
|
|
|
this.markDirty();
|
2015-06-21 02:28:49 +02:00
|
|
|
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
|
|
|
if(meta == 1){
|
|
|
|
if(!(this.currentBurnTime <= 0 && this.slots[0] != null && TileEntityFurnace.getItemBurnTime(this.slots[0]) > 0 && energyProducedPerTick*TileEntityFurnace.getItemBurnTime(this.slots[0]) <= this.getMaxEnergyStored(ForgeDirection.UNKNOWN)-this.getEnergyStored(ForgeDirection.UNKNOWN)))
|
|
|
|
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2);
|
|
|
|
}
|
|
|
|
else worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2);
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
|
|
|
if(this.storage.getEnergyStored() != this.lastEnergy || this.currentBurnTime != this.lastCurrentBurnTime || this.lastBurnTime != this.maxBurnTime){
|
|
|
|
this.lastEnergy = this.storage.getEnergyStored();
|
|
|
|
this.lastCurrentBurnTime = this.currentBurnTime;
|
|
|
|
this.lastBurnTime = this.currentBurnTime;
|
|
|
|
this.sendUpdate();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getEnergyScaled(int i){
|
2015-07-02 00:35:38 +02:00
|
|
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getBurningScaled(int i){
|
|
|
|
return this.currentBurnTime * i / this.maxBurnTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
compound.setInteger("BurnTime", this.currentBurnTime);
|
|
|
|
compound.setInteger("MaxBurnTime", this.maxBurnTime);
|
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
super.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
this.currentBurnTime = compound.getInteger("BurnTime");
|
|
|
|
this.maxBurnTime = compound.getInteger("MaxBurnTime");
|
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
super.readFromNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
|
|
|
return TileEntityFurnace.getItemBurnTime(stack) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-29 18:17:28 +02:00
|
|
|
public int extractEnergy(ForgeDirection from, int maxReceive, boolean simulate){
|
|
|
|
return this.storage.extractEnergy(maxReceive, simulate);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyStored(ForgeDirection from){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxEnergyStored(ForgeDirection from){
|
|
|
|
return this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canConnectEnergy(ForgeDirection from){
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getValues(){
|
|
|
|
return new int[]{this.storage.getEnergyStored(), this.currentBurnTime, this.maxBurnTime};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setValues(int[] values){
|
|
|
|
this.storage.setEnergyStored(values[0]);
|
|
|
|
this.currentBurnTime = values[1];
|
|
|
|
this.maxBurnTime = values[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendUpdate(){
|
|
|
|
PacketSyncerToClient.sendPacket(this);
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|