Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,22 @@ NOTE: Calling `relax_surface_conditions` without a `min` field will not remove a

### Recipe productivity technology helper field

PlanetsLib adds a new field named `PlanetsLib_recipe_productivity_effects` to technologies, used by recipe productivity technologies. During `data-final-fixes,` technologies with this field will have their effects list appended or replaced with recipes matching either an output name or recipe category.
PlanetsLib adds a new field named `PlanetsLib_recipe_productivity_effects` to technologies, used by recipe productivity technologies. During `data-final-fixes`, technologies with this field will have their effects list appended or replaced with recipes matching either an output name or recipe category. Recipes will be excluded if they have the field `PlanetsLib_blacklist_technology_updates` set to true `true`.

Recipe products are ignored if they are not "productivity-capable"—if `ignored_by_productivity` is greater than or equal to `amount` (or `amount_max`)—because changing a recipe's productivity has no effect on such products. If a recipe has no productivity-capable products, it is fully ineligible; and if a recipe has multiple products, but only one product is productivity-capable (e.g. Kovarex enrichment), it is eligible _even if `allow_multiple_results` = false_.

#### [`TechnologyPrototype`](https://lua-api.factorio.com/latest/prototypes/TechnologyPrototype.html) field: `PlanetsLib_recipe_productivity_effects` Properties:
* `effects`: `array[ChangeResultProductivityModifier]`
* `category_blacklist` - `array[`[`RecipeCategoryID`](https://lua-api.factorio.com/latest/types/RecipeCategoryID.html)`]`
* `purge_other_effects`- `boolean`. Default: false. Before adding effects added by `PlanetsLib_recipe_productivity_effects`, remove all
effects not flagged with `PlanetsLib_force_include`.
* `allow_recipes_without_productivity` - `boolean`. Default: false. Captures recipes that have `allow_productivity` set to false.
* `allow_recipes_without_productivity` - `boolean`. Default: false. Captures recipes even if they have `allow_productivity` set to false.

#### `ChangeResultProductivityModifier` Properties:
* `allow_multiple_results`: boolean. Default: false. When false, only recipes with one result are added to the technology's effect list.
* `category` (optional) - [`RecipeCategoryID`](https://lua-api.factorio.com/latest/types/RecipeCategoryID.html) Either `(name and type) or category` required. Forbidden when `category_blacklist ~= nil`.
* `type` (optional) - [`ProductPrototype`](https://lua-api.factorio.com/latest/types/ProductPrototype.html)
* `name` (optional) - [`ItemID`](https://lua-api.factorio.com/latest/types/ItemID.html)
* `name` (optional) - [`ItemID`](https://lua-api.factorio.com/latest/types/ItemID.html) Required if not using `category`. Incompatible with `category`.
* `type` (optional) - [`ProductPrototype`](https://lua-api.factorio.com/latest/types/ProductPrototype.html) Required if using `name`.
* `category` (optional) - [`RecipeCategoryID`](https://lua-api.factorio.com/latest/types/RecipeCategoryID.html) Required if not using `name`. Incompatible with `name` and `category_blacklist`.
* `allow_multiple_results`: `boolean`. Default: false. When false, only recipes with one (productivity-capable) result are added to the technology's effect list. If multiple results have the same name, they are counted as a single result rather than being counted individually.
##### Inherited from [`ChangeRecipeProductivityModifier`](https://lua-api.factorio.com/latest/types/ChangeRecipeProductivityModifier.html)
* `change`
* `icons` (optional)
Expand Down Expand Up @@ -232,7 +234,7 @@ PlanetsLib includes standalone Python scripts for generating graphics. We recomm

# Contributors

[thesixthroc](https://mods.factorio.com/user/thesixthroc), [MeteorSwarm](https://mods.factorio.com/user/MeteorSwarm), [Midnighttigger](https://mods.factorio.com/user/Midnighttigger), [Tserup](https://mods.factorio.com/user/Tserup), [notnotmelon](https://mods.factorio.com/user/notnotmelon), [Frontrider](https://mods.factorio.com/user/Frontrider), Zwvei, [allisonlastname](https://mods.factorio.com/user/allisonlastname), Hoochie63, [SirPuck](https://mods.factorio.com/user/SirPuck), [Osmo](https://mods.factorio.com/user/O5MO).
[thesixthroc](https://mods.factorio.com/user/thesixthroc), [MeteorSwarm](https://mods.factorio.com/user/MeteorSwarm), [Midnighttigger](https://mods.factorio.com/user/Midnighttigger), [Tserup](https://mods.factorio.com/user/Tserup), [notnotmelon](https://mods.factorio.com/user/notnotmelon), [Frontrider](https://mods.factorio.com/user/Frontrider), Zwvei, [allisonlastname](https://mods.factorio.com/user/allisonlastname), Hoochie63, [SirPuck](https://mods.factorio.com/user/SirPuck), [Osmo](https://mods.factorio.com/user/O5MO), [Thremtopod](https://mods.factorio.com/user/thremtopod).


[![Discord](https://img.shields.io/discord/1309620686347702372?style=for-the-badge&logoColor=bf6434&label=The%20Foundry&labelColor=222222&color=bf6434)](https://foundrygg.com)
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
---------------------------------------------------------------------------------------------------
Version: 1.17.1
Date: ????
Bugfixes:
- Fixed that ChangeResultProductivityModifier.type was required even when using ChangeResultProductivityModifier.category.
Changes:
- When evaluating recipes for PlanetsLib_recipe_productivity_effects, products having 'ignored_by_productivity >= (amount or amount_max)' are ignored.
- When evaluating recipes for PlanetsLib_recipe_productivity_effects, multiple products with the same name are counted as a single product for `allow_multiple_results`.
---------------------------------------------------------------------------------------------------
Version: 1.17.0
Date: 2026-02-24
Expand Down
150 changes: 84 additions & 66 deletions lib/technology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,75 +367,93 @@ end

---@param tech table (TechnologyPrototype)
---@author MeteorSwarm
function Public.process_technology_recipe_productivity_effects(tech)
if tech.PlanetsLib_recipe_productivity_effects then
if not tech.effects then tech.effects = {} end
local new_effects = {}
if tech.PlanetsLib_recipe_productivity_effects.purge_other_effects then
for _,effect in pairs(tech.effects) do
if effect.PlanetsLib_force_include then
table.insert(new_effects,effect)
end
end
else
new_effects = table.deepcopy(tech.effects)
end
if not new_effects then new_effects = {} end

local settings = tech.PlanetsLib_recipe_productivity_effects
for _,effect in pairs(settings.effects) do
local type = effect.type
local name = effect.name
local change = effect.change
local category = effect.category
assert(xor(name,category),"You may only filter by result name or by category.")
if category then
assert(tech.PlanetsLib_recipe_productivity_effects.category_blacklist == nil,"category_blacklist and category are incompatible.")
end

local category_blacklist = tech.PlanetsLib_recipe_productivity_effects.category_blacklist or {"recycling"} --Excluded recipe categories

for _,recipe in pairs(data.raw["recipe"]) do
--recipe.allow_productivity = false
local recipe_category = recipe.category
if recipe_category == nil then category = "crafting" end
if not (recipe.Planetslib_blacklist_technology_updates or rro.contains(category_blacklist,recipe_category))
and recipe.results and (#recipe.results == 1 or effect.allow_multiple_results) and (settings.allow_recipes_without_productivity or recipe.allow_productivity) then
for _,result in pairs(recipe.results) do
if result.type == type and ((not name and recipe_category == category) or result.name == name) then
local new_effect = {
type = "change-recipe-productivity",
recipe = recipe.name,
change = change,
hidden = effect.hidden,
use_icon_overlay_constant = effect.use_icon_overlay_constant,
icons = effect.icons,
icon = effect.icon,
icon_size = effect.icon_size,
}
--Check if effect already exists
local contains = false
for _,effect in pairs(new_effects) do
if effect.recipe == new_effect.recipe then
contains = true
end
end
if not contains then
table.insert(new_effects,new_effect)
end
break --To stop the same recipe from being added multiple times per result item.
end
end
end
end
tech.effects = new_effects

end
tech.PlanetsLib_recipe_producitivity_effects = nil
end
function Public.process_technology_recipe_productivity_effects(tech)
if not tech.PlanetsLib_recipe_productivity_effects then
return
end

if not tech.effects then tech.effects = {} end
local new_effects = {}
if tech.PlanetsLib_recipe_productivity_effects.purge_other_effects then
for _,effect in pairs(tech.effects) do
if effect.PlanetsLib_force_include then
table.insert(new_effects,effect)
end
end
else
new_effects = table.deepcopy(tech.effects)
end
if not new_effects then new_effects = {} end

local settings = tech.PlanetsLib_recipe_productivity_effects
for _,effect in pairs(settings.effects) do
local type = effect.type
local name = effect.name
local change = effect.change
local category = effect.category
assert(xor(name,category),"You may only filter either by result name or by category.")
if name then
assert(type,"You must provide a type if filtering by result name name.")
else
assert(tech.PlanetsLib_recipe_productivity_effects.category_blacklist == nil,"category_blacklist and category are incompatible.")
end

local category_blacklist = tech.PlanetsLib_recipe_productivity_effects.category_blacklist or {"recycling"} --Excluded recipe categories

for _,recipe in pairs(data.raw["recipe"]) do
if not recipe.results then
goto continue
end

local recipe_category = recipe.category or "crafting"
if recipe.Planetslib_blacklist_technology_updates or rro.contains(category_blacklist,recipe_category) then
goto continue
end

local net_results = {} --Filter out results that cannot be affected by productivity
for _,result in pairs(recipe.results) do
if not result.ignored_by_productivity or result.ignored_by_productivity < (result.amount or result.amount_max) then
net_results[result.name] = result.type --Count multiple results with the same same name as a single result
end
end
local results_count = table_size(net_results)
if results_count == 0
or (not effect.allow_multiple_results and results_count > 1)
or (not settings.allow_recipes_without_productivity and not recipe.allow_productivity) then
goto continue
end

for result_name,result_type in pairs(net_results) do
if (recipe_category == category) or (result_type == type and result_name == name) then
local new_effect = {
type = "change-recipe-productivity",
recipe = recipe.name,
change = change,
hidden = effect.hidden,
use_icon_overlay_constant = effect.use_icon_overlay_constant,
icons = effect.icons,
icon = effect.icon,
icon_size = effect.icon_size,
}
local contains = false
for _,effect in pairs(new_effects) do
if effect.recipe == new_effect.recipe then
contains = true
break
end
end
if not contains then
table.insert(new_effects,new_effect)
end
break --To stop the same recipe from being added multiple times per result item.
end
end
::continue::
end
tech.effects = new_effects

end
tech.PlanetsLib_recipe_producitivity_effects = nil
end

return Public