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

Untitled

By: a guest on Aug 3rd, 2012  |  syntax: Java  |  size: 7.63 KB  |  hits: 23  |  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. package net.minecraft.src;
  2.  
  3. import java.util.Random;
  4.  
  5. public class BlockChestSmelter extends BlockContainer {
  6.        
  7.         private BaseMod base;
  8.         private Random random;
  9.        
  10.         protected BlockChestSmelter (BaseMod _base, int i) {
  11.                 super (i, Material.wood);
  12.                 base = _base;
  13.                 random = new Random();
  14.                 blockIndexInTexture = 26;
  15.                 setTickRandomly(true);
  16.                 setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
  17.         }
  18.        
  19.         public boolean renderAsNormalBlock()
  20.     {
  21.         return false;
  22.     }
  23.        
  24.         public boolean isOpaqueCube()
  25.     {
  26.         return false;
  27.     }
  28.        
  29.         public int getRenderType()
  30.     {
  31.         return ((mod_utilityChest)base).chestSmelterRenderID;
  32.     }
  33.        
  34.         public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l)
  35.     {
  36.         if(l == 1)
  37.         {
  38.             return blockIndexInTexture - 1;
  39.         }
  40.         if(l == 0)
  41.         {
  42.             return blockIndexInTexture - 1;
  43.         }
  44.         int i1 = iblockaccess.getBlockId(i, j, k - 1);
  45.         int j1 = iblockaccess.getBlockId(i, j, k + 1);
  46.         int k1 = iblockaccess.getBlockId(i - 1, j, k);
  47.         int l1 = iblockaccess.getBlockId(i + 1, j, k);
  48.         byte byte0 = 3;
  49.         if(Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[j1])
  50.         {
  51.             byte0 = 3;
  52.         }
  53.         if(Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[i1])
  54.         {
  55.             byte0 = 2;
  56.         }
  57.         if(Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[l1])
  58.         {
  59.             byte0 = 5;
  60.         }
  61.         if(Block.opaqueCubeLookup[l1] && !Block.opaqueCubeLookup[k1])
  62.         {
  63.             byte0 = 4;
  64.         }
  65.         return l != byte0 ? blockIndexInTexture : blockIndexInTexture + 1;
  66.         }
  67.        
  68.         public int getBlockTextureFromSide(int i)
  69.     {
  70.         if(i == 1)
  71.         {
  72.             return blockIndexInTexture - 1;
  73.         }
  74.         if(i == 0)
  75.         {
  76.             return blockIndexInTexture - 1;
  77.         }
  78.         if(i == 3)
  79.         {
  80.             return blockIndexInTexture + 1;
  81.         } else
  82.         {
  83.             return blockIndexInTexture;
  84.         }
  85.     }
  86.        
  87.         public void updateTick(World world, int i, int j, int k, Random random) {
  88.                
  89.                 System.out.println("TICK");
  90.                
  91.                 if (world.isRemote) {
  92.                         return;
  93.                 }
  94.                
  95.                 TileEntityUtilityChest uchest = (TileEntityUtilityChest)world.getBlockTileEntity(i, j, k);
  96.                
  97.                 for (int i1 = 0; i1 < uchest.getSizeInventory(); i1 ++) {
  98.                         ItemStack is = uchest.getStackInSlot(i1);
  99.                        
  100.                         if (is == null) {
  101.                                 continue;
  102.                         }
  103.                        
  104.                         if (canSmelt(world, is, uchest)) {
  105.                                 uchest.decrStackSize(i1, 1);
  106.                         }
  107.                 }
  108.                 uchest.onInventoryChanged();
  109.         }
  110.        
  111.         public boolean canSmelt(World world, ItemStack is, TileEntityUtilityChest uchest) {
  112.                 ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(is);
  113.                
  114.                 if (itemstack == null) {
  115.                         return false;
  116.                 }
  117.                 return getNextFreeSlot(world, itemstack, uchest);
  118.         }
  119.        
  120.         public boolean getNextFreeSlot(World world, ItemStack is, TileEntityUtilityChest uchest) {
  121.                
  122.                 if (is == null) {
  123.                         return false;
  124.                 }
  125.                
  126.                 int i = 0;
  127.                 ItemStack is2;
  128.                
  129.                 if (is.isStackable()) {
  130.                         System.out.println(is.stackSize);
  131.                         while (is.stackSize > 0 && i < uchest.getSizeInventory()) {
  132.                                 is2 = uchest.getStackInSlot(i);
  133.                                 if (is2 == null) {
  134.                                         i++;
  135.                                         continue;
  136.                                 }
  137.                                 System.out.println("IS2!null: " + (is2 != null) + " IDs " + (is2.itemID == is.itemID) + " Damage " + (!is.getHasSubtypes() || is.getItemDamage() == is2.getItemDamage()) + " Enchant " + (ItemStack.func_46154_a(is, is2)));
  138.                                 if (is2 != null && is2.itemID == is.itemID && (!is.getHasSubtypes() || is.getItemDamage() == is2.getItemDamage()) && ItemStack.func_46154_a(is, is2)) {
  139.                                         int j = is.stackSize + is2.stackSize;
  140.                                         System.out.println("New SS " + j);
  141.                                         if (j <= is.getMaxStackSize()) {
  142.                                                 is.stackSize = 0;
  143.                                                 is2.stackSize = j;
  144.                                         } else if (is.stackSize < is.getMaxStackSize()){
  145.                                                 is.stackSize -= is.getMaxStackSize() - is2.stackSize;
  146.                                                 is2.stackSize = is2.getMaxStackSize();
  147.                                         }
  148.                                 }
  149.                                 i++;
  150.                         }
  151.                 }
  152.                
  153.                 if (is.stackSize > 0) {
  154.                         i = 0;
  155.                         while (i < uchest.getSizeInventory()) {
  156.                                 is2 = uchest.getStackInSlot(i);
  157.                                 if (is2 == null) {
  158.                                         uchest.setInventorySlotContents(i, is.copy());
  159.                                         is.stackSize = 0;
  160.                                         break;
  161.                                 }
  162.                                
  163.                                 i++;
  164.                         }
  165.                        
  166.                         if (is.stackSize > 0) {
  167.                                 dropItem(world, is.copy(), uchest);
  168.                                 is.stackSize = 0;
  169.                         }
  170.                 }
  171.                 return true;
  172.         }
  173.        
  174.         public void dropItem(World world, ItemStack is, TileEntityUtilityChest uchest) {
  175.                 EntityItem item = new EntityItem(world, (float)uchest.xCoord, (float)uchest.yCoord, (float)uchest.zCoord, is);
  176.                 item.motionX = 0.0D;
  177.                 item.motionY = 0.0D;
  178.                 item.motionZ = 0.0D;
  179.                 if (is.hasTagCompound())
  180.         {
  181.             item.item.setTagCompound((NBTTagCompound)is.getTagCompound().copy());
  182.         }
  183.                 world.spawnEntityInWorld(item);
  184.         }
  185.  
  186.         @Override
  187.         public TileEntity getBlockEntity() {
  188.                 return new TileEntitySmelterChest();
  189.         }
  190.        
  191.         public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
  192.         {
  193.                 TileEntitySmelterChest tesc = (TileEntitySmelterChest)world.getBlockTileEntity(i, j, k);
  194.                
  195.                 entityplayer.displayGUIChest(((IInventory) (tesc)));
  196.                 return true;
  197.         }
  198.        
  199.         public void onBlockRemoval(World par1World, int par2, int par3, int par4)
  200.     {
  201.         TileEntitySmelterChest tileentitychest = (TileEntitySmelterChest)par1World.getBlockTileEntity(par2, par3, par4);
  202.  
  203.         if (tileentitychest != null)
  204.         {
  205.             for (int i = 0; i < tileentitychest.getSizeInventory(); i++)
  206.             {
  207.                 ItemStack itemstack = tileentitychest.getStackInSlot(i);
  208.  
  209.                 if (itemstack == null)
  210.                 {
  211.                     continue;
  212.                 }
  213.  
  214.                 float f = random.nextFloat() * 0.8F + 0.1F;
  215.                 float f1 = random.nextFloat() * 0.8F + 0.1F;
  216.                 float f2 = random.nextFloat() * 0.8F + 0.1F;
  217.  
  218.                 while (itemstack.stackSize > 0)
  219.                 {
  220.                     int j = random.nextInt(21) + 10;
  221.  
  222.                     if (j > itemstack.stackSize)
  223.                     {
  224.                         j = itemstack.stackSize;
  225.                     }
  226.  
  227.                     itemstack.stackSize -= j;
  228.                     EntityItem entityitem = new EntityItem(par1World, (float)par2 + f, (float)par3 + f1, (float)par4 + f2, new ItemStack(itemstack.itemID, j, itemstack.getItemDamage()));
  229.                     float f3 = 0.05F;
  230.                     entityitem.motionX = (float)random.nextGaussian() * f3;
  231.                     entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F;
  232.                     entityitem.motionZ = (float)random.nextGaussian() * f3;
  233.  
  234.                     if (itemstack.hasTagCompound())
  235.                     {
  236.                         entityitem.item.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  237.                     }
  238.  
  239.                     par1World.spawnEntityInWorld(entityitem);
  240.                 }
  241.             }
  242.         }
  243.  
  244.         super.onBlockRemoval(par1World, par2, par3, par4);
  245.     }
  246.        
  247.         public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
  248.     {
  249.                
  250.                 byte byte0 = 0;
  251.         int i1 = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
  252.  
  253.         if (i1 == 0)
  254.         {
  255.             byte0 = 2;
  256.         }
  257.  
  258.         if (i1 == 1)
  259.         {
  260.             byte0 = 5;
  261.         }
  262.  
  263.         if (i1 == 2)
  264.         {
  265.             byte0 = 3;
  266.         }
  267.  
  268.         if (i1 == 3)
  269.         {
  270.             byte0 = 4;
  271.         }
  272.        
  273.         world.setBlockMetadataWithNotify(i, j, k, byte0);
  274.     }
  275.  
  276. }