drackiseries

A New Furnace Part 3 Code

Jul 16th, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.74 KB | None | 0 0
  1. 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.
  2.  
  3.  
  4.  
  5.  
  6. CHANGES MADE TO TILEENTITYCOMPRESSOR:
  7.  
  8.  
  9. package net.minecraft.src;
  10.  
  11. public class TileEntityCompressor extends TileEntity implements IInventory
  12. {
  13.     private ItemStack compressorItemStacks[];
  14.  
  15.     /** The number of ticks that the furnace will keep burning */
  16.     public int compressorBurnTime;
  17.  
  18.     /**
  19.      * The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for
  20.      */
  21.     public int currentItemBurnTime;
  22.  
  23.     /** The number of ticks that the current item has been cooking for */
  24.     public int compressorCookTime;
  25.  
  26.     public TileEntityCompressor()
  27.     {
  28.         compressorItemStacks = new ItemStack[3];
  29.         compressorBurnTime = 0;
  30.         currentItemBurnTime = 0;
  31.         compressorCookTime = 0;
  32.     }
  33.  
  34.     /**
  35.      * Returns the number of slots in the inventory.
  36.      */
  37.     public int getSizeInventory()
  38.     {
  39.         return compressorItemStacks.length;
  40.     }
  41.  
  42.     /**
  43.      * Returns the stack in slot i
  44.      */
  45.     public ItemStack getStackInSlot(int par1)
  46.     {
  47.         return compressorItemStacks[par1];
  48.     }
  49.  
  50.     /**
  51.      * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
  52.      * stack.
  53.      */
  54.     public ItemStack decrStackSize(int par1, int par2)
  55.     {
  56.         if (compressorItemStacks[par1] != null)
  57.         {
  58.             if (compressorItemStacks[par1].stackSize <= par2)
  59.             {
  60.                 ItemStack itemstack = compressorItemStacks[par1];
  61.                 compressorItemStacks[par1] = null;
  62.                 return itemstack;
  63.             }
  64.  
  65.             ItemStack itemstack1 = compressorItemStacks[par1].splitStack(par2);
  66.  
  67.             if (compressorItemStacks[par1].stackSize == 0)
  68.             {
  69.                 compressorItemStacks[par1] = null;
  70.             }
  71.  
  72.             return itemstack1;
  73.         }
  74.         else
  75.         {
  76.             return null;
  77.         }
  78.     }
  79.  
  80.     /**
  81.      * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
  82.      * like when you close a workbench GUI.
  83.      */
  84.     public ItemStack getStackInSlotOnClosing(int par1)
  85.     {
  86.         if (compressorItemStacks[par1] != null)
  87.         {
  88.             ItemStack itemstack = compressorItemStacks[par1];
  89.             compressorItemStacks[par1] = null;
  90.             return itemstack;
  91.         }
  92.         else
  93.         {
  94.             return null;
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
  100.      */
  101.     public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
  102.     {
  103.         compressorItemStacks[par1] = par2ItemStack;
  104.  
  105.         if (par2ItemStack != null && par2ItemStack.stackSize > getInventoryStackLimit())
  106.         {
  107.             par2ItemStack.stackSize = getInventoryStackLimit();
  108.         }
  109.     }
  110.  
  111.     /**
  112.      * Returns the name of the inventory.
  113.      */
  114.     public String getInvName()
  115.     {
  116.         return "container.compressor";
  117.     }
  118.  
  119.     /**
  120.      * Reads a tile entity from NBT.
  121.      */
  122.     public void readFromNBT(NBTTagCompound par1NBTTagCompound)
  123.     {
  124.         super.readFromNBT(par1NBTTagCompound);
  125.         NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
  126.         compressorItemStacks = new ItemStack[getSizeInventory()];
  127.  
  128.         for (int i = 0; i < nbttaglist.tagCount(); i++)
  129.         {
  130.             NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.tagAt(i);
  131.             byte byte0 = nbttagcompound.getByte("Slot");
  132.  
  133.             if (byte0 >= 0 && byte0 < compressorItemStacks.length)
  134.             {
  135.                 compressorItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound);
  136.             }
  137.         }
  138.  
  139.         compressorBurnTime = par1NBTTagCompound.getShort("BurnTime");
  140.         compressorCookTime = par1NBTTagCompound.getShort("CookTime");
  141.         currentItemBurnTime = getItemBurnTime(compressorItemStacks[1]);
  142.     }
  143.  
  144.     /**
  145.      * Writes a tile entity to NBT.
  146.      */
  147.     public void writeToNBT(NBTTagCompound par1NBTTagCompound)
  148.     {
  149.         super.writeToNBT(par1NBTTagCompound);
  150.         par1NBTTagCompound.setShort("BurnTime", (short)compressorBurnTime);
  151.         par1NBTTagCompound.setShort("CookTime", (short)compressorCookTime);
  152.         NBTTagList nbttaglist = new NBTTagList();
  153.  
  154.         for (int i = 0; i < compressorItemStacks.length; i++)
  155.         {
  156.             if (compressorItemStacks[i] != null)
  157.             {
  158.                 NBTTagCompound nbttagcompound = new NBTTagCompound();
  159.                 nbttagcompound.setByte("Slot", (byte)i);
  160.                 compressorItemStacks[i].writeToNBT(nbttagcompound);
  161.                 nbttaglist.appendTag(nbttagcompound);
  162.             }
  163.         }
  164.  
  165.         par1NBTTagCompound.setTag("Items", nbttaglist);
  166.     }
  167.  
  168.     /**
  169.      * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
  170.      * this more of a set than a get?*
  171.      */
  172.     public int getInventoryStackLimit()
  173.     {
  174.         return 64;
  175.     }
  176.  
  177.     /**
  178.      * Returns an integer between 0 and the passed value representing how close the current item is to being completely
  179.      * cooked
  180.      */
  181.     public int getCookProgressScaled(int par1)
  182.     {
  183.         return (compressorCookTime * par1) / 200;
  184.     }
  185.  
  186.     /**
  187.      * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel
  188.      * item, where 0 means that the item is exhausted and the passed value means that the item is fresh
  189.      */
  190.     public int getBurnTimeRemainingScaled(int par1)
  191.     {
  192.         if (currentItemBurnTime == 0)
  193.         {
  194.             currentItemBurnTime = 200;
  195.         }
  196.  
  197.         return (compressorBurnTime * par1) / currentItemBurnTime;
  198.     }
  199.  
  200.     /**
  201.      * Returns true if the furnace is currently burning
  202.      */
  203.     public boolean isBurning()
  204.     {
  205.         return compressorBurnTime > 0;
  206.     }
  207.  
  208.     /**
  209.      * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
  210.      * ticks and creates a new spawn inside its implementation.
  211.      */
  212.     public void updateEntity()
  213.     {
  214.         boolean flag = compressorBurnTime > 0;
  215.         boolean flag1 = false;
  216.  
  217.         if (compressorBurnTime > 0)
  218.         {
  219.             compressorBurnTime--;
  220.         }
  221.  
  222.         if (!worldObj.isRemote)
  223.         {
  224.             if (compressorBurnTime == 0 && canSmelt())
  225.             {
  226.                 currentItemBurnTime = compressorBurnTime = getItemBurnTime(compressorItemStacks[1]);
  227.  
  228.                 if (compressorBurnTime > 0)
  229.                 {
  230.                     flag1 = true;
  231.  
  232.                     if (compressorItemStacks[1] != null)
  233.                     {
  234.                         if (compressorItemStacks[1].getItem().func_46056_k())
  235.                         {
  236.                             compressorItemStacks[1] = new ItemStack(compressorItemStacks[1].getItem().setFull3D());
  237.                         }
  238.                         else
  239.                         {
  240.                             compressorItemStacks[1].stackSize--;
  241.                         }
  242.  
  243.                         if (compressorItemStacks[1].stackSize == 0)
  244.                         {
  245.                             compressorItemStacks[1] = null;
  246.                         }
  247.                     }
  248.                 }
  249.             }
  250.  
  251.             if (isBurning() && canSmelt())
  252.             {
  253.                 compressorCookTime++;
  254.  
  255.                 if (compressorCookTime == 200)
  256.                 {
  257.                     compressorCookTime = 0;
  258.                     smeltItem();
  259.                     flag1 = true;
  260.                 }
  261.             }
  262.             else
  263.             {
  264.                 compressorCookTime = 0;
  265.             }
  266.  
  267.             if (flag != (compressorBurnTime > 0))
  268.             {
  269.                 flag1 = true;
  270.                 BlockCompressor.updateCompressorBlockState(compressorBurnTime > 0, worldObj, xCoord, yCoord, zCoord);
  271.             }
  272.         }
  273.  
  274.         if (flag1)
  275.         {
  276.             onInventoryChanged();
  277.         }
  278.     }
  279.  
  280.     /**
  281.      * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
  282.      */
  283.     private boolean canSmelt()
  284.     {
  285.         if (compressorItemStacks[0] == null)
  286.         {
  287.             return false;
  288.         }
  289.  
  290.         ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(compressorItemStacks[0].getItem().shiftedIndex);
  291.  
  292.         if (itemstack == null)
  293.         {
  294.             return false;
  295.         }
  296.  
  297.         if (compressorItemStacks[2] == null)
  298.         {
  299.             return true;
  300.         }
  301.  
  302.         if (!compressorItemStacks[2].isItemEqual(itemstack))
  303.         {
  304.             return false;
  305.         }
  306.  
  307.         if (compressorItemStacks[2].stackSize < getInventoryStackLimit() && compressorItemStacks[2].stackSize < compressorItemStacks[2].getMaxStackSize())
  308.         {
  309.             return true;
  310.         }
  311.  
  312.         return compressorItemStacks[2].stackSize < itemstack.getMaxStackSize();
  313.     }
  314.  
  315.     /**
  316.      * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
  317.      */
  318.     public void smeltItem()
  319.     {
  320.         if (!canSmelt())
  321.         {
  322.             return;
  323.         }
  324.  
  325.         ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(compressorItemStacks[0].getItem().shiftedIndex);
  326.  
  327.         if (compressorItemStacks[2] == null)
  328.         {
  329.             compressorItemStacks[2] = itemstack.copy();
  330.         }
  331.         else if (compressorItemStacks[2].itemID == itemstack.itemID)
  332.         {
  333.             compressorItemStacks[2].stackSize += itemstack.stackSize;
  334.         }
  335.  
  336.         if (compressorItemStacks[0].getItem().func_46056_k())
  337.         {
  338.             compressorItemStacks[0] = new ItemStack(compressorItemStacks[0].getItem().setFull3D());
  339.         }
  340.         else
  341.         {
  342.             compressorItemStacks[0].stackSize--;
  343.         }
  344.  
  345.         if (compressorItemStacks[0].stackSize <= 0)
  346.         {
  347.             compressorItemStacks[0] = null;
  348.         }
  349.     }
  350.  
  351.     /**
  352.      * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
  353.      * fuel
  354.      */
  355.     public static int getItemBurnTime(ItemStack par1ItemStack)
  356.     {
  357.         if (par1ItemStack == null)
  358.         {
  359.             return 0;
  360.         }
  361.  
  362.         int i = par1ItemStack.getItem().shiftedIndex;
  363.  
  364.         if (i == mod_tutorial.FyriteCrystal.shiftedIndex)
  365.         {
  366.             return 1000;
  367.         }
  368.  
  369.         if (i == mod_tutorial.DrackiDust.shiftedIndex)
  370.         {
  371.             return 600;
  372.         }
  373.  
  374.         if (i == mod_tutorial.CompressorCrystal.shiftedIndex)
  375.         {
  376.             return 10000;
  377.         }
  378.      
  379.  
  380.         else
  381.         {
  382.             return ModLoader.addAllFuel(par1ItemStack.itemID, par1ItemStack.getItemDamage());
  383.         }
  384.     }
  385.  
  386.     public static boolean func_52005_b(ItemStack par0ItemStack)
  387.     {
  388.         return getItemBurnTime(par0ItemStack) > 0;
  389.     }
  390.  
  391.     /**
  392.      * Do not make give this method the name canInteractWith because it clashes with Container
  393.      */
  394.     public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
  395.     {
  396.         if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
  397.         {
  398.             return false;
  399.         }
  400.  
  401.         return par1EntityPlayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
  402.     }
  403.  
  404.     public void openChest()
  405.     {
  406.     }
  407.  
  408.     public void closeChest()
  409.     {
  410.     }
  411. }
Advertisement
Add Comment
Please, Sign In to add comment