Don't like ads? PRO users don't see any ads ;-)
Guest

A New Furnace Part 2 Code

By: drackiseries on Jul 15th, 2012  |  syntax: Java  |  size: 31.17 KB  |  hits: 602  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MOD_ FILE CONTENTS:
  2.  
  3.  
  4. package net.minecraft.src;
  5.  
  6. import java.util.Random;
  7.  
  8. public class mod_tutorial extends BaseMod
  9. {
  10.        
  11.         //Textures
  12.        
  13.         public static int CFrontIdle;
  14.         public static int CFrontActive;
  15.         public static int CSide;
  16.        
  17.         //Blocks
  18.        
  19.         //Very Complex Blocks
  20.        
  21.         public static final Block CIdle = (new BlockCompressor(207, false).setHardness(3.0F).setResistance(1F).setStepSound(Block.soundStoneFootstep).setBlockName("CIdle")).setRequiresSelfNotify();
  22.         public static final Block CActive = (new BlockCompressor(208,true).setHardness(3.0F).setResistance(1F).setStepSound(Block.soundStoneFootstep).setBlockName("CActive")).setRequiresSelfNotify();
  23.        
  24.         //Items
  25.  
  26.         public void load()
  27.         {
  28.                
  29.                 CFrontIdle = ModLoader.addOverride("/terrain.png", "/Blocks/compressor_front.png");
  30.                 CFrontActive = ModLoader.addOverride("/terrain.png", "/Blocks/compressor_front_active.png");
  31.                 CSide = ModLoader.addOverride("/terrain.png", "/Blocks/compressor_sides.png");
  32.        
  33.                 //Registering
  34.  
  35.                 ModLoader.registerBlock(CIdle);
  36.                 ModLoader.registerBlock(CActive);
  37.                
  38.                 //Adding names
  39.                
  40.                 ModLoader.addName(CIdle, "Compressor");
  41.                 ModLoader.addName(CActive, "Compressor");
  42.                
  43.                 //Tile Entity
  44.                
  45.                 ModLoader.registerTileEntity(TileEntityCompressor.class, "compressor");
  46.                
  47.                 //Crafting Recipes
  48.                
  49.                 //Smelting Recipes
  50.                
  51.                 //Shapeless Recipes
  52.                
  53.                
  54.         }
  55.  
  56.        
  57.        
  58.         public String getVersion()
  59.         {
  60.                 return "1.2.5";
  61.         }
  62. }
  63.  
  64. BLOCKCOMPRESSOR.JAVA
  65.  
  66. package net.minecraft.src;
  67.  
  68. import java.util.Random;
  69.  
  70. public class BlockCompressor extends BlockContainer
  71. {
  72.     /**
  73.      * Is the random generator used by furnace to drop the inventory contents in random directions.
  74.      */
  75.     private Random compressorRand;
  76.  
  77.     /** True if this is an active furnace, false if idle */
  78.     private final boolean isCompressorActive;
  79.  
  80.     /**
  81.      * This flag is used to prevent the furnace inventory to be dropped upon block removal, is used internally when the
  82.      * furnace block changes from idle to active and vice-versa.
  83.      */
  84.     private static boolean keepcompressorInventory = false;
  85.  
  86.     protected BlockCompressor(int par1, boolean par2)
  87.     {
  88.         super(par1, Material.rock);
  89.         compressorRand = new Random();
  90.         isCompressorActive = par2;
  91.        
  92.     }
  93.  
  94.     /**
  95.      * Returns the ID of the items to drop on destruction.
  96.      */
  97.     public int idDropped(int par1, Random par2Random, int par3)
  98.     {
  99.         return mod_tutorial.CIdle.blockID;
  100.     }
  101.  
  102.     /**
  103.      * Called whenever the block is added into the world. Args: world, x, y, z
  104.      */
  105.     public void onBlockAdded(World par1World, int par2, int par3, int par4)
  106.     {
  107.         super.onBlockAdded(par1World, par2, par3, par4);
  108.         setDefaultDirection(par1World, par2, par3, par4);
  109.     }
  110.  
  111.     /**
  112.      * set a blocks direction
  113.      */
  114.     private void setDefaultDirection(World par1World, int par2, int par3, int par4)
  115.     {
  116.         if (par1World.isRemote)
  117.         {
  118.             return;
  119.         }
  120.  
  121.         int i = par1World.getBlockId(par2, par3, par4 - 1);
  122.         int j = par1World.getBlockId(par2, par3, par4 + 1);
  123.         int k = par1World.getBlockId(par2 - 1, par3, par4);
  124.         int l = par1World.getBlockId(par2 + 1, par3, par4);
  125.         byte byte0 = 3;
  126.  
  127.         if (Block.opaqueCubeLookup[i] && !Block.opaqueCubeLookup[j])
  128.         {
  129.             byte0 = 3;
  130.         }
  131.  
  132.         if (Block.opaqueCubeLookup[j] && !Block.opaqueCubeLookup[i])
  133.         {
  134.             byte0 = 2;
  135.         }
  136.  
  137.         if (Block.opaqueCubeLookup[k] && !Block.opaqueCubeLookup[l])
  138.         {
  139.             byte0 = 5;
  140.         }
  141.  
  142.         if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[k])
  143.         {
  144.             byte0 = 4;
  145.         }
  146.  
  147.         par1World.setBlockMetadataWithNotify(par2, par3, par4, byte0);
  148.     }
  149.  
  150.     /**
  151.      * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side
  152.      */
  153.     public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
  154.     {
  155.         if (par5 == 1)
  156.         {
  157.             return mod_tutorial.CSide;
  158.         }
  159.  
  160.         if (par5 == 0)
  161.         {
  162.             return mod_tutorial.CSide;
  163.         }
  164.  
  165.         int i = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
  166.  
  167.         if (par5 != i)
  168.         {
  169.             return mod_tutorial.CSide;
  170.         }
  171.  
  172.         if (isCompressorActive)
  173.         {
  174.             return mod_tutorial.CFrontActive;
  175.         }
  176.         else
  177.         {
  178.             return mod_tutorial.CFrontIdle;
  179.         }
  180.     }
  181.  
  182.     /**
  183.      * A randomly called display update to be able to add particles or other items for display
  184.      */
  185.     public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
  186.     {
  187.         if (!isCompressorActive)
  188.         {
  189.             return;
  190.         }
  191.  
  192.         int i = par1World.getBlockMetadata(par2, par3, par4);
  193.         float f = (float)par2 + 0.5F;
  194.         float f1 = (float)par3 + 0.0F + (par5Random.nextFloat() * 6F) / 16F;
  195.         float f2 = (float)par4 + 0.5F;
  196.         float f3 = 0.52F;
  197.         float f4 = par5Random.nextFloat() * 0.6F - 0.3F;
  198.  
  199.         if (i == 4)
  200.         {
  201.             par1World.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  202.             par1World.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  203.         }
  204.         else if (i == 5)
  205.         {
  206.             par1World.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  207.             par1World.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
  208.         }
  209.         else if (i == 2)
  210.         {
  211.             par1World.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
  212.             par1World.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
  213.         }
  214.         else if (i == 3)
  215.         {
  216.             par1World.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
  217.             par1World.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
  218.         }
  219.     }
  220.  
  221.     /**
  222.      * Returns the block texture based on the side being looked at.  Args: side
  223.      */
  224.     public int getBlockTextureFromSide(int par1)
  225.     {
  226.         if (par1 == 1)
  227.         {
  228.             return mod_tutorial.CSide;
  229.         }
  230.  
  231.         if (par1 == 0)
  232.         {
  233.             return mod_tutorial.CSide;
  234.         }
  235.  
  236.         if (par1 == 3)
  237.         {
  238.             return mod_tutorial.CFrontIdle;
  239.         }
  240.         else
  241.         {
  242.             return mod_tutorial.CSide;
  243.         }
  244.     }
  245.  
  246.     /**
  247.      * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
  248.      * block.
  249.      */
  250.     public boolean blockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer)
  251.     {
  252.         if (par1World.isRemote)
  253.         {
  254.             return true;
  255.         }
  256.  
  257.         TileEntityCompressor tileentitycompressor = (TileEntityCompressor)par1World.getBlockTileEntity(par2, par3, par4);
  258.  
  259.         if (tileentitycompressor != null)
  260.         {
  261.                 ModLoader.openGUI(par5EntityPlayer, new GuiCompressor(par5EntityPlayer.inventory, tileentitycompressor));
  262.         }
  263.  
  264.         return true;
  265.     }
  266.  
  267.     /**
  268.      * Update which block ID the furnace is using depending on whether or not it is burning
  269.      */
  270.     public static void updateCompressorBlockState(boolean par0, World par1World, int par2, int par3, int par4)
  271.     {
  272.         int i = par1World.getBlockMetadata(par2, par3, par4);
  273.         TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
  274.         keepcompressorInventory = true;
  275.  
  276.         if (par0)
  277.         {
  278.             par1World.setBlockWithNotify(par2, par3, par4, mod_tutorial.CActive.blockID);
  279.         }
  280.         else
  281.         {
  282.             par1World.setBlockWithNotify(par2, par3, par4, mod_tutorial.CIdle.blockID);
  283.         }
  284.  
  285.         keepcompressorInventory = false;
  286.         par1World.setBlockMetadataWithNotify(par2, par3, par4, i);
  287.  
  288.         if (tileentity != null)
  289.         {
  290.             tileentity.validate();
  291.             par1World.setBlockTileEntity(par2, par3, par4, tileentity);
  292.         }
  293.     }
  294.  
  295.     /**
  296.      * Returns the TileEntity used by this block.
  297.      */
  298.     public TileEntity getBlockEntity()
  299.     {
  300.         return new TileEntityCompressor();
  301.     }
  302.  
  303.     /**
  304.      * Called when the block is placed in the world.
  305.      */
  306.     public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
  307.     {
  308.         int i = MathHelper.floor_double((double)((par5EntityLiving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
  309.  
  310.         if (i == 0)
  311.         {
  312.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
  313.         }
  314.  
  315.         if (i == 1)
  316.         {
  317.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 5);
  318.         }
  319.  
  320.         if (i == 2)
  321.         {
  322.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
  323.         }
  324.  
  325.         if (i == 3)
  326.         {
  327.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 4);
  328.         }
  329.     }
  330.  
  331.     /**
  332.      * Called whenever the block is removed.
  333.      */
  334.     public void onBlockRemoval(World par1World, int par2, int par3, int par4)
  335.     {
  336.         if (!keepcompressorInventory)
  337.         {
  338.             TileEntityCompressor tileentitycompressor = (TileEntityCompressor)par1World.getBlockTileEntity(par2, par3, par4);
  339.  
  340.             if (tileentitycompressor != null)
  341.             {
  342.                 label0:
  343.  
  344.                 for (int i = 0; i < tileentitycompressor.getSizeInventory(); i++)
  345.                 {
  346.                     ItemStack itemstack = tileentitycompressor.getStackInSlot(i);
  347.  
  348.                     if (itemstack == null)
  349.                     {
  350.                         continue;
  351.                     }
  352.  
  353.                     float f = compressorRand.nextFloat() * 0.8F + 0.1F;
  354.                     float f1 = compressorRand.nextFloat() * 0.8F + 0.1F;
  355.                     float f2 = compressorRand.nextFloat() * 0.8F + 0.1F;
  356.  
  357.                     do
  358.                     {
  359.                         if (itemstack.stackSize <= 0)
  360.                         {
  361.                             continue label0;
  362.                         }
  363.  
  364.                         int j = compressorRand.nextInt(21) + 10;
  365.  
  366.                         if (j > itemstack.stackSize)
  367.                         {
  368.                             j = itemstack.stackSize;
  369.                         }
  370.  
  371.                         itemstack.stackSize -= j;
  372.                         EntityItem entityitem = new EntityItem(par1World, (float)par2 + f, (float)par3 + f1, (float)par4 + f2, new ItemStack(itemstack.itemID, j, itemstack.getItemDamage()));
  373.  
  374.                         if (itemstack.hasTagCompound())
  375.                         {
  376.                             entityitem.item.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  377.                         }
  378.  
  379.                         float f3 = 0.05F;
  380.                         entityitem.motionX = (float)compressorRand.nextGaussian() * f3;
  381.                         entityitem.motionY = (float)compressorRand.nextGaussian() * f3 + 0.2F;
  382.                         entityitem.motionZ = (float)compressorRand.nextGaussian() * f3;
  383.                         par1World.spawnEntityInWorld(entityitem);
  384.                     }
  385.                     while (true);
  386.                 }
  387.             }
  388.         }
  389.  
  390.         super.onBlockRemoval(par1World, par2, par3, par4);
  391.     }
  392. }
  393.  
  394.  
  395. CONTAINERCOMPRESSOR.JAVA
  396.  
  397. package net.minecraft.src;
  398.  
  399. import java.util.List;
  400.  
  401. public class ContainerCompressor extends Container
  402. {
  403.     private TileEntityCompressor compressor;
  404.     private int lastCompressorCookTime;
  405.     private int lastCompressorBurnTime;
  406.     private int lastCompressorItemBurnTime;
  407.  
  408.     public ContainerCompressor(InventoryPlayer par1InventoryPlayer, TileEntityCompressor par2TileEntityCompressor)
  409.     {
  410.         lastCompressorCookTime = 0;
  411.         lastCompressorBurnTime = 0;
  412.         lastCompressorItemBurnTime = 0;
  413.         compressor = par2TileEntityCompressor;
  414.         addSlot(new Slot(par2TileEntityCompressor, 0, 56, 17));
  415.         addSlot(new Slot(par2TileEntityCompressor, 1, 56, 53));
  416.         addSlot(new SlotCompressor(par1InventoryPlayer.player, par2TileEntityCompressor, 2, 116, 35));
  417.  
  418.         for (int i = 0; i < 3; i++)
  419.         {
  420.             for (int k = 0; k < 9; k++)
  421.             {
  422.                 addSlot(new Slot(par1InventoryPlayer, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));
  423.             }
  424.         }
  425.  
  426.         for (int j = 0; j < 9; j++)
  427.         {
  428.             addSlot(new Slot(par1InventoryPlayer, j, 8 + j * 18, 142));
  429.         }
  430.     }
  431.  
  432.     /**
  433.      * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
  434.      */
  435.     public void updateCraftingResults()
  436.     {
  437.         super.updateCraftingResults();
  438.  
  439.         for (int i = 0; i < crafters.size(); i++)
  440.         {
  441.             ICrafting icrafting = (ICrafting)crafters.get(i);
  442.  
  443.             if (lastCompressorCookTime != compressor.compressorCookTime)
  444.             {
  445.                 icrafting.updateCraftingInventoryInfo(this, 0, compressor.compressorCookTime);
  446.             }
  447.  
  448.             if (lastCompressorBurnTime != compressor.compressorBurnTime)
  449.             {
  450.                 icrafting.updateCraftingInventoryInfo(this, 1, compressor.compressorBurnTime);
  451.             }
  452.  
  453.             if (lastCompressorItemBurnTime != compressor.currentItemBurnTime)
  454.             {
  455.                 icrafting.updateCraftingInventoryInfo(this, 2, compressor.currentItemBurnTime);
  456.             }
  457.         }
  458.  
  459.         lastCompressorCookTime = compressor.compressorCookTime;
  460.         lastCompressorBurnTime = compressor.compressorBurnTime;
  461.         lastCompressorItemBurnTime = compressor.currentItemBurnTime;
  462.     }
  463.  
  464.     public void updateProgressBar(int par1, int par2)
  465.     {
  466.         if (par1 == 0)
  467.         {
  468.             compressor.compressorCookTime = par2;
  469.         }
  470.  
  471.         if (par1 == 1)
  472.         {
  473.             compressor.compressorBurnTime = par2;
  474.         }
  475.  
  476.         if (par1 == 2)
  477.         {
  478.             compressor.currentItemBurnTime = par2;
  479.         }
  480.     }
  481.  
  482.     public boolean canInteractWith(EntityPlayer par1EntityPlayer)
  483.     {
  484.         return compressor.isUseableByPlayer(par1EntityPlayer);
  485.     }
  486.  
  487.     /**
  488.      * Called to transfer a stack from one inventory to the other eg. when shift clicking.
  489.      */
  490.     public ItemStack transferStackInSlot(int par1)
  491.     {
  492.         ItemStack itemstack = null;
  493.         Slot slot = (Slot)inventorySlots.get(par1);
  494.  
  495.         if (slot != null && slot.getHasStack())
  496.         {
  497.             ItemStack itemstack1 = slot.getStack();
  498.             itemstack = itemstack1.copy();
  499.  
  500.             if (par1 == 2)
  501.             {
  502.                 if (!mergeItemStack(itemstack1, 3, 39, true))
  503.                 {
  504.                     return null;
  505.                 }
  506.  
  507.                 slot.func_48433_a(itemstack1, itemstack);
  508.             }
  509.             else if (par1 == 1 || par1 == 0)
  510.             {
  511.                 if (!mergeItemStack(itemstack1, 3, 39, false))
  512.                 {
  513.                     return null;
  514.                 }
  515.             }
  516.             else if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1.getItem().shiftedIndex) != null)
  517.             {
  518.                 if (!mergeItemStack(itemstack1, 0, 1, false))
  519.                 {
  520.                     return null;
  521.                 }
  522.             }
  523.             else if (TileEntityCompressor.func_52005_b(itemstack1))
  524.             {
  525.                 if (!mergeItemStack(itemstack1, 1, 2, false))
  526.                 {
  527.                     return null;
  528.                 }
  529.             }
  530.             else if (par1 >= 3 && par1 < 30)
  531.             {
  532.                 if (!mergeItemStack(itemstack1, 30, 39, false))
  533.                 {
  534.                     return null;
  535.                 }
  536.             }
  537.             else if (par1 >= 30 && par1 < 39 && !mergeItemStack(itemstack1, 3, 30, false))
  538.             {
  539.                 return null;
  540.             }
  541.  
  542.             if (itemstack1.stackSize == 0)
  543.             {
  544.                 slot.putStack(null);
  545.             }
  546.             else
  547.             {
  548.                 slot.onSlotChanged();
  549.             }
  550.  
  551.             if (itemstack1.stackSize != itemstack.stackSize)
  552.             {
  553.                 slot.onPickupFromSlot(itemstack1);
  554.             }
  555.             else
  556.             {
  557.                 return null;
  558.             }
  559.         }
  560.  
  561.         return itemstack;
  562.     }
  563. }
  564.  
  565.  
  566. GUICOMPRESSOR.JAVA
  567.  
  568. package net.minecraft.src;
  569.  
  570. import net.minecraft.client.Minecraft;
  571. import org.lwjgl.opengl.GL11;
  572.  
  573. public class GuiCompressor extends GuiContainer
  574. {
  575.     private TileEntityCompressor compressorInventory;
  576.  
  577.     public GuiCompressor(InventoryPlayer par1InventoryPlayer, TileEntityCompressor par2TileEntityCompressor)
  578.     {
  579.         super(new ContainerCompressor(par1InventoryPlayer, par2TileEntityCompressor));
  580.         compressorInventory = par2TileEntityCompressor;
  581.     }
  582.  
  583.     /**
  584.      * Draw the foreground layer for the GuiContainer (everythin in front of the items)
  585.      */
  586.     protected void drawGuiContainerForegroundLayer()
  587.     {
  588.         fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0xffffff);
  589.     }
  590.  
  591.     /**
  592.      * Draw the background layer for the GuiContainer (everything behind the items)
  593.      */
  594.     protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
  595.     {
  596.         int i = mc.renderEngine.getTexture("/gui/compressor.png");
  597.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  598.         mc.renderEngine.bindTexture(i);
  599.         int j = (width - xSize) / 2;
  600.         int k = (height - ySize) / 2;
  601.         drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
  602.  
  603.         if (compressorInventory.isBurning())
  604.         {
  605.             int l = compressorInventory.getBurnTimeRemainingScaled(12);
  606.             drawTexturedModalRect(j + 56, (k + 36 + 12) - l, 176, 12 - l, 14, l + 2);
  607.         }
  608.  
  609.         int i1 = compressorInventory.getCookProgressScaled(24);
  610.         drawTexturedModalRect(j + 79, k + 34, 176, 14, i1 + 1, 16);
  611.     }
  612. }
  613.  
  614. SLOTCOMPRESSOR.JAVA
  615.  
  616. package net.minecraft.src;
  617.  
  618. public class SlotCompressor extends Slot
  619. {
  620.     /** The player that is using the GUI where this slot resides. */
  621.     private EntityPlayer thePlayer;
  622.     private int field_48437_f;
  623.  
  624.     public SlotCompressor(EntityPlayer par1EntityPlayer, IInventory par2IInventory, int par3, int par4, int par5)
  625.     {
  626.         super(par2IInventory, par3, par4, par5);
  627.         thePlayer = par1EntityPlayer;
  628.     }
  629.  
  630.     /**
  631.      * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
  632.      */
  633.     public boolean isItemValid(ItemStack par1ItemStack)
  634.     {
  635.         return false;
  636.     }
  637.  
  638.     /**
  639.      * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
  640.      * stack.
  641.      */
  642.     public ItemStack decrStackSize(int par1)
  643.     {
  644.         if (getHasStack())
  645.         {
  646.             field_48437_f += Math.min(par1, getStack().stackSize);
  647.         }
  648.  
  649.         return super.decrStackSize(par1);
  650.     }
  651.  
  652.     /**
  653.      * Called when the player picks up an item from an inventory slot
  654.      */
  655.     public void onPickupFromSlot(ItemStack par1ItemStack)
  656.     {
  657.         func_48434_c(par1ItemStack);
  658.         super.onPickupFromSlot(par1ItemStack);
  659.     }
  660.  
  661.     protected void func_48435_a(ItemStack par1ItemStack, int par2)
  662.     {
  663.         field_48437_f += par2;
  664.         func_48434_c(par1ItemStack);
  665.     }
  666.  
  667.  
  668. }
  669.  
  670. TILEENTITYCOMPRESSOR.JAVA
  671.  
  672. package net.minecraft.src;
  673.  
  674. public class TileEntityCompressor extends TileEntity implements IInventory
  675. {
  676.     private ItemStack compressorItemStacks[];
  677.  
  678.     /** The number of ticks that the furnace will keep burning */
  679.     public int compressorBurnTime;
  680.  
  681.     /**
  682.      * The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for
  683.      */
  684.     public int currentItemBurnTime;
  685.  
  686.     /** The number of ticks that the current item has been cooking for */
  687.     public int compressorCookTime;
  688.  
  689.     public TileEntityCompressor()
  690.     {
  691.         compressorItemStacks = new ItemStack[3];
  692.         compressorBurnTime = 0;
  693.         currentItemBurnTime = 0;
  694.         compressorCookTime = 0;
  695.     }
  696.  
  697.     /**
  698.      * Returns the number of slots in the inventory.
  699.      */
  700.     public int getSizeInventory()
  701.     {
  702.         return compressorItemStacks.length;
  703.     }
  704.  
  705.     /**
  706.      * Returns the stack in slot i
  707.      */
  708.     public ItemStack getStackInSlot(int par1)
  709.     {
  710.         return compressorItemStacks[par1];
  711.     }
  712.  
  713.     /**
  714.      * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
  715.      * stack.
  716.      */
  717.     public ItemStack decrStackSize(int par1, int par2)
  718.     {
  719.         if (compressorItemStacks[par1] != null)
  720.         {
  721.             if (compressorItemStacks[par1].stackSize <= par2)
  722.             {
  723.                 ItemStack itemstack = compressorItemStacks[par1];
  724.                 compressorItemStacks[par1] = null;
  725.                 return itemstack;
  726.             }
  727.  
  728.             ItemStack itemstack1 = compressorItemStacks[par1].splitStack(par2);
  729.  
  730.             if (compressorItemStacks[par1].stackSize == 0)
  731.             {
  732.                 compressorItemStacks[par1] = null;
  733.             }
  734.  
  735.             return itemstack1;
  736.         }
  737.         else
  738.         {
  739.             return null;
  740.         }
  741.     }
  742.  
  743.     /**
  744.      * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
  745.      * like when you close a workbench GUI.
  746.      */
  747.     public ItemStack getStackInSlotOnClosing(int par1)
  748.     {
  749.         if (compressorItemStacks[par1] != null)
  750.         {
  751.             ItemStack itemstack = compressorItemStacks[par1];
  752.             compressorItemStacks[par1] = null;
  753.             return itemstack;
  754.         }
  755.         else
  756.         {
  757.             return null;
  758.         }
  759.     }
  760.  
  761.     /**
  762.      * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
  763.      */
  764.     public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
  765.     {
  766.         compressorItemStacks[par1] = par2ItemStack;
  767.  
  768.         if (par2ItemStack != null && par2ItemStack.stackSize > getInventoryStackLimit())
  769.         {
  770.             par2ItemStack.stackSize = getInventoryStackLimit();
  771.         }
  772.     }
  773.  
  774.     /**
  775.      * Returns the name of the inventory.
  776.      */
  777.     public String getInvName()
  778.     {
  779.         return "container.compressor";
  780.     }
  781.  
  782.     /**
  783.      * Reads a tile entity from NBT.
  784.      */
  785.     public void readFromNBT(NBTTagCompound par1NBTTagCompound)
  786.     {
  787.         super.readFromNBT(par1NBTTagCompound);
  788.         NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
  789.         compressorItemStacks = new ItemStack[getSizeInventory()];
  790.  
  791.         for (int i = 0; i < nbttaglist.tagCount(); i++)
  792.         {
  793.             NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.tagAt(i);
  794.             byte byte0 = nbttagcompound.getByte("Slot");
  795.  
  796.             if (byte0 >= 0 && byte0 < compressorItemStacks.length)
  797.             {
  798.                 compressorItemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound);
  799.             }
  800.         }
  801.  
  802.         compressorBurnTime = par1NBTTagCompound.getShort("BurnTime");
  803.         compressorCookTime = par1NBTTagCompound.getShort("CookTime");
  804.         currentItemBurnTime = getItemBurnTime(compressorItemStacks[1]);
  805.     }
  806.  
  807.     /**
  808.      * Writes a tile entity to NBT.
  809.      */
  810.     public void writeToNBT(NBTTagCompound par1NBTTagCompound)
  811.     {
  812.         super.writeToNBT(par1NBTTagCompound);
  813.         par1NBTTagCompound.setShort("BurnTime", (short)compressorBurnTime);
  814.         par1NBTTagCompound.setShort("CookTime", (short)compressorCookTime);
  815.         NBTTagList nbttaglist = new NBTTagList();
  816.  
  817.         for (int i = 0; i < compressorItemStacks.length; i++)
  818.         {
  819.             if (compressorItemStacks[i] != null)
  820.             {
  821.                 NBTTagCompound nbttagcompound = new NBTTagCompound();
  822.                 nbttagcompound.setByte("Slot", (byte)i);
  823.                 compressorItemStacks[i].writeToNBT(nbttagcompound);
  824.                 nbttaglist.appendTag(nbttagcompound);
  825.             }
  826.         }
  827.  
  828.         par1NBTTagCompound.setTag("Items", nbttaglist);
  829.     }
  830.  
  831.     /**
  832.      * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
  833.      * this more of a set than a get?*
  834.      */
  835.     public int getInventoryStackLimit()
  836.     {
  837.         return 64;
  838.     }
  839.  
  840.     /**
  841.      * Returns an integer between 0 and the passed value representing how close the current item is to being completely
  842.      * cooked
  843.      */
  844.     public int getCookProgressScaled(int par1)
  845.     {
  846.         return (compressorCookTime * par1) / 200;
  847.     }
  848.  
  849.     /**
  850.      * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel
  851.      * item, where 0 means that the item is exhausted and the passed value means that the item is fresh
  852.      */
  853.     public int getBurnTimeRemainingScaled(int par1)
  854.     {
  855.         if (currentItemBurnTime == 0)
  856.         {
  857.             currentItemBurnTime = 200;
  858.         }
  859.  
  860.         return (compressorBurnTime * par1) / currentItemBurnTime;
  861.     }
  862.  
  863.     /**
  864.      * Returns true if the furnace is currently burning
  865.      */
  866.     public boolean isBurning()
  867.     {
  868.         return compressorBurnTime > 0;
  869.     }
  870.  
  871.     /**
  872.      * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
  873.      * ticks and creates a new spawn inside its implementation.
  874.      */
  875.     public void updateEntity()
  876.     {
  877.         boolean flag = compressorBurnTime > 0;
  878.         boolean flag1 = false;
  879.  
  880.         if (compressorBurnTime > 0)
  881.         {
  882.                 compressorBurnTime--;
  883.         }
  884.  
  885.         if (!worldObj.isRemote)
  886.         {
  887.             if (compressorBurnTime == 0 && canSmelt())
  888.             {
  889.                 currentItemBurnTime = compressorBurnTime = getItemBurnTime(compressorItemStacks[1]);
  890.  
  891.                 if (compressorBurnTime > 0)
  892.                 {
  893.                     flag1 = true;
  894.  
  895.                     if (compressorItemStacks[1] != null)
  896.                     {
  897.                         if (compressorItemStacks[1].getItem().func_46056_k())
  898.                         {
  899.                                 compressorItemStacks[1] = new ItemStack(compressorItemStacks[1].getItem().setFull3D());
  900.                         }
  901.                         else
  902.                         {
  903.                                 compressorItemStacks[1].stackSize--;
  904.                         }
  905.  
  906.                         if (compressorItemStacks[1].stackSize == 0)
  907.                         {
  908.                                 compressorItemStacks[1] = null;
  909.                         }
  910.                     }
  911.                 }
  912.             }
  913.  
  914.             if (isBurning() && canSmelt())
  915.             {
  916.                 compressorCookTime++;
  917.  
  918.                 if (compressorCookTime == 200)
  919.                 {
  920.                         compressorCookTime = 0;
  921.                     smeltItem();
  922.                     flag1 = true;
  923.                 }
  924.             }
  925.             else
  926.             {
  927.                 compressorCookTime = 0;
  928.             }
  929.  
  930.             if (flag != (compressorBurnTime > 0))
  931.             {
  932.                 flag1 = true;
  933.                 BlockCompressor.updateCompressorBlockState(compressorBurnTime > 0, worldObj, xCoord, yCoord, zCoord);
  934.             }
  935.         }
  936.  
  937.         if (flag1)
  938.         {
  939.             onInventoryChanged();
  940.         }
  941.     }
  942.  
  943.     /**
  944.      * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
  945.      */
  946.     private boolean canSmelt()
  947.     {
  948.         if (compressorItemStacks[0] == null)
  949.         {
  950.             return false;
  951.         }
  952.  
  953.         ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(compressorItemStacks[0].getItem().shiftedIndex);
  954.  
  955.         if (itemstack == null)
  956.         {
  957.             return false;
  958.         }
  959.  
  960.         if (compressorItemStacks[2] == null)
  961.         {
  962.             return true;
  963.         }
  964.  
  965.         if (!compressorItemStacks[2].isItemEqual(itemstack))
  966.         {
  967.             return false;
  968.         }
  969.  
  970.         if (compressorItemStacks[2].stackSize < getInventoryStackLimit() && compressorItemStacks[2].stackSize < compressorItemStacks[2].getMaxStackSize())
  971.         {
  972.             return true;
  973.         }
  974.  
  975.         return compressorItemStacks[2].stackSize < itemstack.getMaxStackSize();
  976.     }
  977.  
  978.     /**
  979.      * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
  980.      */
  981.     public void smeltItem()
  982.     {
  983.         if (!canSmelt())
  984.         {
  985.             return;
  986.         }
  987.  
  988.         ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(compressorItemStacks[0].getItem().shiftedIndex);
  989.  
  990.         if (compressorItemStacks[2] == null)
  991.         {
  992.                 compressorItemStacks[2] = itemstack.copy();
  993.         }
  994.         else if (compressorItemStacks[2].itemID == itemstack.itemID)
  995.         {
  996.                 compressorItemStacks[2].stackSize += itemstack.stackSize;
  997.         }
  998.  
  999.         if (compressorItemStacks[0].getItem().func_46056_k())
  1000.         {
  1001.                 compressorItemStacks[0] = new ItemStack(compressorItemStacks[0].getItem().setFull3D());
  1002.         }
  1003.         else
  1004.         {
  1005.                 compressorItemStacks[0].stackSize--;
  1006.         }
  1007.  
  1008.         if (compressorItemStacks[0].stackSize <= 0)
  1009.         {
  1010.                 compressorItemStacks[0] = null;
  1011.         }
  1012.     }
  1013.  
  1014.     /**
  1015.      * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
  1016.      * fuel
  1017.      */
  1018.     public static int getItemBurnTime(ItemStack par1ItemStack)
  1019.     {
  1020.         if (par1ItemStack == null)
  1021.         {
  1022.             return 0;
  1023.         }
  1024.  
  1025.         int i = par1ItemStack.getItem().shiftedIndex;
  1026.  
  1027.         if (i < 256 && Block.blocksList[i].blockMaterial == Material.wood)
  1028.         {
  1029.             return 300;
  1030.         }
  1031.  
  1032.         if (i == Item.stick.shiftedIndex)
  1033.         {
  1034.             return 100;
  1035.         }
  1036.  
  1037.         if (i == Item.coal.shiftedIndex)
  1038.         {
  1039.             return 1600;
  1040.         }
  1041.  
  1042.         if (i == Item.bucketLava.shiftedIndex)
  1043.         {
  1044.             return 20000;
  1045.         }
  1046.  
  1047.         if (i == Block.sapling.blockID)
  1048.         {
  1049.             return 100;
  1050.         }
  1051.  
  1052.         if (i == Item.blazeRod.shiftedIndex)
  1053.         {
  1054.             return 2400;
  1055.         }
  1056.         else
  1057.         {
  1058.             return ModLoader.addAllFuel(par1ItemStack.itemID, par1ItemStack.getItemDamage());
  1059.         }
  1060.     }
  1061.  
  1062.     public static boolean func_52005_b(ItemStack par0ItemStack)
  1063.     {
  1064.         return getItemBurnTime(par0ItemStack) > 0;
  1065.     }
  1066.  
  1067.     /**
  1068.      * Do not make give this method the name canInteractWith because it clashes with Container
  1069.      */
  1070.     public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
  1071.     {
  1072.         if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
  1073.         {
  1074.             return false;
  1075.         }
  1076.  
  1077.         return par1EntityPlayer.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64D;
  1078.     }
  1079.  
  1080.     public void openChest()
  1081.     {
  1082.     }
  1083.  
  1084.     public void closeChest()
  1085.     {
  1086.     }
  1087. }