Page 1 of 1

Allow spoil_result to spoil into multiple weighted items

Posted: Tue Nov 12, 2024 1:49 pm
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
	}
}

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 10:17 am
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.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 11:57 am
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.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 3:48 pm
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.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 9:09 pm
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.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Thu Dec 05, 2024 9:31 pm
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.

Re: Allow spoil_result to spoil into multiple weighted items

Posted: Fri Dec 06, 2024 12:18 am
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.