Solved Give shapedrecipe item to player

Discussion in 'Plugin Development' started by torpkev, Dec 10, 2018.

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

    torpkev

    I've created a custom shapedrecipe that i can create on a crafting table without issue.

    However, I'd like to be able to give it to a player when they interact with something else. I've got the interact part down but can't for the life of me see how to give the item.

    I have the NamespacedKey value ("allowburnblock") as well as display name ("Allow Burn") etc. of the item I want to give.

    How do I get that item into an itemstack?

    Thanks
     
  2. Offline

    The_Spaceman

    When creating the recipe you could save the ItemStack somewhere. When you need that ItemStack create a clone of it and give it to the player
     
  3. Offline

    torpkev

    Thanks. Seems like an awfully inefficient way of doing it. I would have thought there'd be a way to pull by key if the recipe is added to the server, but I guess that approach should work easily enough.
     
  4. Offline

    The_Spaceman

    maybe this could work, but you have to use NMS classes... and you get a NMS ItemStack
    Code:java
    1. ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this/*your plugin*/, "CustomItem"), someItem);
    2. net.minecraft.server.v1_13_R2.ItemStack result = MinecraftServer.getServer().getCraftingManager().recipes.get(new MinecraftKey("CustomItem")).d();
    3. //OR (but is deprecated)
    4. ShapedRecipe recipe = new ShapedRecipe(quarry);
    5. net.minecraft.server.v1_13_R2.ItemStack result = MinecraftServer.getServer().getCraftingManager().recipes.get(new MinecraftKey(recipe.getKey().getKey())).d();
    6.  
     
  5. Offline

    torpkev

    Thanks - NMS is definitely something for me to investigate as time allows, but I suspect adds a huge amount of complexity for something that while it isn't overly efficient, is nowhere near inefficient enough for me to start pulling at that thread to solve this issue.

    I appreciate the help!
     
Thread Status:
Not open for further replies.

Share This Page