Creepinson

onBlockAct

Jun 9th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1. @Override
  2. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  3.       if (world.isRemote) {
  4.        
  5.        
  6.          
  7.           TileEntityPedastal_Magic te = getTE(world, pos);
  8.          
  9.          
  10.        
  11.           if(player.getHeldItem(hand).getItem() == ItemHandler.key  && player.getHeldItem(hand).getMetadata() == 0){
  12.            
  13.            
  14.               if(!te.isLocked()){
  15.                     te.setLocked(true);
  16.                     player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Security> " + TextFormatting.DARK_RED + "This pedestal has been locked!"));
  17.                 }
  18.                 else {
  19.                     player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Security> " + TextFormatting.DARK_GREEN + "This pedestal has been unlocked!"));
  20.               te.setLocked(false);
  21.                 }
  22.           }      
  23.              
  24.           else{
  25.            
  26.          
  27.           if (te.getStack().isEmpty()) {
  28.               if(te.isLocked()){
  29.                  
  30.                  player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] " + TextFormatting.RED + "This pedestal is locked!"));
  31.              
  32.              
  33.            }
  34.              
  35.            else{
  36.               if (!player.getHeldItem(hand).isEmpty()) {
  37.                   // There is no item in the pedestal and the player is holding an item. We move that item
  38.                   // to the pedestal
  39.                   te.setStack(player.getHeldItem(hand));
  40.                   player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
  41.                   // Make sure the client knows about the changes in the player inventory
  42.    
  43.               }
  44.            
  45.           else if (!te.getStack().isEmpty()){
  46.               if(te.isLocked()){
  47.                  
  48.                  player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] " + TextFormatting.RED + "This pedestal is locked!"));
  49.              
  50.              
  51.            }
  52.            else{
  53.               // There is a stack in the pedestal. In this case we remove it and try to put it in the
  54.               // players inventory if there is room
  55.               ItemStack stack = te.getStack();
  56.            
  57.               if (!player.inventory.addItemStackToInventory(stack)) {
  58.                   // Not possible. Throw item in the world
  59.                   EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), stack);
  60.                   world.spawnEntity(entityItem);
  61.               }
  62.               te.setStack(ItemStack.EMPTY);
  63.           }
  64.              
  65.           }  
  66.              
  67.           }
  68.              
  69.           }  
  70.          
  71.           }
  72.          
  73.           }    
  74.      
  75.       // Return true also on the client to make sure that MC knows we handled this and will not try to place
  76.       // a block on the client
  77.       return true;
  78.   }
Advertisement
Add Comment
Please, Sign In to add comment