forked from MineClone5/MineClone5
feat: Use probes to determine whether outdoors or not.
This commit is contained in:
parent
ee2418f91c
commit
609c60cc73
|
@ -100,7 +100,35 @@ end
|
|||
function mcl_weather.is_outdoor(pos)
|
||||
local cpos = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local dim = mcl_worlds.pos_to_dimension(cpos)
|
||||
if minetest.get_node_light(cpos, 0.5) == 15 and dim == "overworld" then
|
||||
|
||||
local probe_is_outdoors = function ()
|
||||
-- Place probes in a square around the player just above their head.
|
||||
local probe_distance = {
|
||||
x = 7,
|
||||
y = 1,
|
||||
z = 7
|
||||
}
|
||||
|
||||
local probe_offsets = { -1, 0, 1 }
|
||||
for _, x in ipairs(probe_offsets) do
|
||||
for _, z in ipairs(probe_offsets) do
|
||||
local probe_pos = {
|
||||
x = cpos.x + x * probe_distance.x,
|
||||
y = cpos.y + probe_distance.y,
|
||||
z = cpos.z + z * probe_distance.z
|
||||
}
|
||||
|
||||
local light = minetest.get_node_light(probe_pos, 0.5)
|
||||
if light ~= nil and light == 15 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- If at least one probe is "outdoors", the player is considered outdoors.
|
||||
if probe_is_outdoors() and dim == "overworld" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
|
|
Loading…
Reference in New Issue