Skip to content
Draft
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
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -231,4 +232,4 @@ Date: 2023-06-14
- Intial release
- Reads chest contents
- Reads recipe input/output
- Reads fuel input/output
- Reads fuel input/output
25 changes: 25 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -272,6 +281,14 @@ end
---@param items table<string, ItemWithQuality>
---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)
Expand Down Expand Up @@ -347,6 +364,14 @@ end
---@param items table<string, ItemWithQuality>
---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
Expand Down
21 changes: 20 additions & 1 deletion data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,23 @@ styles["fh_deep_frame"] = {
-- left_margin = 8,
-- right_margin = 8,
-- bottom_margin = 4
}
}

-- 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.