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= }
This would allow doing the placement check with the entity itself "in place" and there would be no need for teleporting around.