1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Recipe Manager (1.13.2+ ONLY)

Discussion in 'Snippets' started by ShaneBee, Jan 21, 2019.

  1. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    I just wanted to share some custom recipe effects I created.
    These will ONLY work on Spigot/Paper 1.13.2+ (Due to the custom ingredient methods added to the BukkitAPI in 1.13.x)

    All of these require Skript-Mirror to work. As per usual, place these custom effects at the top of the script you will be using it in, or place it in another script that loads before the one you are using (spoiler alert: scripts load in alphabetical order)

    Note: You may be looking thru these and wondering "Hey Shane, why do I need an ID for my recipe?" Well, I am glad you asked. I did this for a few reasons.
    1) When the recipe is registered it is given an ID. You can use this ID for unlocking recipes for players, also you can run them in the console, like:
    Code (Skript):
    1. /recipe give ShaneBee skript:emerald_sword
    The pattern will always start with 'skript:' followed by the ID you put. (This is because the recipes are registered per plugin, and in this case, to Skript)
    2) I originally created a randomized ID system so you wouldn't have to worry about it. The problem with that was, each time your server loads it technically creates a NEW recipe (and disposes of the old ones), therefore a player would have to unlock the recipe every time the server restarted.

    Custom Shaped Recipe - This includes a custom item result (item with name, lore, enchantments, etc) as well as custom ingredients.
    Code (Skript):
    1. import:
    2.     org.bukkit.Bukkit
    3.     org.bukkit.inventory.ShapedRecipe
    4.     org.bukkit.inventory.RecipeChoice$ExactChoice
    5.     org.bukkit.NamespacedKey
    6.  
    7. #! Register shaped recipe with custom ingredients !#
    8. effect register [new] shaped recipe for %item% using %items% with id %string%:
    9.     trigger:
    10.         set {_ing::*} to expressions-2
    11.         loop 9 times:
    12.             if {_ing::%loop-number%} is not set:
    13.                 set {_ing::%loop-number%} to air
    14.         #! ID + NamespacedKey !#
    15.         set {_id} to expression-3
    16.         replace all " " with "_" in {_id}
    17.         set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_id})
    18.         #! Create Recipe !#
    19.         set {_recipe} to new ShapedRecipe({_key}, expression-1)
    20.         loop 9 times:
    21.             set {_choices::%loop-number%} to new ExactChoice({_ing::%loop-number%})
    22.         #! Ingredients !#
    23.         {_recipe}.shape("123","456","789")
    24.         loop {_ing::*}:
    25.             {_recipe}.setIngredient(loop-index, {_choices::%loop-index%})
    26.         Bukkit.addRecipe({_recipe})

    Custom Shapeless Recipe - This includes a custom item result (item with name, lore, enchantments, etc) but with only vanilla ingredients (As of right now the API does not support custom ingredients on shapeless recipes. If you require custom ingredients, use the shaped recipes)
    Code (Skript):
    1. import:
    2.     org.bukkit.Bukkit
    3.     org.bukkit.inventory.ShapelessRecipe
    4.     org.bukkit.inventory.RecipeChoice$ExactChoice
    5.     org.bukkit.NamespacedKey
    6.  
    7. #! Register shapeless recipe, no custom ingredients !#
    8. effect register [new] shapeless recipe for %item% using %items% with id %string%:
    9.     trigger:
    10.         set {_ing::*} to expressions-2
    11.         set {_id} to expression-3
    12.         replace all " " with "_" in {_id}
    13.         set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_id})
    14.         set {_recipe} to new ShapelessRecipe({_key}, expression-1)
    15.         loop {_ing::*}:
    16.             {_recipe}.addIngredient(new ExactChoice(loop-value))
    17.         Bukkit.addRecipe({_recipe})

    Custom Furnace Recipe - This includes a custom item result (item with name, lore, enchantments, etc) as well as a custom ingredient. It also includes an optional ability to set the experience a player gains when smelting this item (default=0) and cook time (in ticks, default=200)
    Code (Skript):
    1. import:
    2.     org.bukkit.Bukkit
    3.     org.bukkit.inventory.FurnaceRecipe
    4.     org.bukkit.inventory.RecipeChoice$ExactChoice
    5.     org.bukkit.NamespacedKey
    6.  
    7. #! Regsiter furnace recipe (not sure yet about custom ingredients) !#
    8. effect register [new] furnace recipe for %item% using %item% with id %string%[([ and] with|,) experience %integer%][([ and] with|,) cook[ ]time %integer%]:
    9.     trigger:
    10.         set {_result} to expression-1
    11.         set {_ing} to expression-2
    12.         set {_id} to expression-3
    13.         set {_exp} to expression-4 ? 0
    14.         set {_cookTime} to expression-5 ? 200
    15.         set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript") and {_id})
    16.         if name of {_ing} is set:
    17.             set {_recipe} to new FurnaceRecipe({_key}, {_result}, new ExactChoice({_ing}), {_exp} and {_cookTime})
    18.         else:
    19.             set {_recipe} to new FurnaceRecipe({_key}, {_result}, {_ing}.getType(), {_exp} and {_cookTime})
    20.         Bukkit.addRecipe({_recipe})

    When recipes are added to the server, they are not automatically unlocked for players. For some silly reason, unlike other items in the recipe book, players cannot seem to unlock recipes in-game until they have crafted said item. Silly right!?! So I added another syntax for you to unlock (discover) recipes for players however you see fit (See examples)

    Discover Recipes for Players
    Code (Skript):
    1. #! Unlock a recipe for a player !#
    2. effect [(1¦un)]discover recipe %string% for %players%:
    3.     trigger:
    4.         set {_string} to expression-1
    5.         replace all " " with "_" in {_string}
    6.         set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_string})
    7.         loop expressions-2:
    8.             if parse mark is 1:
    9.                 loop-expression.undiscoverRecipe({_key})
    10.             else:
    11.                 loop-expression.discoverRecipe({_key})

    Here are some examples. Just a heads up, its best to load new recipes on a 'on skript load' event. Also take note that if you load a recipe whilst a player is on the server, they won't see the new recipe in their book until after they log out/log in again.

    Registering Recipe Examples - Here I have created 3 examples to show how you can create a custom shaped recipe with a custom result as well as custom ingredients. Take note to put the ingredients in order as the would appear in a crafting grid. (Supports only a crafting table) You should include all 9 ingredients, but if you miss one, the code will automatically fill the rest with air.
    In the example for shapeless you will notice the ingredients are just vanilla ingredients but the output item can be a custom item. Shapless recipes can have their incredients in any order. If there are 4 or less ingredients these recipes will work in the players crafting grid, 5 or more will require the crafting table.
    In the example for furnace recipes, you will notice I have used a custom ingredient and custom result. Wahoo, supports both!
    Code (Skript):
    1. #! Examples !#
    2. on skript load:
    3.     set {_item} to diamond sword of sharpness 10 and mending named "&5POWERFUL EMERALD SWORD"
    4.     set {_ing} to diamond sword of sharpness 5 named "&aEMERALD SWORD"
    5.     register new shaped recipe for {_ing} using air, emerald, air, air, emerald, air, air, stick and air with id "emerald_sword"
    6.     register new shaped recipe for {_item} using air, air, air, air, {_ing}, air, air, air and air with id "powerful_emerald_sword"
    7.  
    8.     set {_elytra} to elytra named "&aFAST ELYTRA"
    9.     set {_felytra} to elytra named "&dFASTER ELYTRA"
    10.     register new shapeless recipe for {_elytra} using elytra with id "elytra"
    11.     register new shapeless recipe for {_felytra} using elytra and elytra with id "fast_elytra"
    12.  
    13.     set {_egg} to egg named "&cHOT EGG"
    14.     set {_begg} to egg named "&4BOILING EGG"
    15.     register new furnace recipe for {_egg} using egg with id "hot_egg", experience 10, cook time 20
    16.     register new furnace recipe for {_begg} using {_egg} with id "boiling_egg", experience 10, cook time 200

    Unlocking Recipes for Players - As stated above recipes don't seem to unlock naturally for players, maybe this is because of the custom items. But you can simply create events for the players to unlock recipes. Like where I have used the pickup emerald event to give the player the emerald sword recipe. Even if you don't give them the recipe they can still craft the item, they just won't see it in their recipe guide.
    Code (Skript):
    1. on join:
    2.     discover recipe "emerald_sword" for player
    3.     discover recipe "powerful_emerald_sword" for player
    4.  
    5. on pickup of elytra:
    6.     discover recipe "elytra" for player
    7.     discover recipe "fast_elytra" for player
    8.  
    9. on pickup of emerald:
    10.     discover recipe "emerald_sword" for player
    --- Double Post Merged, Mar 17, 2019, Original Post Date: Jan 21, 2019 ---
    Updated furnace recipe thing.
    I wrote something wrong with totally screwed it up.... if you are using it, please update :emoji_slight_smile:
     
    #1 ShaneBee, Mar 17, 2019
    Last edited: Jul 13, 2019
    Diclo, aescraft and EWS like this.
  2. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    "When recipes are added to the server, they are not automatically unlocked for players. For some silly reason, unlike other items in the recipe book, players cannot seem to unlock recipes in-game until they have crafted said item. Silly right!?! So I added another syntax for you to unlock (discover) recipes for players however you see fit (See examples)"

    I think this is related to the advancements / recipes.

    Maybe you need to edit the .json files inside the server .jar to add these recipes as default, then, all players will have them.

    Thanks for the snippet.
    --- Double Post Merged, Aug 27, 2019, Original Post Date: Aug 27, 2019 ---
    Also, got this when using the shaped recipe:

    [​IMG]
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Those are just general Skript warnings, you can turn off the and/or warnings in your Skript config if you so choose to ignore those warnings.
     
  4. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Any idea on why this is not working? (no errors, but won't craft in craft table):

    Code (Text):
    1. on skript load:
    2.   set {_nbt} to "{SkullOwner:{Id:""04049c90-d3e9-4621-9caf-000000aaa218"",Properties:{textures:[{Value:""eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGQxZDhjNTA0ODY3OTMzNzAzZGEzNmVjMTFmNTM4ZjYyNjVmOTg0NDFkODgxZWFjNDhlZjJjNDkzNGMxYiJ9fX0=""}]}},display:{Lore:['{""text"":""§aToca-Discos""}'],Name:'{""text"":""§9Jukebox""}'},Damage:3}"
    3.   set {_item} to player head
    4.   set nbt of {_item} to {_nbt}
    5.   set {_nbt} to "{HideFlags:47,display:{Lore:['{""text"":""§eTĂ­tulo - 64x §6AesCoins""}'],Name:'{""text"":""§6AesCheque""}'},Enchantments:[{lvl:1s,id:""minecraft:unbreaking""}]}"
    6.   set {_ing} to paper
    7.   set nbt of {_ing} to {_nbt}
    8.   register new shaped recipe for {_item} using plank, plank, plank, plank, {_ing}, plank, plank, plank and plank with id "jukebox"
    I want to add a recipe for crafting a custom player head (jukebox) that will take 8 planks + 1 custom paper.
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    When running your code, and looking in the recipe book, this is what I got:

    Screen Shot 2019-08-27 at 12.09.55 AM.png

    I think the issue is you put "plank" which Skript randomly picks a plank ... I think you need to specify the plank type
     
  6. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Weird that i can't find the custom head in the recipe book, even using this (while you can see in the recipe book):

    Code (Text):
    1. on join:
    2.   discover recipe "jukebox" for player
    I'll try to change to a specific plank.
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    I had to run the recipe command to see it in the book `/minecraft:recipe give ShaneBee skript:jukebox'
     
  8. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Well, something is off.
    I used the command /minecraft:recipe give, and it says that the recipe does not exist.

    So, this is not working (the recipe register part.)

    I just copied your code and edited just the recipe part, and it works for you.

    I'll paste it all here so you can see:

    Code (Text):
    1. import:
    2.   org.bukkit.Bukkit
    3.   org.bukkit.inventory.ShapedRecipe
    4.   org.bukkit.inventory.RecipeChoice$ExactChoice
    5.   org.bukkit.NamespacedKey
    6.  
    7. #! Register shaped recipe with custom ingredients !#
    8. effect register [new] shaped recipe for %item% using %items% with id %string%:
    9.   trigger:
    10.     set {_ing::*} to expressions-2
    11.     loop 9 times:
    12.       if {_ing::%loop-number%} is not set:
    13.         set {_ing::%loop-number%} to air
    14.     #! ID + NamespacedKey !#
    15.     set {_id} to expression-3
    16.     replace all " " with "_" in {_id}
    17.     set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_id})
    18.     #! Create Recipe !#
    19.     set {_recipe} to new ShapedRecipe({_key}, expression-1)
    20.     loop 9 times:
    21.       set {_choices::%loop-number%} to new ExactChoice({_ing::%loop-number%})
    22.     #! Ingredients !#
    23.     {_recipe}.shape("123","456","789")
    24.     loop {_ing::*}:
    25.       {_recipe}.setIngredient(loop-index, {_choices::%loop-index%})
    26.     Bukkit.addRecipe({_recipe})
    27.  
    28. #! Unlock a recipe for a player !#
    29. effect [(1¦un)]discover recipe %string% for %players%:
    30.   trigger:
    31.     set {_string} to expression-1
    32.     replace all " " with "_" in {_string}
    33.     set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_string})
    34.     loop expressions-2:
    35.       if parse mark is 1:
    36.         loop-expression.undiscoverRecipe({_key})
    37.       else:
    38.         loop-expression.discoverRecipe({_key})
    39.  
    40. on join:
    41.   discover recipe "jukebox" for player
    42.  
    43. on skript load:
    44.   set {_nbt} to "{SkullOwner:{Id:""04049c90-d3e9-4621-9caf-000000aaa218"",Properties:{textures:[{Value:""eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGQxZDhjNTA0ODY3OTMzNzAzZGEzNmVjMTFmNTM4ZjYyNjVmOTg0NDFkODgxZWFjNDhlZjJjNDkzNGMxYiJ9fX0=""}]}},display:{Lore:['{""text"":""§aToca-Discos""}'],Name:'{""text"":""§9Jukebox""}'},Damage:3}"
    45.   set {_item} to player head
    46.   set nbt of {_item} to {_nbt}
    47.   set {_nbt} to "{HideFlags:47,display:{Lore:['{""text"":""§eTĂ­tulo - 64x §6AesCoins""}'],Name:'{""text"":""§6AesCheque""}'},Enchantments:[{lvl:1s,id:""minecraft:unbreaking""}]}"
    48.   set {_ing} to paper
    49.   set nbt of {_ing} to {_nbt}
    50.   register new shaped recipe for {_item} using oak plank, oak plank, oak plank, oak plank, {_ing}, oak plank, oak plank, oak plank and oak plank with id "jukebox"
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    on skript load only works when Skript loads, not when a script loads.
    You will need to restart your server (or if you are daring, run "/reload")
     
  10. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Now I feel really stupid. :emoji_slight_smile:
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    no need to feel stupid.
    Recipes have issues loading if its not a server load. This is why I recommend using Skript load, so the recipes only register when the server starts up.
     
  12. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    I got confused about on skript load and "on load", for me was both the same.

    But I got this when restarting, is this a error?

    Code (Text):
    1. 27.08 03:26:17 [Server] Server thread/WARN method ShapedRecipe#shape called with (123 (String), 456 (String), 789 (String)) returned shaped recipe (ShapedRecipe), which could not be converted to Boolean
    and after restarting, using the "/minecraft:recipe give aescraft skript:jukebox" command won't work (skript:jukebox doesn't exist).

    skript 2.4-beta 5
    skript-mirror 2.0
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Hmm that is odd, I have never seen that error/warning before, im not really sure what is causing that.

    just to double check, which spigot version are you using?
     
  14. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Craftbukkit ver git-spigot-ea7e48b-368f4e9 (mc 1.14.4) ver 1.14.4-R0.1 Snapshot.

    12 versions behind.
     
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    hmmm yeah im not sure what is causing that error, try restarting your server again.
     
  16. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Plugins (skript related only):

    skript
    reqn
    skquery
    skriptjson
    tuske
    sk-nbeet
    tablisknu
    skrayfall
    skript-mirror
    --- Double Post Merged, Aug 27, 2019, Original Post Date: Aug 27, 2019 ---
    Same error:

    Code (Text):
    1. 27.08 03:44:53 [Server] Server thread/WARN List is missing 'and' or 'or', defaulting to 'and': Bukkit.getPluginManager().getPlugin("Skript"), {_id} (jukebox.sk, line 17: set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_id})')
    2. 27.08 03:44:53 [Server] Server thread/WARN List is missing 'and' or 'or', defaulting to 'and': {_key}, expression-1 (jukebox.sk, line 19: set {_recipe} to new ShapedRecipe({_key}, expression-1)')
    3. 27.08 03:44:53 [Server] Server thread/WARN List is missing 'and' or 'or', defaulting to 'and': "123","456","789" (jukebox.sk, line 23: {_recipe}.shape("123","456","789")')
    4. 27.08 03:44:53 [Server] Server thread/WARN List is missing 'and' or 'or', defaulting to 'and': loop-index, {_choices::%loop-index%} (jukebox.sk, line 25: {_recipe}.setIngredient(loop-index, {_choices::%loop-index%})')
    5. 27.08 03:44:53 [Server] Server thread/WARN List is missing 'and' or 'or', defaulting to 'and': Bukkit.getPluginManager().getPlugin("Skript"), {_string} (jukebox.sk, line 33: set {_key} to new NamespacedKey(Bukkit.getPluginManager().getPlugin("Skript"), {_string})')
    6. 27.08 03:44:54 [Server] Server thread/INFO All scripts loaded without errors.
    7. 27.08 03:44:54 [Server] Server thread/INFO Loaded 5 scripts with a total of 36 triggers and 36 commands in 4.22 seconds
    8. 27.08 03:44:54 [Server] Server thread/INFO Finished loading.
    9. 27.08 03:44:54 [Server] Server thread/WARN method ShapedRecipe#shape called with (123 (String), 456 (String), 789 (String)) returned shaped recipe (ShapedRecipe), which could not be converted to Boolean
    --- Double Post Merged, Aug 27, 2019 ---
    I'll remove the plugins one by one and restart.
    --- Double Post Merged, Aug 27, 2019 ---
    Tablisknu is the one causing issues.
    https://github.com/TlatoaniHJ/Tablisknu/issues/4
     
  17. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,501
    Likes Received:
    108
    Medals:
    That is probably because the method returns a value, which is weird because the description of the method says that it changes the shape of this recipe, so it's weird that it also returns itself. You could probably work around the issue by using it as an expression instead.
     
  18. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    That part of the code I got from shanebee.
    I never used those before, so I don't know what a method is or the difference from expressions.
     
  19. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,501
    Likes Received:
    108
    Medals:
    Yea it was a little more directed towards @ShaneBee, but your post had the error so I quoted that. It's just weird since the line seems to get recognized as a condition, and that's why Skript tried to convert it to a boolean. It's probably because skript-mirror has registered methods as an effect and expression, otherwise value returning wouldn't be possible, and Skript thought this should be parsed as an expression (which could then be converted to a boolean for the condition), not an effect for some reason. But this doesn't make sense, Skript should clearly parse this as an effect.
     
  20. aescraft

    aescraft Well-Known Member

    Joined:
    Mar 1, 2017
    Messages:
    295
    Likes Received:
    13
    Ok.

    But the thing is, if I remove tablisknu, it works.
    With the addon tablisknu, this error happens.
     

Share This Page

Loading...