[RESOURCE][NO-NMS] Make custom crafting recipes (ingredients obey ItemMeta, displayName, e.t.c.)

Discussion in 'Resources' started by Plo124, Jun 17, 2014.

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

    Plo124

    Hi, So I was making my own server project, and was going to involve overriding the default Minecraft crafting recipes, but now since Minecraft is virtually unprofitable from 1st August 2014, I have closed my project and am giving out sections of the code (My tutorial where you can hide lore from a client using protocol lib was the first one).

    Ok, moving from my sob story, the code. Since the code is quite big I'm not going to make a step by step tutorial, but I will cover some of the usage for this.

    Very important is the download link to this [RESOURCE].
    There is a basic tutorial on how to setup recipes, including a example.

    Setting Up:

    First you need to extract the zip, and put the 'me' folder into your source folder.

    In your onEnable you need to put 2 simple lines,
    Code:java
    1. new RecipeList(); // Creates the list of recipes
    2. this.getServer().getPluginManager().registerEvents(new CraftManager(),this); // Register the crafting event


    Making your recipes:
    Making your recipes can be a time consuming process. Luckily I have made this simpler by including an ItemStackBuilder (also created by me).
    How to use the ItemStackBuilder class (open)

    To use the ItemStackBuilder class is simple once you know how, first you start with this
    Code:java
    1. new ItemStackBuilder(Material.AIR).build();

    This simply makes a new ItemStack which is air.
    After defining the class, and before the build(), simply put a period to see all the available methods. There should be ones like setDisplayName(), setAmount(), setDamage()

    Important reminder that if your IDE is giving an error with the ItemStackBuilder, you likely have forgotten to put the .build() on the end, this converts the output from an ItemStackBuilder to a ItemStack.

    Setting up your recipes
    Setting up the recipes has been made in (my opinion) the simplest way possible.​
    The syntax is similar to the ItemStackBuilder, where you create a​
    Code:java
    1. new PloRecipe(ItemStack output);
    Then you add more options to it. By default if you do not set any of the slots, the grid would be 9 air blocks, which I have no idea what does.​
    To set some of the slots, simply put​
    Code:java
    1. new PloRecipe(itemStack)
    2. .setSlot1(slot1).setSlot3(slot3);

    If you do not set a slot, that slot will then remain empty in the crafting recipe, so you do not need to define them all.​
    Then lastly you need to put .register() at the end of the recipe, to add it to the list of registered recipes.​
    You could probably work out how this example works then, which is the example, and default recipe when you download the library.​
    Code:java
    1. new PloRecipe(new ItemStackBuilder(Material.STONE).setDisplayName("Solid Stone").build())
    2. .setSlot5(new ItemStack(Material.STONE))
    3. .setSlot8(new ItemStack(Material.STONE))
    4. .register();


    Lastly you need to repeat the process of making new recipes and registering them until you are satisfied you have enough recipes to craft.​




    Things to note:
    1. This code completely overrides the default Minecraft crafting recipes, so if you are wanting to keep the default Minecraft crafting recipes, you could either enter all the recipes you want, or make an exception in the RecipeMatch.java where it will return true if there is no ItemMeta, which also means your custom recipe needs an ItemMeta always.
    2. This code is written from scratch, so there may be errors which I have not seen in my testing, just comment below the error, and I'll try find a fix :)
    3. Lots of effort has been put into this, at the very least if you are releasing this snippet in a project on dev.bukkit.org, please leave my @author Plo457 so people who decompile plugins can at the minimum see its my work.
    Known bugs:
    • Shift + Clicking on the output grid of the crafting table only makes 1, but when you close your inventory it updates to make 64. This appears to be some client side bug with inventory updating, similar to how clicking on a server menu, or 'icon list' can create a phantom/ghost item
     
    ChipDev and Aqua like this.
  2. Offline

    xTrollxDudex

  3. Offline

    Plo124

  4. Offline

    Onlineids

    Plo124 Would be much easier if it was a class so plugins didn't have to rely on other plugins
     
  5. Offline

    ChipDev

    What do you mean? Minecraft is unprofitable? :O
     
  6. Offline

    Plo124

    Onlineids
    It is a few classes, if you look, the files are .java inside the zip. Should I change [LIB] to [RESOURCE] ?

    ChipDev
    With the changes to the EULA and the possibility of them enforcing the EULA.
     
  7. Offline

    Onlineids

    Plo124 Yea with lib I am assuming depending on a jar
     
  8. Offline

    Iroh Retired Staff

    Removed offtopic posts.
     
  9. Offline

    StanRadner

    I am sorry for this, but I do not understand how this plugin takes a custom item and implements it into a shaped recipe. Could you please further explain this?
     
  10. Offline

    Freack100

    Look at this:
    Code:
    new PloRecipe(
        //This is the ItemStackBuilder which builds the outcome of the recipe. If you would do it like this, you could craft "Solid Stone".
        new ItemStackBuilder(Material.STONE)   
            .setDisplayName("Solid Stone")
            .build()
        )
       
        //Here you set the specific items for the crafting grid.
        //In this example you set slot 5 and 8 to normal stone. because of the ItemStack constructor used here, the amount is 1, the data and damage is 0.
        //You could also use an ItemStackBuilder to add, for example, a display name to the items, so you can only make "Solid Stone" with, for example, "My Awesome Stone".
        .setSlot5(new ItemStack(Material.STONE))
        .setSlot8(new ItemStack(Material.STONE))
        .register();
     
  11. Offline

    zombiekiller753

    Good luck with that. I hear Java does this weird thing where it removes comments. Far out, right?

    [​IMG]

    EDIT:
    Just took a look at PloRecipe.java

    Ever heard of an array? I hear it r gud

    In PloRecipeList.java, I can reset the entire recipe list by passing a null argument? Nice. Who needs a removeRecipe method when you can clear the whole thing!

    In RecipeMatch.java, you clone the itemstack in the array but you then replace the array. What?
    Also, == false? == true? what????
    What happened to ItemStack#equals(Object)?

    Also, what's wrong with the Bukkit Recipe API? Why use this one?
     
    Last edited: Dec 24, 2014
  12. Offline

    ChipDev

    Nice Skype .gif!
     
  13. Offline

    nverdier

    It's not "Java" that removes the comments.
     
Thread Status:
Not open for further replies.

Share This Page