Skip to content

Commit

Permalink
Retrieve light value from node adjacent to the face clicked on, rathe…
Browse files Browse the repository at this point in the history
…r than node above.

Means lighting values work when inspecting nodes in a wall or overhang, or air under a ceiling/overhang, etc.
Also means the same node may report different light values depending on which face you click - which is accurate, but perhaps not made clear by the inspection dialog.
minetest.get_node_light() was never returning nil which meant a light level was always displayed by the inspector even in cases where the node at y+1 contained no light value.
  • Loading branch information
Treer authored and sofar committed Jan 8, 2020
1 parent 729feb1 commit 37a96c9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ local function describe_param(paramtype, value)
return ""
end

local function inspect_pos(pos)
local function inspect_pos(pos, light_pos)
local node = minetest.get_node(pos)
local nodedef = minetest.registered_items[node.name]

Expand All @@ -126,10 +126,10 @@ local function inspect_pos(pos)
desc = desc .. indent(1, "param2 = " .. pad_figure(node.param2, 3) .. indent_string ..
describe_param(nodedef.paramtype2, node.param2)) .. "\n"

local posAbove = {x = pos.x, y = pos.y + 1, z = pos.z}
local light_current = minetest.get_node_light(posAbove, nil)
local light_noon = minetest.get_node_light(posAbove, 0.5)
local light_night = minetest.get_node_light(posAbove, 0)
if light_pos == nil then light_pos = {x = pos.x, y = pos.y + 1, z = pos.z} end
local light_current = minetest.get_node_light(light_pos, nil)
local light_noon = minetest.get_node_light(light_pos, 0.5)
local light_night = minetest.get_node_light(light_pos, 0)
if light_current ~= nil then
desc = desc .. indent(1, "light = " .. pad_figure(light_current, 2)) ..
" " .. light_noon .. " at noon, " .. light_night .." at night\n"
Expand Down Expand Up @@ -220,7 +220,7 @@ minetest.register_tool("inspector:inspector", {
if pointed_thing.type ~= "node" then
desc = "..."
else
desc = inspect_pos(pos)
desc = inspect_pos(pos, pointed_thing.above)
end
elseif pointed_thing.type == "object" then
local ref = pointed_thing.ref
Expand Down Expand Up @@ -251,7 +251,7 @@ minetest.register_tool("inspector:inspector", {
if pointed_thing.type ~= "node" then
desc = "..."
else
desc = inspect_pos(pos)
desc = inspect_pos(pos, pos)
end
elseif pointed_thing.type == "object" then
local ref = pointed_thing.ref
Expand Down

0 comments on commit 37a96c9

Please sign in to comment.