forked from Mineclonia/Mineclonia
Item HUD: Show metadata description, if present
This commit is contained in:
parent
22f3451b17
commit
1becc44732
|
@ -26,7 +26,8 @@ end)
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local wstack = player:get_wielded_item():get_name()
|
local wstack = player:get_wielded_item()
|
||||||
|
local wname = wstack:get_name()
|
||||||
|
|
||||||
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
||||||
dtimes[player_name] = dtimes[player_name] + dtime
|
dtimes[player_name] = dtimes[player_name] + dtime
|
||||||
|
@ -35,15 +36,23 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if wstack ~= wield[player_name] then
|
if wname ~= wield[player_name] then
|
||||||
wield[player_name] = wstack
|
wield[player_name] = wname
|
||||||
dtimes[player_name] = 0
|
dtimes[player_name] = 0
|
||||||
if huds[player_name] then
|
if huds[player_name] then
|
||||||
local def = minetest.registered_items[wstack]
|
local def = minetest.registered_items[wname]
|
||||||
local desc = def and def.description
|
local meta = wstack:get_meta()
|
||||||
if not desc or desc == "" then
|
|
||||||
-- Use itemstring as fallback
|
--[[ Get description. Order of preference:
|
||||||
desc = wstack
|
* description from metadata
|
||||||
|
* description from item definition
|
||||||
|
* itemstring ]]
|
||||||
|
local desc = meta:get_string("description")
|
||||||
|
if (desc == nil or desc == "") and def then
|
||||||
|
desc = def.description
|
||||||
|
end
|
||||||
|
if desc == nil or desc == "" then
|
||||||
|
desc = wname
|
||||||
end
|
end
|
||||||
-- Cut off item description after first newline
|
-- Cut off item description after first newline
|
||||||
local firstnewline = string.find(desc, "\n")
|
local firstnewline = string.find(desc, "\n")
|
||||||
|
|
Loading…
Reference in New Issue