Crafting recipes with custom items.

Discussion in 'Plugin Development' started by Maxim Savenkov, Jul 11, 2019.

  1. Offline

    Maxim Savenkov

    I have been working on a kitPvP plugin, which I need help with. Basically to craft a kit (which I figured out how to give on craft) you need some shiny diamond blocks, which are enchanted diamonds with a custom name and lore, to craft them you need shiny diamonds, which again, have enchantments, custom name and lore. I have made the recipe for shiny diamond, but can't figure out how to make a recipe where the ingredient has custom ItemMeta, it just doesn't let me. If you don't understand what I mean it is basically the recipes from hypixel sky block but edited in a way.

    Can somebody help me or send me a template of code I can edit to my liking?

  2. Online


    It can't be done the old fashioned way. You're going to have to use an event listener.
    public void handleCustomCrafting(PrepareItemCraftEvent event) {
    CraftingInventory inventory event.getInventory();
        for (
    ItemStack item inventory.getMatrix()) {
    ItemMeta itemMeta item.getItemMeta();
    // do checks here
    // If some condition
    ItemStack customItem // your custom item
  3. Offline

    Maxim Savenkov

    How would you test the shape of the recipe? Like test if the slot x contains the item stack with the meta I defined? I do not know the slots of a crafting table. Thank you for your help.
    Last edited: Jul 11, 2019
  4. Online


    @Maxim Savenkov I don't know either. You're going to have to test it out.

    getMatrix() returns an ItemStack array. The documentation states individual entries may be null. Logically this corresponds to the slots of the crafting table. You can find out which index corresponds to which slot by printing them out.

    CraftingInventory inventory event.getInventory();
    ItemStack[] items inventory.getMatrix();

    for (
    int i 0items.lengthi++) {
    String msg = (items[i] == null)
    " is null"
    " is " items[i].getType;
    By putting different materials in, you are able to deduce which index corresponds to which slot. You can write your logic accordingly.

Share This Page