I have a mod that modifies the collision mask of some entities, and for some of them it's also placing entities of type "simple-entity" with them (to give them, essentially, a secondary collision box that I can give different layers to than the main). I have a global setting to do needed cleanup operations - just in case - using the LuaSurface method of "find_entities_filtered", but in testing, the code wasn't finding any of these simple-entity's, but it's finding everything else just fine. I started playing with it and discovered that it wasn't finding any of the simple-entity's if I specified the collision_mask to filter on.
Code excerpt I ran (this will not run for you as is because some of the values are defined elsewhere, not to mention the collision mask layer and entity I'm looking for are exclusive to my mod):
Code: Select all
log("Collision layer: " .. global.artificial_tile_collision_layer)
local entities = surface.find_entities_filtered{collision_mask = global.artificial_tile_collision_layer}
log("Found entities by collision_mask only: " .. #entities)
local found = false
for _, entity in pairs(entities) do
if entity.name == "tree-roots" then
found = true
log(entity.name .. " : " .. serpent.line(entity.position) .. " : " .. serpent.line(entity.prototype.collision_mask))
end
end
if #entities > 0 and not found then
log("None were \"tree-roots\"")
end
local tree_roots = surface.find_entities_filtered{name = "tree-roots", collision_mask = global.artificial_tile_collision_layer}
log("Found entities by name and collision_mask: " .. #tree_roots)
found = false
for _, tree_root in pairs(tree_roots) do
if tree_root.name == "tree-roots" then
found = true
log(tree_root.name .. " : " .. serpent.line(tree_root.position) .. " : " .. serpent.line(tree_root.prototype.collision_mask))
end
end
if #tree_roots > 0 and not found then
log("None were \"tree-roots\"")
end
local tree_roots2 = surface.find_entities_filtered{name = "tree-roots"}
log("Found entities by name only: " .. #tree_roots2)
found = false
for _, tree_root2 in pairs(tree_roots2) do
if tree_root2.name == "tree-roots" then
found = true
log(tree_root2.name .. " : " .. serpent.line(tree_root2.position) .. " : " .. serpent.line(tree_root2.prototype.collision_mask))
end
end
if #tree_roots2 > 0 and not found then
log("None were \"tree-roots\"")
end
Code: Select all
18.637 Script @__RestrictionsOnArtificialTiles__/control.lua:420: Collision layer: layer-13
18.640 Script @__RestrictionsOnArtificialTiles__/control.lua:422: Found entities by collision_mask only: 2947
18.641 Script @__RestrictionsOnArtificialTiles__/control.lua:431: None were "tree-roots"
18.642 Script @__RestrictionsOnArtificialTiles__/control.lua:435: Found entities by name and collision_mask: 0
18.644 Script @__RestrictionsOnArtificialTiles__/control.lua:448: Found entities by name only: 2307
18.644 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.9375, y = -94} : {["layer-13"] = true}
18.644 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.875, y = -90.875} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.0625, y = -83.4375} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.5625, y = -81.375} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.125, y = -82.4375} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.375, y = -72.5} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.125, y = -64.375} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -223.4375, y = -38} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -209.625, y = -141.0625} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -203.5625, y = -127.1875} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -201.1875, y = -131.3125} : {["layer-13"] = true}
18.645 Script @__RestrictionsOnArtificialTiles__/control.lua:453: tree-roots : {x = -215.625, y = -113.8125} : {["layer-13"] = true}
[...] --> continues on for the total of 2307 found
I do not know if this is true for other entity types, or if there are other parameters that if I define will break its ability to find them. This is as far as my testing went.