0.16.51 - Multiple entities on same position not found by API call

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

0.16.51 - Multiple entities on same position not found by API call

Post by Muppet9010 »

When there are 2 entities on the same position using surface.find_entities_filtered with position specified only returns 1, however using an area of -/+ 0.00001 returns both. The 2nd entity is created on to the same position as the first, but has custom flags on its prototype.


I have attached a cut down version of the mod and ingame script to demonstrate the issue. When the 2

The custom prototype is a hidden light entity with the below as the mod code in data-updates.lua

Code: Select all

local lightRange = 5
local hiddenLight = table.deepcopy(data.raw["lamp"]["small-lamp"])
hiddenLight.name = "hiddenlight"
hiddenLight.collision_box = nil
hiddenLight.collision_mask = nil
hiddenLight.selection_box = nil
hiddenLight.flags = {"not-blueprintable", "not-deconstructable", "placeable-off-grid", "not-on-map"}
hiddenLight.selectable_in_game = false
hiddenLight.picture_off = {
	filename = "__base__/graphics/entity/small-lamp/lamp.png",
	width = 0,
	height = 0
}
hiddenLight.picture_on = {
	filename = "__base__/graphics/entity/small-lamp/lamp.png",
	width = 0,
	height = 0
}
hiddenLight.light = {intensity = 0.6, size = lightRange, color = {r=1.0, g=1.0, b=1.0}}
hiddenLight.energy_usage_per_tick = "0W"
hiddenLight.energy_source.render_no_network_icon = false
hiddenLight.energy_source.render_no_power_icon = false
data:extend({hiddenLight})
The ingame script code to create the entities with the exact same position

Code: Select all

/c
local surface = game.player.surface
local playerPositionOffset = {game.player.position.x + 2, game.player.position.y + 2}
local powerPoleEntity = surface.create_entity{name="small-electric-pole", position=playerPositionOffset}
surface.create_entity{name="hiddenlight", position=powerPoleEntity.position}
The ingame script code to demonstrate the issue. Both commands should return the power pole and light, however the position command only returns the power pole.

Code: Select all

/c 
local surface = game.player.surface
for _, mainEntity in pairs(surface.find_entities_filtered{type="electric-pole"}) do
	for lightEntityIndex, lightEntity in pairs(surface.find_entities_filtered{ position = mainEntity.position }) do
		game.print("light position: " .. lightEntity.name .. " - " .. lightEntity.type .. " pos: " .. lightEntity.position.x .. ", " .. lightEntity.position.y)
	end
end
for _, mainEntity in pairs(surface.find_entities_filtered{type="electric-pole"}) do
	for lightEntityIndex, lightEntity in pairs(surface.find_entities_filtered{ area = {{mainEntity.position.x-0.0001, mainEntity.position.y-0.0001}, {mainEntity.position.x+0.0001, mainEntity.position.y+0.0001}}}) do
		game.print("light area: " .. lightEntity.name .. " - " .. lightEntity.type .. " pos: " .. lightEntity.position.x .. ", " .. lightEntity.position.y)
	end
end

As a side note use of surface.find_entity with the "hiddenlight" name and the position of the power pole will find the hiddenlight entity.
Attachments
inbuilt_lighting_0.1.1.zip
(927 Bytes) Downloaded 136 times

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: 0.16.51 - Multiple entities on same position not found by API call

Post by Nexela »

Entities are created on a grid unless the off-grid flag is set

The pole is being created at {x.4245234, y.32423} then being grid moved to x.5 and y.5

The hidden entity has the off-grid flag so it is not being moved to be on the grid.

hence you won't find the hidden entity at the lights position

Or maybe it is related to not having a bounding box at all...... I think I remember there being changes around that.

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: 0.16.51 - Multiple entities on same position not found by API call

Post by Muppet9010 »

But I am creating the off-grid entity at the position returned of the on-grid entity.
Also if the returned position of the on-grid entity was somehow different to its real position why does the "surface.find_entity" find the off-grid named item at the position of the on-grid entity.

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: 0.16.51 - Multiple entities on same position not found by API call

Post by Nexela »

I believe this is fixed for .17 with 0 sized bounding boxes

User avatar
Muppet9010
Filter Inserter
Filter Inserter
Posts: 278
Joined: Sat Dec 09, 2017 6:01 pm
Contact:

Re: 0.16.51 - Multiple entities on same position not found by API call

Post by Muppet9010 »

I can't find any resolved in 0.17 bugs related to this

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: 0.16.51 - Multiple entities on same position not found by API call

Post by Rseding91 »

Thanks for the report. It's now fixed for 0.17.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Resolved Problems and Bugs”