LuaSurface::find_entity returns no-collision entity

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

LuaSurface::find_entity returns no-collision entity

Post by Mooncat »

Request:
LuaSurface::find_entity can find entities that have zero-sized collision box (collision_box = {{0, 0}, {0, 0}}), e.g. item-request-proxy


This thing has bugged me for quite some time: we have to use LuaSurface::find_entities_filtered to get the entity that we know its name and exact position, but LuaSurface::find_entity cannot get it for us.
At the end, we have to do this

Code: Select all

local x = position.x
local y = position.y
local arr = surface.find_entities_filtered{area = {{x - 0.1, y - 0.1}, {x + 0.1, y + 0.1}}, name = "item-request-proxy", force = force, limit = 1}
if #arr > 0 then
    local item_request_proxy = arr[1]
    -- We can finally work on the proxy!!
instead of the expected, clean way

Code: Select all

local item_request_proxy  = surface.find_entity("item-request-proxy", position)
if item_request_proxy then
    -- blah blah blah
end
We do this not just for item-request-proxy, but most of the time, we do this for our custom entities (e.g. combinator) with zero-sized collision box so players cannot select them in normal way.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14312
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaSurface::find_entity returns no-collision entity

Post by Rseding91 »

You can't have both. An entity with zero sized collision box never collides with a single point (or anything else for that matter) and find_entity only searches a single point.

Either it does collide or it can't be found with entity_search.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: LuaSurface::find_entity returns no-collision entity

Post by Mooncat »

Rseding91 wrote:You can't have both. An entity with zero sized collision box never collides with a single point (or anything else for that matter) and find_entity only searches a single point.

Either it does collide or it can't be found with entity_search.
hm... so find_entity(position) searches entity by checking collision... but why does find_entities(area) work?
I'm thinking of an API that really checks the positions of entities rather than collision for searching. Don't know whether it is possible on your side. :mrgreen:
Last edited by Mooncat on Tue Mar 07, 2017 1:45 am, edited 2 times in total.
posila
Factorio Staff
Factorio Staff
Posts: 5357
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: LuaSurface::find_entity returns no-collision entity

Post by posila »

Hm, I find to be strange inconsistency.

Entity has two collide() overloads:

Code: Select all

virtual bool collide(const BoundingBox& boundingBox) const
{
  if (this->boundingBox.isZero())
    return boundingBox.collide(this->position);
  return this->boundingBox.collide(boundingBox);
}

Code: Select all

virtual bool collide(const RealPosition& position) const
{ 
  return this->boundingBox.collide(position);
}
The second overload doesn't check for empty bounding box, but there might be some good reason for it.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: LuaSurface::find_entity returns no-collision entity

Post by Mooncat »

Sorry to bother, but is someone investigating the inconsistency mentioned by Posila? Just asking. :mrgreen:
Rseding91
Factorio Staff
Factorio Staff
Posts: 14312
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaSurface::find_entity returns no-collision entity

Post by Rseding91 »

Not currently.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: LuaSurface::find_entity returns no-collision entity

Post by Mooncat »

OK. Will keep my eye on any update about this. :D
Post Reply

Return to “Modding interface requests”