Ways to leverage freshness in recipes?

Place to get help with not working mods / modding interface.
Rykuta
Inserter
Inserter
Posts: 25
Joined: Fri Dec 25, 2020 7:37 am
Contact:

Ways to leverage freshness in recipes?

Post by Rykuta »

There are a number of different things I am trying to see if I can do with freshness. Primarily I am trying to see if I can use it to alter the result of recipes based on it. Some examples include:
  • Fresher materials result in more output (either in terms of items, or fluids).
  • Item with a certain freshness results in a unique output or bonus output (different from just quantity).
  • Increasing the quality of items based on the freshness of the ingredients.
  • A fuel source that provides energy based on freshness (So if you craft it with 50% freshness, it has 50% of its fuel value left).
However: it seems like, based on the documentation, that the freshness/spoilage mechanic is basically only used to impact the freshness of recipe crafts; there is no way to alter the actual output besides just modulating its spoilage %age.

Further, it seems the only item with a unique interaction with spoilage is that the gleba science pack's 'durability' (as a tool) decreases as it rots.

So it looks like using purely prototypes to do any of the above seems like a bit of a dead end. So the next best thing is doing something with triggers/events. Unless I'm missing something.

My first thought here was to try listening for a recipe completed event; however no such event exists. Another thought was to listen for an item creation event to de-spawn and re-spawn based on freshness; however this sort of event also does not exist.

So at this point, I'm completely stumped. If there isn't a way to do any of the above at all (even with clever workarounds) that's fine of course; I have some less desirable fallbacks in mind for such a situation; but knowing would be helpful nonetheless.
User avatar
Osmo
Filter Inserter
Filter Inserter
Posts: 257
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

Re: Ways to leverage freshness in recipes?

Post by Osmo »

The closest thing i've seen people do is Diffused plastic recipe in Planet Muluna.
053b99311cb29d1e.png
053b99311cb29d1e.png (104.56 KiB) Viewed 483 times
But its far from what you want. It produces items with very short spoil time, and many of the same result at different freshness levels. This means the recipe output is higher when the recipe finishes faster (speed modules).
But i think the product freshness doesn't depend on ingredient freshness in such a case (but it'd be good to double check).

There is no event for when recipe finishes. There is some stuff you can do with scripts though, but in your case it has some downsides. You can have an item with very short spoil time and a script_to_trigger_result that triggers a lua event, and then replace the items with whatever you want. Sometimes people do it with result_is_always_fresh set to true on recipe and an item with 1 tick spoil time to detect when recipe finishes (with 1 tick of delay).

But if you want it to depend on ingredient freshness, you'll probably need a higher spoil time, which means the temporary items exist for longer. For example, you can have a recipe with result_is_always_fresh set to false, and a spoilable item that takes recipe_crafting_time*2 to spoil. This would make it only be produced if ingredient has >50% freshness (and speed module effects would affect it too, unless you forbid them). If it is less, the event is not raised. You can produce multiple items with different inherent spoil times to detect different spoil levels of the ingredient.
Rykuta
Inserter
Inserter
Posts: 25
Joined: Fri Dec 25, 2020 7:37 am
Contact:

Re: Ways to leverage freshness in recipes?

Post by Rykuta »

When something spoils does that event contain information about the initial freshness of the item? Is that a property? If not, it sounds like I'd want to have a sort of compound system with that approach.

A temp item that expires the tick it is created that triggers an event with some information about the inventory that actually triggered the event and a second item that has an expiration that is longer and is based on the freshness of the result. This second item too would be temporary. This second item could be detectable by checking the inventory of wherever the first spoil event got fired and could then be deleted and replaced with whatever it /should/ be based on its spoiled percentage.

This sounds like it has the potential to generate a race condition with things like inserters though. If the inserter grabs the item after it triggers that expiration event, or grabs the secondary item when the first item expires this sounds like quite the dilemma. If there exists a mechanism to blacklist items from being moved between inventories this could resolve that race condition issue; but it still feels a tad jank.
========================

Another thought that came to mind the possibility of using tool durability. AS mentioned in the first post: the only instance of an item where freshness directly impacts how it actually gets used is the gleban science pack. It seems like if a tool "spoils" its durability is tied to its spoiled amount. Labs consume research pack "tools" by a chunk of durability each tick.

I am unsure if this is a unique interaction, or if it would be possible to create machines that drain tool durability to produce results other than research progress. If this is something that can be done it sounds like a far less jank solution than the one above; though I don't actually know if it IS possible. (The only other tool example that exists in the game is the repair pack, which has its own unique functionality sort of hard coded.)
Post Reply

Return to “Modding help”