Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ minetest.register_globalstep(function(dtime) -- This will run every tick, so aro
if lookat then
if player_to_cnode[player] ~= lookat.name then -- Only do anything if they are looking at a different type of block than before
player_to_animtime[player] = nil -- Reset the animation
local nodename, mod = describe_node(lookat) -- Get the details of the block in a nice looking way
local locale = core.get_player_information(player:get_player_name())["lang_code"]
if locale == nil then
locale = 'en'
end
local nodename, mod = describe_node(lookat, locale) -- Get the details of the block in a nice looking way
player:hud_change(player_to_id_text[player], "text", nodename) -- If they are looking at something, display that
player:hud_change(player_to_id_mtext[player], "text", mod)
local node_object = minetest.registered_nodes[lookat.name] -- Get information about the block
Expand Down Expand Up @@ -109,13 +113,13 @@ function get_looking_node(player) -- Return the node the given player is looking
return lookat
end

function describe_node(node) -- Return a string that describes the node and mod
function describe_node(node, locale) -- Return a string that describes the node and mod
local mod, nodename = minetest.registered_nodes[node.name].mod_origin, minetest.registered_nodes[node.name].description -- Get basic (not pretty) info
if nodename == "" then -- If it doesn't have a proper name, just use the technical one
nodename = node.name
end
mod = remove_unneeded(capitalize(mod)) -- Make it look good
nodename = remove_unneeded(capitalize(nodename))
nodename = remove_unneeded(capitalize(core.get_translated_string(locale, nodename)))
return nodename, mod
end

Expand All @@ -124,7 +128,7 @@ function remove_unneeded(str) -- Remove characters like '-' and '_' to make the
end

function capitalize(str) -- Capitalize every word in a string, looks good for node names
return string.gsub(" "..str, "%W%l", string.upper):sub(2)
return string.gsub(" "..str, " %W%l", string.upper):sub(2)
end

function handle_tiles(node) -- Return an image of the tile
Expand Down