Guest User

BlockItemCollectorShulkerBox

a guest
Aug 9th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.79 KB | None | 0 0
  1. package com.jam.icc.block;
  2.  
  3.  
  4.  
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Random;
  8.  
  9. import com.ibm.icu.impl.duration.TimeUnit;
  10. import com.jam.icc.MainVE;
  11. import com.jam.icc.lib.Names;
  12. import com.jam.icc.tileentity.TileEntityICC;
  13. import com.jam.icc.tileentity.TileEntityICSB;
  14.  
  15. import net.minecraft.block.BlockHorizontal;
  16. import net.minecraft.block.ITileEntityProvider;
  17. import net.minecraft.block.material.Material;
  18. import net.minecraft.block.properties.PropertyDirection;
  19. import net.minecraft.block.state.BlockStateContainer;
  20. import net.minecraft.block.state.IBlockState;
  21. import net.minecraft.creativetab.CreativeTabs;
  22. import net.minecraft.entity.EntityLivingBase;
  23. import net.minecraft.entity.player.EntityPlayer;
  24. import net.minecraft.inventory.InventoryHelper;
  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.tileentity.TileEntityShulkerBox;
  30. import net.minecraft.util.BlockRenderLayer;
  31. import net.minecraft.util.EnumFacing;
  32. import net.minecraft.util.EnumHand;
  33. import net.minecraft.util.math.AxisAlignedBB;
  34. import net.minecraft.util.math.BlockPos;
  35. import net.minecraft.util.math.RayTraceResult;
  36. import net.minecraft.world.Explosion;
  37. import net.minecraft.world.IBlockAccess;
  38. import net.minecraft.world.World;
  39. import net.minecraftforge.items.CapabilityItemHandler;
  40. import net.minecraftforge.items.IItemHandler;
  41. import net.minecraftforge.items.ItemStackHandler;
  42.  
  43. public class BlockItemCollectorShulkerBox extends BlockBase implements ITileEntityProvider{
  44.    
  45.     public ItemStackHandler stackPlacer = null;
  46.    
  47.     public static final int GUI_ID = 3;
  48.  
  49.     public BlockItemCollectorShulkerBox(Material materialIn, CreativeTabs tab, String name) {
  50.         super(materialIn, tab, name);
  51.         setHardness(5F);
  52.         setResistance(2000F);
  53.        
  54.     }
  55.  
  56.    
  57.    
  58.    
  59.    
  60.     @Override
  61.     public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  62.        
  63.           // Only execute on the server
  64.         if (world.isRemote) {
  65.             return true;
  66.         }
  67.         TileEntity te = world.getTileEntity(pos);
  68.         if (!(te instanceof TileEntityICSB)) {
  69.             return false;
  70.         }
  71.         player.openGui(MainVE.instance, GUI_ID, world, pos.getX(), pos.getY(), pos.getZ());
  72.         return true;
  73.     }
  74.    
  75.        
  76.     @Override
  77.     public boolean canDropFromExplosion(Explosion explosionIn) {
  78.        
  79.         return true;
  80.     }
  81.     @Override
  82.     public boolean isFullCube(IBlockState state) {
  83.        
  84.         return false;
  85.     }
  86.     @Override
  87.     public boolean isOpaqueCube(IBlockState state) {
  88.        
  89.         return false;
  90.     }
  91.     @Override
  92.     public BlockRenderLayer getBlockLayer() {
  93.        
  94.         return BlockRenderLayer.CUTOUT;
  95.     }
  96.  
  97.    
  98.     //this was me trying to set the items in the tile entity from the stacks nbt
  99.     /*@Override
  100.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
  101.             ItemStack stack) {
  102.            
  103.         TileEntityICSB te = (TileEntityICSB)worldIn.getTileEntity(pos);
  104.        
  105.         stackPlacer = te.itemStackHandler;
  106.        
  107.         for(int i = 0; i < 27; i++)
  108.         {
  109.            
  110.                 te.itemStackHandler.setStackInSlot(i, stackPlacer.getStackInSlot(i));
  111.            
  112.            
  113.         }
  114.        
  115.         super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
  116.     }
  117.     */
  118.     @Override
  119.     public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  120.          TileEntity tee = worldIn.getTileEntity(pos);
  121.  
  122.            
  123.                 TileEntityICSB te = (TileEntityICSB)tee;
  124.  
  125.                
  126.                 ItemStack itemstack = new ItemStack(Item.getItemFromBlock(this));
  127.                
  128.                 NBTTagCompound nbttagcompound = new NBTTagCompound();
  129.                 NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  130.                
  131.                 nbttagcompound.setTag("items", te.itemStackHandler.serializeNBT());
  132.                
  133.                 itemstack.setTagCompound(nbttagcompound);
  134.                    
  135.                     spawnAsEntity(worldIn, pos, itemstack);
  136.                 System.out.println(itemstack.getTagCompound().getTag("items"));
  137.  
  138.              
  139.  
  140.             super.breakBlock(worldIn, pos, state);
  141.     }
  142.    
  143.    
  144.     @Override
  145.     public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
  146.             EntityPlayer player) {
  147.        
  148.         TileEntityICSB te = (TileEntityICSB) world.getTileEntity(pos);
  149.        
  150.         ItemStack itemstack = new ItemStack(Item.getItemFromBlock(this));
  151.         NBTTagCompound tag = new NBTTagCompound();
  152.        
  153.         tag.setTag("items", te.itemStackHandler.serializeNBT());
  154.        
  155.         itemstack.setTagCompound(tag);
  156.        
  157.        
  158.         return itemstack;
  159.     }
  160.    
  161.    
  162.     @Override
  163.     public TileEntity createNewTileEntity(World worldIn, int meta) {
  164.    
  165.         return new TileEntityICSB();
  166.     }
  167.    
  168.    
  169.    
  170.    
  171.    
  172. }
Advertisement
Add Comment
Please, Sign In to add comment