Lapis refusing to go into enchanting table

Discussion in 'Plugin Development' started by Rixterz, Nov 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Rixterz

    Hi,

    All I want to do is place 3 lapis in the 2nd slot of the clicked enchanting table.
    Nothing is appearing in the table, halp!

    Code:
    @EventHandler
        public void onPlayerInteractBlock(PlayerInteractEvent e){
            if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
                if(e.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE){
                    e.setCancelled(true);
                    Inventory enchantingInventory = Bukkit.createInventory(null, InventoryType.ENCHANTING);
                    Dye lapis = new Dye();
                    lapis.setColor(DyeColor.BLUE);
                    enchantingInventory.setItem(1, lapis.toItemStack(3));
                    e.getPlayer().openInventory(enchantingInventory);
                   
                }
            }
        }
     
  2. Offline

    Zombie_Striker

    PlayerInteractEvent is for rightclicking BLOCKS , not inventories. Use IventoryClickEvent for this.
     
  3. Offline

    WinX64

    What is the version of the server you're running this on?
     
  4. Offline

    Rixterz

    Incorrect; the event was fired.

    The event is fired when the player right-clicks an enchanting table, so a custom inventory is shown.
    The lapis refuses to be set into that inventory

    So what do I have to do differently?
     
    Last edited by a moderator: Nov 21, 2015
  5. Well, first of all by looking at your code it seems as if you're trying to detect when a player opens an enchanting table inventory, you could replace this with InventoryOpenEvent.

    What worked for me was casting the inventory to EnchantingInventory, then use EnchantingInventory#setItem().
     
    Rixterz likes this.
Thread Status:
Not open for further replies.

Share This Page