Advertisement
Creepinson

again

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