Advertisement
Guest User

Untitled

a guest
Feb 15th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.28 KB | None | 0 0
  1. package pirate.common;
  2.  
  3. import java.util.List;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockContainer;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.client.renderer.texture.IconRegister;
  9. import net.minecraft.creativetab.CreativeTabs;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.item.EntityItem;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.tileentity.TileEntity;
  15. import net.minecraft.util.Icon;
  16. import net.minecraft.util.MathHelper;
  17. import net.minecraft.world.IBlockAccess;
  18. import net.minecraft.world.World;
  19. import cpw.mods.fml.common.network.FMLNetworkHandler;
  20. import cpw.mods.fml.relauncher.Side;
  21. import cpw.mods.fml.relauncher.SideOnly;
  22. import net.minecraft.entity.item.EntityItem;
  23. import net.minecraft.nbt.NBTTagCompound;
  24. import net.minecraft.tileentity.TileEntityChest;
  25. import cpw.mods.fml.common.network.FMLNetworkHandler;
  26.  
  27. public class Baril extends BlockContainer{
  28.     private Icon icontop, iconbottom, iconfront;
  29.    
  30.     public Baril(int id)
  31.     {
  32.         super(id, Material.wood);
  33.         this.setCreativeTab(CreativeTabs.tabDecorations);
  34.     }
  35.     public void registerIcons(IconRegister iconRegister)
  36.     {
  37.         blockIcon = iconRegister.registerIcon("modpirate:Baril");
  38.         iconfront = iconRegister.registerIcon("modpirate:Baril");
  39.         icontop = iconRegister.registerIcon("modpirate:Baril_Top");
  40.         iconbottom = iconRegister.registerIcon("modpirate:Baril_Bottom");
  41.     }
  42.      @SideOnly(Side.CLIENT)
  43.      public Icon getIcon(int side, int metadata)
  44.      {
  45.              return side == 1 ? this.icontop : (side == 0 ? this.iconbottom : (metadata == 2 && side == 2 ? this.iconfront : (metadata == 3 && side == 5 ? this.iconfront : (metadata == 0 && side == 3 ? this.iconfront : (metadata == 1 && side == 4 ? this.iconfront : this.blockIcon)))));
  46.      }
  47.  
  48.      @@ -117,17 121,22 @@ public TileEntity createNewTileEntity(World world)
  49.         @Override
  50.         public TileEntity createTileEntity(World world, int metadata)
  51.         {
  52.             switch(metadata)
  53.             {
  54.             case 0:
  55.             case 2:
  56.                 return new TileEntityTutorial2();
  57.             case 3:
  58.                 return new TileEntityBigChest();
  59.             default:
  60.                 return null;
  61.             }
  62.         }
  63.  
  64.      
  65.         public boolean hasTileEntity(int metadata)
  66.         {
  67.             if(metadata == 0 || metadata == 2 || metadata == 3)
  68.                 return true;
  69.             else
  70.                 return false;
  71.      @@ -160,10 169,13 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p
  72.                 }
  73.                 return true;
  74.             }
  75.            
  76.             if(world.getBlockMetadata(x, y, z) == 3)
  77.             {
  78.                 FMLNetworkHandler.openGui(player, ModPirate.instance, 0, world, x, y, z);
  79.                 return true;
  80.             }
  81.             return false;
  82.         }
  83.      
  84.         public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
  85.      @@ -175,5 187,60 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase l
  86.            
  87.             }
  88.             if(te != null && stack.getItemDamage() == 3 && te instanceof TileEntityBigChest && stack.hasDisplayName())
  89.             {
  90.                 ((TileEntityBigChest)te).setCustomGuiName(stack.getDisplayName());
  91.             }
  92.         }
  93.        
  94.          public void breakBlock(World world, int x, int y, int z, int side, int metadata)
  95.          {
  96.             if(metadata == 3)
  97.             {
  98.                 dropContainerItem(world, x, y, z);
  99.             }
  100.              super.breakBlock(world, x, y, z, side, metadata);
  101.          }
  102.          
  103.          protected void dropContainerItem(World world, int x, int y, int z)
  104.          {
  105.             TileEntityBigChest bigchest = (TileEntityBigChest)world.getBlockTileEntity(x, y, z);
  106.      
  107.              if (bigchest != null)
  108.              {
  109.                  for (int slotId = 0; slotId < bigchest.getSizeInventory(); slotId)
  110.                  {
  111.                      ItemStack stack = bigchest.getStackInSlot(slotId);
  112.      
  113.                      if (stack != null)
  114.                      {
  115.                          float f = world.rand.nextFloat() * 0.8F  ;
  116.                          float f1 = world.rand.nextFloat() * 0.8F  ;
  117.                          EntityItem entityitem;
  118.      
  119.                          for (float f2 = world.rand.nextFloat() * 0.8F  ; stack.stackSize > 0; world.spawnEntityInWorld(entityitem))
  120.                          {
  121.                              int k1 = world.rand.nextInt(21)  ;
  122.      
  123.                              if (k1 > stack.stackSize)
  124.                              {
  125.                                  k1 = stack.stackSize;
  126.                              }
  127.      
  128.                              stack.stackSize -= k1;
  129.                              entityitem = new EntityItem(world, (double)((float)x  ), (double)((float)y  ), (double)((float)z  ), new ItemStack(stack.itemID, k1, stack.getItemDamage()));
  130.                              float f3 = 0.05F;
  131.                              entityitem.motionX = (double)((float)world.rand.nextGaussian() * f3);
  132.                              entityitem.motionY = (double)((float)world.rand.nextGaussian() * f3  );
  133.                              entityitem.motionZ = (double)((float)world.rand.nextGaussian() * f3);
  134.      
  135.                              if (stack.hasTagCompound())
  136.                              {
  137.                                  entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
  138.                              }
  139.                          }
  140.                      }
  141.                  }
  142.              }
  143.          }
  144.       }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement