[0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

[0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

Post by Deadlock989 »

Let's say you have a recipe that specifies results like this:

Code: Select all

results = {
	{type = "item", name = "steel-rod", amount_min = 0, amount_max = 12},
	{type = "item", name = "copper-cable", amount_min = 0, amount_max = 7},
}
From what I understand from the documentation, this means that the result has an equal chance of producing 12 steel rods, 11 steel rods, etc. down to and including 0 steel rods. (0+1+2+3...+12) / 13 = 6, so on average you get 6 steel rods. For the copper cables, the same maths works out at an average of 3.5 copper cables. In both cases, it's an average over time of exactly 50% of the max amount.

What you actually see in the recipe tooltip is this:

disassembly.png
disassembly.png (155.52 KiB) Viewed 2081 times
I think one of two things is happening: either amount_min = 0 is not being taken into account when calculating the average result and it's reporting the average of 1-12 instead, or there is an undocumented lower limit of 1 for amount_min which is being silently set instead. If it's the latter, it's inconsistent with plain ol' amount, which can be set to 0 just fine.

You can work around this to some extent by applying a probability as well - for example if you want a real spread of 0-12, you can specify amount_min = 1, amount_max = 12 and probability = (amount_max/amount_max+1), in this case 12/13ths. You then get the correct expected results in the tooltip. The drawbacks of that are (a) it's a pain, (b) you get very confusing descriptions from other mods (like FNEI) that report on results, and (c) it doesn't work well for more complex recipes where some of the ingredients have a low amount and are expensive to make.
Last edited by Deadlock989 on Sun May 19, 2019 12:38 pm, edited 4 times in total.
"If Stalin had a good writeup on programming, would linking that be dangerous?"

Bilka
Factorio Staff
Factorio Staff
Posts: 2853
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.17.41] Results reported wrongly for recipes that specify amount_min = 0

Post by Bilka »

Deadlock989 wrote: โ†‘
Sun May 19, 2019 12:04 pm
or there is an undocumented lower limit of 1 for amount_min which is being silently set instead. If it's the latter, it's inconsistent with plain ol' amount, which can be set to 0 just fine.
Indeed:

Code: Select all

  this->countMin = Math::max(uint16_t(1), this->countMin);
  this->countMax = Math::max(this->countMax, this->countMin);
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.17.41] Results reported wrongly for recipes that specify amount_min = 0

Post by Deadlock989 »

Thought so. Is there any reason it can't be 0? amount can be 0.

Edited thread title to better describe the problem.
"If Stalin had a good writeup on programming, would linking that be dangerous?"

posila
Factorio Staff
Factorio Staff
Posts: 5147
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.17.41] Results reported wrongly for recipes that specify amount_min = 0

Post by posila »

Deadlock989 wrote: โ†‘
Sun May 19, 2019 12:17 pm
Thought so. Is there any reason it can't be 0? amount can be 0.
I don't know if there is any reason for it, but amount can't be 0. It'll be set to 1 by the same code.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.17.41] Results reported wrongly for recipes that specify amount_min = 0

Post by Deadlock989 »

posila wrote: โ†‘
Sun May 19, 2019 12:24 pm
Deadlock989 wrote: โ†‘
Sun May 19, 2019 12:17 pm
Thought so. Is there any reason it can't be 0? amount can be 0.
I don't know if there is any reason for it, but amount can't be 0. It'll be set to 1 by the same code.
Then why does this mod work just fine, and also another mod I have in development which has "incinerator" recipes that produce 0 items, easy as you like?

Code: Select all

for _,item in pairs(data.raw.item) do
	if item.fuel_value and item.fuel_category == "chemical" then
		local days = read_fuel_value(item.fuel_value)/4000000
		if days > 0 then
			local result = item.burnt_result or "deadlock-lamp-emptiness"
			local result_count = item.burnt_result and 1 or 0
			data:extend({{
				name = "deadlock-lamp-burning-"..item.name,
				type = "recipe",
				category = "deadlock-lamp-burning",
				result = result,
				result_count = result_count,
				emissions_multiplier = item.fuel_emissions_multiplier,
				ingredients = {{item.name,1}},
				hidden = true,
				enabled = true,
				hide_from_stats = true,
				allow_decomposition = false,
				allow_as_intermediate = false,
				allow_intermediates = false,
				energy_required = days * day,
			}})
			log("Created lamp fuel for "..item.name.." with burn time of "..days.." days")
		else
			log("Skipped creating lamp fuel for "..item.name..", couldn't read a sane fuel value.")
		end
	end
end
"If Stalin had a good writeup on programming, would linking that be dangerous?"

Bilka
Factorio Staff
Factorio Staff
Posts: 2853
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.17.41] ItemProductPrototype "amount_min" is silently being capped at a lower limit of 1, should be 0 like "amount

Post by Bilka »

Deadlock989 wrote: โ†‘
Sun May 19, 2019 12:26 pm
Then why does this mod work just fine, and also another mod I have in development which has "incinerator" recipes that produce 0 items, easy as you like?
result_count isn't capped, amount and amount_min is capped (for items). Interestingly, 0 fluid recipes are *not* silently changed.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.17.41] ItemProductPrototype "amount_min" is silently being capped at a lower limit of 1, should be 0 like "amount

Post by Deadlock989 »

Bilka wrote: โ†‘
Sun May 19, 2019 12:29 pm
Deadlock989 wrote: โ†‘
Sun May 19, 2019 12:26 pm
Then why does this mod work just fine, and also another mod I have in development which has "incinerator" recipes that produce 0 items, easy as you like?
result_count isn't capped, amount and amount_min is capped (for items). Interestingly, 0 fluid recipes are *not* silently changed.
So result_count is not capped but amount is capped? That's ... odd.

If result_count = 0 works as expected, then amount = 0, amount_min = 0 should follow that behaviour, no?
"If Stalin had a good writeup on programming, would linking that be dangerous?"

Rseding91
Factorio Staff
Factorio Staff
Posts: 12219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

Post by Rseding91 »

The values where set to always be > 0 due to a bug wayy back related to mining drills producing infinite items. I don't think it needs to exist these days and instead the original issue should have been fixed a different way (have the mining drill just not produce anything if it gets 0 items from some ore).
If you want to get ahold of me I'm almost always on Discord.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

Post by Deadlock989 »

Great, thanks very much.
"If Stalin had a good writeup on programming, would linking that be dangerous?"

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

Post by Deadlock989 »

Tested this in .42, works much better now, thanks for doing this.

@Bilka - you'll need to tweak your updated docs to reflect the change.
"If Stalin had a good writeup on programming, would linking that be dangerous?"

Bilka
Factorio Staff
Factorio Staff
Posts: 2853
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: [0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

Post by Bilka »

Deadlock989 wrote: โ†‘
Wed May 22, 2019 1:31 pm
@Bilka - you'll need to tweak your updated docs to reflect the change.
Thanks for the reminder, I fixed the doc and added that fluid amounts now may not be < 0.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2393
Joined: Fri Nov 06, 2015 7:41 pm

Re: [0.17.41] ItemProductPrototype "amount" and "amount_min" capped at lower limit of 1, should be 0 like "result_count"

Post by Deadlock989 »

Bilka wrote: โ†‘
Wed May 22, 2019 1:39 pm
Thanks for the reminder, I fixed the doc and added that fluid amounts now may not be < 0.
Cheers ๐Ÿ‘
"If Stalin had a good writeup on programming, would linking that be dangerous?"

Post Reply

Return to โ€œResolved Problems and Bugsโ€