Page 1 of 1

Expose entity-ghost Inventory Filters to Lua

Posted: Fri Sep 09, 2022 1:15 am
by _CodeGreen
Still working on Redo, and I'm running into the problem where I can't access the LuaInventory of a ghost container. Obviously it wouldn't be a good idea to expose the entire LuaInventory, you wouldn't want people inserting items in and out of them, but some parts of it (like `get_filter()` and more importantly set_filter()) would be really nice to have, if it's not too much trouble.

Example code works on normal entities but not ghost entities, data is the serialized entity properties.

Code: Select all

local inventory = entity.get_inventory(defines.inventory.chest)
for index, filter in pairs(data.inventory_filters) do
    inventory.set_filter(index, filter)
end

Re: Expose entity-ghost Inventory Filters to Lua

Posted: Wed Oct 25, 2023 4:49 am
by BinarySpike
👍 +1

I'm trying to set filters on cargo-wagon and it looks like I will have to use a similar workaround I used for train schedules: viewtopic.php?f=28&t=109275

That is, when the blueprint is placed, I check the `event.stack.get_blueprint_entities()` for cargo-wagons with filters. If I find any one wagon with a filter, I tag all cargo wagon ghosts made during that tick so when they are built, the tag tells me to check them again.