2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityCoalGenerator.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-12-18 17:28:29 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.tileentity.TileEntityFurnace;
|
2016-01-07 19:04:29 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-11-26 08:58:42 +01:00
|
|
|
import net.minecraftforge.energy.IEnergyStorage;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-08-31 20:16:36 +02:00
|
|
|
public class TileEntityCoalGenerator extends TileEntityInventoryBase implements ISharingEnergyProvider{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
public static final int PRODUCE = 30;
|
2016-11-26 20:43:50 +01:00
|
|
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(60000, 0, 80);
|
2015-05-20 22:39:43 +02:00
|
|
|
public int maxBurnTime;
|
|
|
|
public int currentBurnTime;
|
2015-10-03 10:16:18 +02:00
|
|
|
private int lastEnergy;
|
|
|
|
private int lastBurnTime;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastCurrentBurnTime;
|
2016-11-28 13:02:42 +01:00
|
|
|
private int lastCompare;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public TileEntityCoalGenerator(){
|
|
|
|
super(1, "coalGenerator");
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getEnergyScaled(int i){
|
|
|
|
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getBurningScaled(int i){
|
|
|
|
return this.currentBurnTime*i/this.maxBurnTime;
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
compound.setInteger("BurnTime", this.currentBurnTime);
|
|
|
|
compound.setInteger("MaxBurnTime", this.maxBurnTime);
|
|
|
|
}
|
2016-02-01 20:32:49 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
2016-07-02 15:01:46 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
this.currentBurnTime = compound.getInteger("BurnTime");
|
|
|
|
this.maxBurnTime = compound.getInteger("MaxBurnTime");
|
|
|
|
}
|
2016-02-01 20:32:49 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
2016-07-02 15:01:46 +02:00
|
|
|
super.readSyncableNBT(compound, type);
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2016-11-26 21:32:27 +01:00
|
|
|
if(!this.world.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--;
|
2016-11-23 18:10:55 +01:00
|
|
|
this.storage.receiveEnergyInternal(PRODUCE, false);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2016-12-04 00:10:52 +01:00
|
|
|
if(!this.isRedstonePowered && this.currentBurnTime <= 0 && StackUtil.isValid(this.slots.getStackInSlot(0)) && TileEntityFurnace.getItemBurnTime(this.slots.getStackInSlot(0)) > 0 && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){
|
|
|
|
int burnTime = TileEntityFurnace.getItemBurnTime(this.slots.getStackInSlot(0));
|
2015-12-16 00:08:18 +01:00
|
|
|
this.maxBurnTime = burnTime;
|
|
|
|
this.currentBurnTime = burnTime;
|
|
|
|
|
2016-12-04 00:10:52 +01:00
|
|
|
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1, true));
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2016-11-28 13:02:42 +01:00
|
|
|
if(flag != this.currentBurnTime > 0 || this.lastCompare != this.getComparatorStrength()){
|
|
|
|
this.lastCompare = this.getComparatorStrength();
|
|
|
|
|
2015-07-02 00:35:38 +02:00
|
|
|
this.markDirty();
|
2015-06-21 02:28:49 +02:00
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
2015-12-01 17:28:50 +01:00
|
|
|
if((this.storage.getEnergyStored() != this.lastEnergy || this.currentBurnTime != this.lastCurrentBurnTime || this.lastBurnTime != this.maxBurnTime) && this.sendUpdateWithInterval()){
|
2015-07-02 04:21:21 +02:00
|
|
|
this.lastEnergy = this.storage.getEnergyStored();
|
|
|
|
this.lastCurrentBurnTime = this.currentBurnTime;
|
|
|
|
this.lastBurnTime = this.currentBurnTime;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 13:02:42 +01:00
|
|
|
@Override
|
|
|
|
public int getComparatorStrength(){
|
|
|
|
float calc = ((float)this.storage.getEnergyStored()/(float)this.storage.getMaxEnergyStored())*15F;
|
|
|
|
return (int)calc;
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2016-02-01 17:49:55 +01:00
|
|
|
return TileEntityFurnace.getItemBurnTime(stack) > 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
@Override
|
2016-12-04 00:10:52 +01:00
|
|
|
public boolean canExtractItem(int slot, ItemStack stack){
|
|
|
|
return TileEntityFurnace.getItemBurnTime(this.slots.getStackInSlot(0)) <= 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 20:16:36 +02:00
|
|
|
@Override
|
|
|
|
public int getEnergyToSplitShare(){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean doesShareEnergy(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing[] getEnergyShareSides(){
|
|
|
|
return EnumFacing.values();
|
|
|
|
}
|
2016-11-26 08:58:42 +01:00
|
|
|
|
2016-12-18 17:28:29 +01:00
|
|
|
@Override
|
|
|
|
public boolean canShareTo(TileEntity tile){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-26 08:58:42 +01:00
|
|
|
@Override
|
|
|
|
public IEnergyStorage getEnergyStorage(EnumFacing facing){
|
|
|
|
return this.storage;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|