Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- public class TileEntityCocoaExtractor extends TileEntity
- implements IInventory
- {
- public TileEntityCocoaExtractor()
- {
- cocoaExtractorItemStacks = new ItemStack[5];
- extractingTime = 0;
- currentItemBurnTime = 0;
- extractTime = 0;
- }
- public int getSizeInventory()
- {
- return cocoaExtractorItemStacks.length;
- }
- public ItemStack getStackInSlot(int i)
- {
- return cocoaExtractorItemStacks[i];
- }
- public ItemStack decrStackSize(int i, int j)
- {
- if(cocoaExtractorItemStacks[i] != null)
- {
- if(cocoaExtractorItemStacks[i].stackSize <= j)
- {
- ItemStack itemstack = cocoaExtractorItemStacks[i];
- cocoaExtractorItemStacks[i] = null;
- return itemstack;
- }
- ItemStack itemstack1 = cocoaExtractorItemStacks[i].splitStack(j);
- if(cocoaExtractorItemStacks[i].stackSize == 0)
- {
- cocoaExtractorItemStacks[i] = null;
- }
- return itemstack1;
- } else
- {
- return null;
- }
- }
- public void setInventorySlotContents(int i, ItemStack itemstack)
- {
- cocoaExtractorItemStacks[i] = itemstack;
- if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
- {
- itemstack.stackSize = getInventoryStackLimit();
- }
- }
- public String getInvName()
- {
- return "CocoaExtractor";
- }
- public void readFromNBT(NBTTagCompound nbttagcompound)
- {
- super.readFromNBT(nbttagcompound);
- NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
- cocoaExtractorItemStacks = new ItemStack[getSizeInventory()];
- for(int i = 0; i < nbttaglist.tagCount(); i++)
- {
- NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
- byte byte0 = nbttagcompound1.getByte("Slot");
- if(byte0 >= 0 && byte0 < cocoaExtractorItemStacks.length)
- {
- cocoaExtractorItemStacks[byte0] = new ItemStack(nbttagcompound1);
- }
- }
- extractingTime = nbttagcompound.getShort("BurnTime");
- extractTime = nbttagcompound.getShort("CookTime");
- currentItemBurnTime = getItemBurnTime(cocoaExtractorItemStacks[1]);
- }
- public void writeToNBT(NBTTagCompound nbttagcompound)
- {
- super.writeToNBT(nbttagcompound);
- nbttagcompound.setShort("BurnTime", (short)extractingTime);
- nbttagcompound.setShort("CookTime", (short)extractTime);
- NBTTagList nbttaglist = new NBTTagList();
- for(int i = 0; i < cocoaExtractorItemStacks.length; i++)
- {
- if(cocoaExtractorItemStacks[i] != null)
- {
- NBTTagCompound nbttagcompound1 = new NBTTagCompound();
- nbttagcompound1.setByte("Slot", (byte)i);
- cocoaExtractorItemStacks[i].writeToNBT(nbttagcompound1);
- nbttaglist.setTag(nbttagcompound1);
- }
- }
- nbttagcompound.setTag("Items", nbttaglist);
- }
- public int getInventoryStackLimit()
- {
- return 64;
- }
- public int getCookProgressScaled(int i)
- {
- return (extractTime * i) / 200;
- }
- public int getBurnTimeRemainingScaled(int i)
- {
- if(currentItemBurnTime == 0)
- {
- currentItemBurnTime = 200;
- }
- return (extractingTime * i) / currentItemBurnTime;
- }
- public boolean isBurning()
- {
- return extractingTime > 0;
- }
- public void updateEntity()
- {
- boolean flag = extractingTime > 0;
- boolean flag1 = false;
- if(extractingTime > 0)
- {
- extractingTime--;
- }
- if(!worldObj.multiplayerWorld)
- {
- if(extractingTime == 0 && canSmelt())
- {
- currentItemBurnTime = extractingTime = getItemBurnTime(cocoaExtractorItemStacks[1]);
- if(extractingTime > 0)
- {
- flag1 = true;
- if(cocoaExtractorItemStacks[1] != null)
- {
- if(cocoaExtractorItemStacks[1].getItem().hasContainerItem())
- {
- cocoaExtractorItemStacks[1] = new ItemStack(cocoaExtractorItemStacks[1].getItem().getContainerItem());
- } else
- {
- cocoaExtractorItemStacks[1].stackSize--;
- }
- if(cocoaExtractorItemStacks[1].stackSize == 0)
- {
- cocoaExtractorItemStacks[1] = null;
- }
- }
- }
- }
- if(isBurning() && canSmelt())
- {
- extractTime++;
- if(extractTime == 200)
- {
- extractTime = 0;
- smeltItem();
- flag1 = true;
- }
- } else
- {
- extractTime = 0;
- }
- if(flag != (extractingTime > 0))
- {
- flag1 = true;
- BlockCocoaExtractor.updateCocoaExtractorBlockState(extractingTime > 0, worldObj, xCoord, yCoord, zCoord);
- }
- }
- if(flag1)
- {
- onInventoryChanged();
- }
- }
- private boolean canSmelt()
- {
- if(cocoaExtractorItemStacks[0] == null)
- {
- return false;
- }
- ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(cocoaExtractorItemStacks[0].getItem().shiftedIndex);
- if(itemstack == null)
- {
- return false;
- }
- if(cocoaExtractorItemStacks[2] == null)
- {
- if(cocoaExtractorItemStacks[3] == null)
- if(cocoaExtractorItemStacks[4] == null)
- {
- return true;
- } else
- if(!cocoaExtractorItemStacks[3].isItemEqual(itemstack))
- {
- return false;
- }else
- if(!cocoaExtractorItemStacks[4].isItemEqual(itemstack))
- {
- return false;
- }
- } else
- if(!cocoaExtractorItemStacks[2].isItemEqual(itemstack))
- {
- return false;
- }
- if(cocoaExtractorItemStacks[3] == null)
- {
- return true;
- }
- if(cocoaExtractorItemStacks[4] == null)
- {
- return true;
- }
- if(cocoaExtractorItemStacks[2].stackSize < getInventoryStackLimit() && cocoaExtractorItemStacks[2].stackSize < cocoaExtractorItemStacks[2].getMaxStackSize() && cocoaExtractorItemStacks[3].stackSize < getInventoryStackLimit() && cocoaExtractorItemStacks[3].stackSize < cocoaExtractorItemStacks[3].getMaxStackSize() && cocoaExtractorItemStacks[4].stackSize < getInventoryStackLimit() && cocoaExtractorItemStacks[4].stackSize < cocoaExtractorItemStacks[4].getMaxStackSize())
- {
- return true;
- }
- return cocoaExtractorItemStacks[2].stackSize < itemstack.getMaxStackSize() && cocoaExtractorItemStacks[3].stackSize < itemstack.getMaxStackSize() && cocoaExtractorItemStacks[4].stackSize < itemstack.getMaxStackSize();
- }
- public void smeltItem()
- {
- if(!canSmelt())
- {
- return;
- }
- ItemStack itemstack2 = FurnaceRecipes.smelting().getSmeltingResult(cocoaExtractorItemStacks[0].getItem().shiftedIndex);
- if(cocoaExtractorItemStacks[4] == null)
- {
- cocoaExtractorItemStacks[4] = itemstack2.copy();
- } else
- if(cocoaExtractorItemStacks[4].itemID == itemstack2.itemID)
- {
- cocoaExtractorItemStacks[4].stackSize += itemstack2.stackSize;
- }
- if(cocoaExtractorItemStacks[0].getItem().hasContainerItem())
- {
- cocoaExtractorItemStacks[0] = new ItemStack(cocoaExtractorItemStacks[0].getItem().getContainerItem());
- } else
- {
- cocoaExtractorItemStacks[0].stackSize--;
- }
- if(cocoaExtractorItemStacks[0].stackSize <= 0)
- {
- cocoaExtractorItemStacks[0] = null;
- }
- }
- private int getItemBurnTime(ItemStack itemstack)
- {
- if(itemstack == null)
- {
- return 0;
- }
- int i = itemstack.getItem().shiftedIndex;
- if(i == Item.coal.shiftedIndex)
- {
- return 2400;
- }
- else
- {
- return 0;
- }
- }
- public boolean canInteractWith(EntityPlayer entityplayer)
- {
- if(worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
- {
- return false;
- }
- return entityplayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
- }
- public void onInventoryChanged()
- {
- }
- public void func_35142_x_()
- {
- }
- public void func_35141_y_()
- {
- }
- private ItemStack cocoaExtractorItemStacks[];
- public int extractingTime;
- public int currentItemBurnTime;
- public int extractTime;
- }
Add Comment
Please, Sign In to add comment