Create CraftingInventory?

Discussion in 'Plugin Development' started by Kepler_, Jul 13, 2014.

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

    Kepler_

    How do I create a CraftingInventory? I want to create a CraftingInventory variable without ever having to show the inventory to the player, and I haven't had any luck with it so far. I currently have this code...
    Code:
    CraftingInventory result = (CraftingInventory)Bukkit.createInventory(p, InventoryType.CRAFTING);
    //I also tried InventoryType.WORKBENCH
    ...but I'm getting a casting error...
    Code:
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryCustom cannot be cast to org.bukkit.inventory.CraftingInventory
    Any help is much appreciated. Thanks!
     
  2. Offline

    chasechocolate

    player.openWorkbench(null, true)
     
  3. Offline

    xShiftet

    Code:java
    1. Inventory inv = Bukkit.createInventory(null, InventoryType.WORKBENCH);
    2.  
    3. // do anything with it..


    Easy.. isn't it?
     
  4. Offline

    Kepler_

    I'm trying to create the inventory without having to show it to the player.
     
  5. Offline

    izarooni

    Kepler_
    Change the InventoryType from Crafting to Workbench
     
  6. Offline

    Kepler_

    I tried that, the resulting inventory is still a CraftInventoryCustom type, no matter what I set that parameter to, and that can't be casted to a CraftingInventory.
     
  7. Offline

    izarooni

    Kepler_
    What's the difference between those two?
     
  8. Offline

    Kepler_

    All (or most, I'm not sure) classes in CraftBukkit begin with Craft, so think of CraftInventoryCustom as InventoryCustom. InventoryCustom can't be crafted to CraftingInventory.
     
  9. Offline

    iSentry

    Code:java
    1. public Inventory inv;
    2. Player p = (Player) sender;
    3. inv = Bukkit.getServer().createInventory(player, InventoryType.WORKBENCH);
    4. p.openInventory(inv);
     
  10. Offline

    Kepler_

    For now I made my own CraftingInventory class, but if you have a better solution, please share!
    http://pastebin.com/mx2ubey0

    I'm trying to create a CraftingInventory without showing it to the player. Bukkit.getServer().createInventory() creates a type CraftInventoryCustom, which cannot be casted to CraftingInventory.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page