Setting recipe outputs' quality

Place to get help with not working mods / modding interface.
niflthaena
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Jul 11, 2025 11:47 pm
Contact:

Setting recipe outputs' quality

Post by niflthaena »

I'm trying to find a way to make a recipe with ingredients of quality n yield a result of quality n+1. The recipe prototypes don't supply this natively, so I'm trying to find a code-based solution. I've run into a few obstacles, though.
* I don't see an event for when crafting machines get assigned a recipe, so I can't listen for that in order to override recipe properties with the intended qualities.
* I don't see an event for when crafting machines finish a recipe, so I can't listen for that in order to override the result items' quality.

There's a couple factors that might make this easier to find workarounds for:
* This does not need to interact with quality modules. Quality modules are removed from the mod.
* This does not need to work on vanilla recipes. All affected recipes are modded recipes.
* This does not need to result in different qualities for byproducts; it's acceptable for all result items to be of the same quality.

One option I'm considering is to somehow force relevant crafting machines to have +100% quality (and remove the tier skipping mechanic). This would theoretically yield the right items, but the interface is still going to show the result items at tier n, which seems unpolished - and possibly unavoidable through this method.

I would much rather be able to specify it at the recipe level somehow, so the UI gets the right qualities for each inventory slot to begin with. Does anyone know of a way I could approach the problem?
Last edited by niflthaena on Sun Jul 13, 2025 7:52 am, edited 1 time in total.
robot256
Smart Inserter
Smart Inserter
Posts: 1237
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Setting recipe outputs' quality

Post by robot256 »

Here's a different hack: make a dummy item as the product of the recipe that immediately spoils into the item you want. I'm not sure if it can spoil into a specific quality, but you can also attach a script trigger to the spoiling and change the quality of the output in code.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
niflthaena
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Jul 11, 2025 11:47 pm
Contact:

Re: Setting recipe outputs' quality

Post by niflthaena »

Interesting. It looks like a spoilage quality can be specified, but that appears absolute, not relative to the source item.
Is the trigger idea using the SpoilToTriggerResult api? I'll have to experiment; the use of a trigger sounds fairly performant, but I worry that dummy items would break pedia links. I expect that to be a solvable problem, though.
Osmo
Long Handed Inserter
Long Handed Inserter
Posts: 92
Joined: Wed Oct 23, 2024 12:08 pm
Contact:

Re: Setting recipe outputs' quality

Post by Osmo »

The spoil to trigger result will have to be a script (lua) trigger to which you then react at runtime in control.lua.
There is also a factoriopedia_alternative field on every prototype you can set on the fake item to point to the real item
niflthaena
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Jul 11, 2025 11:47 pm
Contact:

Re: Setting recipe outputs' quality

Post by niflthaena »

I got the SpoilToTriggerResult approach running. The script only gets the containing entity, so I'm checking every inventory in the entity for relevant items to perform item replacement, but there's a couple problems.

First, while the script-based item swap works fine in normal inventories, in a crafting machine output it refuses the 'insert' part of the item replacement.
I looked into preserve_products_in_machine_output, but if the placeholder item stays unspoiled in the machine output then inserters would ignore it for direct-insertion chains. (or filters, etc)

An alternative might be to insert the result item into defines.inventory.crafter_trash instead, but the documentation is sparse on what objects actually have that inventory. Worse, the API itself is intentionally unhelpful - LuaEntity.get_inventory() says the following:
You may get a value back but if the type of 'this' isn't the type referred to by the defines.inventory it's almost guaranteed to not be the inventory asked for.
defines.inventory doesn't refer to clearly defined types, though. "crafter" isn't a type. Is "assembling-machine" the relevant type? Are all "assembling-machine"s guaranteed to have a meaningful result for "defines.inventory.crafter_trash"?

----

Second, not everything uses inventories. Inserters, for example, don't have an inventory for the hand. Neither do items on ground. Any type that doesn't have an Inventory would need special case code to handle it - and I'm not familiar enough with modding to know offhand what is or isn't an inventory. I don't see an inventory type for belts - do I need to worry about those too? Are there other cases I need to consider?
Post Reply

Return to “Modding help”