V1.4: HUD Graphics

We now display XRAY or OREHUD when either feature is enabled.

  We also fix an issue where in singleplayer mode xray nodes don't get
cleaned up. (Like they do on a server)  < The ABM is still needed on the
server in cases where the server crashed.
This commit is contained in:
david 2021-10-10 20:13:40 -04:00
parent d0d2a0eb3a
commit 4d73085af4
3 changed files with 61 additions and 27 deletions

@ -171,7 +171,7 @@ minetest.register_globalstep(function(dtime)
end
-- I need to clean up the player's ore waypoints added by the latter code
orehud.clear_pos(p:get_player_name())
if orehud.p_stats[p:get_player_name()] or false then
if orehud.p_stats[p:get_player_name()] then
-- Only run if that player wants to run
orehud.check_player(p)
end
@ -181,7 +181,7 @@ minetest.register_globalstep(function(dtime)
end)
minetest.register_on_joinplayer(function(player, laston)
orehud.p_stats[player:get_player_name()] = false
orehud.p_stats[player:get_player_name()] = nil
end)
minetest.register_on_leaveplayer(function(player, timeout)
@ -195,6 +195,7 @@ minetest.register_on_leaveplayer(function(player, timeout)
indx = indx + 1
end
if found then
player:hud_remove(orehud.p_stats(orehud.p_stats[player:get_player_name()]))
table.remove(orehud.p_stats, indx)
end
end)
@ -212,11 +213,24 @@ minetest.register_chatcommand("orehud", {
},
func = function(name, param)
if orehud.p_stats[name] then
orehud.p_stats[name] = false
minetest.chat_send_player(name, "Orehud: OFF")
local p = minetest.get_player_by_name(name)
if p ~= nil then
p:hud_remove(orehud.p_stats[name])
orehud.p_stats[name] = nil
end
else
orehud.p_stats[name] = true
minetest.chat_send_player(name, "Orehud: ON")
local p = minetest.get_player_by_name(name)
if p ~= nil then
orehud.p_stats[name] = p:hud_add({
hud_elem_type = "text",
position = {x = 0.9, y = 0.87},
offset = {x = 0.0, y = 0.0},
text = "OREHUD",
number = 0x00e100, -- 0, 225, 0 (RGB)
alignment = {x = 0.0, y = 0.0},
scale = {x = 100.0, y = 100.0}
})
end
end
end,
})

@ -4,7 +4,7 @@
-- MTG
minetest.register_abm({
nodenames = {"xray:mtg_stone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "default:stone"})
@ -12,7 +12,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mtg_dstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "default:desert_stone"})
@ -20,7 +20,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mtg_sstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "default:sandstone"})
@ -28,7 +28,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mtg_dsstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "default:desert_sandstone"})
@ -36,7 +36,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mtg_ssstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "default:silver_sandstone"})
@ -54,7 +54,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_granite"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_core:granite"})
@ -62,7 +62,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_andesite"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_core:andesite"})
@ -70,7 +70,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_diorite"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_core:diorite"})
@ -78,7 +78,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_sstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_core:sandstone"})
@ -86,7 +86,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_rsstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_core:redsandstone"})
@ -96,7 +96,7 @@ minetest.register_abm({
-- MCL (5 only)
minetest.register_abm({
nodenames = {"xray:mcl_bstone"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_blackstone:blackstone"})
@ -104,7 +104,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_basalt"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_blackstone:basalt"})
@ -112,7 +112,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_netherrack"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_nether:netherrack"})
@ -120,7 +120,7 @@ minetest.register_abm({
})
minetest.register_abm({
nodenames = {"xray:mcl_deepslate"},
interval = 0, -- Run every X seconds
interval = 1, -- Run every X seconds
action = function(pos, node, active_object_count,
active_object_count_wider)
minetest.set_node(pos, {name = "mcl_deepslate:deepslate"})

@ -153,7 +153,7 @@ minetest.register_globalstep(function(dtime)
end)
minetest.register_on_joinplayer(function(player, laston)
xray.p_stats[player:get_player_name()] = false
xray.p_stats[player:get_player_name()] = nil
end)
minetest.register_on_leaveplayer(function(player, timeout)
@ -168,13 +168,20 @@ minetest.register_on_leaveplayer(function(player, timeout)
end
if found then
-- Attempt to cleanup that player's invisible nodes before they log off
xray.p_stats[player:get_player_name()] = false
minetest.log("action", "Cleaning up "..player:get_player_name().." as they wish to leave.")
player:hud_remove(xray.p_stats[player:get_player_name()])
xray.clear_pos(player:get_player_name())
xray.p_stats[player:get_player_name()] = nil
table.remove(xray.p_stats, indx)
end
end)
-- Attempt to cleanup xrays in a singleplayer world
minetest.register_on_shutdown(function ()
for _, player in ipairs(minetest.get_connected_players()) do
xray.clear_pos(player:get_player_name())
end
end)
-- A priv for players so they can't abuse this power
minetest.register_privilege("xray", {
description = "Oretracker Xray Priv",
@ -188,11 +195,24 @@ minetest.register_chatcommand("xray", {
},
func = function(name, param)
if xray.p_stats[name] then
xray.p_stats[name] = false
minetest.chat_send_player(name, "Xray: OFF")
local p = minetest.get_player_by_name(name)
if p ~= nil then
p:hud_remove(xray.p_stats[name])
xray.p_stats[name] = nil
end
else
xray.p_stats[name] = true
minetest.chat_send_player(name, "Xray: ON")
local p = minetest.get_player_by_name(name)
if p ~= nil then
xray.p_stats[name] = p:hud_add({
hud_elem_type = "text",
position = {x = 0.9, y = 0.9},
offset = {x = 0.0, y = 0.0},
text = " XRAY ",
number = 0x00e100, -- 0, 225, 0 (RGB)
alignment = {x = 0.0, y = 0.0},
scale = {x = 100.0, y = 100.0}
})
end
end
end,
})