Add seethru node list support to mcl_mobs.check_line_of_sight

This commit is contained in:
teknomunk 2025-01-08 06:13:53 -06:00 committed by the-real-herowl
parent 299c209b60
commit 374db5ad24

View file

@ -1,4 +1,11 @@
function mcl_mobs.check_line_of_sight(origin, target)
local default_seethru = {air = true}
---@param origin vector.Vector
---@param target vector.Vector
---@param seethru? {[string]: boolean} Set (look-up table) of nodes to treat as seethrough. Defaults to {air: true}
---@return boolean True if line-of-sight is blocked, false otherwise
function mcl_mobs.check_line_of_sight(origin, target, seethru)
seethru = seethru or default_seethru
local raycast = core.raycast(origin, target, false, true)
local los_blocked = false
@ -7,7 +14,7 @@ function mcl_mobs.check_line_of_sight(origin, target)
--TODO: type object could block vision, for example minecarts
local node = core.get_node(core.get_pointed_thing_position(hitpoint))
if node.name ~= "air" then
if not seethru[node.name] then
local nodef = core.registered_nodes[node.name]
if nodef and nodef.walkable then
los_blocked = true
@ -18,4 +25,3 @@ function mcl_mobs.check_line_of_sight(origin, target)
end
return not los_blocked
end