Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TileEntityForge extends TileEntity implements ISidedInventory
- {
- private String localizedName;
- private static final int[] slots_top = new int[] {0, 1, 2, 3};
- private static final int[] slots_bottom = new int[] {4, 5};
- private static final int[] slots_sides = new int[] {4};
- private ItemStack[] slots = new ItemStack[6];
- public int furnaceSpeed = 500;
- public int burnTime;
- public int currentItemBurnTime;
- public int cookTime;
- public int getSizeInventory()
- {
- return this.slots.length;
- }
- public boolean isInvNameLocalized()
- {
- return this.localizedName != null && this.localizedName.length() > 0;
- }
- public String getInvName()
- {
- return this.isInvNameLocalized() ? this.localizedName : "container.Forge";
- }
- public void setGuiDisplayName(String displayName)
- {
- this.localizedName = displayName;
- }
- public ItemStack getStackInSlot(int i)
- {
- return this.slots[i];
- }
- public ItemStack decrStackSize(int i, int j)
- {
- if(this.slots[i] != null)
- {
- ItemStack itemstack;
- if(this.slots[i].stackSize <= j)
- {
- itemstack = this.slots[i];
- this.slots[i] = null;
- return itemstack;
- }
- else
- {
- itemstack = this.slots[i].splitStack(j);
- if(this.slots[i].stackSize == 0)
- {
- this.slots[i] = null;
- }
- return itemstack;
- }
- }
- return null;
- }
- public ItemStack getStackInSlotOnClosing(int i)
- {
- if(this.slots[i] != null)
- {
- ItemStack itemstack = this.slots[i];
- this.slots[i] = null;
- return itemstack;
- }
- return null;
- }
- public void setInventorySlotContents(int i, ItemStack itemstack)
- {
- this.slots[i] = itemstack;
- if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
- {
- itemstack.stackSize = this.getInventoryStackLimit();
- }
- }
- public int getInventoryStackLimit()
- {
- return 64;
- }
- public boolean isUseableByPlayer(EntityPlayer entityplayer)
- {
- return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
- }
- public void openChest()
- {
- }
- public void closeChest()
- {
- }
- public boolean isBurning()
- {
- return this.burnTime > 0;
- }
- public void updateEntity()
- {
- boolean flag = this.burnTime > 0;
- boolean flag1 = false;
- if(this.burnTime > 0)
- {
- this.burnTime--;
- }
- if(!this.worldObj.isRemote)
- {
- if(this.burnTime == 0 && this.canSmelt() && this.doStuff() && this.doStuff2() && this.doStuff3())
- {
- this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[4]);
- if(this.burnTime > 0)
- {
- flag1 = true;
- if(this.slots[4] != null)
- {
- this.slots[4].stackSize--;
- if(this.slots[4].stackSize == 0)
- {
- this.slots[4] = this.slots[4].getItem().getContainerItemStack(this.slots[4]);
- }
- }
- }
- }
- if(this.isBurning() && this.canSmelt() && this.doStuff() && this.doStuff2() && this.doStuff3())
- {
- this.cookTime++;
- if(this.cookTime == this.furnaceSpeed)
- {
- this.cookTime = 0;
- this.smeltItem();
- flag1 = true;
- }
- }
- else
- {
- this.cookTime = 0;
- }
- if(flag != this.burnTime > 0)
- {
- flag1 = true;
- BlockForge.updateForgeBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
- }
- }
- if(flag1)
- {
- this.onInventoryChanged();
- }
- }
- private boolean canSmelt()
- {
- if(this.slots[0] == null)
- {
- return false;
- }
- else
- {
- ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);
- if(itemstack == null) return false;
- if(this.slots[5] == null) return true;
- if(!this.slots[5].isItemEqual(itemstack)) return false;
- return (this.slots[5].stackSize + itemstack.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack.stackSize <= itemstack.getMaxStackSize());
- }
- }
- public boolean doStuff()
- {
- if(this.slots[1] == null)
- {
- return false;
- }
- else
- {
- ItemStack itemstack1 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[1]);
- if(itemstack1 == null) return false;
- if(this.slots[5] == null) return true;
- if(!this.slots[5].isItemEqual(itemstack1)) return false;
- return (this.slots[5].stackSize + itemstack1.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack1.stackSize <= itemstack1.getMaxStackSize());
- }
- }
- public boolean doStuff2()
- {
- if(this.slots[2] == null)
- {
- return false;
- }
- else
- {
- ItemStack itemstack2 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[2]);
- if(itemstack2 == null) return false;
- if(this.slots[5] == null) return true;
- if(!this.slots[5].isItemEqual(itemstack2)) return false;
- return (this.slots[5].stackSize + itemstack2.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack2.stackSize <= itemstack2.getMaxStackSize());
- }
- }
- public boolean doStuff3()
- {
- if(this.slots[3] == null)
- {
- return false;
- }
- else
- {
- ItemStack itemstack3 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[3]);
- if(itemstack3 == null) return false;
- if(this.slots[5] == null) return true;
- if(!this.slots[5].isItemEqual(itemstack3)) return false;
- return (this.slots[5].stackSize + itemstack3.stackSize <= getInventoryStackLimit() && this.slots[5].stackSize + itemstack3.stackSize <= itemstack3.getMaxStackSize());
- }
- }
- public void smeltItem()
- {
- if(this.canSmelt() && this.doStuff() && this.doStuff2() && this.doStuff3())
- {
- ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);
- ItemStack itemstack1 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[1]);
- ItemStack itemstack2 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[2]);
- ItemStack itemstack3 = FurnaceRecipes.smelting().getSmeltingResult(this.slots[3]);
- if(this.slots[5] == null)
- {
- this.slots[5] = itemstack.copy();
- this.slots[5] = itemstack1.copy();
- this.slots[5] = itemstack2.copy();
- this.slots[5] = itemstack3.copy();
- }
- else if(this.slots[5].isItemEqual(itemstack))
- {
- this.slots[5].stackSize += itemstack.stackSize;
- }
- else if(this.slots[5].isItemEqual(itemstack1))
- {
- this.slots[5].stackSize += itemstack1.stackSize;
- }
- else if(this.slots[5].isItemEqual(itemstack2))
- {
- this.slots[5].stackSize += itemstack2.stackSize;
- }
- else if(this.slots[5].isItemEqual(itemstack3))
- {
- this.slots[5].stackSize += itemstack3.stackSize;
- }
- this.slots[0].stackSize--;
- this.slots[1].stackSize--;
- this.slots[2].stackSize--;
- this.slots[3].stackSize--;
- if(this.slots[0].stackSize <= 0 && this.slots[1].stackSize <= 0 && this.slots[2].stackSize <= 0 && this.slots[3].stackSize <= 0)
- {
- this.slots[0] = null;
- this.slots[1] = null;
- this.slots[2] = null;
- this.slots[3] = null;
- }
- }
- }
- public static int getItemBurnTime(ItemStack itemstack)
- {
- if(itemstack == null)
- {
- return 0;
- }
- else
- {
- int i = itemstack.getItem().itemID;
- if(i == Item.bucketLava.itemID) return 20000;
- return GameRegistry.getFuelValue(itemstack);
- }
- }
- public static boolean isItemFuel(ItemStack itemstack)
- {
- return getItemBurnTime(itemstack) == 20000;
- }
- public boolean isItemValidForSlot(int i, ItemStack itemstack)
- {
- return i == 5 ? false : (i == 4 ? isItemFuel(itemstack) : true);
- }
- public int[] getAccessibleSlotsFromSide(int var1)
- {
- return var1 == 0 ? slots_bottom : (var1 == 4 ? slots_top : slots_sides);
- }
- public boolean canInsertItem(int i, ItemStack itemstack, int j)
- {
- return this.isItemValidForSlot(i, itemstack);
- }
- public boolean canExtractItem(int i, ItemStack itemstack, int j)
- {
- return j != 0 || i != 1 || itemstack.itemID == Item.bucketEmpty.itemID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment