LuaSurface::can_place_entity() has a "forced" parameter with the following description: "If true, entities that can be marked for deconstruction are ignored. Only used if build_check_type is either manual_ghost, script_ghost or blueprint_ghost."
EDIT: It appears that the "forced" parameter DOES change the behavior when the blocking entity is already marked for deconstruction. Therefore, the documentation would appear to be accurate if it stated "If true, entities that are marked for deconstruction are ignored." Unfortunately this does not help my use case.
This would be great for me, because I am trying to update Auto Deconstruct with logic to identify which pipe prototypes can be built in a location after the mining drill is removed. I need a simple way to determine if the tiles under the drill will collide with a particular pipe prototype, while the drill is still in place. I thought that can_place_entity() would be usable for this task.
However, as you can see below, no combination of options will give "false" for building over water and "true" for building over a deconstructible entity. Am I mistaken how this API function is supposed to work? Are the docs incomplete? Should I revert to directly reading the tile collision masks?
All tests can be replicated in Vanilla 2.0.75 with the attached save file.
Simple building fails on water tiles, succeeds on empty concrete, and fails on a colliding entity (respectively), as expected:
Code: Select all
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-21.5,-38.5}})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-14.5,-38.5}})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-7.5,-38.5}})
falseCode: Select all
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-21.5,-38.5}, forced=false, build_check_type=defines.build_check_type.blueprint_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-14.5,-38.5}, forced=false, build_check_type=defines.build_check_type.blueprint_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-7.5,-38.5}, forced=false, build_check_type=defines.build_check_type.blueprint_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-21.5,-38.5}, forced=true, build_check_type=defines.build_check_type.blueprint_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-14.5,-38.5}, forced=true, build_check_type=defines.build_check_type.blueprint_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-7.5,-38.5}, forced=true, build_check_type=defines.build_check_type.blueprint_ghost})
falseCode: Select all
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-21.5,-38.5}, forced=false, build_check_type=defines.build_check_type.script_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-14.5,-38.5}, forced=false, build_check_type=defines.build_check_type.script_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-7.5,-38.5}, forced=false, build_check_type=defines.build_check_type.script_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-21.5,-38.5}, forced=true, build_check_type=defines.build_check_type.script_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-14.5,-38.5}, forced=true, build_check_type=defines.build_check_type.script_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-7.5,-38.5}, forced=true, build_check_type=defines.build_check_type.script_ghost})
trueCode: Select all
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-21.5,-38.5}, forced=false, build_check_type=defines.build_check_type.manual_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-14.5,-38.5}, forced=false, build_check_type=defines.build_check_type.manual_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-7.5,-38.5}, forced=false, build_check_type=defines.build_check_type.manual_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-21.5,-38.5}, forced=true, build_check_type=defines.build_check_type.manual_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-14.5,-38.5}, forced=true, build_check_type=defines.build_check_type.manual_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="entity-ghost", inner_name="pipe", position={-7.5,-38.5}, forced=true, build_check_type=defines.build_check_type.manual_ghost})
falseCode: Select all
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-21.5,-38.5}, forced=false, build_check_type=defines.build_check_type.blueprint_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-14.5,-38.5}, forced=false, build_check_type=defines.build_check_type.blueprint_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-7.5,-38.5}, forced=false, build_check_type=defines.build_check_type.blueprint_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-21.5,-38.5}, forced=true, build_check_type=defines.build_check_type.blueprint_ghost})
false
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-14.5,-38.5}, forced=true, build_check_type=defines.build_check_type.blueprint_ghost})
true
/c game.print(game.surfaces["nauvis"].can_place_entity{name="pipe", position={-7.5,-38.5}, forced=true, build_check_type=defines.build_check_type.blueprint_ghost})
false