Page 1 of 1

LuaSurface::find_entity returns no-collision entity

Posted: Sun Mar 05, 2017 9:41 am
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.

Re: LuaSurface::find_entity returns no-collision entity

Posted: Sun Mar 05, 2017 7:36 pm
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.

Re: LuaSurface::find_entity returns no-collision entity

Posted: Mon Mar 06, 2017 12:42 pm
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:

Re: LuaSurface::find_entity returns no-collision entity

Posted: Mon Mar 06, 2017 1:05 pm
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.

Re: LuaSurface::find_entity returns no-collision entity

Posted: Fri Mar 24, 2017 6:21 pm
by Mooncat
Sorry to bother, but is someone investigating the inconsistency mentioned by Posila? Just asking. :mrgreen:

Re: LuaSurface::find_entity returns no-collision entity

Posted: Fri Mar 24, 2017 6:47 pm
by Rseding91
Not currently.

Re: LuaSurface::find_entity returns no-collision entity

Posted: Fri Mar 24, 2017 7:12 pm
by Mooncat
OK. Will keep my eye on any update about this. :D