Advertisement
Guest User

Comparison

a guest
Apr 27th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.33 KB | None | 0 0
  1. // REWRITTEN VERSION
  2.     @Override
  3.     public ItemStack decrStackSize(int par1, int par2)
  4.     {
  5.         ItemStack itemstack = getStackInSlot(par1);
  6.  
  7.         if (itemstack != null)
  8.         {
  9.             if (itemstack.stackSize <= par2)
  10.             {
  11.                 setInventorySlotContents(par1, null);
  12.             }
  13.             else
  14.             {
  15.                 itemstack = itemstack.splitStack(par2);
  16.  
  17.                 // Mark dirty seems to handle this for me, but I left it in your
  18.                 // code just in case
  19.                 if (this.furnaceItemStacks[par1].stackSize == 0)
  20.                 {
  21.                     this.furnaceItemStacks[par1] = null;
  22.                 }
  23.             }
  24.  
  25.             this.markDirty();
  26.         }
  27.  
  28.         // Returns null if it is null, otherwise it returns the itemstack that
  29.         // was changed inside the if statements
  30.         return itemstack;
  31.     }
  32.  
  33.     // OLD VERSION
  34.     @Override
  35.     public ItemStack decrStackSize(int par1, int par2)
  36.     {
  37.         if (this.furnaceItemStacks[par1] != null)
  38.         {
  39.             ItemStack itemstack;
  40.             if (this.furnaceItemStacks[par1].stackSize <= par2)
  41.             {
  42.                 itemstack = this.furnaceItemStacks[par1];
  43.                 this.furnaceItemStacks[par1] = null;
  44.                 return itemstack;
  45.             }
  46.             else
  47.             {
  48.                 itemstack = this.furnaceItemStacks[par1].splitStack(par2);
  49.                 if (this.furnaceItemStacks[par1].stackSize == 0)
  50.                 {
  51.                     this.furnaceItemStacks[par1] = null;
  52.                 }
  53.                 return itemstack;
  54.             }
  55.  
  56.         }
  57.         else
  58.         {
  59.             return null;
  60.         }
  61.     }
  62.  
  63.    
  64.    
  65.    
  66.    
  67.     // REWRITTEN VERSION
  68.     @Override
  69.     public ItemStack getStackInSlotOnClosing(int par1)
  70.     {
  71.         ItemStack itemstack = getStackInSlot(par1);
  72.  
  73.         // Uses your own function to set the inventory instead of manually, and
  74.         // it auto calls markDirty() for you then.
  75.         setInventorySlotContents(par1, null);
  76.  
  77.         // Once again, returns null if it is null otherwise the itemstack was
  78.         // set to something and returned.
  79.         return itemstack;
  80.     }
  81.  
  82.     // OLD VERSION
  83.     @Override
  84.     public ItemStack getStackInSlotOnClosing(int par1)
  85.     {
  86.         if (this.furnaceItemStacks[par1] != null)
  87.         {
  88.             ItemStack itemstack = this.furnaceItemStacks[par1];
  89.             this.furnaceItemStacks[par1] = null;
  90.             return itemstack;
  91.         }
  92.         else
  93.         {
  94.             return null;
  95.         }
  96.     }
  97.  
  98.    
  99.    
  100.    
  101.    
  102.     // REWRITTEN / OLD VERSION
  103.     @Override
  104.     public void setInventorySlotContents(int par1, ItemStack itemstack)
  105.     {
  106.         furnaceItemStacks[par1] = itemstack;
  107.  
  108.         if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
  109.         {
  110.             itemstack.stackSize = getInventoryStackLimit();
  111.         }
  112.  
  113.         // Just added a markDirty().
  114.         this.markDirty();
  115.     }
  116.  
  117.    
  118.    
  119.    
  120.    
  121.     // REMOVE THIS FUNCTION!!!!
  122.     // public int getBlockMetadata(int par1)
  123.     // {
  124.     // return par1;
  125.     // }
  126.  
  127.    
  128.    
  129.    
  130.    
  131.     // REWRITTEN / OLD VERSION
  132.     @Override
  133.     public Packet getDescriptionPacket()
  134.     {
  135.         NBTTagCompound tag = new NBTTagCompound();
  136.         writeToNBT(tag);
  137.  
  138.         // REMOVE THE LINE BELOW THIS!
  139.         /* nbt.setInteger("BlockMetadata", this.blockMetadata); */
  140.  
  141.         // Change the 0 back to 1 if you need to in the S35PacketUpdate.
  142.         return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
  143.     }
  144.  
  145.    
  146.    
  147.    
  148.    
  149.     // Unsure if you even need this, depends on what things you end up doing.
  150.     @Override
  151.     public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
  152.     {
  153.         readFromNBT(pkt.func_148857_g());
  154.  
  155.         // I've yet to have to call this, I don't know if you need it or not.
  156.         super.onDataPacket(net, pkt);
  157.  
  158.         // I use this snippet for when I have textures being changed on the
  159.         // block based on whether or not it contains a certain item or boolean
  160.         // etc, think of modular input/outputs i.e. in ThermalExpansion.
  161.         if (!getWorldObj().isRemote)
  162.         {
  163.             Minecraft.getMinecraft().renderGlobal.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
  164.             worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
  165.         }
  166.     }
  167.  
  168.    
  169.    
  170.    
  171.    
  172.     // REWRITTEN VERSION
  173.     public void readFromNBT(NBTTagCompound tagCompound)
  174.     {
  175.         super.readFromNBT(tagCompound);
  176.  
  177.         // Used tagCompound.getId() instead of 10.
  178.         NBTTagList tagList = tagCompound.getTagList("Items", tagCompound.getId());
  179.  
  180.         // You had this line. I think this was reseting the inventory, even
  181.         // though it looks like it was resetting before being read into. Still,
  182.         // I got rid of this.
  183.         // this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
  184.  
  185.         for (int i = 0; i < tagList.tagCount(); ++i)
  186.         {
  187.             // Gave the variables more meaningful names.
  188.             NBTTagCompound item = tagList.getCompoundTagAt(i);
  189.  
  190.             byte slot = item.getByte("Slot");
  191.  
  192.             // Using your classes' getSizeInventory because although it is
  193.             // "technically slower", it is more easily readible. The change will
  194.             // not ever be noticed. Personal preference.
  195.             if (slot >= 0 && slot < this.getSizeInventory())
  196.             {
  197.                 this.furnaceItemStacks[slot] = ItemStack.loadItemStackFromNBT(item);
  198.             }
  199.         }
  200.  
  201.         // Changed to getInteger seeing how the class has them already declared as integers.
  202.         this.furnaceBurnTime = tagCompound.getInteger("BurnTime");
  203.         this.furnaceCookTime = tagCompound.getInteger("CookTime");
  204.  
  205.         // Not sure what you are doing this for, but you said that the smelting
  206.         // was working so I left this.
  207.         this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
  208.  
  209.         // You aren't ever saving a name in the writeToNBT?!
  210.         if (tagCompound.hasKey("CustomName", 8))
  211.         {
  212.             this.furnaceName = tagCompound.getString("CustomName");
  213.         }
  214.  
  215.     }
  216.  
  217.     // OLD VERSION
  218.     public void readFromNBT(NBTTagCompound tagCompound)
  219.     {
  220.         super.readFromNBT(tagCompound);
  221.         NBTTagList tagList = tagCompound.getTagList("Items", 10);
  222.  
  223.         this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
  224.  
  225.         this.blockMetadata = tagCompound.getInteger("BlockMetadata");
  226.  
  227.         for (int i = 0; i < tagList.tagCount(); ++i)
  228.         {
  229.             NBTTagCompound tagCompound1 = tagList.getCompoundTagAt(i);
  230.             byte byte0 = tagCompound1.getByte("Slot");
  231.  
  232.             if (byte0 >= 0 && byte0 < this.furnaceItemStacks.length)
  233.             {
  234.                 this.furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tagCompound1);
  235.             }
  236.         }
  237.  
  238.         this.furnaceBurnTime = tagCompound.getShort("BurnTime");
  239.         this.furnaceCookTime = tagCompound.getShort("CookTime");
  240.         this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
  241.  
  242.         if (tagCompound.hasKey("CustomName", 8))
  243.         {
  244.             this.furnaceName = tagCompound.getString("CustomName");
  245.         }
  246.  
  247.     }
  248.  
  249.    
  250.    
  251.    
  252.    
  253.     // REWRITTEN VERSION
  254.     public void writeToNBT(NBTTagCompound tagCompound)
  255.     {
  256.         super.writeToNBT(tagCompound);
  257.  
  258.         // changed variables to be more meaningful
  259.         NBTTagList items = new NBTTagList();
  260.  
  261.         for (int i = 0; i < getSizeInventory(); i++)
  262.         {
  263.             ItemStack stack = this.getStackInSlot(i);
  264.  
  265.             if (stack != null)
  266.             {
  267.                 NBTTagCompound writeitem = new NBTTagCompound();
  268.                 // You had it writing to the wrong tag compound.
  269.                 writeitem.setByte("Slot", (byte) i);
  270.                
  271.                 // You also were writing the entire stack each time, instead of just looping through it with the for loop.
  272.                 stack.writeToNBT(writeitem);
  273.                 items.appendTag(writeitem);
  274.             }
  275.         }
  276.  
  277.         // Changed to setInteger seeing how the class has them already declared as integers.
  278.         tagCompound.setInteger("BurnTime", this.furnaceBurnTime);
  279.         tagCompound.setInteger("CookTime", this.furnaceBurnTime);
  280.     }
  281.  
  282.     // OLD VERSION
  283.     public void writeToNBT(NBTTagCompound tagCompound)
  284.     {
  285.         super.writeToNBT(tagCompound);
  286.         tagCompound.setShort("BurnTime", (short) this.furnaceBurnTime);
  287.         tagCompound.setShort("CookTime", (short) this.furnaceBurnTime);
  288.         tagCompound.setInteger("BlockMetadata", worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
  289.         NBTTagList tagList = new NBTTagList();
  290.  
  291.         for (int i = 0; i < this.furnaceItemStacks.length; ++i)
  292.         {
  293.             if (this.furnaceItemStacks != null)
  294.             {
  295.                 NBTTagCompound tagCompound1 = new NBTTagCompound();
  296.                 tagCompound.setByte("Slot", (byte) i);
  297.                 this.furnaceItemStacks.writeToNBT(tagCompound1);
  298.                 tagList.appendTag(tagCompound1);
  299.             }
  300.         }
  301.  
  302.     }
  303.  
  304.    
  305.    
  306.    
  307.    
  308.     // I'm assuming you have a reason for doing this this way. I just
  309.     // "return true" in 99% of mine. Why wouldn't the player be able to access
  310.     // it?
  311.     // If the TileEntity was used by the player, why would the tileentity ever
  312.     // NOT be this instance of it? It wouldn't have called this method then.
  313.     @Override
  314.     public boolean isUseableByPlayer(EntityPlayer player)
  315.     {
  316.         return true;
  317.         // return this.worldObj.getTileEntity(this.xCoord, this.yCoord,
  318.         // this.zCoord) != this ? false : player.getDistanceSq((double)
  319.         // this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord
  320.         // + 0.5D) <= 64.0D;
  321.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement