Modding crafting?

It seems to be fairly simple to add recipes, workbenches, and jobs. But is it curently possible to do anything more advanced with the crafting - basically just taking advantage of the menu but changing most of how it works?

  • Recipes that take no ingredients? It seems like this should be possible, but I wanted to check.
  • Calling code as a result of crafting? From what I’ve heard, it should be possible to detect if an item’s in the world, run some code, and then remove that item, but is there a better way?
  • Changing how the crafting time is calculated for a specific job/workbench?

I have a particular misuse of the crafting system in mind for the mod I’ve always wanted to make (the musical instruments from my old voxel modeling thread) but it seemed like these might be nice for other things, too. I just wanted to see if anyone knew whether any were possible already before getting my hands dirty with modding myself. Or if it would be better to start from scratch instead of poorly hacking it together with the crafting system.

1 Like

Everything you’ve mentioned there is possible, if not easy. I haven’t taken a close look at the crafting actions, have a look at /ai/packs/crafting_ai_pack.json to explore the actions involved in crafting something. Of what you listed, crafting ingredient-less items seems the hardest, since gathering ingredients appears to be at least 60% of the total code describing crafting. Calling code as a result of crafting should be a lot easier – create a custom component that’s applied onto your item, and trigger it when the item is first created. Crafting time should be the easiest – it’s specified in the JSON file for every recipe.

1 Like

The recipe json also calls which ingredients are used, I would think if you left it empty it shouldn’t call for any items and just initiate the crafting section of the code.

I tested out an item recipe without any ingredients. I got an error.

Having / finding crafting materials doesn’t seem like a trivial thing to separate from the crafting process. I’m sure some workaround actions can be made, but it’s not as easy as having an empty recipe, unfortunately. That said, it may be easier – maybe even more logical – to create your action as a separate action from crafting. Stonehearth’s code is quite granular, and you can get a lot of mileage with just copy+paste.

1 Like

did you just not add ingredients or did you remove the section that calls for ingredients all together?

I had tried both. Both had given me the identical error.

The best I could do with json alone was to make the recipe asks for 0 (zero) items, Like 0 wood. The crafting goes as far as being queued, but no one will actually start it.

This would be better doing something like the trapper for example. He “crafts” the traps and place it where needed, without using resources.

2 Likes