Lua Bits n Pieces...
I thought this would be an ideal place to store snippets of code that do interesting things for other people to check out and maybe learn new ideas...
Here's the code for a Node Inspector tool, punch any node to find the item code for it...
Here's the code for a Node Inspector tool, punch any node to find the item code for it...
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
--= Node Inspector (click on node to give details)
local huds={}
minetest.register_tool("mymod:node_inspector", {
description = "Node Inspector",
inventory_image = "default_tool_steelaxe.png",
liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing)
local pll = user:get_player_name()
local pos = pointed_thing.under
if pointed_thing.type ~= "node" then
desc = "..."
else
local node = minetest.get_node(pos)
desc = node.name
end
-- Clear HUD element
user:hud_remove(huds[pll])
-- Display new HUD text
local off = {x=0, y=-80}
huds[pll] = user:hud_add({
hud_elem_type = "text",
position = {x=0.5, y=1},
offset = off,
alignment = {x=0, y=0},
number = 0xFFFFFF ,
text = desc,
})
end,
})