public class TileEntityG1 extends TileEntity implements ISidedInventory {
public ItemStack[] stacks = new ItemStack[2];
public String invName;
public static final int[] chargeSlot = new int[] {0};
public static final int[] fuelSlot = new int[] {1};
public int processingTime;
public int currentTime;
public int storage;
public final short maxStorage = 4000;
public boolean burnFuel() {
int fuelValue = getItemProcessingTime(stacks[1]);
if (fuelValue == 0) return false;
this.processingTime += fuelValue;
this.currentTime = fuelValue;
return true;
}
public int getSizeInventory()
{
return this.stacks.length;
}
public ItemStack getStackInSlot(int slot)
{
return this.stacks[slot];
}
public ItemStack decrStackSize(int slot, int amount)
{
if (this.stacks[slot] != null)
{
ItemStack itemstack;
if (this.stacks[slot].stackSize <= amount)
{
itemstack = this.stacks[slot];
this.stacks[slot] = null;
return itemstack;
}
else
{
itemstack = this.stacks[slot].splitStack(amount);
if (this.stacks[slot].stackSize == 0)
{
this.stacks[slot] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
public ItemStack getStackInSlotOnClosing(int slot)
{
if (this.stacks[slot] != null)
{
ItemStack itemstack = this.stacks[slot];
this.stacks[slot] = null;
return itemstack;
}
else
{
return null;
}
}
public void setInventorySlotContents(int slot, ItemStack is)
{
this.stacks[slot] = is;
if (is != null && is.stackSize > this.getInventoryStackLimit())
{
is.stackSize = this.getInventoryStackLimit();
}
}
public boolean hasCustomInventoryName()
{
return this.invName != null && this.invName.length() > 0;
}
public void getName(String str)
{
this.invName = str;
}
public int getInventoryStackLimit()
{
return 64;
}
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items", 10);
this.stacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.stacks.length)
{
this.stacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
this.processingTime = nbt.getShort("processingTime");
this.storage = nbt.getShort("storage");
this.currentTime = getItemProcessingTime(this.stacks[1]);
if (nbt.hasKey("CustomName", 8))
{
this.invName = nbt.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setShort("processingTime", (short)this.processingTime);
nbt.setShort("storage", (short)this.storage);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.stacks.length; ++i)
{
if (this.stacks[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
this.stacks[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbt.setTag("Items", nbttaglist);
if (this.hasCustomInventoryName())
{
nbt.setString("CustomName", this.invName);
}
}
public boolean isActive()
{
return this.processingTime > 0;
}
public static int getItemProcessingTime(ItemStack is)
{
if (is == null)
{
return 0;
}
else
{
Item item = is.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
{
Block block = Block.getBlockFromItem(item);
if (block == Blocks.wooden_slab)
{
return 150;
}
if (block.getMaterial() == Material.wood)
{
return 300;
}
if (block == Blocks.coal_block)
{
return 16000;
}
}
if (item instanceof ItemTool && ((ItemTool)item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemSword && ((ItemSword)item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemHoe && ((ItemHoe)item).getToolMaterialName().equals("WOOD")) return 200;
if (item == Items.stick) return 100;
if (item == Items.coal) return 1600;
if (item == Items.lava_bucket) return 20000;
if (item == Item.getItemFromBlock(Blocks.sapling)) return 100;
if (item == Items.blaze_rod) return 2400;
return GameRegistry.getFuelValue(is);
}
}
public static boolean isItemFuel(ItemStack is)
{
return getItemProcessingTime(is) > 0;
}
public boolean isItemValidForSlot(int slot, ItemStack is)
{
return slot == 1 ? isItemFuel(is) : true;
}
public int[] getAccessibleSlotsFromSide(int slot)
{
return slot == 0 ? fuelSlot : chargeSlot;
}
public boolean canInsertItem(int slot, ItemStack is, int side)
{
return this.isItemValidForSlot(slot, is);
}
public boolean canExtractItem(int slot, ItemStack is, int side)
{
return side != 0 || slot != 1 || is.getItem() == Items.bucket;
}
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
public String getInventoryName()
{
return this.hasCustomInventoryName() ? this.invName : "container.g1";
}
@SideOnly(Side.CLIENT)
public int getStorageProgressScaled(int time)
{
return (this.storage * time / maxStorage);
}
@SideOnly(Side.CLIENT)
public int getProcessingTimeRemainingScaled(int time)
{
if(processingTime <= 0) return 0;
if (this.currentTime <= 0) this.currentTime = this.processingTime;
return Math.min(this.processingTime * time / this.currentTime, time);
}
public boolean needFuel() {
return (this.processingTime <= 0) && (this.storage + 10 <= this.maxStorage);
}
public void updateEntity()
{
boolean flag = this.inProcess();
boolean flag1 = false;
if (this.inProcess())
{
--this.processingTime;
}
if (needFuel()) {
flag1 = burnFuel();
}
if (!this.worldObj.isRemote)
{
if (this.processingTime != 0 || this.stacks[1] != null && this.stacks[0] != null)
{
if (this.processingTime == 0)
{
this.currentTime = this.processingTime = getItemProcessingTime(this.stacks[1]);
if (this.inProcess())
{
flag1 = true;
if (this.stacks[1] != null)
{
--this.stacks[1].stackSize;
if (this.stacks[1].stackSize == 0)
{
this.stacks[1] = stacks[1].getItem().getContainerItem(stacks[1]);
}
}
}
}
if (this.isActive())
{
storage += 10;
processingTime -= 1;
if (this.storage >= maxStorage){
storage = maxStorage;
processingTime = 0;
}
if(processingTime >= getItemProcessingTime(stacks[1])) {
--this.stacks[1].stackSize;
if(stacks[1].stackSize <= 0) {
stacks[1].stackSize = 0;
if(stacks[1].stackSize == 0) {
processingTime = 0;
}
}
}
}
}
if (flag != this.inProcess())
{
flag1 = true;
BlockG1.updateBlockState(this.processingTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
if (flag1)
{
this.markDirty();
}
}
public boolean inProcess() {
if(isActive()) {
storage += 10;
processingTime -= 1;
return true;
}
return false;
}
}