Advertisement
Guest User

BlockCulinary

a guest
Sep 21st, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.59 KB | None | 0 0
  1. package KBI.agricrafture.core;
  2.  
  3. import KBI.agricrafture.api.*;
  4. import net.minecraft.src.*;
  5. import java.util.Random;
  6.  
  7. public class BlockCulinary extends BlockContainer {
  8.  
  9.         protected BlockCulinary (int id)
  10.         {
  11.                 super(id, Material.wood);
  12.                 setHardness(2.0F);
  13.                 setResistance(5.0F);
  14.                 setBlockName("blockCulinary");
  15.                 setCreativeTab(CreativeTabs.tabFood);
  16.                 float var5 = 0.0625F;
  17.                 this.setBlockBounds(var5, 0.0F, var5, 1.0F - var5, 0.03125F, 1.0F - var5);
  18.         }
  19.        
  20.         @Override
  21.         public int getBlockTextureFromSideAndMetadata(int side, int md)
  22.         {
  23.             if(side==0 || side==1)
  24.             {
  25.                 return 0;
  26.             }
  27.             else
  28.             {
  29.                 return 1;
  30.             }
  31.         }
  32.        
  33.        
  34.         @Override
  35.         public boolean isOpaqueCube()
  36.         {
  37.             return false;
  38.         }
  39.  
  40.         @Override
  41.         public boolean renderAsNormalBlock()
  42.         {
  43.            
  44.             return false;
  45.         }
  46.        
  47.         @Override
  48.         public void setBlockBoundsForItemRender()
  49.         {
  50.             float var1 = 0.5F;
  51.             float var2 = 0.125F;
  52.             float var3 = 0.5F;
  53.             this.setBlockBounds(0.5F - var1, 0.5F - var2, 0.5F - var3, 0.5F + var1, 0.5F + var2, 0.5F + var3);
  54.         }
  55.        
  56.         @Override
  57.         public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
  58.         {
  59.             return par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) || BlockFence.isIdAFence(par1World.getBlockId(par2, par3 - 1, par4));
  60.         }
  61.        
  62.         @Override
  63.         public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  64.         {
  65.             boolean var6 = false;
  66.  
  67.             if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && !BlockFence.isIdAFence(par1World.getBlockId(par2, par3 - 1, par4)))
  68.             {
  69.                 var6 = true;
  70.             }
  71.  
  72.             if (var6)
  73.             {
  74.                 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
  75.                 par1World.setBlockWithNotify(par2, par3, par4, 0);
  76.             }
  77.         }
  78.  
  79.         @Override
  80.         public boolean onBlockActivated(World world, int x, int y, int z,
  81.                         EntityPlayer player, int idk, float what, float these, float are)
  82.         {
  83.             TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
  84.             if (tileEntity == null || player.isSneaking())
  85.             {
  86.                 return false;
  87.             }
  88.             player.openGui(AgricraftureMain.instance, 1420, world, x, y, z);
  89.             return true;
  90.         }
  91.  
  92.         @Override
  93.         public void breakBlock(World world, int x, int y, int z, int par5, int par6)
  94.         {
  95.                 dropItems(world, x, y, z);
  96.                 super.breakBlock(world, x, y, z, par5, par6);
  97.         }
  98.        
  99.         private void dropItems(World world, int x, int y, int z)
  100.         {
  101.                 Random rand = new Random();
  102.  
  103.                 TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
  104.                 if (!(tileEntity instanceof IInventory)) {
  105.                         return;
  106.                 }
  107.                 IInventory inventory = (IInventory) tileEntity;
  108.  
  109.                 for (int i = 0; i < inventory.getSizeInventory(); i++) {
  110.                         ItemStack item = inventory.getStackInSlot(i);
  111.  
  112.                         if (item != null && item.stackSize > 0) {
  113.                                 float rx = rand.nextFloat() * 0.8F + 0.1F;
  114.                                 float ry = rand.nextFloat() * 0.8F + 0.1F;
  115.                                 float rz = rand.nextFloat() * 0.8F + 0.1F;
  116.  
  117.                                 EntityItem entityItem = new EntityItem(world,
  118.                                                 x + rx, y + ry, z + rz,
  119.                                                 new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
  120.  
  121.                                 if (item.hasTagCompound()) {
  122.                                         entityItem.item.setTagCompound((NBTTagCompound) item.getTagCompound().copy());
  123.                                 }
  124.  
  125.                                 float factor = 0.05F;
  126.                                 entityItem.motionX = rand.nextGaussian() * factor;
  127.                                 entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
  128.                                 entityItem.motionZ = rand.nextGaussian() * factor;
  129.                                 world.spawnEntityInWorld(entityItem);
  130.                                 item.stackSize = 0;
  131.                         }
  132.                 }
  133.         }
  134.  
  135.         @Override
  136.         public TileEntity createNewTileEntity(World world) {
  137.                 return new TileEntityCulinary();
  138.         }
  139.        
  140.         public String getTextureFile()
  141.         {
  142.             return "/KBI/agricrafture/resources/1.png";
  143.         }
  144.  
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement