Guest User

Untitled

a guest
Jul 17th, 2018
128
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.natura.minestuckarsenal.block;
  2.  
  3. import javax.annotation.Nullable;
  4.  
  5. import com.mraof.minestuck.item.MinestuckItems;
  6. import com.natura.minestuckarsenal.MinestuckArsenal;
  7. import com.natura.minestuckarsenal.TabArsenal;
  8. import com.natura.minestuckarsenal.tileentity.EnergyMaster;
  9. import com.natura.minestuckarsenal.tileentity.TileEntityHub;
  10.  
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.material.MapColor;
  13. import net.minecraft.block.material.Material;
  14. import net.minecraft.block.state.BlockFaceShape;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.entity.item.EntityItem;
  17. import net.minecraft.entity.player.EntityPlayer;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.tileentity.TileEntity;
  20. import net.minecraft.util.EnumFacing;
  21. import net.minecraft.util.EnumHand;
  22. import net.minecraft.util.ITickable;
  23. import net.minecraft.util.math.AxisAlignedBB;
  24. import net.minecraft.util.math.BlockPos;
  25. import net.minecraft.util.text.TextComponentString;
  26. import net.minecraft.world.IBlockAccess;
  27. import net.minecraft.world.World;
  28. import net.minecraftforge.energy.CapabilityEnergy;
  29. import net.minecraftforge.energy.IEnergyStorage;
  30. import net.minecraftforge.items.CapabilityItemHandler;
  31. import net.minecraftforge.items.IItemHandler;
  32.  
  33. public class BlockPowerHub extends Block implements ITickable {
  34.    
  35.     protected static final AxisAlignedBB AABB_HALF = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D);
  36.  
  37.     public BlockPowerHub() {
  38.         super(Material.IRON, MapColor.GREEN);
  39.         this.setUnlocalizedName("powerHub");
  40.         this.setRegistryName(MinestuckArsenal.MODID, "power_hub");
  41.         this.setHardness(6.0F);
  42.         this.setResistance(8.0F);
  43.         this.setLightLevel(6.0F);
  44.         this.setCreativeTab(TabArsenal.instance);
  45.         this.setTickRandomly(true);
  46.     }
  47.    
  48.     public Class<TileEntityHub> getTileEntityClass() {
  49.         return TileEntityHub.class;
  50.     }
  51.    
  52.     public TileEntity getTileEntity(IBlockAccess world, BlockPos pos) {
  53.         return world.getTileEntity(pos);
  54.     }
  55.    
  56.     @Override
  57.     public boolean hasTileEntity(IBlockState state) {
  58.         return true;
  59.     }
  60.    
  61.     @Nullable
  62.     @Override
  63.     public TileEntity createTileEntity(World world, IBlockState state) {
  64.         return (TileEntity) new TileEntityHub();
  65.     }
  66.  
  67.     @Override
  68.     public void update() {
  69.         // Ticking Methods here.
  70.     }
  71.    
  72.     @Override
  73.     public boolean isFullBlock(IBlockState state) {
  74.         // TODO Auto-generated method stub
  75.         return false;
  76.     }
  77.    
  78.     @Override
  79.     public boolean isOpaqueCube(IBlockState state)
  80.     {
  81.         return false;
  82.     }
  83.    
  84.     @Override
  85.     public boolean isFullCube(IBlockState state) {
  86.         // TODO Auto-generated method stub
  87.         return false;
  88.     }
  89.    
  90.     @Override
  91.     public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
  92.         // TODO Auto-generated method stub
  93.         return AABB_HALF;
  94.     }
  95.    
  96.     @Override
  97.     public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
  98.         // TODO Auto-generated method stub
  99.         return AABB_HALF;
  100.     }
  101.    
  102.     @Override
  103.     public boolean isTopSolid(IBlockState state) {
  104.         // TODO Auto-generated method stub
  105.         return false;
  106.     }
  107.    
  108.     @Override
  109.     public BlockFaceShape getBlockFaceShape(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_,
  110.             EnumFacing p_193383_4_) {
  111.         // TODO Auto-generated method stub
  112.         if(p_193383_4_ == EnumFacing.UP) {
  113.             return BlockFaceShape.UNDEFINED;
  114.         }
  115.        
  116.         else return BlockFaceShape.SOLID;
  117.     }
  118.    
  119.     @Override
  120.     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
  121.             EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  122.        
  123.         if (!worldIn.isRemote) {
  124.             TileEntityHub tile = (TileEntityHub) getTileEntity(worldIn, pos);
  125.             IItemHandler itemHandler = (IItemHandler) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, playerIn.getHorizontalFacing().getOpposite());
  126.             IEnergyStorage energyHandler = (IEnergyStorage) tile.getCapability(CapabilityEnergy.ENERGY, playerIn.getHorizontalFacing().getOpposite());
  127.             if (!playerIn.isSneaking()) {
  128.                 if (playerIn.getHeldItem(playerIn.getActiveHand()) == null) {
  129.                 } else {
  130.                     if(playerIn.getHeldItem(playerIn.getActiveHand()).getItem() == MinestuckItems.rawUranium) {
  131.                         ItemStack uranium = playerIn.getHeldItem(playerIn.getActiveHand());
  132.                         if(itemHandler.getStackInSlot(0).getCount() + playerIn.getHeldItem(playerIn.getActiveHand()).getCount() <= 64) {
  133.                             itemHandler.insertItem(0, playerIn.getHeldItem(playerIn.getActiveHand()), false);
  134.                             playerIn.setHeldItem(playerIn.getActiveHand(), ItemStack.EMPTY);
  135.                         }
  136.                         else {
  137.                             int amountToAdd = 0;
  138.                             amountToAdd = 64 - itemHandler.getStackInSlot(0).getCount();
  139.                             int amountLeft = 0;
  140.                             amountLeft = playerIn.getHeldItem(playerIn.getActiveHand()).getCount() - amountToAdd;
  141.                            
  142.                             itemHandler.insertItem(0, new ItemStack(MinestuckItems.rawUranium), false);
  143.                             playerIn.setHeldItem(playerIn.getActiveHand(), new ItemStack(MinestuckItems.rawUranium, amountLeft));
  144.                         }
  145.                     }
  146.                 }
  147.                 tile.markDirty();
  148.             } else {
  149.                 ItemStack stack = itemHandler.getStackInSlot(0);
  150.                 if (stack != null) {
  151.                     playerIn.sendMessage(new TextComponentString(String.valueOf(stack.getCount()) + " Uranium Lumps. Storing " + String.valueOf(energyHandler.getEnergyStored() + "FE")));
  152.                 } else {
  153.                     playerIn.sendMessage(new TextComponentString("No Uranium! Storing " + String.valueOf(energyHandler.getEnergyStored() + "FE.")));
  154.                 }
  155.             }
  156.         }
  157.        
  158.         return true;
  159.     }
  160.    
  161.     @Override
  162.     public void breakBlock(World world, BlockPos pos, IBlockState state) {
  163.         TileEntityHub tile = (TileEntityHub) getTileEntity(world, pos);
  164.         IItemHandler itemHandler = (IItemHandler) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
  165.         ItemStack stack = itemHandler.getStackInSlot(0);
  166.         if (stack != null) {
  167.             EntityItem item = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), stack);
  168.             world.spawnEntity(item);
  169.         }
  170.         super.breakBlock(world, pos, state);
  171.     }
  172.  
  173.  
  174. }
RAW Paste Data