How do I - Remove one of my recipes if another mod is loaded?

Hey there! It’s another round of Wouter is asking pointlessly complicated questions for further understanding!

Today: a fancy one.

Say we have blacksmith A. (nordling blacksmith) who has his own raecipes.

And we want to add recipes from a seperate recipes.Json in a seperate mod (specifically the ace mod)

Now if I want ALL of those recipes I could just make a mix in that loads up that entire file, and it will only load it up when the ace mod is there.

But say I want - some- of the stuff in that file… And only when that file exists. Any clever plans?

Some mixintos will simply fail with an error in the log, so in the game they simply won’t load and the player shouldn’t get affected.

You could try making a mixinto to your recipes index, and in the mixinto file having a mixin pointing to the recipes index from ACE.

Another way to check for existence is with the dependencies stuff (but doesn’t enforce anything, it will fail silently if the required mod is not present), or with a client / server init script (Lua).

Is this the opposite case? Or just like you only want -some- of the recipes and not all of them?

A bit more detailed then:
Ace’s blacksmith recipe file holds new forge-stuff like workbenches and recourses and stuff So those id like to load in-but only when ace is also around)

but the file also holds a bunch of weapons, which I don’t want my nordlings to be able to make. So those I don’t want to load in

Yeah this

If ACE’s blacksmith has the same URI as yours, then when both are loaded all the recipes will be already there :thinking:

You could have a separate mixinto using mixintypes to get rid of the ACE recipes, this is from RC for example:

"mixins": "/stonehearth/jobs/weaver/recipes/recipes.json",
   "craftable_recipes": {
      "clothing_armor": {
         "recipes": {
            "mixintypes": {
               "worker_outfit_winter": "remove"
            }
         }
      },

Hopefully it’ll fail silently if ACE’s not there.

You can do a mixin to import the whole file and then use the mixintype: remove for stuff you don’t want.
https://stonehearth.github.io/modding_guide/modding_guide/essentials/removing/index.html

But doesn’t the mixin remove throw a wobbler when you try to remove stuff that’s not there? It did some months ago at least, not sure if that’s still the case I’ll try tonight

@Wouter_Sikkema I just tested something that might help you out in this case.

If you do this on your nordling recipe file:

"example_recipe": {
    "recipe": ""
}

You remove that recipe without having to use the mixintypes. If the recipe doesn’t exist (ie: the person doesn’t use ACE), nothing happens either.

So that might work for you :slight_smile:

1 Like

Thanks dani! I found out that the mixintype: remove stuff has become robust enough to do this stuff without exploding, but this is always a usefull trick to remember (especially if you want to mix this Into another file for instance)

That can cause even more problems, as the recipes is a table ( { } ), not a string (" "). In the last version that would actually throw an error, but they patch it so old mods would not break the game from mixintos using strings into the items that are now all arrays. If you turn it into a string, then another mod tries to match it as a table, that can probably error.

Wait, that is a table? After the "recipe":

(from the base game):

"door_clay_latticed": {
    "recipe": "file(door_clay_latticed_recipe.json)"
}

Doesn’t seem to be one, what happens if I put more than one recipe under the same recipe? :thinking:

I was imagining the previous key, like this:

{
   "craftable_recipes": {
      "workbenches": {
         "ordinal": 1,
         "name": "i18n(stonehearth:jobs.engineer.recipes.workbenches_name)",
         "recipes": {
            "blacksmith_workbench": {
               "recipe": "file(engineer_workbench_recipe.json)"
            }
         }
      },

Ahhh, no, I meant the individual recipe file;

As far as I know doing the “” just “blanks” the file and should cause no harm? At least it didn’t on my accidental test :stuck_out_tongue:

Oh, looking at the code there is a specific
if recipe_data.recipe == "" then
so that is why it is working fine. It simple skips it.

3 Likes

now for a more complicated one: how do i make something in my own mod go away if another mod exists?
i know how to do it from the other mods point of view but is there a way to say “if ace is loaded up, remove my charcoal mound recipe from the carpenter?”

I think there are two options. You could make an init script to apply a manifest, or try a JSON hack.

Normally I wouldn’t recommend this (haven’t mentioned it in the guide), but at Discourse you can find a thread that says you can make a mixinto to another mod’s manifest (since it’s a JSON file and mixintos would silently fail with just a warning in the log if they can’t find the files). Not sure if it’ll work but like:

{
   //rest of your manifest
   "mixintos" : {
      "path to ace manifest.json" : "a file located in your mod, containing another mixintos section"
   }
}

The file pointed to above would be like

{
   "mixintos" : {
      "path to the carpenter recipes" : "path to mixinto file with mixintypes or whatever to remove the recipes"
   }
}

Just suggestions that you can try, never attempted them so not sure if they work :woman_shrugging:

I’ll give those a shot! And let you know the results for SCIENCE!

for posterity: mixing additions to a manifest, that loads corrections to my own mods seems to work

so i made a file called manifest_ace, that i mix into the actual ace’s manifest, and then ace’s manifest calls for a file that handles the removal of my stuff. so it works! but it does seem to cause a hit to startup time. but that might just because of ACE in general (because its not a zipped file for me at this time…and its even larger than my own mod, which i also have unzipped because im working on it ofc.)