Guest User

BlockGrinder.java

a guest
Aug 19th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.48 KB | None | 0 0
  1. package com.xenocorpse.wulfenite.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. import net.minecraft.block.Block;
  13. import net.minecraft.block.BlockContainer;
  14. import net.minecraft.block.BlockWorkbench;
  15. import net.minecraft.block.material.Material;
  16. import net.minecraft.block.state.BlockState;
  17. import net.minecraft.block.state.IBlockState;
  18. import net.minecraft.entity.item.EntityItem;
  19. import net.minecraft.entity.player.EntityPlayer;
  20. import net.minecraft.entity.player.InventoryPlayer;
  21. import net.minecraft.init.Blocks;
  22. import net.minecraft.inventory.Container;
  23. import net.minecraft.inventory.ContainerFurnace;
  24. import net.minecraft.inventory.ContainerWorkbench;
  25. import net.minecraft.item.Item;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraft.nbt.NBTTagCompound;
  28. import net.minecraft.tileentity.TileEntity;
  29. import net.minecraft.util.BlockPos;
  30. import net.minecraft.util.ChatComponentTranslation;
  31. import net.minecraft.util.EnumFacing;
  32. import net.minecraft.util.IChatComponent;
  33. import net.minecraft.world.IInteractionObject;
  34. import net.minecraft.world.World;
  35. import net.minecraftforge.fml.relauncher.Side;
  36. import net.minecraftforge.fml.relauncher.SideOnly;
  37.  
  38. import com.xenocorpse.wulfenite.Wulfenite;
  39. import com.xenocorpse.wulfenite.init.wulfeniteBlocks;
  40. import com.xenocorpse.wulfenite.inventory.ContainerGrinder;
  41. import com.xenocorpse.wulfenite.tileentities.TileEntityGrinder;
  42.  
  43. public class BlockGrinder extends BlockContainer{
  44.    
  45.     private static boolean isBurning;
  46.     private final Random random = new Random();
  47.     private World world;
  48.     private BlockPos pos;
  49.  
  50.     public BlockGrinder(Material material) {
  51.         super(material);
  52.  
  53.     }
  54.    
  55.     @Override
  56.     public TileEntityGrinder createNewTileEntity(World worldIn, int meta) {
  57.  
  58.         return new TileEntityGrinder();
  59.     }
  60.    
  61.      public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
  62.         {
  63.             if (worldIn.isRemote)
  64.             {
  65.                 return true;
  66.             }
  67.             else
  68.             {
  69.                 playerIn.displayGui(new BlockGrinder.InterfaceGrinder(worldIn, pos));
  70.                 return true;
  71.             }
  72.         }
  73.      
  74.      public static class InterfaceGrinder implements IInteractionObject
  75.      {
  76.          private final World world;
  77.          private final BlockPos position;
  78.          private static final String __OBFID = "CL_00002127";
  79.  
  80.          public InterfaceGrinder(World worldIn, BlockPos pos)
  81.          {
  82.              this.world = worldIn;
  83.              this.position = pos;
  84.          }
  85.  
  86.          public String getName()
  87.          {
  88.              return null;
  89.          }
  90.  
  91.          public boolean hasCustomName()
  92.          {
  93.              return false;
  94.          }
  95.          
  96.          public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
  97.          {
  98.              return new ContainerGrinder(playerInventory, this.world, this.position);
  99.          }
  100.  
  101.          public String getGuiID()
  102.          {
  103.              return "minecraft:crafting_table";
  104.          }
  105.  
  106.         @Override
  107.         public IChatComponent getDisplayName() {
  108.  
  109.             return new ChatComponentTranslation(wulfeniteBlocks.grinder.getUnlocalizedName() + ".name", new Object[0]);
  110.         }
  111.      }
  112.    
  113.     public Item getItemDropped(int par1, Random random, int par3){
  114.         return Item.getItemFromBlock(wulfeniteBlocks.grinder);
  115.        
  116.     }
  117.    
  118.     public Item getItem(World world, int par2, int par3, int par4){
  119.         return Item.getItemFromBlock(wulfeniteBlocks.grinder);
  120.     }
  121.    
  122.     @SideOnly(Side.CLIENT)
  123.     public void onBlockAdded(World world, BlockPos blockPos, BlockState blockState){
  124.         super.onBlockAdded(world, blockPos, (IBlockState) blockState);
  125.     }
  126.    
  127.     public static void updateBlockState(boolean burning, BlockPos pos, World world){
  128.         TileEntity tileentity = world.getTileEntity(pos);
  129.        
  130.         if(tileentity != null){
  131.             tileentity.validate();
  132.             world.setTileEntity(pos, tileentity);
  133.         }
  134.        
  135.     }
  136.    
  137.     public void breakBlock(World world, BlockPos pos, Block block, IBlockState meta){
  138.         if(!isBurning(world, pos)){
  139.             TileEntityGrinder tileentitygrinder = (TileEntityGrinder) world.getTileEntity(pos);
  140.            
  141.             if(tileentitygrinder != null){
  142.                 for(int i = 0; i < tileentitygrinder.getInventoryStackLimit(); ++i){
  143.                     ItemStack itemstack = tileentitygrinder.getStackInSlot(i);
  144.                    
  145.                     if(itemstack != null){
  146.                         float f = this.random.nextFloat() * 0.6f + 0.1f;
  147.                         float f1 = this.random.nextFloat() * 0.6f + 0.1f;
  148.                         float f2 = this.random.nextFloat() * 0.6f + 0.1f;
  149.                        
  150.                         while(itemstack.stackSize > 0){
  151.                             int j = this.random.nextInt(21) + 10;
  152.                            
  153.                             if(j > itemstack.stackSize){
  154.                                 j = itemstack.stackSize;
  155.                                
  156.                             }
  157.                            
  158.                             itemstack.stackSize -= j;
  159.                             EntityItem entityitem = new EntityItem(world, (double) ((float) pos.getX() + f), (double) ((float) pos.getY() + f1), (double) ((float) pos.getZ() + f2), itemstack);
  160.                            
  161.                             if(itemstack.hasTagCompound()){
  162.                                 entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
  163.                             }
  164.                            
  165.                             float f3 = 0.025f;
  166.                             entityitem.motionX = (double) ((float) this.random.nextGaussian() * f3);
  167.                             entityitem.motionY = (double) ((float) this.random.nextGaussian() * f3 + 0.1f);
  168.                             entityitem.motionZ = (double) ((float) this.random.nextGaussian() * f3);
  169.                             world.spawnEntityInWorld(entityitem);
  170.                         }
  171.                     }
  172.                 }
  173.                
  174.                 world.func_175665_u(pos);
  175.             }
  176.         }
  177.        
  178.         super.breakBlock(world, pos, meta);
  179.     }
  180.    
  181. }
Advertisement
Add Comment
Please, Sign In to add comment