Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
- EnumFacing facing, float hitX, float hitY, float hitZ) {
- if (!world.isRemote) {
- TileEntityPedastal_Magic te = getTE(world, pos);
- if (player.getHeldItem(hand).getItem() == ItemHandler.key && player.getHeldItem(hand).getMetadata() == 0) {
- if (!te.isLocked()) {
- te.setLocked(true);
- player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Security> "
- + TextFormatting.DARK_RED + "This pedestal has been locked!"));
- } else {
- player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] Security> "
- + TextFormatting.DARK_GREEN + "This pedestal has been unlocked!"));
- te.setLocked(false);
- }
- }
- else {
- if (te.getStack().isEmpty()) {
- if (te.isLocked()) {
- player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] "
- + TextFormatting.RED + "This pedestal is locked!"));
- }
- }
- else {
- if (!player.getHeldItem(hand).isEmpty()) {
- // There is no item in the pedestal and the player
- // is holding an item. We move that item
- // to the pedestal
- te.setStack(player.getHeldItem(hand));
- player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
- // Make sure the client knows about the changes in
- // the player inventory
- }
- else if (!te.getStack().isEmpty()) {
- if (te.isLocked()) {
- player.sendMessage(new TextComponentTranslation(TextFormatting.AQUA + "[EssencePlus] "
- + TextFormatting.RED + "This pedestal is locked!"));
- } else {
- // There is a stack in the pedestal. In this
- // case we remove it and try to put it in the
- // players inventory if there is room
- ItemStack stack = te.getStack();
- if (!player.inventory.addItemStackToInventory(stack)) {
- // Not possible. Throw item in the world
- EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY() + 1,
- pos.getZ(), stack);
- world.spawnEntity(entityItem);
- }
- te.setStack(ItemStack.EMPTY);
- }
- }
- }
- }
- }
- // Return true also on the client to make sure that MC knows we handled
- // this and will not try to place
- // a block on the client
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement