Have a can_place_entity on LuaEntity itself

User avatar
hgschmie
Inserter
Inserter
Posts: 33
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Have a can_place_entity on LuaEntity itself

Post by hgschmie »

One of the really popular mods is Picker Dollies (and its spirtual successor Even Pickier Dollies for 2.0) which allows a player to move entities around instead of destroying and recreating.

The mod works by teleporting an entity into a "safe space", then checking a target location whether the entity can "fit" in there and then teleport it back. If it would just teleport the entity into the new location, then the player could happily move entities into water, over other entities etc. teleport does no checks. :-)

The right way is to check the target position first with LuaSurface::can_place_entity. But if the mod does not move the entity away first, then, for any entity wider than a single tile, the check would always return false because the new position overlaps with the old position by a tile and therefore an entity can not be placed in the new position because it collides with itself.

The teleporting around causes a slew of other problem e.g. if teleporting around a full storage tank in 2.0 and the "safe position" by accident connects the tank to a pipe or another tank, the fluid will "leak out".

An amazing addition to the API (which would solve all these problems) would be a

Code: Select all

LuaEntity::can_place_entity { position=, direction=, force= , build_check_type=, forced= } 
that works exactly like LuaSurface::can_place_entity with name/inner_name filled out and ignores the entity itself when doing placement checking.

This would allow doing the placement check with the entity itself "in place" and there would be no need for teleporting around.
curiosity
Filter Inserter
Filter Inserter
Posts: 469
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Have a can_place_entity on LuaEntity itself

Post by curiosity »

Seems to me like you'd want LuaSurface::can_place_entity{entity=} instead. Who is to say you aren't supposed to move entities between surfaces?
User avatar
hgschmie
Inserter
Inserter
Posts: 33
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: Have a can_place_entity on LuaEntity itself

Post by hgschmie »

I think the exact details of the API will be left to the game developers. Adding an "entity=" attribute that would override/preset name, direction, position etc. would work as well.

The docs for teleport state that "Only players, cars, and spidertrons can be teleported cross-surface." and teleport creates an error if you try.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14244
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Have a can_place_entity on LuaEntity itself

Post by Rseding91 »

What about an option on teleport that changes which collision check it uses for validating the teleport? Right now it does a script check which is “won’t crash the game” but it could easily be overridden to be any of the build check types . That way, the teleport would simply fail if it collided with the destination.
If you want to get ahold of me I'm almost always on Discord.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14244
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Have a can_place_entity on LuaEntity itself

Post by Rseding91 »

I've added build_check_type to LuaControl::teleport for the next release. It will allow you to simply call teleport(...) and it will fail the teleport if the build check type fails at the destination. It automatically ignores itself for collision checks so moving half a tile to a direction won't fail the teleport like can_place_entity does for the existing entity.
If you want to get ahold of me I'm almost always on Discord.
User avatar
hgschmie
Inserter
Inserter
Posts: 33
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: Have a can_place_entity on LuaEntity itself

Post by hgschmie »

Rseding91 wrote: Tue Nov 19, 2024 11:36 pm I've added build_check_type to LuaControl::teleport for the next release. It will allow you to simply call teleport(...) and it will fail the teleport if the build check type fails at the destination. It automatically ignores itself for collision checks so moving half a tile to a direction won't fail the teleport like can_place_entity does for the existing entity.
<happy dance!> This sounds great! Looking forward to the next release to try that out. It sounds like exactly what I am looking for.
Post Reply

Return to “Implemented mod requests”