- Placing an entity that is blocked by collision does not fire the on_pre_build event
- Placing an entity that is out of build range does call the event.
Currently I am working around this by re-implementing the build range check myself:
Code: Select all
local function canReach(player, position, entity)
-- building reach is based on the entity's north-facing collision box
local box = entity.collision_box
local dx = math.max(box.left_top.x + position.x - player.position.x, 0, player.position.x - (box.right_bottom.x + position.x))
local dy = math.max(box.left_top.y + position.y - player.position.y, 0, player.position.y - (box.right_bottom.y + position.y))
return math.sqrt(dx*dx + dy*dy) <= player.build_distance
end
So I have a workaround that works (although I haven't checked if that should be a "<" or a "<=" - I don't expect it to matter, it's literally an edge case!) but it would be nice if either the event didn't fire at all (potentially breaks existing mods?) or had the built-in range check exposed in "event.can_reach" (backwards-compatible).