Jump to content

Mod API Update: AddRecipe


Recommended Posts

  • Developer

Hey everyone,
 
I updated the mod api while we were adding Reign of Giants content to DST, and now those API changes are available to everyone. In particular, I added a new API to add recipes that will allow multiple mods to add recipes without conflict.
 
Instead of using the Recipe constructor or Recipe mod API, instead you should call AddRecipe from modmain. I've updated the Soulmates mod to use this new API. I've tried to make is so that changing to this new method is as easy as possible.
 

-this code was previously in my prefab def lua fileRecipe("bindingring", {Ingredient("goldnugget", 10),Ingredient("moonrocknugget", 1)}, RECIPETABS.MAGIC, TECH.NONE)AllRecipes["bindingring"].atlas = resolvefilepath("images/inventoryimages/bindingring.xml")--now it it is replaced with the following code in your modmain.lualocal Ingredient = GLOBAL.IngredientAddRecipe("bindingring", {Ingredient("goldnugget", 10), Ingredient("moonrocknugget", 1)}, GLOBAL.RECIPETABS.MAGIC, GLOBAL.TECH.NONE, nil, nil, nil, nil, nil, "images/inventoryimages/bindingring.xml", "bindingring.tex" )

The main difference here is that you call AddRecipe instead of Recipe. This was changed to make it clearer that you're calling the API function and not the Recipe's constructor. Also, the function needs to be called from modmain so that we know automatically which mod the recipes belongs to, which is how we handle the inter-mod compatibility.

The last two parameters are new, and are an optional atlas and image. You no longer need to resolve and assign the atlas file in a second step.

 

Existing mods should continue to function, but if they were previously calling into the Recipe constructor, you'll still have potential mod compatibility problems, and should get warnings printed into your log.txt.

 

Also as a consequence of this change, your mods will be able to modify the recipe's sortkey without affecting the RPC communication.

 

Please let me know if you have any questions!

Link to comment
Share on other sites

  • Developer
Oh good. More log.txt spam.
 It's not spam, it's useful debug data for the modders to know why their mods are failing to work correctly. I assume most modders would prefer the log warnings, rather than their mod simply becoming broken when the old functionality is removed.

 

On a side note, I recently removed a bunch of the actual spam from the startup sequence (GL prints and invalid prefab warnings), so you should see a more readable log.txt now.

Link to comment
Share on other sites

For others looking into this, the arguments for AddRecipe match the constructor for Recipe found at /data/scripts/recipe.lua, currently:

(name, ingredients, tab, level, placer, min_spacing, nounlock, numtogive, builder_tag, atlas, image)
Edited by CarlZalph
Link to comment
Share on other sites

 It's not spam, it's useful debug data for the modders to know why their mods are failing to work correctly. I assume most modders would prefer the log warnings, rather than their mod simply becoming broken when the old functionality is removed.

 

On a side note, I recently removed a bunch of the actual spam from the startup sequence (GL prints and invalid prefab warnings), so you should see a more readable log.txt now.

 

 

Thank you! I need every debug-data i can get and for mods i even like to have more :)

Maybe you can entangle it with the "EnableModDebugPrint()"-Switch in modsettings.lua?

 

The issue i'm dealing with right now is that i have at least one mod on my server which is causing severe performance issues (but not all the time) but i just can't figure out which mods are causing problems, because the log is giving absolutely no clue about it.

 

ofcourse i'm consistently trying to turn off/turn on some mods and experiment with the results but because i have to test quite a number of cases it does taking forever :/

Link to comment
Share on other sites

2 minutes ago, DracoS2 said:

 I have one question though: How to add recipe with 2 items as an outcome??

This post is over 7 years old my dude, you may wanna make a new thread in the future, lol.

Are you using AddRecipe, AddRecipe2, or AddCharacterRecipe?

  • Haha 1
Link to comment
Share on other sites

Haha, that's true, this post has been over 7 years old. 

I'm using "AddRecipe", sir.

And about the question, nevermind, I have found the answer just seconds later. It is the fourth "nil" after "Techlevel" which can be changed to the number of outcome

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...