Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FOR THE FOLLOWING TILEENTOTYCOMPRESSOR.JAVA FILE TO WORK YOU NEED TO CREATE YOUR SPECIFIC FUEL YOU WANT TO CREATE AND SUBSTITUTE FOR THE OTHER IF STATEMENT CONDITIONS AND/OR ADD NEW IF STATEMENTS YOU WANT TO ADD MORE FUEL.
- CHANGES MADE TO TILEENTITYCOMPRESSOR:
- package net.minecraft.src;
- public class TileEntityCompressor extends TileEntity implements IInventory
- {
- private ItemStack compressorItemStacks[];
- /** The number of ticks that the furnace will keep burning */
- public int compressorBurnTime;
- /**
- * The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for
- */
- public int currentItemBurnTime;
- /** The number of ticks that the current item has been cooking for */
- public int compressorCookTime;
- public TileEntityCompressor()
- {
- compressorItemStacks = new ItemStack[3];
- compressorBurnTime = 0;
- currentItemBurnTime = 0;
- compressorCookTime = 0;
- }
- /**
- * Returns the number of slots in the inventory.
- */
- public int getSizeInventory()
- {
- return compressorItemStacks.length;
- }
- /**
- * Returns the stack in slot i
- */
- public ItemStack getStackInSlot(int par1)
- {
- return compressorItemStacks[par1];
- }
- /**
- * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
- * stack.
- */
- public ItemStack decrStackSize(int par1, int par2)
- {
- if (compressorItemStacks[par1] != null)
- {
- if (compressorItemStacks[par1].stackSize <= par2)
- {
- ItemStack itemstack = compressorItemStacks[par1];
- compressorItemStacks[par1] = null;
- return itemstack;
- }
- ItemStack itemstack1 = compressorItemStacks[par1].splitStack(par2);
- if (compressorItemStacks[par1].stackSize == 0)
- {
- compressorItemStacks[par1] = null;
- }
- return itemstack1;
- }
- else
- {
- return null;
- }
- }
- /**
- * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
- * like when you close a workbench GUI.
- */
- public ItemStack getStackInSlotOnClosing(int par1)
- {
- if (compressorItemStacks[par1] != null)
- {
- ItemStack itemstack = compressorItemStacks[par1];
- compressorItemStacks[par1] = null;
- return itemstack;
- }
- else
- {
- return null;
- }
- }
- /**
- * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
- */
- public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
- {
- compressorItemStacks[par1] = par2ItemStack;
- if (par2ItemStack != null && par2ItemStack.stackSize > getInventoryStackLimit())
- {
- par2ItemStack.stackSize = getInventoryStackLimit();
- }
- }
- /**
- * Returns the name of the inventory.
- */
- public String getInvName()
- {
- return "container.compressor";
- }
- /**
- * Reads a tile entity from NBT.
- */
- public void readFromNBT(NBTTagCompound par1NBTTagCompound)
- {
- super.readFromNBT(par1NBTTagCompound);
- NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
- compressorItemStacks = new ItemStack[getSizeInventory()];
- for (int i = 0; i < nbttaglist.tagCount(); i++)
- {
- NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.tagAt(i);
- byte byte0 = nbttagcompound.getByte("Slot");
- if (byte0 >= 0 && byte0 < compressorItemStacks.length)
- {
- compressorItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound);
- }
- }
- compressorBurnTime = par1NBTTagCompound.getShort("BurnTime");
- compressorCookTime = par1NBTTagCompound.getShort("CookTime");
- currentItemBurnTime = getItemBurnTime(compressorItemStacks[1]);
- }
- /**
- * Writes a tile entity to NBT.
- */
- public void writeToNBT(NBTTagCompound par1NBTTagCompound)
- {
- super.writeToNBT(par1NBTTagCompound);
- par1NBTTagCompound.setShort("BurnTime", (short)compressorBurnTime);
- par1NBTTagCompound.setShort("CookTime", (short)compressorCookTime);
- NBTTagList nbttaglist = new NBTTagList();
- for (int i = 0; i < compressorItemStacks.length; i++)
- {
- if (compressorItemStacks[i] != null)
- {
- NBTTagCompound nbttagcompound = new NBTTagCompound();
- nbttagcompound.setByte("Slot", (byte)i);
- compressorItemStacks[i].writeToNBT(nbttagcompound);
- nbttaglist.appendTag(nbttagcompound);
- }
- }
- par1NBTTagCompound.setTag("Items", nbttaglist);
- }
- /**
- * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
- * this more of a set than a get?*
- */
- public int getInventoryStackLimit()
- {
- return 64;
- }
- /**
- * Returns an integer between 0 and the passed value representing how close the current item is to being completely
- * cooked
- */
- public int getCookProgressScaled(int par1)
- {
- return (compressorCookTime * par1) / 200;
- }
- /**
- * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel
- * item, where 0 means that the item is exhausted and the passed value means that the item is fresh
- */
- public int getBurnTimeRemainingScaled(int par1)
- {
- if (currentItemBurnTime == 0)
- {
- currentItemBurnTime = 200;
- }
- return (compressorBurnTime * par1) / currentItemBurnTime;
- }
- /**
- * Returns true if the furnace is currently burning
- */
- public boolean isBurning()
- {
- return compressorBurnTime > 0;
- }
- /**
- * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
- * ticks and creates a new spawn inside its implementation.
- */
- public void updateEntity()
- {
- boolean flag = compressorBurnTime > 0;
- boolean flag1 = false;
- if (compressorBurnTime > 0)
- {
- compressorBurnTime--;
- }
- if (!worldObj.isRemote)
- {
- if (compressorBurnTime == 0 && canSmelt())
- {
- currentItemBurnTime = compressorBurnTime = getItemBurnTime(compressorItemStacks[1]);
- if (compressorBurnTime > 0)
- {
- flag1 = true;
- if (compressorItemStacks[1] != null)
- {
- if (compressorItemStacks[1].getItem().func_46056_k())
- {
- compressorItemStacks[1] = new ItemStack(compressorItemStacks[1].getItem().setFull3D());
- }
- else
- {
- compressorItemStacks[1].stackSize--;
- }
- if (compressorItemStacks[1].stackSize == 0)
- {
- compressorItemStacks[1] = null;
- }
- }
- }
- }
- if (isBurning() && canSmelt())
- {
- compressorCookTime++;
- if (compressorCookTime == 200)
- {
- compressorCookTime = 0;
- smeltItem();
- flag1 = true;
- }
- }
- else
- {
- compressorCookTime = 0;
- }
- if (flag != (compressorBurnTime > 0))
- {
- flag1 = true;
- BlockCompressor.updateCompressorBlockState(compressorBurnTime > 0, worldObj, xCoord, yCoord, zCoord);
- }
- }
- if (flag1)
- {
- onInventoryChanged();
- }
- }
- /**
- * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
- */
- private boolean canSmelt()
- {
- if (compressorItemStacks[0] == null)
- {
- return false;
- }
- ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(compressorItemStacks[0].getItem().shiftedIndex);
- if (itemstack == null)
- {
- return false;
- }
- if (compressorItemStacks[2] == null)
- {
- return true;
- }
- if (!compressorItemStacks[2].isItemEqual(itemstack))
- {
- return false;
- }
- if (compressorItemStacks[2].stackSize < getInventoryStackLimit() && compressorItemStacks[2].stackSize < compressorItemStacks[2].getMaxStackSize())
- {
- return true;
- }
- return compressorItemStacks[2].stackSize < itemstack.getMaxStackSize();
- }
- /**
- * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
- */
- public void smeltItem()
- {
- if (!canSmelt())
- {
- return;
- }
- ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(compressorItemStacks[0].getItem().shiftedIndex);
- if (compressorItemStacks[2] == null)
- {
- compressorItemStacks[2] = itemstack.copy();
- }
- else if (compressorItemStacks[2].itemID == itemstack.itemID)
- {
- compressorItemStacks[2].stackSize += itemstack.stackSize;
- }
- if (compressorItemStacks[0].getItem().func_46056_k())
- {
- compressorItemStacks[0] = new ItemStack(compressorItemStacks[0].getItem().setFull3D());
- }
- else
- {
- compressorItemStacks[0].stackSize--;
- }
- if (compressorItemStacks[0].stackSize <= 0)
- {
- compressorItemStacks[0] = null;
- }
- }
- /**
- * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
- * fuel
- */
- public static int getItemBurnTime(ItemStack par1ItemStack)
- {
- if (par1ItemStack == null)
- {
- return 0;
- }
- int i = par1ItemStack.getItem().shiftedIndex;
- if (i == mod_tutorial.FyriteCrystal.shiftedIndex)
- {
- return 1000;
- }
- if (i == mod_tutorial.DrackiDust.shiftedIndex)
- {
- return 600;
- }
- if (i == mod_tutorial.CompressorCrystal.shiftedIndex)
- {
- return 10000;
- }
- else
- {
- return ModLoader.addAllFuel(par1ItemStack.itemID, par1ItemStack.getItemDamage());
- }
- }
- public static boolean func_52005_b(ItemStack par0ItemStack)
- {
- return getItemBurnTime(par0ItemStack) > 0;
- }
- /**
- * Do not make give this method the name canInteractWith because it clashes with Container
- */
- public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
- {
- if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
- {
- return false;
- }
- return par1EntityPlayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
- }
- public void openChest()
- {
- }
- public void closeChest()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment