Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // REWRITTEN VERSION
- @Override
- public ItemStack decrStackSize(int par1, int par2)
- {
- ItemStack itemstack = getStackInSlot(par1);
- if (itemstack != null)
- {
- if (itemstack.stackSize <= par2)
- {
- setInventorySlotContents(par1, null);
- }
- else
- {
- itemstack = itemstack.splitStack(par2);
- // Mark dirty seems to handle this for me, but I left it in your
- // code just in case
- if (this.furnaceItemStacks[par1].stackSize == 0)
- {
- this.furnaceItemStacks[par1] = null;
- }
- }
- this.markDirty();
- }
- // Returns null if it is null, otherwise it returns the itemstack that
- // was changed inside the if statements
- return itemstack;
- }
- // OLD VERSION
- @Override
- public ItemStack decrStackSize(int par1, int par2)
- {
- if (this.furnaceItemStacks[par1] != null)
- {
- ItemStack itemstack;
- if (this.furnaceItemStacks[par1].stackSize <= par2)
- {
- itemstack = this.furnaceItemStacks[par1];
- this.furnaceItemStacks[par1] = null;
- return itemstack;
- }
- else
- {
- itemstack = this.furnaceItemStacks[par1].splitStack(par2);
- if (this.furnaceItemStacks[par1].stackSize == 0)
- {
- this.furnaceItemStacks[par1] = null;
- }
- return itemstack;
- }
- }
- else
- {
- return null;
- }
- }
- // REWRITTEN VERSION
- @Override
- public ItemStack getStackInSlotOnClosing(int par1)
- {
- ItemStack itemstack = getStackInSlot(par1);
- // Uses your own function to set the inventory instead of manually, and
- // it auto calls markDirty() for you then.
- setInventorySlotContents(par1, null);
- // Once again, returns null if it is null otherwise the itemstack was
- // set to something and returned.
- return itemstack;
- }
- // OLD VERSION
- @Override
- public ItemStack getStackInSlotOnClosing(int par1)
- {
- if (this.furnaceItemStacks[par1] != null)
- {
- ItemStack itemstack = this.furnaceItemStacks[par1];
- this.furnaceItemStacks[par1] = null;
- return itemstack;
- }
- else
- {
- return null;
- }
- }
- // REWRITTEN / OLD VERSION
- @Override
- public void setInventorySlotContents(int par1, ItemStack itemstack)
- {
- furnaceItemStacks[par1] = itemstack;
- if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
- {
- itemstack.stackSize = getInventoryStackLimit();
- }
- // Just added a markDirty().
- this.markDirty();
- }
- // REMOVE THIS FUNCTION!!!!
- // public int getBlockMetadata(int par1)
- // {
- // return par1;
- // }
- // REWRITTEN / OLD VERSION
- @Override
- public Packet getDescriptionPacket()
- {
- NBTTagCompound tag = new NBTTagCompound();
- writeToNBT(tag);
- // REMOVE THE LINE BELOW THIS!
- /* nbt.setInteger("BlockMetadata", this.blockMetadata); */
- // Change the 0 back to 1 if you need to in the S35PacketUpdate.
- return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
- }
- // Unsure if you even need this, depends on what things you end up doing.
- @Override
- public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
- {
- readFromNBT(pkt.func_148857_g());
- // I've yet to have to call this, I don't know if you need it or not.
- super.onDataPacket(net, pkt);
- // I use this snippet for when I have textures being changed on the
- // block based on whether or not it contains a certain item or boolean
- // etc, think of modular input/outputs i.e. in ThermalExpansion.
- if (!getWorldObj().isRemote)
- {
- Minecraft.getMinecraft().renderGlobal.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
- worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
- }
- }
- // REWRITTEN VERSION
- public void readFromNBT(NBTTagCompound tagCompound)
- {
- super.readFromNBT(tagCompound);
- // Used tagCompound.getId() instead of 10.
- NBTTagList tagList = tagCompound.getTagList("Items", tagCompound.getId());
- // You had this line. I think this was reseting the inventory, even
- // though it looks like it was resetting before being read into. Still,
- // I got rid of this.
- // this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
- for (int i = 0; i < tagList.tagCount(); ++i)
- {
- // Gave the variables more meaningful names.
- NBTTagCompound item = tagList.getCompoundTagAt(i);
- byte slot = item.getByte("Slot");
- // Using your classes' getSizeInventory because although it is
- // "technically slower", it is more easily readible. The change will
- // not ever be noticed. Personal preference.
- if (slot >= 0 && slot < this.getSizeInventory())
- {
- this.furnaceItemStacks[slot] = ItemStack.loadItemStackFromNBT(item);
- }
- }
- // Changed to getInteger seeing how the class has them already declared as integers.
- this.furnaceBurnTime = tagCompound.getInteger("BurnTime");
- this.furnaceCookTime = tagCompound.getInteger("CookTime");
- // Not sure what you are doing this for, but you said that the smelting
- // was working so I left this.
- this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
- // You aren't ever saving a name in the writeToNBT?!
- if (tagCompound.hasKey("CustomName", 8))
- {
- this.furnaceName = tagCompound.getString("CustomName");
- }
- }
- // OLD VERSION
- public void readFromNBT(NBTTagCompound tagCompound)
- {
- super.readFromNBT(tagCompound);
- NBTTagList tagList = tagCompound.getTagList("Items", 10);
- this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
- this.blockMetadata = tagCompound.getInteger("BlockMetadata");
- for (int i = 0; i < tagList.tagCount(); ++i)
- {
- NBTTagCompound tagCompound1 = tagList.getCompoundTagAt(i);
- byte byte0 = tagCompound1.getByte("Slot");
- if (byte0 >= 0 && byte0 < this.furnaceItemStacks.length)
- {
- this.furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tagCompound1);
- }
- }
- this.furnaceBurnTime = tagCompound.getShort("BurnTime");
- this.furnaceCookTime = tagCompound.getShort("CookTime");
- this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
- if (tagCompound.hasKey("CustomName", 8))
- {
- this.furnaceName = tagCompound.getString("CustomName");
- }
- }
- // REWRITTEN VERSION
- public void writeToNBT(NBTTagCompound tagCompound)
- {
- super.writeToNBT(tagCompound);
- // changed variables to be more meaningful
- NBTTagList items = new NBTTagList();
- for (int i = 0; i < getSizeInventory(); i++)
- {
- ItemStack stack = this.getStackInSlot(i);
- if (stack != null)
- {
- NBTTagCompound writeitem = new NBTTagCompound();
- // You had it writing to the wrong tag compound.
- writeitem.setByte("Slot", (byte) i);
- // You also were writing the entire stack each time, instead of just looping through it with the for loop.
- stack.writeToNBT(writeitem);
- items.appendTag(writeitem);
- }
- }
- // Changed to setInteger seeing how the class has them already declared as integers.
- tagCompound.setInteger("BurnTime", this.furnaceBurnTime);
- tagCompound.setInteger("CookTime", this.furnaceBurnTime);
- }
- // OLD VERSION
- public void writeToNBT(NBTTagCompound tagCompound)
- {
- super.writeToNBT(tagCompound);
- tagCompound.setShort("BurnTime", (short) this.furnaceBurnTime);
- tagCompound.setShort("CookTime", (short) this.furnaceBurnTime);
- tagCompound.setInteger("BlockMetadata", worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
- NBTTagList tagList = new NBTTagList();
- for (int i = 0; i < this.furnaceItemStacks.length; ++i)
- {
- if (this.furnaceItemStacks != null)
- {
- NBTTagCompound tagCompound1 = new NBTTagCompound();
- tagCompound.setByte("Slot", (byte) i);
- this.furnaceItemStacks.writeToNBT(tagCompound1);
- tagList.appendTag(tagCompound1);
- }
- }
- }
- // I'm assuming you have a reason for doing this this way. I just
- // "return true" in 99% of mine. Why wouldn't the player be able to access
- // it?
- // If the TileEntity was used by the player, why would the tileentity ever
- // NOT be this instance of it? It wouldn't have called this method then.
- @Override
- public boolean isUseableByPlayer(EntityPlayer player)
- {
- return true;
- // 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement