diff --git a/changelog.txt b/changelog.txt index 59c86e5..664b5ef 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Version: 0.2.22 Date: ???? Changes: + - Added support for overriding the suggested filters for an entity through a remote interface. --------------------------------------------------------------------------------------------------- Version: 0.2.21 Date: 2025-10-03 @@ -231,4 +232,4 @@ Date: 2023-06-14 - Intial release - Reads chest contents - Reads recipe input/output - - Reads fuel input/output \ No newline at end of file + - Reads fuel input/output diff --git a/control.lua b/control.lua index f862424..97c7589 100644 --- a/control.lua +++ b/control.lua @@ -1,6 +1,15 @@ local get_filter_updater = require("filter_updaters") local fh_util = require("fh_util") +-- validate the mod data to ensure each entity name exists and points to a valid remote interface. +for _, hook in ipairs({"fh_add_items_drop_target_entity", "fh_add_items_pickup_target_entity"}) do + for entity_name, data in pairs(prototypes.mod_data[hook].data) do + assert(prototypes.entity[entity_name], string.format('prototypes.entity["%s"] == nil', entity_name)) + -- assert(remote.interfaces[data[1]], string.format('remote.interfaces["%s"] == nil', data[1])) + -- assert(remote.interfaces[data[1]][data[2]], string.format('remote.interfaces["%s"]["%s"] == nil', data[1], data[2])) + end +end + local function contains(table, val) for i = 1, #table do if table[i] == val then @@ -272,6 +281,14 @@ end ---@param items table ---Adds to the filter item list based on an entity being taken from function FilterHelper.add_items_pickup_target_entity(target, items) + local mod_data = prototypes.mod_data["fh_add_items_pickup_target_entity"].get(target.name) + if mod_data then + for _, item in ipairs(remote.call(mod_data[1], mod_data[2], target, {})) do + fh_util.add_item_to_table(items, item) + end + return + end + local inventory = target.get_output_inventory() if target.type == "proxy-container" and target.proxy_target_entity then inventory = target.proxy_target_entity.get_inventory(target.proxy_target_inventory) @@ -347,6 +364,14 @@ end ---@param items table ---Adds to the filter item list based on an entity being given to function FilterHelper.add_items_drop_target_entity(target, items) + local mod_data = prototypes.mod_data["fh_add_items_drop_target_entity"].get(target.name) + if mod_data then + for _, item in ipairs(remote.call(mod_data[1], mod_data[2], target, {})) do + fh_util.add_item_to_table(items, item) + end + return + end + if contains({ "assembling-machine", "rocket-silo" }, fh_util.get_effective_type(target)) then local recipe, quality = target.get_recipe() if recipe then diff --git a/data.lua b/data.lua index b0ac749..1f30949 100644 --- a/data.lua +++ b/data.lua @@ -15,4 +15,23 @@ styles["fh_deep_frame"] = { -- left_margin = 8, -- right_margin = 8, -- bottom_margin = 4 -} \ No newline at end of file +} + +-- in order to override the logic for an entity just add their name pointing to a remote interface in your own mod: +-- data.raw["mod-data"]["fh_add_items_drop_target_entity"].data["assembling-machine-3"] = {"interface", "function"} +data:extend{ + { + type = "mod-data", + name = "fh_add_items_drop_target_entity", + data = {}, + }, + { + type = "mod-data", + name = "fh_add_items_pickup_target_entity", + data = {}, + }, +} +-- in your remote interface you will receive the entity and an empty array of items for your convenience, +-- the array of items should always be returned, items are allowed to be in several formats. +-- (see fh_util for details, most notably: item_name, {name = "name"} & prototypes) +-- note: your mod becomes responsible for ALL suggestions for that entity, like burn results and spoilage.