TL;DR
Some recipes are missing subgroups, but they still appear correctly in the crafting GUI because of some "background magic". This makes mod creation slightly inconvenient when you want to index all recipes from one group such as intermediate-products.I would really appreciate if the background code which makes recipes appear correctly in the crafting GUI would also make it easier for mods to know the result of what the code did by setting recipe subgroup or having an alternative group property so mods can more easily know exactly where a recipe stands in the crafting GUI.
More info
Because the goal is to more easily index all recipes of a certain group, this can be done alternatively by making the group prototype give subgroups and each subgroup would have a list of recipes, but that approach is more of a weirdness and the first one is more directly in line with what the modding API already does.Code speaks for itself so here's the code I'm using currently to accomplish what I'm saying here. It's a generic system in data-final-fixes.lua supposed to be compatible with mods such that every recipe from the intermediate-products gets a multiplier applied to its crafting time. My wish is for it to be simpler. (Don't look at me not using guard clauses haha, it was 3 AM when i whipped this up)
Code: Select all
function apply_intermediate_speed_multiplier(recipe)
local subgroup = recipe.subgroup
if subgroup then
if data.raw["item-subgroup"][subgroup].group == "intermediate-products" then
recipe.energy_required = recipe.energy_required / intermediate_speed_multiplier
return
end
elseif not subgroup then
if recipe.results then
for _, result in pairs(recipe.results) do
if data.raw[result.type][result.name] then
subgroup = data.raw[result.type][result.name].subgroup
else
for type, _ in pairs(defines.prototypes["item"]) do
if data.raw[type] then
if data.raw[type][result.name] then
subgroup = data.raw[type][result.name].subgroup
end
end
end
end
if subgroup then
if data.raw["item-subgroup"][subgroup].group == "intermediate-products" then
recipe.energy_required = recipe.energy_required / intermediate_speed_multiplier
return
end
end
end
end
end
if not subgroup then
log(recipe.name .. " nil subgroup")
end
end