Page 1 of 1

How to generate items/recipes from existing items?

Posted: Thu Aug 13, 2020 6:01 pm
by Ch4rl1e
Hello!

So I want to iterate through all the barrels, which I know the game itself generates from all valid fluids, in order to create a new item based on each, and a corresponding recipe.

I found through looking at other mods that one can iterate over barrels as such in data-updates.lua:

Code: Select all

for _,r in pairs(data.raw.recipe) do
	if r.subgroup=="fill-barrel" then
		r.energy_required = TIME_FIL
		r.ingredients[1].amount = CAP
	elseif r.subgroup=="empty-barrel" then
		r.energy_required = TIME_EMP
		r.results[1].amount = CAP
	end
end
which is a starting point, but this is just for modifying values about the existing barrels, not creating new items/recipes from them.

I want to use the name of the barrel within the name of the item as well, and I am then unsure on how you'd go about generating locales for all of the items as well. In theory this should support any mod fluids as well as at this point they'll have been barrellised by the base game already.

Any ideas on how to do this? I understand you can add recipes and items with data:extend() which I've already done successfully but doing this "procedurally" is confusing.

The idea is silly and is effectively just compression, making "pallet of {barrel name}" with 1 wood and 4 barrels. Would have a reverse recipe too of course. Image
It's more just practice than anything else.

Thanks

Re: How to generate items/recipes from existing items?

Posted: Fri Aug 21, 2020 11:25 am
by darkfrei
gogglebot wrote: Thu Aug 13, 2020 6:01 pm I want to use the name of the barrel within the name of the item as well, and I am then unsure on how you'd go about generating locales for all of the items as well. In theory this should support any mod fluids as well as at this point they'll have been barrellised by the base game already.
See how it was done in the barreled fluids:
localised_name
localised_name
2020-08-21T13_23_04.png (8.54 KiB) Viewed 1271 times
item locale
item locale
2020-08-21T13_26_47-_D__Factorio_0.18_data_base_locale_en_base.cfg.png (1.72 KiB) Viewed 1271 times
The same for recipe:
2020-08-21T13_30_59-empty.png
2020-08-21T13_30_59-empty.png (10.54 KiB) Viewed 1269 times
2020-08-21T13_30_32-fill.png
2020-08-21T13_30_32-fill.png (9.22 KiB) Viewed 1269 times
recipe locale
recipe locale
2020-08-21T13_28_20-recipe-locale.png (6.54 KiB) Viewed 1270 times
gogglebot wrote: Thu Aug 13, 2020 6:01 pm Any ideas on how to do this? I understand you can add recipes and items with data:extend() which I've already done successfully but doing this "procedurally" is confusing.
See the code of https://mods.factorio.com/mod/BottledFluids, it's the same as barreling, but bottling and the script is much simpler (I think).
gogglebot wrote: Thu Aug 13, 2020 6:01 pm The idea is silly and is effectively just compression, making "pallet of {barrel name}" with 1 wood and 4 barrels. Would have a reverse recipe too of course. Image
It's more just practice than anything else.
1. You are need the list of barreled fluids;
You can just search by data.raw.item for them; it can be empty barrel too!

2. You are need the palette, item and recipe for it.

3. The main cycle, where you make prototypes for new barrels-on-palette items, recipes for pack- and unpacking and icons for them. One set for every element from point 1.