[1.1.60] LuaGameScript::get_filtered_entity_prototypes

Post Reply
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

[1.1.60] LuaGameScript::get_filtered_entity_prototypes

Post by FuryoftheStars »

Same issue as 102706, only with LuaGameScript::get_filtered_entity_prototypes. Entity prototypes with the collision_mask flag "colliding-with-tiles-only" are not found on a filtered search where collision_mask is one of the filter parameters.

I don't know if the fix to 102706 will fix this too or not, thus I'm reporting it.

code excerpt from data.lua (creation of entity prototype):

Code: Select all

local artificial_tile_collision_layer = collision_mask_util.get_first_unused_layer() --> passed to control stage via dummy item and tech holding the returned name and then stored to global.layer during on_init

[...]

local tree_roots = { --> added to table with other prototypes that is then later fed into data:extend()
    type = "simple-entity",
    name = "tree-roots",
    icon = "__core__/graphics/icons/unknown.png",
    icon_size = 64,
    flags = {"placeable-neutral", "placeable-off-grid", "hidden"},
    collision_box = {{-0.95, -0.95}, {0.95, 0.95}},
    collision_mask = {"colliding-with-tiles-only", artificial_tile_collision_layer},
    picture = {
        layers = {
            {
                filename = "__core__/graphics/empty.png",
                size = 1
            }
        }
    }
}
code excerpt from control.lua (attempt to find entity prototype via get_filtered_entity_prototypes):

Code: Select all

log("Collision mask: " .. global.layer)

log("Search by collision_mask only...")
local prototypes = game.get_filtered_entity_prototypes{{filter = "collision-mask", mask = global.layer, mask_mode = "collides"}}
if prototypes["tree-roots"] then log("tree-roots found; collision mask: " .. serpent.line(prototypes["tree-roots"].collision_mask_with_flags)) else log("no tree roots") end

log("Search by name and collision_mask...")
local tree_roots = game.get_filtered_entity_prototypes{{filter = "name", name = "tree-roots"}, {filter = "collision-mask", mask = global.layer, mask_mode = "collides", mode = "and"}}
if tree_roots["tree-roots"] then log("tree-roots found; collision mask: " .. serpent.line(tree_roots["tree-roots"].collision_mask_with_flags)) else log("no tree roots") end

log("Search by name only...")
local tree_roots2 = game.get_filtered_entity_prototypes{{filter = "name", name = "tree-roots"}}
if tree_roots2["tree-roots"] then log("tree-roots found; collision mask: " .. serpent.line(tree_roots2["tree-roots"].collision_mask_with_flags)) else log("no tree roots") end
log output:

Code: Select all

1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:263: Collision mask: layer-13
1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:265: Search by collision_mask only...
1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:267: no tree roots
1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:269: Search by name and collision_mask...
1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:271: no tree roots
1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:273: Search by name only...
1317.840 Script @__RestrictionsOnArtificialTiles__/control.lua:275: tree-roots found; collision mask: {["colliding-with-tiles-only"] = true, ["layer-13"] = true}
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2242
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.60] LuaGameScript::get_filtered_entity_prototypes

Post by boskid »

There are some extremally subtle differences between 102706 and this report which are making this report a Not a bug. In case of a LuaSurface::find_entities_filtered input was given as a CollisionMaskLayer making it not possible to specify any special flags like "not-colliding-with-itself", "consider-tile-transitions" or "colliding-with-tiles-only" and there was one place where a CollisionMaskLayer was implicitly converted into a CollisionMask and doing a collision check where the collision mask on the entity was unable to collide. In case of a LuaGameScript::get_filtered_entity_prototypes with collision-mask filter, the input is fully capable of loading a CollisionMask with custom flags including the "colliding-with-tiles-only" or "not-colliding-with-itself", and the mode being called "collide" must be going through the internal "collide" check due to mode name. In that case i would expect that if you give a collision mask that does not collide with itself, it will not find collision masks that are equal because they are said to not collide with itself and the mode is "collides".

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2242
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.60] LuaGameScript::get_filtered_entity_prototypes

Post by boskid »

While the bug report is a Not a bug, because it may be annoying to filter prototypes that have collision_mask containing "colliding-with-tiles-only" flag, for 1.1.61 i implemented 2 new filter modes for the collision_mask: "contains-any" and "contains-all". First is essentialy ((value & mask) != 0) which means a collision mask will pass a filter if it contains any layer (not flags) as the collision mask from the filter and second is essentially ((value & mask) == mask) which means a collision mask will pass if it contains all layers (not flags) specified by the collision mask from the filter. Moving this out of Bug reports and moving to Implemented modding interface requests.
1.1.61 changelog wrote: Scripting:
- Collision-mask prototype filters for Entity, Tile and Decorative now support a 'contains-any' and 'contains-all' modes.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [1.1.60] LuaGameScript::get_filtered_entity_prototypes

Post by FuryoftheStars »

Thanks, boskid.

Ok, I think I understand. I will say that's not exactly intuitive to me, but those extra mask_mode values should allow me to do what I need to. Thank you!
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Implemented mod requests”