[1.1.60]LuaSurface::find_entities_filtered does not find entities of type "simple-entity" if collision_mask is specified

This subforum contains all the issues which we already resolved.
Post Reply
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2541
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

[1.1.60]LuaSurface::find_entities_filtered does not find entities of type "simple-entity" if collision_mask is specified

Post by FuryoftheStars »

(Edit: Forgot the game version in the title. Sorry :oops: )

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
Log output:

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
My expectation was that find_entities_filtered with the collision_mask parameter defined would find all matching entities, regardless of the entity type.

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.
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: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.60]LuaSurface::find_entities_filtered does not find entities of type "simple-entity" if collision_mask is speci

Post by boskid »

I was unable to reproduce this issue in 1.1.60.

For testing purposes i created a simple-entity with layer-13 only as suggested in the report
Prototype
then i created a save file with this entity and used your command with tiny modifications to adjust for the prototype name:
command
But it is working fine:

Code: Select all

   0.000 2022-06-18 08:13:59; Factorio 1.1.60 (build 59770, win64, full)
...
 475.152 Script ...:1: Collision layer: layer-13
 475.152 Script ...:1: Found entities by collision_mask only: 1
 475.152 Script ...:1: layer-13-ship-wreck : {x = 19.875, y = 19.91796875} : {["layer-13"] = true}
 475.152 Script ...:1: Found entities by name and collision_mask: 1
 475.152 Script ...:1: layer-13-ship-wreck : {x = 19.875, y = 19.91796875} : {["layer-13"] = true}
 475.153 Script ...:1: Found entities by name only: 1
 475.153 Script ...:1: layer-13-ship-wreck : {x = 19.875, y = 19.91796875} : {["layer-13"] = true}
Please provide your full reproduction.

--

Edit: Is your entity "tree-roots" using collision mask "colliding-with-tiles-only"?

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

Re: [1.1.60]LuaSurface::find_entities_filtered does not find entities of type "simple-entity" if collision_mask is speci

Post by boskid »

Ok, the "colliding-with-tiles-only" is the only possible explanation for the issue happening here so the issue is now fixed for 1.1.61.
1.1.61 changelog wrote:Fixed LuaSurface::find_entities_filtered would fail to find entities by collision mask if they only collide with tiles. (102706)

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

Re: [1.1.60]LuaSurface::find_entities_filtered does not find entities of type "simple-entity" if collision_mask is speci

Post by FuryoftheStars »

(Just as I was going to post I see your new post. I'm going to post this anyway in case it helps any. And yes, my "tree-roots" entity does have the "colliding-with-tiles-only" flag.)

Mod attached. I've made some heavy edits to it since posting, but I put the code from my OP back into it and the issue still occurs for me, even with this being the only running mod.

It appears to happen with any game: new, existing, map editor. I've added a separate global setting for the purposes of testing it and added some additional lines in the debug code to print basic results to the console (the actual per entity results are logged only, still). Just load the mod up into a game, go into mod settings and hit the "debug" setting (it's colored orange) and then exit the menu to get the results (it's set up as a "run once" per toggle).

The collision layer is created in data.lua at line 6, and the simple-entity "tree-roots" starts at line 57 in the same file. The debug code in control.lua starts at line 533, but you can just search for the triple hash ( ### ).

If you're unable to repro, then there's a good chance I mucked something up. Let me know if you find it! :lol:
Attachments
RestrictionsOnArtificialTiles_0.4.0.zip
(11.8 KiB) Downloaded 121 times
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 “Resolved Problems and Bugs”