1
0
Fork 0
MineClone2/mods/HUD/mcl_info/init.lua

95 lines
3.0 KiB
Lua
Raw Normal View History

2022-03-01 00:34:44 +01:00
local refresh_interval = .63
local huds = {}
2022-03-01 23:47:38 +01:00
local default_debug = 3
2022-03-01 00:34:44 +01:00
local after = minetest.after
local get_connected_players = minetest.get_connected_players
local get_biome_name = minetest.get_biome_name
local get_biome_data = minetest.get_biome_data
local format = string.format
local min1, min2, min3 = mcl_vars.mg_overworld_min, mcl_vars.mg_end_min, mcl_vars.mg_nether_min
local max1, max2, max3 = mcl_vars.mg_overworld_max, mcl_vars.mg_end_max, mcl_vars.mg_nether_max + 128
2022-03-01 00:34:44 +01:00
2022-03-01 23:47:38 +01:00
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local S = minetest.get_translator(modname)
local storage = minetest.get_mod_storage()
local player_dbg = minetest.deserialize(storage:get_string("player_dbg") or "return {}") or {}
local function get_text(pos, bits)
local bits = bits
if bits == 0 then return "" end
2022-03-01 00:34:44 +01:00
local biome_data = get_biome_data(pos)
local biome_name = biome_data and get_biome_name(biome_data.biome) or "No biome"
local biome = format("%s (%s), Humidity: %.1f, Temperature: %.1f",biome_name, biome_data.biome, biome_data.humidity, biome_data.heat)
local coord = format("x:%.1f y:%.1f z:%.1f", pos.x, pos.y, pos.z)
--local pointed =
return biome.."\n"..coord
2022-03-01 00:34:44 +01:00
end
local function info()
for _, player in pairs(get_connected_players()) do
local name = player:get_player_name()
local pos = player:get_pos()
2022-03-01 23:47:38 +01:00
local text = get_text(pos, player_dbg[name] or default_debug)
2022-03-01 00:34:44 +01:00
local hud = huds[name]
if not hud then
local def = {
hud_elem_type = "text",
alignment = {x = 1, y = -1},
scale = {x = 100, y = 100},
position = {x = 0.0073, y = 0.889},
2022-03-01 00:34:44 +01:00
text = text,
style = 5,
["number"] = 0xcccac0,
z_index = 0,
}
local def_bg = table.copy(def)
def_bg.offset = {x = 2, y = 1}
def_bg["number"] = 0
def_bg.z_index = -1
huds[name] = {
player:hud_add(def),
player:hud_add(def_bg),
text,
}
elseif text ~= hud[3] then
hud[3] = text
player:hud_change(huds[name][1], "text", text)
player:hud_change(huds[name][2], "text", text)
end
end
after(refresh_interval, info)
end
minetest.register_on_authplayer(function(name, ip, is_success)
if is_success then
huds[name] = nil
end
end)
2022-03-01 23:47:38 +01:00
minetest.register_chatcommand("debug",{
description = S("Set debug bit mask: 0 = disable, 1 = biome name, 2 = coordinates, 3 = all"),
func = function(name, params)
local dbg = math.floor(tonumber(params) or default_debug)
if dbg < 0 or dbg > 4 then
minetest.chat_send_player(name, S("Error! Possible values are integer numbers from @1 to @2", 0, 4))
2022-03-01 23:47:38 +01:00
return
end
if dbg == default_debug then
2022-03-01 23:47:38 +01:00
player_dbg[name] = nil
else
player_dbg[name] = dbg
end
minetest.chat_send_player(name, S("Debug bit mask set to @1", dbg))
end
})
--why is this saved on shutdown but not on playerleave / changes ?
2022-03-01 23:47:38 +01:00
minetest.register_on_shutdown(function()
storage:set_string("player_dbg", minetest.serialize(player_dbg))
end)
2022-03-01 00:34:44 +01:00
info()