Custom Recipes and Custom Items

Discussion in 'Plugin Development' started by harrisonG, Jul 30, 2014.

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

    harrisonG

    I've been developing some recipe handling for custom items and have run into some issues. I've opted not to use the add recipe function due to the complications of using custom items (materials with altered display names) and to simply intercept crafting myself in a custom class. The issue is, CraftItemEvent only occurs when an item has already been crafted so the result will not be shown in the box to the right of the grid. PrepareItemCraftEvent only triggers once a recipe has been shaped, and since I know I don't want to add the custom recipes into Bukkit that won't ever be triggered when I need it to. The last plausible Event to use is the InventoryClickEvent, however I can't seem to be able to retrieve the inventory being used, so I can't use setResult. Any help? Best case scenario I've just missed the way to get the crafting inventory in IventoryClickEvent, but I'm seriously stumped.
     
  2. Just to make it clear for myself, what you want to do is have a custom recipe without using ShapedRecipe or ShapelessRecipe? As in the player places items into the crafting bench and automatically gets out the result?
     
  3. Offline

    harrisonG

    Because I wish use custom items (which again are just renamed materials) in other custom recipes as well. The only way to create a shaped or shapeless recipe that uses a custom item would be to put the material the custom item is in the recipe and then intercept the recipe at crafting time. Because I would be intercepting every time to check anyway, I decided the easiest thing to do would be to check the whole recipe myself and not let Bukkit have a chance to make it wrongly.
     
  4. harrisonG Try this:
    Code:java
    1. public void makeRecipe()
    2. {
    3. ItemStack yourCustomItemIngredient = whatever you do to make this;
    4. ItemStack result = again, whatever you do to make this.
    5. ShapelessRecipe shapeless = new ShapelessRecipe(result);
    6. shapeless.addIngredient(1, yourCustomItemIngredient.getData());
    7. shapeless.addIngredient(1, otherIngredients);
    8. }
     
  5. Offline

    harrisonG

    The problem with this is the recipe is shapeless where as I'd like shaped recipes, and the getData() method returns material data which if i'm correct doesn't include display name so any iron ingot would work in place of what i'd like the be a steel ingot. What I'm really looking for is a way to get the crafting inventory out of an InventoryClickEvent.
     
  6. harrisonG Okay, I just tested this.
    Code:java
    1. //Inside your InventoryClickEvent handler
    2.  
    3. if (event.getInventory() instanceof CraftingInventory)
    4. {
    5. CraftingInventory craft = (CraftingInventory) event.getInventory();
    6. }
    7.  


    After that I checked to see if craft contained a certain item and if it did I set the result to something. It worked but the result box didn't show anything until I clicked on it. There's probably some way to update the inventory so that it shows automatically but I didn't see it when I looked for 15 seconds. I think this is more like what you wanted.

    For what it's worth, I also tested a custom recipe with an ingredient with an altered displayName and used getData() and that also worked just as well.
     
  7. Offline

    Phasesaber

    Try using the MaterialAPI, it's great.
     
  8. Offline

    harrisonG

    Thank you very much, when looking through the javadocs I was too stupid to look at the inherited methods as well. (Also with getData, if I'm correct, the display name doesn't carry in the gottenData if you know what I mean) Thanks so much
     
  9. Offline

    StanRadner

    So this code lets you use custom items in custom crafting recipes?
     
Thread Status:
Not open for further replies.

Share This Page