I started deriving things from new things in data, data-updates and data-final-fixes.
On the one hand, I should run my code in data, so that other mods that derive things can see the new things as soon as possible.
Unfortunately, this conflicts with mods that edit existing prototypes if they do not run before my mod does, as my mod currently only derives new things from a given prototype once, and does not check if the prototype has changed since the last time.
So, I skipped running my derivation function in data, so that I would pick up edits to the vanilla prototypes.
Now another mod I'm using derives things from other things and only runs in data-updates, and derives new things from the things my mod creates quite happily.
Unfortunately yet another mod edits vanilla items in data-updates (which is probably where it should), but it sorts after the mod I'm creating, so I do not pick the new values up in data-updates.
To fix this, I added an optional dependency on that mod. This caused the derived items my mod creates to include the changes added to the vanilla item by this mod.
This however now causes my mod to run after that mod, and also after the mod that used to derive things from my mod.
The current order of operations:
- Robot World - edits logistics chests in data.
- bullet-trails - Adds bullet trails to turrets - in data-updates.
- Loaded Turrets - Creates an item that combines turret + ammo into a single item in data-updates.
- Big_Things - My mod that builds bigger things from other things - currently runs in data updates and data-final-fixes.
What I'm beginning to think is that what I need to have is a framework that allows me to register a callback for when a new thing is added, or the definition of an existing thing I've seen before is changed, collect new/updated things from my mod, then pass them around again.
Something similar to the control phase, where you don't actually do anything in the top level script, just register callbacks, and the framework calls your callbacks at the appropriate times.
From what I understand of things, it should be entirely feasible to implement something like that in a library and have it shared by any mod that cares to use it.
As a programming exercise, it might be fun to try implementing something like that.