Storing items in crafting recipe

Discussion in 'Plugin Development' started by AdmiralAqua, Dec 4, 2015.

Thread Status:
Not open for further replies.
  1. Hi. I've been working on a plugin where players can craft presents, and place any item they want in the middle slot of the crafting table. When the present block is broken, the specific item is then dropped.
    Code:
                 ItemStack present = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal()); //Creates a skull item
                 SkullMeta meta = (SkullMeta) present.getItemMeta(); //Gets Skull Item Meta
                 meta.setOwner("MHF_Present1"); //Sets skull owner
                 meta.setDisplayName(ChatColor.GREEN + "Present [Green]"); //Sets display name
                 present.setItemMeta(meta); //set item meta
                 ShapedRecipe craftpresent = new ShapedRecipe(present); //creates new recipe
                 craftpresent.shape(" & ","#*#","%#%"); //recipe
                 craftpresent.setIngredient('&', Material.STRING);
                 craftpresent.setIngredient('#', Material.PAPER);
                 craftpresent.setIngredient('*', Material.DIAMOND);
                 craftpresent.setIngredient('%', Material.INK_SACK, 2);
    This is the code I have so far. In this example, if they player placed a diamond in the middle slot (diamond was just a placeholder to test out crafting of the item, I have to figure out a way to make it so that I can place any item at all), the diamond would be then stored with the present, and when broken, the diamond would drop.

    I know this is rather complicated, but I really need this plugin done soon for a Christmas event on a server. Any help will be much appreciated. Thanks a lot.
     
  2. Offline

    Scimiguy

    I'm not really understanding what your problem is, can you re-explain?
    Is it that you're only able to place diamonds?
     
  3. Offline

    mcdorli

    Save it inside the lore maybe. You can also make it invisible (By only using color code) or send it trough a base64
    He wants it so, that you can place any item in the middle, and the it saves, wich item it was, then if somebody opens it, he gets that item.
     
  4. Offline

    Scimiguy

    @mcdorli
    Ah, cheers

    Store it in the ItemMeta.

    When the item is placed as a block, you can store it in the BlockMeta.
    Just remember that BlockMeta isn't persistent, you'll have to save to a file through restarts
     
  5. Offline

    Mathias Eklund

    I'd make something with the InventoryClick event, you should be able to get the crafting matrix content from that event.
    From there you can set the result.
     
  6. Offline

    Scimiguy

    Ah yeah I just realised the issue lol..

    What Mathias said is about the only way you can do it
     
  7. Thanks for your help, could you give me an example? I'm kind of new to this
     
  8. Offline

    Scimiguy

    Listen to InventoryClickEvent.

    Check if the slot is your middle slot (probably with getRawSlot() or something)

    If so, get the Material of the Item that will be placed there, and create your ItemStack.
    Put that itemstack in the Result Slot, with the ItemMeta of the Material from before
     
  9. Offline

    mcdorli

    You should create a normal recipe for it, so for example paper on the outside 8 slots, because it would disable recipes like crafting red dye
     
  10. Thanks for your help, and sorry to bother you, but if you could provide me with an example in form of a code snippet, that would be more helpful, as while I have decent knowledge of Java, I don't really have a lot of knowledge when it comes to Bukkit.

    :O That would actually be bad though, as I have 2 different forms of presents, the green box present and the red box present, and I need some way of differentiating the recipes.
     
    Last edited: Dec 4, 2015
  11. @Scimiguy
    I think I've figured most of it out, except for the listen to InventoryClickEvent part. Could you please give me a snippet of code (not asking you to do my stuff, for me, just need an example to see if I'm doing it correctly/show me how to do it)
     
  12. Offline

    Scimiguy

    I don't provide code.

    Listen to the event like you would any other.
    Check the slot.

    If it's the middle slot (or whatever one you're using for storage), set a BukkitRunnable() to run after one tick, removing the item, and putting the appropriate itemstack in the result slot.
     
Thread Status:
Not open for further replies.

Share This Page