Allow spoil_result to spoil into multiple weighted items

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
lambdalemon
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Oct 23, 2024 12:03 pm
Contact:

Allow spoil_result to spoil into multiple weighted items

Post by lambdalemon »

Allow items to spoil into multiple items using a weighted value. And also only allow the item to spoil into one item at a time.

Code: Select all

data.raw["item"]["iron-plate"].spoil_result = {
	{
		name = "copper-ore",
		weight = 1
	},
	{
		name = "iron-ore",
		weight = 99
	}
}
Puke
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jun 13, 2016 7:00 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by Puke »

+1 to that
Currently, you can have multiple "spoil_result" for an item. Each spoil result can have a probability to happen.
But there is no way I'm aware of to make these results mutually exclusive.

Using the scripting option (spoil_to_trigger) can allow to make this possible, but runs into a wall as soon as the item spoils on a belt (because the item disappears first, then the script triggers, so you cannot replace it where it was on the belt).
Plus, scripting it may have a huge performance impact.
Xorimuth
Filter Inserter
Filter Inserter
Posts: 730
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by Xorimuth »

Puke wrote: Thu Dec 05, 2024 10:17 am Currently, you can have multiple "spoil_result" for an item. Each spoil result can have a probability to happen.
Nope, currently you can only specify a single spoil_result, unless you do more complex shenanigans with spoil_to_trigger_result.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Puke
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Jun 13, 2016 7:00 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by Puke »

That is indeed what I did, I was pretty sure I just tried putting a list of strings, but looking back at the code, I used the insert_item trigger with two items.

Still ! Have the ability to mod multiple results which could be mutually exclusive or not would be nice, in order to be able to spoil in place on a belt simply for instance.
protocol_1903
Filter Inserter
Filter Inserter
Posts: 291
Joined: Fri Sep 09, 2022 4:33 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by protocol_1903 »

+1, this would be interesting for uranium and nuclear mods modeling half-lives. Imagine that each u-235 has a 50% chance to become whatever u235 decays into, and a 50% chance to stay as u235. That would be so cool.
If you need to reach me, message me on discord.

I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
MacFeejj
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon Apr 24, 2023 9:23 am
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by MacFeejj »

This is a nice idea, but technically it'd raise a _lot_ of implementation issues. Currently, one stack of items will always spoil into one stack of items - if a stack spoils while an inserter is moving it, or in a container with limited size, or while being carried in a rocket, it'll spoil into exactly one stack replacing the one already there - if one stack of items could spoil into multiple stacks, that would raise a _lot_ of issues. The only sane way I can see this working is if each stack spoils into the same item, which, while averaging out into the same result, would be quite janky.
protocol_1903
Filter Inserter
Filter Inserter
Posts: 291
Joined: Fri Sep 09, 2022 4:33 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by protocol_1903 »

MacFeejj wrote: Thu Dec 05, 2024 9:31 pm This is a nice idea, but technically it'd raise a _lot_ of implementation issues. Currently, one stack of items will always spoil into one stack of items - if a stack spoils while an inserter is moving it, or in a container with limited size, or while being carried in a rocket, it'll spoil into exactly one stack replacing the one already there - if one stack of items could spoil into multiple stacks, that would raise a _lot_ of issues. The only sane way I can see this working is if each stack spoils into the same item, which, while averaging out into the same result, would be quite janky.
It wouldn't really be that janky. When combining items into a stack, the spoilage time is averaged, so it's already "janky" by your definition. Making the whole stack spoil into the same item based on the defined weights would be no less jank, and still makes sense.
If you need to reach me, message me on discord.

I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
User avatar
snouz
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by snouz »

+ 1, adding a way to spoil into a random result (based on a probability value) would allow for new gameplay possibilities.
Planet Moshine, GUI Unifier + 17 mods, contributed graphically and otherwise to 70+ mods
Rseding91
Factorio Staff
Factorio Staff
Posts: 15981
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by Rseding91 »

Code wise this would be fairly simple to do. Tooltip wise I have zero idea how it would be shown.
If you want to get ahold of me I'm almost always on Discord.
User avatar
snouz
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by snouz »

Rseding91 wrote: Mon Aug 11, 2025 3:30 pm Code wise this would be fairly simple to do. Tooltip wise I have zero idea how it would be shown.
A simple suggestion, which I think is clean and clear
Attachments
demo.png
demo.png (9.15 KiB) Viewed 200 times
Planet Moshine, GUI Unifier + 17 mods, contributed graphically and otherwise to 70+ mods
curiosity
Filter Inserter
Filter Inserter
Posts: 670
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by curiosity »

Rseding91 wrote: Mon Aug 11, 2025 3:30 pm Code wise this would be fairly simple to do. Tooltip wise I have zero idea how it would be shown.
I recall raiguard(?) had a WIP implementation of weighted recipe products. See how he's done it?
snouz wrote: Mon Aug 11, 2025 9:53 pm A simple suggestion, which I think is clean and clear
That's not great, because the weight is divorced from the item.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15981
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by Rseding91 »

curiosity wrote: Tue Aug 12, 2025 12:18 am I recall raiguard(?) had a WIP implementation of weighted recipe products. See how he's done it?
Well… in fact one of the two kind of blocker issues with that was the tooltip.
If you want to get ahold of me I'm almost always on Discord.
Jap2.0
Smart Inserter
Smart Inserter
Posts: 2538
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by Jap2.0 »

I would expect basically the same as seen for e.g. uranium and scrap. No clue how to denote independent chances vs. exactly one though, considering that as it is now is a bit ambiguous.

Edit: checking now, I'm mixing up a couple things (or they've changed); what I was imagining was a percent on top of the icon, although [icon] 12.3% [name] would work too.
There are 10 types of people: those who get this joke and those who don't.
User avatar
snouz
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by snouz »

Something to consider: if the result is like recipe results, that means you could have several items out of 1 spoiling item? That would mean you could hit a container max and items would need to be able to spill, but I guess that's already taken into account since it can already theoretically spoil into an item with a lower stack size.
Planet Moshine, GUI Unifier + 17 mods, contributed graphically and otherwise to 70+ mods
protocol_1903
Filter Inserter
Filter Inserter
Posts: 291
Joined: Fri Sep 09, 2022 4:33 pm
Contact:

Re: Allow spoil_result to spoil into multiple weighted items

Post by protocol_1903 »

snouz wrote: Tue Aug 12, 2025 12:46 pm Something to consider: if the result is like recipe results, that means you could have several items out of 1 spoiling item? That would mean you could hit a container max and items would need to be able to spill, but I guess that's already taken into account since it can already theoretically spoil into an item with a lower stack size.
The point was to have it weighted such that there would only ever be one outcome. So item A could spoil into item B or item C with a set probability for each totaling 100%, but not both. One of the other suggestions which i like is also having a "spoil to nothing" option where the item just disappears, so you can have item B @ 30%, item C @ 20%, and nothing @ 50%

It is "like recipe results" only in the sense of defining individual "product options" with distinct probabilities
If you need to reach me, message me on discord.

I make qol mods. Check them out, maybe.
https://mods.factorio.com/user/protocol_1903
If you have a mod idea, I can look into it.
Post Reply

Return to “Modding interface requests”