feat: Use probes to determine whether outdoors or not.

This commit is contained in:
Adam Macumber 2022-09-18 20:16:10 -04:00
parent ee2418f91c
commit 609c60cc73
1 changed files with 29 additions and 1 deletions

View File

@ -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