Aaron Suen 7da2ed13df Fix crosshairs/looktips in the void
It seems like Minetest actually generates terrain
beyond the map limit boundaries and raycast
and get_node can retrieve them server-side, even
though they aren't rendered client-side and air is
still filled with ignores.  This causes players to see
"stone" with looktips looking thru the bottom of
the world.  Fix it with an explicit check for world
bounds.
2021-11-27 09:24:28 -05:00

41 lines
1.1 KiB
Lua

-- LUALOCALS < ---------------------------------------------------------
local nodecore
= nodecore
-- LUALOCALS > ---------------------------------------------------------
local function crosshair(player, fade)
nodecore.hud_set(player, {
label = "crosshair",
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
text = "nc_player_hud_crosshair.png^[opacity:"
.. (fade and 32 or 192),
direction = 0,
alignment = {x = 0, y = 0},
scale = {x = 1, y = 1},
offset = {x = 0, y = 0},
z_index = -275,
quick = true
})
end
nodecore.register_playerstep({
label = "crosshair",
priority = -101,
action = function(player, data)
local pt = data.raycast()
if pt then
if pt.type == "node" and nodecore.within_map_limits(pt.under) then
local llu = nodecore.get_node_light(pt.under) or 0
local lla = nodecore.get_node_light(pt.above) or 0
local ll = (llu > lla) and llu or lla
return crosshair(player, ll <= 0)
elseif pt.type == "object" then
local ll = nodecore.get_node_light(pt.ref:get_pos()) or 0
return crosshair(player, ll <= 0)
end
end
return crosshair(player, true)
end
})