From b70ba39c17ac91cfd1e7bcc1d065cc03e7996f99 Mon Sep 17 00:00:00 2001 From: Jacob Gustafson Date: Fri, 19 May 2017 17:05:11 -0400 Subject: [PATCH 01/20] created batch for testing purposes only --- update local.bat | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 update local.bat diff --git a/update local.bat b/update local.bat new file mode 100644 index 0000000..193c56b --- /dev/null +++ b/update local.bat @@ -0,0 +1,4 @@ +copy /y *.lua C:\games\Minetest\games\ENLIVEN\mods\metatools\ +copy /y *.md C:\games\Minetest\games\ENLIVEN\mods\metatools\ +copy /y textures\*.png C:\games\Minetest\games\ENLIVEN\mods\metatools\textures\ +if NOT ["%errorlevel%"]==["0"] pause \ No newline at end of file From ad4dffe5943e3366ce693103d307473f4050172c Mon Sep 17 00:00:00 2001 From: Jacob Gustafson Date: Fri, 19 May 2017 17:07:45 -0400 Subject: [PATCH 02/20] added destination detection --- update local.bat | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/update local.bat b/update local.bat index 193c56b..92b946e 100644 --- a/update local.bat +++ b/update local.bat @@ -1,4 +1,6 @@ -copy /y *.lua C:\games\Minetest\games\ENLIVEN\mods\metatools\ -copy /y *.md C:\games\Minetest\games\ENLIVEN\mods\metatools\ -copy /y textures\*.png C:\games\Minetest\games\ENLIVEN\mods\metatools\textures\ +SET MT_PROGRAM_DIR=C:\games\Minetest +IF EXIST "C:\Games\ENLIVEN" SET MT_PROGRAM_DIR=C:\Games\ENLIVEN +copy /y *.lua "%MT_PROGRAM_DIR%\games\ENLIVEN\mods\metatools\" +copy /y *.md "%MT_PROGRAM_DIR%\games\ENLIVEN\mods\metatools\" +copy /y textures\*.png "%MT_PROGRAM_DIR%\games\ENLIVEN\mods\metatools\textures\" if NOT ["%errorlevel%"]==["0"] pause \ No newline at end of file From 14021606d5bf6c732a21dc3535d45cb7d35bcb05 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 5 Jun 2019 14:52:46 -0400 Subject: [PATCH 03/20] add howlight command --- chatcommands.lua | 17 +++++++++++++++++ init.lua | 15 ++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 chatcommands.lua diff --git a/chatcommands.lua b/chatcommands.lua new file mode 100644 index 0000000..27785ff --- /dev/null +++ b/chatcommands.lua @@ -0,0 +1,17 @@ +minetest.register_chatcommand("howlight", { + description = "Show the light level of the ground below you", + func = function(name) + local player = minetest.get_player_by_name(name) + if player then + local player_pos = vector.round(player:get_pos()) + -- local pos = vector.new(player_pos.x, player_pos.y - 1 , player_pos.z) + local pos = player_pos + -- underground, light is always zero, so z-1 doesn't work. + local pos_string = minetest.pos_to_string(pos) + minetest.chat_send_player(name, "Light level at " .. pos_string .. " is " .. minetest.get_node_light(pos) .. ".") + return true + else + return false, "You are not connected to minetestserver." + end + end +}) diff --git a/init.lua b/init.lua index 8838e49..88aa3d6 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,7 @@ local nodelock = {} local modpath = minetest.get_modpath("metatools") dofile(modpath .. "/assertions.lua") +dofile(modpath .. "/chatcommands.lua") minetest.register_craftitem("metatools:stick",{ description = "Meta stick", @@ -162,7 +163,7 @@ function meta_exec(struct) for category, req in pairs(struct.required) do if category == "position" and not assert_pos(req) then return false, ("- %s - Failure : Invalid position : %s"):format(struct.scope, dump_normalize(req)) - + elseif category == "contextid" and not assert_contextid(req) then return false, ("- %s - Failutre : Invalid contextid : %s"):format(struct.scope, dump_normalize(req)) @@ -215,7 +216,7 @@ function meta_exec(struct) if not assert_contextid(req.contextid) then return false, ("- %s - Failure : Invalid context id : %s"):format(struct.scope, dump_normalize(req.contextid)) end - + if not metatools.contexts[req.contextid].mode == req.mode then return false, ("- %s - Failure : Invalid mode, %s is required"):format(struct.scope, dump_normalize(req.mode)) end @@ -350,7 +351,7 @@ function metatools.purge(contextid) local inv = meta:get_inventory() inv:set_lists({}) return true, "inventory purged" - + else meta:from_table(nil) return true, "fields purged" @@ -543,7 +544,7 @@ minetest.register_chatcommand("meta", { format(summ.id, summ.mode, minetest.pos_to_string(summ.pos), summ.owner) end return true, retstr .. ("- meta::contexts - %d contexts"):format(#ctxs) - + -- meta open (x,y,z) [fields|inventory] elseif params[1] == "open" then @@ -702,7 +703,7 @@ minetest.register_chatcommand("meta", { } } }) - + -- meta purge elseif params[1] == "purge" then return meta_exec({ @@ -782,7 +783,7 @@ minetest.register_chatcommand("meta", { } } }) - + else return false, "- meta::list - Unknown subcommand '" .. params[2] .. "', please consult '/meta help' for help" end @@ -822,7 +823,7 @@ minetest.register_chatcommand("meta", { } } }) - + -- meta itemstack add elseif params[2] == "add" then return meta_exec({ From 2ece081cf89153bdaa485e2d25d83dcc6bd5cd9d Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Thu, 6 Jun 2019 16:27:29 -0400 Subject: [PATCH 04/20] stick shows light level (nearby if clicked opaque) --- init.lua | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 88aa3d6..c11182b 100644 --- a/init.lua +++ b/init.lua @@ -12,6 +12,16 @@ -- ]]-- +local function get_nodedef_field(nodename, fieldname) + if not minetest.registered_nodes[nodename] then + -- print("metatools.get_nodedef_field: no registered node named " .. nodename) + return nil + end + -- print("metatools.get_nodedef_field: checking " .. nodename .. " for " .. fieldname .. " in " .. dump(minetest.registered_nodes[nodename])) + -- print("* result:" .. dump(minetest.registered_nodes[nodename][fieldname])) + return minetest.registered_nodes[nodename][fieldname] +end + metatools = {} -- Public namespace metatools.contexts = {} metatools.playerlocks = {} -- Selection locks of the players @@ -27,6 +37,7 @@ minetest.register_craftitem("metatools:stick",{ inventory_image = "metatools_stick.png", on_use = function(itemstack, user, pointed_thing) local username = user:get_player_name() + local userpos = user:get_pos() local nodepos = pointed_thing.under if not nodepos or not minetest.get_node(nodepos) then return end local nodename = minetest.get_node(nodepos).name @@ -34,9 +45,161 @@ minetest.register_craftitem("metatools:stick",{ local meta = minetest.get_meta(nodepos) local metalist = meta:to_table() - minetest.chat_send_player(username, "- meta::stick - Node located at "..minetest.pos_to_string(nodepos)) - minetest.chat_send_player(username, "- meta::stick - Metadata fields dump : " .. dump(meta:to_table()["fields"]):gsub('\n', "")) - minetest.log("action","[metatools] Player "..username.." saw metadatas of node at "..minetest.pos_to_string(nodepos)) + minetest.chat_send_player( + username, + "[metatools::stick] You pointed at the '" .. nodename .. "':" + ) + minetest.chat_send_player( + username, + "[metatools::stick] pos:" + .. minetest.pos_to_string(nodepos) + ) + -- minetest.chat_send_player( + -- username, + -- "[metatools::stick] drawtype:" + -- .. get_nodedef_field(nodename, "drawtype") + -- ) + -- minetest.chat_send_player( + -- username, + -- "[metatools::stick] sunlight_propagates:" + -- .. (get_nodedef_field(nodename, "sunlight_propagates") and 'true' or 'false') + -- ) + + + minetest.chat_send_player( + username, + "[metatools::stick] metadata: " + .. dump(meta:to_table()["fields"]):gsub('\n', "") + ) + local airname = minetest.get_name_from_content_id(minetest.CONTENT_AIR) + -- local litnode = nil + local litpos = nil + local litdist = nil + local litwhy = "unknown" + local litmsg = "" + local litid = nil + local litwhat = nil + local litindent = "" + local foundPointed = false + local offsets = { + [0] = {["x"] = 0, ["y"] = 0, ["z"] = 0}, + [1] = {["x"] = 0, ["y"] = 1, ["z"] = 0}, + [2] = {["x"] = 0, ["y"] = -1, ["z"] = 0}, + [3] = {["x"] = 1, ["y"] = 0, ["z"] = 0}, + [4] = {["x"] = -1, ["y"] = 0, ["z"] = 0}, + [5] = {["x"] = 0, ["y"] = 0, ["z"] = 1}, + [6] = {["x"] = 0, ["y"] = 0, ["z"] = -1}, + } + -- local touching = {} + for key, value in pairs(offsets) do + local trydist = nil + local trywhy = nil + local trypos = vector.new( + nodepos.x + value.x, + nodepos.y + value.y, + nodepos.z + value.z + ) + -- touching[key] = trypos + local trynode = minetest.get_node(trypos) + local tryid = nil + local tryname = nil + if (trynode) then + tryname = trynode.name + tryid = minetest.get_content_id(tryname) + + print("tryname:" .. tryname) + print("trynode.name:" .. trynode.name) + -- if (tryid == minetest.CONTENT_AIR) then + if trynode.name == airname then + -- found: + if (userpos) then + trydist = vector.distance(userpos, trypos) + else + -- dummy value for "found" state: + trydist = vector.distance(nodepos, trypos) + end + trywhy = "air" + else + -- local trygroup = minetest.get_item_group(trynode.name, "air") + -- local drawtype = get_nodedef_field(tryname, "drawtype") + if (get_nodedef_field(tryname, "drawtype") == "airlike") then + trywhy = "airlike" + elseif (get_nodedef_field(tryname, "sunlight_propagates") == true) then + trywhy = "sunlight_propagates" + else + trynode = nil + -- print("[metatools::stick] " .. key .. ": "..tryname.." is not airlike, no sunlight_propagates") + end + if (trynode) then + -- found: + if (userpos) then + trydist = vector.distance(userpos, trypos) + else + -- dummy value for "found" state: + trydist = vector.distance(nodepos, trypos) + end + end + -- if trydef.sunlight_propagates + end + else + trywhy = "non-node" + -- (non-node pos should work for the later light check) + -- found: + if (userpos) then + trydist = vector.distance(userpos, trypos) + else + -- dummy value for "found" state: + trydist = vector.distance(nodepos, trypos) + end + end + if (trydist) then + if (litpos == nil) or (trydist < litdist) then + litdist = trydist + litpos = trypos + litid = tryid -- nil if trywhy == "non-node" + litwhy = trywhy + if (key > 0) then + litwhat = "neighbor:" + litindent = " " + else + foundPointed = true + -- is the pointed node + break -- always use pointed node if lightable + end + end + end + end + local nodelightsource = get_nodedef_field(nodename, "light_source") + if (nodelightsource) and (nodelightsource > 0) then + if not foundPointed then + litmsg = " # next to pointed light_source=" .. nodelightsource + end + end + + + -- litnode = minetest.find_node_near(nodepos, 1, minetest.get_name_from_content_id(minetest.CONTENT_AIR)) + if (litpos) then + if (litwhat) then + minetest.chat_send_player( + username, + "[metatools::stick] nearby lit: #"..minetest.pos_to_string(litpos) + ) + end + minetest.chat_send_player( + username, + "[metatools::stick] "..litindent.."why lit:" .. litwhy .. litmsg + ) + minetest.chat_send_player( + username, + "[metatools::stick] "..litindent.."light:" .. minetest.get_node_light(litpos) + ) + else + minetest.chat_send_player( + username, + "[metatools::stick] nearby lit: ~ # no air/propogator for determining lighting" + ) + end + minetest.log("action","[metatools] Player " .. username .. " saw metadatas of node at " .. minetest.pos_to_string(nodepos)) end, }) From fa471185a7c59d02ae1f6b39e5d4503e73d647a8 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Thu, 30 Jan 2020 23:23:25 -0500 Subject: [PATCH 05/20] If the node has an inventory, show it! --- init.lua | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 170 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index c11182b..817e999 100644 --- a/init.lua +++ b/init.lua @@ -1,17 +1,156 @@ --[[ - -- Metadata Tools +-- Metadata Tools -- --- A mod providing write and read access to a nodes' metadata using commands --- ßÿ Lymkwi/LeMagnesium/Mg ; 2015-2016 --- License: WTFPL --- Contributors : --- - Lymkwi/LeMagnesium --- - Paly2 +-- A mod providing write and read access to a nodes' metadata using commands +-- ßÿ Lymkwi/LeMagnesium/Mg ; 2015-2016 +-- License: WTFPL +-- Contributors : +-- - Lymkwi/LeMagnesium +-- - Paly2 +-- - Poikilos -- --- Version: 1.2.2 +-- Version: Poikilos fork of 1.2.2 -- ]]-- +local function token_indices(haystack, needle) + local results = {} + for i = 1, #haystack do + local try = haystack:sub(i,i + needle:len() - 1) + if try == needle then + table.insert(results, i) + end + end + return results +end + +local function split_and_keep_token(s, needle) + local results = {} + local indices = token_indices(s, needle) + local start = 1 + for k, v in pairs(indices) do + table.insert(results, s:sub(start, v)) + start = v + 1 + end + if start < #s then + table.insert(results, s:sub(start)) + end + return results +end + +local function delimit(table, tab, delimiter) + if not tab then + tab = "" + end + if not table then + return tab .. "nil" + end + if not delimiter then + delimiter = " " + end + local ret = "" + if delimiter ~= "\n" then + ret = tab + end + for k, v in pairs(table) do + if delimiter == "\n" then + ret = ret .. tab .. k .. ":" .. v .. "\n" + else + ret = ret .. k .. ":" .. v .. "\n" + end + end +return ret +end + +local function delimit_sequence(table, tab, delimiter) + if not tab then + tab = "" + end + if not table then + return tab .. "nil" + end + if not delimiter then + delimiter = " " + end + local ret = "" + if delimiter ~= "\n" then + ret = tab + end + for k, v in pairs(table) do + if delimiter == "\n" then + ret = ret .. tab .. v .. delimiter + else + ret = ret .. v .. delimiter + end + end + return ret +end + +local function send_messages_sequence(username, table, tab) + if not tab then + tab = "" + end + if not table then + minetest.chat_send_player(username, tab .. "nil") + return + end + for k, v in pairs(table) do + minetest.chat_send_player(username, tab .. v .. ",") + end + +end + +local function inv_to_tables(inv) + -- see bones mod + results = {} + for i = 1, inv:get_size("main") do + local stk = inv:get_stack("main", i) + table.insert(results, stk:to_table()) + -- to_table shows everything: + -- meta: + -- metadata: "" + -- count:1 + -- name:"default:sapling" + -- wear:0 + end + return results +end + +local function inv_to_table(inv, blank) + -- see bones mod + results = {} + for i = 1, inv:get_size("main") do + local stk = inv:get_stack("main", i) + local stk_s = stk:to_string() + if #stk_s > 0 or blank then + table.insert(results, stk_s) + end + end + return results +end + +local function send_messages(username, table, tab) + if not tab then + tab = "" + end + if not table then + minetest.chat_send_player(username, tab .. "nil") + return + end + for k, v in pairs(table) do + if type(v) == "table" then + minetest.chat_send_player(username, tab .. k .. ":") + send_messages(username, v, tab.."\t") + elseif k == "formspec" then + minetest.chat_send_player(username, tab .. k .. ":") + local chunks = split_and_keep_token(v, "]") + send_messages_sequence(username, chunks, tab.."\t") + else + minetest.chat_send_player(username, tab..k..":"..dump(v)) + end + end +end + local function get_nodedef_field(nodename, fieldname) if not minetest.registered_nodes[nodename] then -- print("metatools.get_nodedef_field: no registered node named " .. nodename) @@ -41,8 +180,8 @@ minetest.register_craftitem("metatools:stick",{ local nodepos = pointed_thing.under if not nodepos or not minetest.get_node(nodepos) then return end local nodename = minetest.get_node(nodepos).name - local node = minetest.registered_nodes[nodename] - local meta = minetest.get_meta(nodepos) + local node = minetest.registered_nodes[nodename] + local meta = minetest.get_meta(nodepos) local metalist = meta:to_table() minetest.chat_send_player( @@ -69,8 +208,26 @@ minetest.register_craftitem("metatools:stick",{ minetest.chat_send_player( username, "[metatools::stick] metadata: " - .. dump(meta:to_table()["fields"]):gsub('\n', "") + --.. delimit(meta:to_table()["fields"], "", "\n") ) + -- send_messages(username, meta:to_table()["fields"]) + send_messages(username, meta:to_table()) + minetest.chat_send_player( + username, + "[metatools::stick] inventory: " + --.. delimit(meta:to_table()["fields"], "", "\n") + ) + if meta["get_inventory"] then + local inventory = meta:get_inventory() + minetest.chat_send_player(username, "get_inventory():") + if inventory then -- this is never true for some reason + send_messages(username, inv_to_table(inventory)) + else + minetest.chat_send_player(username, "\tnil") + end + else + minetest.chat_send_player(username, "get_inventory():") + end local airname = minetest.get_name_from_content_id(minetest.CONTENT_AIR) -- local litnode = nil local litpos = nil @@ -107,8 +264,8 @@ minetest.register_craftitem("metatools:stick",{ tryname = trynode.name tryid = minetest.get_content_id(tryname) - print("tryname:" .. tryname) - print("trynode.name:" .. trynode.name) + -- print("tryname:" .. tryname) + -- print("trynode.name:" .. trynode.name) -- if (tryid == minetest.CONTENT_AIR) then if trynode.name == airname then -- found: From 01efdd987735c65c78adbeb45fc1951de93ef3bf Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Fri, 31 Jan 2020 12:48:49 -0500 Subject: [PATCH 06/20] show actual inventory slot number --- init.lua | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/init.lua b/init.lua index 817e999..908ad24 100644 --- a/init.lua +++ b/init.lua @@ -129,7 +129,7 @@ local function inv_to_table(inv, blank) return results end -local function send_messages(username, table, tab) +local function send_messages(username, table, tab, blank) if not tab then tab = "" end @@ -138,15 +138,17 @@ local function send_messages(username, table, tab) return end for k, v in pairs(table) do - if type(v) == "table" then - minetest.chat_send_player(username, tab .. k .. ":") - send_messages(username, v, tab.."\t") - elseif k == "formspec" then - minetest.chat_send_player(username, tab .. k .. ":") - local chunks = split_and_keep_token(v, "]") - send_messages_sequence(username, chunks, tab.."\t") - else - minetest.chat_send_player(username, tab..k..":"..dump(v)) + if blank or ((v ~= nil) and (dump(v) ~= "") and (dump(v) ~= "\"\"")) then + if type(v) == "table" then + minetest.chat_send_player(username, tab .. k .. ":") + send_messages(username, v, tab.."\t") + elseif k == "formspec" then + minetest.chat_send_player(username, tab .. k .. ":") + local chunks = split_and_keep_token(v, "]") + send_messages_sequence(username, chunks, tab.."\t") + else + minetest.chat_send_player(username, tab..k..":"..dump(v)) + end end end end @@ -210,23 +212,23 @@ minetest.register_craftitem("metatools:stick",{ "[metatools::stick] metadata: " --.. delimit(meta:to_table()["fields"], "", "\n") ) - -- send_messages(username, meta:to_table()["fields"]) send_messages(username, meta:to_table()) - minetest.chat_send_player( - username, - "[metatools::stick] inventory: " - --.. delimit(meta:to_table()["fields"], "", "\n") - ) + -- send_messages(username, meta:to_table()["fields"]) + -- minetest.chat_send_player( + -- username, + -- "[metatools::stick] inventory: " + -- --.. delimit(meta:to_table()["fields"], "", "\n") + -- ) if meta["get_inventory"] then local inventory = meta:get_inventory() - minetest.chat_send_player(username, "get_inventory():") if inventory then -- this is never true for some reason - send_messages(username, inv_to_table(inventory)) - else - minetest.chat_send_player(username, "\tnil") + minetest.chat_send_player(username, "get_inventory():") + send_messages(username, inv_to_table(inventory, true)) + -- else + -- minetest.chat_send_player(username, "\tnil") end - else - minetest.chat_send_player(username, "get_inventory():") + -- else + -- minetest.chat_send_player(username, "get_inventory:nil") end local airname = minetest.get_name_from_content_id(minetest.CONTENT_AIR) -- local litnode = nil From 8f16640b66e95619103b57b5eb631bf737194c9e Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Fri, 31 Jan 2020 12:53:07 -0500 Subject: [PATCH 07/20] avoid showing empty tables --- init.lua | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/init.lua b/init.lua index 908ad24..d7aefab 100644 --- a/init.lua +++ b/init.lua @@ -206,24 +206,29 @@ minetest.register_craftitem("metatools:stick",{ -- .. (get_nodedef_field(nodename, "sunlight_propagates") and 'true' or 'false') -- ) - - minetest.chat_send_player( - username, - "[metatools::stick] metadata: " - --.. delimit(meta:to_table()["fields"], "", "\n") - ) - send_messages(username, meta:to_table()) - -- send_messages(username, meta:to_table()["fields"]) - -- minetest.chat_send_player( - -- username, - -- "[metatools::stick] inventory: " - -- --.. delimit(meta:to_table()["fields"], "", "\n") - -- ) + local this_meta_to_table = meta:to_table() + if #this_meta_to_table > 0 then + minetest.chat_send_player( + username, + "[metatools::stick] metadata: " + --.. delimit(meta:to_table()["fields"], "", "\n") + ) + send_messages(username, this_meta_to_table) + -- send_messages(username, meta:to_table()["fields"]) + -- minetest.chat_send_player( + -- username, + -- "[metatools::stick] inventory: " + -- --.. delimit(meta:to_table()["fields"], "", "\n") + -- ) + end if meta["get_inventory"] then local inventory = meta:get_inventory() if inventory then -- this is never true for some reason - minetest.chat_send_player(username, "get_inventory():") - send_messages(username, inv_to_table(inventory, true)) + local this_inv_table = inv_to_table(inventory, true) + if #this_inv_table > 0 then + minetest.chat_send_player(username, "get_inventory():") + send_messages(username, this_inv_table) + end -- else -- minetest.chat_send_player(username, "\tnil") end From 2317dca231d208fc47ed321be9ccc25f07d6b679 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 13 Apr 2021 19:06:24 -0400 Subject: [PATCH 08/20] Remove 1 redundant add 1 missing local. --- init.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index d7aefab..4de591f 100644 --- a/init.lua +++ b/init.lua @@ -118,7 +118,7 @@ end local function inv_to_table(inv, blank) -- see bones mod - results = {} + local results = {} for i = 1, inv:get_size("main") do local stk = inv:get_stack("main", i) local stk_s = stk:to_string() @@ -206,14 +206,13 @@ minetest.register_craftitem("metatools:stick",{ -- .. (get_nodedef_field(nodename, "sunlight_propagates") and 'true' or 'false') -- ) - local this_meta_to_table = meta:to_table() - if #this_meta_to_table > 0 then + if #metalist > 0 then minetest.chat_send_player( username, "[metatools::stick] metadata: " --.. delimit(meta:to_table()["fields"], "", "\n") ) - send_messages(username, this_meta_to_table) + send_messages(username, metalist) -- send_messages(username, meta:to_table()["fields"]) -- minetest.chat_send_player( -- username, From c003d1a80a6994ab5aaa9abe107c15da9b2b9526 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 13 Apr 2021 19:13:27 -0400 Subject: [PATCH 09/20] Show frame contents. Indent inventory output. --- init.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 4de591f..74dc753 100644 --- a/init.lua +++ b/init.lua @@ -226,7 +226,7 @@ minetest.register_craftitem("metatools:stick",{ local this_inv_table = inv_to_table(inventory, true) if #this_inv_table > 0 then minetest.chat_send_player(username, "get_inventory():") - send_messages(username, this_inv_table) + send_messages(username, this_inv_table, " ") end -- else -- minetest.chat_send_player(username, "\tnil") @@ -234,6 +234,16 @@ minetest.register_craftitem("metatools:stick",{ -- else -- minetest.chat_send_player(username, "get_inventory:nil") end + if node.frame_contents then + local frame_contents = node.frame_contents + if frame_contents then + minetest.chat_send_player(username, "frame_contents: "..frame_contents) + -- else + -- minetest.chat_send_player(username, "\tnil") + end + -- else + -- minetest.chat_send_player(username, "get_inventory:nil") + end local airname = minetest.get_name_from_content_id(minetest.CONTENT_AIR) -- local litnode = nil local litpos = nil From 7305724a95d6e4934a8417fa0ea5d015d178dde6 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Tue, 13 Apr 2021 19:26:27 -0400 Subject: [PATCH 10/20] Also show framed item when using the itemframes mod. --- init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/init.lua b/init.lua index 74dc753..4290297 100644 --- a/init.lua +++ b/init.lua @@ -235,6 +235,7 @@ minetest.register_craftitem("metatools:stick",{ -- minetest.chat_send_player(username, "get_inventory:nil") end if node.frame_contents then + -- frames mod local frame_contents = node.frame_contents if frame_contents then minetest.chat_send_player(username, "frame_contents: "..frame_contents) @@ -244,6 +245,17 @@ minetest.register_craftitem("metatools:stick",{ -- else -- minetest.chat_send_player(username, "get_inventory:nil") end + if meta:get_string("item") ~= "" then + -- itemframes mod or xdecor:itemframe + local frame_contents = meta:get_string("item") + if frame_contents then + minetest.chat_send_player(username, "meta item: "..frame_contents) + -- else + -- minetest.chat_send_player(username, "\tnil") + end + -- else + -- minetest.chat_send_player(username, "get_inventory:nil") + end local airname = minetest.get_name_from_content_id(minetest.CONTENT_AIR) -- local litnode = nil local litpos = nil From 86b8c8ebb33039324d35872dbb87d600310ccc61 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Sun, 28 Nov 2021 19:03:22 -0500 Subject: [PATCH 11/20] Try to serialize mobs (not working yet). Fix a crash on unknown node. --- init.lua | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 4290297..1f41914 100644 --- a/init.lua +++ b/init.lua @@ -13,6 +13,44 @@ -- ]]-- +function serializeTable(val, name, skipnewlines, depth) + -- Make a table into a string. + -- (c) 2011 Henrik Ilgen + -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) + -- answered May 21 '11 at 12:14 Henrik Ilgen + -- edited May 13, 2019 at 9:10 + -- on + -- Only the first argument is required. + -- Get the object back from the string via: + -- a = loadstring(s)() + skipnewlines = skipnewlines or false + depth = depth or 0 + + local tmp = string.rep(" ", depth) + + if name then tmp = tmp .. name .. " = " end + + if type(val) == "table" then + tmp = tmp .. "{" .. (not skipnewlines and "\n" or "") + + for k, v in pairs(val) do + tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "") + end + + tmp = tmp .. string.rep(" ", depth) .. "}" + elseif type(val) == "number" then + tmp = tmp .. tostring(val) + elseif type(val) == "string" then + tmp = tmp .. string.format("%q", val) + elseif type(val) == "boolean" then + tmp = tmp .. (val and "true" or "false") + else + tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" + end + + return tmp +end + local function token_indices(haystack, needle) local results = {} for i = 1, #haystack do @@ -176,10 +214,42 @@ dofile(modpath .. "/chatcommands.lua") minetest.register_craftitem("metatools:stick",{ description = "Meta stick", inventory_image = "metatools_stick.png", + stack_max = 1, on_use = function(itemstack, user, pointed_thing) local username = user:get_player_name() local userpos = user:get_pos() + if pointed_thing.type == "nothing" then + minetest.chat_send_player( + username, + "[metatools::stick] You pointed at nothing." + ) + return + end + if pointed_thing.type == "object" then + local pointedObjRef = pointed_thing.ref + -- local objAsStr = minetest.serialize(pointedObjRef) + -- ^ if param is pointed_thing or pointed_thing.ref, minetest.serialize causes "2021-11-14 16:45:39: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'metatools' in callback item_OnUse(): /home/owner/minetest/bin/../builtin/common/serialize.lua:151: Can't serialize data of type userdata" + -- - even serializeTable returns [inserializeable datatype:userdata] + -- unrelated note: minetest.serialize(nil) returns "return nil" + -- TODO: + -- Show ObjectRef armor groups (See ) + -- documentation for ObjectRef: + local objAsStr = serializeTable(pointedObjRef) + minetest.chat_send_player( + username, + "[metatools::stick] You pointed at an object:" + ) + local pointedObjRef = pointed_thing.ref + minetest.chat_send_player( + username, + "[metatools::stick] " .. objAsStr + ) + minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr) + end local nodepos = pointed_thing.under + -- > * `under` refers to the node position behind the pointed face + -- > * `above` refers to the node position in front of the pointed face. + -- - if not nodepos or not minetest.get_node(nodepos) then return end local nodename = minetest.get_node(nodepos).name local node = minetest.registered_nodes[nodename] @@ -234,7 +304,8 @@ minetest.register_craftitem("metatools:stick",{ -- else -- minetest.chat_send_player(username, "get_inventory:nil") end - if node.frame_contents then + -- node is nil at this point if the node is an "unknown node"! + if node and node.frame_contents then -- frames mod local frame_contents = node.frame_contents if frame_contents then From 3ada6172300d35c96a588b6546666e585e5e22c7 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 13 Apr 2022 11:56:17 -0400 Subject: [PATCH 12/20] Show the LuaEntity table for clicked entities! --- init.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 1f41914..786651f 100644 --- a/init.lua +++ b/init.lua @@ -224,8 +224,7 @@ minetest.register_craftitem("metatools:stick",{ "[metatools::stick] You pointed at nothing." ) return - end - if pointed_thing.type == "object" then + elseif pointed_thing.type == "object" then local pointedObjRef = pointed_thing.ref -- local objAsStr = minetest.serialize(pointedObjRef) -- ^ if param is pointed_thing or pointed_thing.ref, minetest.serialize causes "2021-11-14 16:45:39: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'metatools' in callback item_OnUse(): /home/owner/minetest/bin/../builtin/common/serialize.lua:151: Can't serialize data of type userdata" @@ -244,7 +243,18 @@ minetest.register_craftitem("metatools:stick",{ username, "[metatools::stick] " .. objAsStr ) - minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr) + -- minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr) + local luaEntity = pointedObjRef:get_luaentity() + minetest.chat_send_player( + username, + "[metatools::stick] LuaEntity name: " .. luaEntity.name + ) + -- ^ This is the entity name such as namespace:sheep_black where namespace is a mod name. + minetest.chat_send_player( + username, + "[metatools::stick] LuaEntity: " .. serializeTable(luaEntity) + ) + -- else type is usually "node" end local nodepos = pointed_thing.under -- > * `under` refers to the node position behind the pointed face From 2d51afef5152c45424060d81427c1f255046ba1a Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 13 Apr 2022 15:18:44 -0400 Subject: [PATCH 13/20] Show hp of the pointed_thing.ref object. --- init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 786651f..de35bd3 100644 --- a/init.lua +++ b/init.lua @@ -236,15 +236,18 @@ minetest.register_craftitem("metatools:stick",{ local objAsStr = serializeTable(pointedObjRef) minetest.chat_send_player( username, - "[metatools::stick] You pointed at an object:" + "[metatools::stick] You pointed at an object (" .. objAsStr .. ")" ) local pointedObjRef = pointed_thing.ref + -- if pointed_thing.ref.get_hp then minetest.chat_send_player( username, - "[metatools::stick] " .. objAsStr + "[metatools::stick] pointed_thing.ref:get_hp(): " .. pointedObjRef:get_hp() ) + -- end -- minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr) local luaEntity = pointedObjRef:get_luaentity() + -- INFO: For player name, use user:get_player_name() minetest.chat_send_player( username, "[metatools::stick] LuaEntity name: " .. luaEntity.name From 4757a123ce79f8e235102b6bf594edc205a988c8 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Sat, 16 Apr 2022 22:39:21 -0400 Subject: [PATCH 14/20] Stop shouting, FLOSS world. --- README.md => readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => readme.md (100%) diff --git a/README.md b/readme.md similarity index 100% rename from README.md rename to readme.md From f802bf0888bd8b4bf18f1f1c16cf803dad440577 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Sat, 16 Apr 2022 23:44:51 -0400 Subject: [PATCH 15/20] Improve markdown. The license said I could do anything I want, and I wanted to change to a legally viable license. Replace the texture to remove the invasive and inappropriate invasive and inappropriate CC-BY-NC-SA license. Add a node metadata diagram that is legible above the sparse ASCII art table. Move "Rewrite the table stocking" to an issue: https://github.com/poikilos/metatools/issues/4 --- .gitignore | 1 + init.lua | 8 +-- projects/node_metadata.dia | Bin 0 -> 2443 bytes projects/node_metadata.png | Bin 0 -> 8389 bytes readme.md | 120 +++++++++++++++++++++-------------- textures/metatools_stick.png | Bin 3484 -> 753 bytes 6 files changed, 77 insertions(+), 52 deletions(-) create mode 100644 .gitignore create mode 100644 projects/node_metadata.dia create mode 100644 projects/node_metadata.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a803116 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/projects/node_metadata.dia.autosave diff --git a/init.lua b/init.lua index de35bd3..bd0e708 100644 --- a/init.lua +++ b/init.lua @@ -2,12 +2,8 @@ -- Metadata Tools -- -- A mod providing write and read access to a nodes' metadata using commands --- ßÿ Lymkwi/LeMagnesium/Mg ; 2015-2016 --- License: WTFPL --- Contributors : --- - Lymkwi/LeMagnesium --- - Paly2 --- - Poikilos +-- (c) 2015-2016 ßÿ Lymkwi/LeMagnesium/Mg and Paly2; (c) 2017-2022 Poikilos +-- License: [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/) -- -- Version: Poikilos fork of 1.2.2 -- diff --git a/projects/node_metadata.dia b/projects/node_metadata.dia new file mode 100644 index 0000000000000000000000000000000000000000..9b16b559caf269d6fbc78b3031e60743a77c008c GIT binary patch literal 2443 zcmV;633T=!iwFP!000021MOYQa^toV-OpF37^L(dK^p1xP9~DNz;$f_@ZK<(UE9M58I-obE${^W#t7SMlgM%r;S)+>Q}|<58H* z(?yglZ^wWB@$0o5|8)25$3+zUpnsNGuo~$zl8tHIjvw=U{lm@8%gYOhx0@hOGZ05l zU=!Z_FNovdMjPFX@4k&juRB--d0>uJM}s`iqS;d(j*?&%-i~L%{GVl(J|&BBX;sTpW&p~`UzIv!WFSXF-%7x}2qH90p10HP4>H%l&NTL9D0Psjw`fc!=^m zePjF&LA*I9fb#IatF7zGU1rhZ^un!KwDhvr>c6A8)34+uTI7%S-yMA=W$#-@y+22r zXcmXZMjs`4Z{2VE>ApDw3Xa&HZaL%1-dag$Aww3jOGs$>6fMHd8{C`Ye z&WWf8FY`1>bT~QdB>!mFNSVOEXwmwj$Js?eqy$*3BC@aj;Y z!+GAdUd{LNi>v1GuW|Y^e+;sGbUped{XX6&<2n_O7PsU7!1_XHUOnBLP6i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SCK#P+SR$rLi>6CaqmKx^PVOa*E9~_Q*Lns6 zN+`WniFq)>L52nEE)_Nfk$3OmzVDa^gfefGjEx51t-8zZiJZcM`)zA7Z$~#HiAeamQl# z&JpB=7+y5FX}T7}Z6owzxEC<4003UX7(l|1q`(EQUJR^W$j_}_RBVE{kRM3Cps0f- zW_2<=L1yf7+VttSPrtud`Yqlm{kGn_NdRV)(Fs9-U_l&0ruGCYPgn>t)kukoHYwUJ zGw@!5^eMPc!Ts|n?h|mGN-<>?E7my{qCN{B?7#AXJ&*}iT$!yNLUN~Eg4E6t;hIXI z#8OTOG)>1$VjZD>7{wEbe;8#DBB2N?^JWm`-;g`7n1ii1X+nT_`DPcZjf3aViFSo{ zu8__-rUa0(RxvL&RLG^A(;ntA=|><$I#}xQ*K4a2wGp-`!@Q#76`c>K=qMXO=Uw+_ zV*I(m6Bo(3&c>l~tA%$2Pbj76WUA`*#EE)9U0!*3@buvMrN9%v)6Psx`cT6qmqwFj zOen`{_|6j)s!+p=HY?h$)o|+|y&CRC4F5pNKr#j=X1P*eUb^pvjDdv=`q_mHSxz3w zFMZ*k8zF-b(Zy6pP$$L{#6~SR)Mw*98~<9_xb?o8vKy001kduQdPw literal 0 HcmV?d00001 diff --git a/projects/node_metadata.png b/projects/node_metadata.png new file mode 100644 index 0000000000000000000000000000000000000000..e6f55981493e9667eb5b20f7abd8f59aadd64c53 GIT binary patch literal 8389 zcmdUVcT`h(w{`%9K?a#YQIHY~3=o=1mu3S@=)DIJ=@4q@RRyFg5|EA*=}meKf`If+ zsG;{32%V7JFwT7MJM+!G*Z0r6vi3Ub{7!Pt$=>_f`+4>`!ODuV)R%5t0ssKi;Ac-& z0RWOp0Dx5QCsN|dN`k^DaYO!GPWCB)aQ;cH&w394+ysE1K2mo}+??_>l6OV>?M%O` zGQ7>2aql)Q58Rr&2C~W%8Y3;t!FK~OpjtQXTDe)FUa`NGH?F$LyQV3vF>RFq3a>1X z)6i1s_$*K$Cr}b>tsech)1B~v^<|e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F^+2-*K@M|DArwVnL!^Ym>t7CB~+RyOo>rh^Dz#hJ%iHQ3gX>;zScC z+Y+*5X_OHOQ>V2rQ@vvO9Ef#ta>QbtsG>WNiSOU1UsTV74$s+H3gT-4xQ79*@`h^d zsA%}=XroS*XF5eO|4~zB$eDcffBw-rjiHtX z2pbj6>(k@C|Ku_pSBTBLDI@N8dhlb9H|=>nnOmE*vRP*=;y?967!Vf{^Ns-5pf-z< z+ft$#vesH>y5%=yzV3ORyh`EqT!eA`9w>yS*{3ArW^kqCbZkt8^`ePCSCHggcy0Tk zwod$hWZ;FFz)5)CXlM1%{TO|9(`&pF64e?(-SZK4$)n%iWX6>x6Y~o)i>TfmT`Hmx z-W=_J`!qf%9Ycz5#uUaebYLewwJLxaOLo&?pQZxt5k2&*YmCDcwk~&gXuwi$G> z)oC#lbW~5p2PN_*&vyk?;qdgEh{!{guv5u#rsq)gQnZ8|V;!e5vE>iD!*M{9pL>KaK7GwzfPV z&<$-n-Jv9cG4>R2?RPYCNOMV~NBN~2IEf4Bx=Vm4XLQRxvqm&g9nqK!EX&S7B zh#5&6NK7%Jqs->6JkYMYQrARvNOm5;kLxwF+vPNM1ROAS1N4iM-YP6U)Z`UvmCw?K_Y>xqs(4_FhCyfs^7)+vqnG~$ZmpNV literal 0 HcmV?d00001 diff --git a/readme.md b/readme.md index a610b0c..1e447bd 100644 --- a/readme.md +++ b/readme.md @@ -1,58 +1,86 @@ -Minetest mod metatools -###################### +# Minetest mod metatools -A mod inspired by mgl512's itemframe issue -Version : 1.2.2 +Get everything possible* about a node just by clicking it with metatools:stick! -# Authors - - LeMagnesium / Mg / ElectronLibre : Source code writer - - Paly2 / Palige : Contributor for the source code - - Ataron : Texture creater +This goes far beyond Lymkwi's metatools. -# Purpose + +## Differences in Poikilos' fork +- All known* metadata is shown on click! There is no need for various commands to traverse the tree, though the original chat command code is intact. +- Click a node and get its inventory. +- Click an entity and list the entire LuaEntitySOA tree! + - See the "[Minetest API Notes](minetest-api-notes)" section below. +- The texture is redone so that doesn't any longer have an invasive and inappropriate CC-BY-NC-SA license from the upstream version of metatools. + +`*` All metadata where how to obtain it is known by the maintainer of this repo (except where there is an open issue). + + +## Authors +Code: +- 2015-2016 LeMagnesium/Mg/ElectronLibre and Paly2/Palige (mod inspired by mgl512's itemframe issue) +- 2017-2022 Poikilos (Poikilos' fork of Version 1.2.2) + +Textures: +- 2022 Poikilos (redone "metatools_stick.png" *replaces one with invasive and inappropriate CC-BY-NC-SA license [old texture was by Ataron]*) + + +## Purpose This mod's aim is to provide a way for admins to navigate through any (ok, not ignores) nodes on the map, and see values of its metadatas at any of their stratum. -# Media -"metatools_stick.png" by Ataron (CC-BY-NC-SA) -# Todo - - Rewrite the table stocking : a variable containing a copy of the global - table returned by :to_table(), on which we would work, and a save command to - apply it on the node +## Install +- You can remove the project folder to lighten the "game" if necessary (Keeping the png is useful but only for documentation--Nothing in "projects" is used by the mod code). -# Special thanks - - mgl512 (Le_Docteur) for its locked itemframe which gave me the idea of a tool -allowing to see/edit metadatas - - Ataron who created the stick's texture - - palige who agreed to test the mod for its first release, and contributed to the last version -# Command tutorial - - Soon to come, please refer to /meta help until then +## Special thanks +- mgl512 (Le_Docteur) for its locked itemframe which gave me the idea of a tool + allowing to see/edit metadatas +- Ataron who created the stick's texture +- palige who agreed to test the mod for its first release, and contributed to the last version - Node metadatas look like this : - 0 1 2 3 ... - Node/ - | - +- fields - | | - | +- foo - | +- bar - | +- ... - +- inventory - | - +- main - | | - | +- 1 - | +- 2 - | +- 3 - | +- ... - +- craft - | | - | +- 1 - | +- 2 - | +- 3 - | +- ... - +- ... +## Command tutorial +- Soon to come, please refer to /meta help until then + + +## Development + +### Minetest API Notes + +#### Entity Metadata +The magic sauce to get the entire LuaEntitySOA of a pointed_thing was finally discovered by accident (when researching unrelated API feature(s)) after no one would/could answer my question: +```Lua +local pointedObjRef = pointed_thing.ref; +-- . . . some other code is here, then ... +local luaEntity = pointedObjRef:get_luaentity(); +``` + +#### Node metadata +![Node has fields and inventory; there are main and craft inventories, where each is a sequential table where each entry is an itemstack](projects/node_metadata.png) + +``` +Node +| ++-fields +| | +| +-foo +| +-bar +| +-... ++-inventory + | + +-main + | | + | +-1 + | +-2 + | +-3 + | +-... + +-craft + | | + | +-1 + | +-2 + | +-3 + | +-... + +-... +``` diff --git a/textures/metatools_stick.png b/textures/metatools_stick.png index 42302e667f00d5d1503939b2548ab94fe3688270..16f7c1f7326f22c8240a8f6a5afb0e15d087525d 100644 GIT binary patch delta 729 zcmV;~0w(>O8}S8@B!3BTNLh0L01FcU01FcV0GgZ_00007bV*G`2j&D310fF&igGRh z00NLnL_t(|+U?puPZMDr!13?HwY?OYGN>GMF$Ib?#Y7V0L?H1`d;ts$Bsv-s6Bh%wGsJf321?k+-vv2DTL-VZ)3X8HW(dD9&-6`x2vW_~`+#Dqm8 z0zExYEDjJ3CkTb2GW+SN0O&C>fa6RtGjqF%Zyn3J#`PPI7$1Kljl2UgnFSe(B@x1+ zQh|*P$?h)LHh&Zfu(k%#=pcQ4H_hAv{rzKDR)nP`0Qu+m|HNXA0LEi=G>O-^M z0uB5fMpGj^nOf(#nnTJO>9io3Y`pgW;!CCPW_<{?;(vu`kT$o5*w{`{I!uAE0YSA| zqEEU8KoEFk0tAIu zB0!M%z<&b-jSn<{3i!YRsDck9fJ%7Z1E_}gHGqnE-vX$L_a%VJc+UfSD@=Qc*UBgwo_-WElZjrhL%L}MDlpQ zZ-1P4e<33&w&hfgvb+Exo`%JSFJ630=moFJV&7~1Fz!3v@dO+`d@xyDT*kI-bX^BX0HF(ha8Su!yRs6j zd%w8T!3RNzuIr4C@4>chCMG5T5>*z_bdgd~e@53fhq+@3xaXd`l4i4w>v|Llc^VBH zP1Bg0o1;>x@CSeT<7Bj~u~73qdIa2e-`ze=(@(@;xeU@$<)*&nx;`InOK&^ z=N>qlk+8B7;D>Qv0^E@V9654t;y59W>enc3MnY}?LA@Z5Mq zfABl53?4ahZ{oTg9490QA{@uVbv<-l!*xAswHi}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ATCH 16/20] Clarify install notes and project goals. --- readme.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 1e447bd..7454f40 100644 --- a/readme.md +++ b/readme.md @@ -2,10 +2,8 @@ Get everything possible* about a node just by clicking it with metatools:stick! -This goes far beyond Lymkwi's metatools. - - -## Differences in Poikilos' fork +## Differences in Poikilos' fork: +This is a hard fork oriented around getting information without typing any commands. - All known* metadata is shown on click! There is no need for various commands to traverse the tree, though the original chat command code is intact. - Click a node and get its inventory. - Click an entity and list the entire LuaEntitySOA tree! @@ -31,7 +29,9 @@ stratum. ## Install -- You can remove the project folder to lighten the "game" if necessary (Keeping the png is useful but only for documentation--Nothing in "projects" is used by the mod code). +- Copy the repo folder containing init.lua to your Minetest mods folder (The resulting folder should be mods/metatools/). +- Enable the mod for the world. +- You can remove the "projects" folder to lighten the "game" if necessary (Keeping the png is useful but only for documentation--Nothing in "projects" is used by the mod code). ## Special thanks @@ -41,8 +41,13 @@ stratum. - palige who agreed to test the mod for its first release, and contributed to the last version -## Command tutorial -- Soon to come, please refer to /meta help until then +## Use +- After following the "Install" steps above, open the world in Minetest. +- Type `/grantme all` +- Type `/giveme metatools:stick` + +The chat commands from https://github.com/Lymkwi/minetest-mod-metatools are still present but usually not necessary: +- Type `/meta help` to see instructions on chat commands. ## Development From 170e39796176184982351eeae3f054628472ffaa Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 27 Apr 2022 21:47:24 -0400 Subject: [PATCH 17/20] Represent objects as YAML for brevity. --- init.lua | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index bd0e708..1c73cd5 100644 --- a/init.lua +++ b/init.lua @@ -9,6 +9,71 @@ -- ]]-- + +local function isArray(t) + -- Check if a table only contains sequential values. + -- by kikito + -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) + -- answered May 21, 2011 at 7:22 + -- edited Mar 2, 2014 at 17:13 + -- + local i = 0 + for _ in pairs(t) do + i = i + 1 + if t[i] == nil then return false end + end + return true +end + + +function yamlSerializeTable(val, name, depth) + -- Make a table into a string. + -- (c) 2011 Henrik Ilgen, 2022 Poikilos + -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) + -- answered May 21 '11 at 12:14 Henrik Ilgen + -- edited May 13, 2019 at 9:10 + -- on + -- Only the first argument is required. + -- Get the object back from the string via: + -- a = loadstring(s)() + depth = depth or 0 + + local tmp = string.rep(" ", depth) + + if name then + if name == "METATOOLS_ARRAY_ELEMENT" then + tmp = tmp .. "- " + else + tmp = tmp .. name .. ": " + end + end + + if type(val) == "table" then + if isArray(val) then + tmp = tmp .. "\n" + for k, v in pairs(val) do + tmp = tmp .. yamlSerializeTable(v, "METATOOLS_ARRAY_ELEMENT", depth + 1) .. "\n" + end + -- tmp = tmp .. string.rep(" ", depth) + else + tmp = tmp .. "\n" -- Newline is after : for tables. + for k, v in pairs(val) do + tmp = tmp .. yamlSerializeTable(v, k, depth + 1) .. "\n" + end + -- tmp = tmp .. string.rep(" ", depth) + end + elseif type(val) == "number" then + tmp = tmp .. tostring(val) + elseif type(val) == "string" then + tmp = tmp .. string.format("%q", val) + elseif type(val) == "boolean" then + tmp = tmp .. (val and "true" or "false") + else + tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" + end + return tmp +end + function serializeTable(val, name, skipnewlines, depth) -- Make a table into a string. -- (c) 2011 Henrik Ilgen @@ -224,12 +289,12 @@ minetest.register_craftitem("metatools:stick",{ local pointedObjRef = pointed_thing.ref -- local objAsStr = minetest.serialize(pointedObjRef) -- ^ if param is pointed_thing or pointed_thing.ref, minetest.serialize causes "2021-11-14 16:45:39: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'metatools' in callback item_OnUse(): /home/owner/minetest/bin/../builtin/common/serialize.lua:151: Can't serialize data of type userdata" - -- - even serializeTable returns [inserializeable datatype:userdata] + -- - even yamlSerializeTable returns [inserializeable datatype:userdata] -- unrelated note: minetest.serialize(nil) returns "return nil" -- TODO: -- Show ObjectRef armor groups (See ) -- documentation for ObjectRef: - local objAsStr = serializeTable(pointedObjRef) + local objAsStr = yamlSerializeTable(pointedObjRef) minetest.chat_send_player( username, "[metatools::stick] You pointed at an object (" .. objAsStr .. ")" @@ -251,8 +316,25 @@ minetest.register_craftitem("metatools:stick",{ -- ^ This is the entity name such as namespace:sheep_black where namespace is a mod name. minetest.chat_send_player( username, - "[metatools::stick] LuaEntity: " .. serializeTable(luaEntity) + "[metatools::stick] LuaEntity: " .. yamlSerializeTable(luaEntity) ) + local animation = pointedObjRef:get_animation() + minetest.chat_send_player( + username, + "[metatools::stick] LuaEntity.ref:get_animation():" .. yamlSerializeTable(animation) + ) + -- Hmm, animation.range, animation['range'] are nil + -- (same for other variables), + -- so API documentation is unclear: + -- `get_animation()`: returns `range`, `frame_speed`, `frame_blend` and + -- `frame_loop`. + -- yamlSerializeTable(animation) only gets: + -- y: 65 + -- x: 35 + -- minetest.chat_send_player( + -- username, + -- yamlSerializeTable(animation.range, " range") + -- ) -- else type is usually "node" end local nodepos = pointed_thing.under From b995b401e8316e5c6e4a3d8502bebac261aa7b93 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 27 Apr 2022 21:49:17 -0400 Subject: [PATCH 18/20] Use tabs consistently. --- init.lua | 174 +++++++++++++++++++++++++++---------------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/init.lua b/init.lua index 1c73cd5..4120c09 100644 --- a/init.lua +++ b/init.lua @@ -11,105 +11,105 @@ local function isArray(t) - -- Check if a table only contains sequential values. - -- by kikito - -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) - -- answered May 21, 2011 at 7:22 - -- edited Mar 2, 2014 at 17:13 - -- - local i = 0 - for _ in pairs(t) do - i = i + 1 - if t[i] == nil then return false end - end - return true + -- Check if a table only contains sequential values. + -- by kikito + -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) + -- answered May 21, 2011 at 7:22 + -- edited Mar 2, 2014 at 17:13 + -- + local i = 0 + for _ in pairs(t) do + i = i + 1 + if t[i] == nil then return false end + end + return true end function yamlSerializeTable(val, name, depth) - -- Make a table into a string. - -- (c) 2011 Henrik Ilgen, 2022 Poikilos - -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) - -- answered May 21 '11 at 12:14 Henrik Ilgen - -- edited May 13, 2019 at 9:10 - -- on - -- Only the first argument is required. - -- Get the object back from the string via: - -- a = loadstring(s)() - depth = depth or 0 + -- Make a table into a string. + -- (c) 2011 Henrik Ilgen, 2022 Poikilos + -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) + -- answered May 21 '11 at 12:14 Henrik Ilgen + -- edited May 13, 2019 at 9:10 + -- on + -- Only the first argument is required. + -- Get the object back from the string via: + -- a = loadstring(s)() + depth = depth or 0 - local tmp = string.rep(" ", depth) + local tmp = string.rep(" ", depth) - if name then - if name == "METATOOLS_ARRAY_ELEMENT" then - tmp = tmp .. "- " - else - tmp = tmp .. name .. ": " - end - end + if name then + if name == "METATOOLS_ARRAY_ELEMENT" then + tmp = tmp .. "- " + else + tmp = tmp .. name .. ": " + end + end - if type(val) == "table" then - if isArray(val) then - tmp = tmp .. "\n" - for k, v in pairs(val) do - tmp = tmp .. yamlSerializeTable(v, "METATOOLS_ARRAY_ELEMENT", depth + 1) .. "\n" - end - -- tmp = tmp .. string.rep(" ", depth) - else - tmp = tmp .. "\n" -- Newline is after : for tables. - for k, v in pairs(val) do - tmp = tmp .. yamlSerializeTable(v, k, depth + 1) .. "\n" - end - -- tmp = tmp .. string.rep(" ", depth) - end - elseif type(val) == "number" then - tmp = tmp .. tostring(val) - elseif type(val) == "string" then - tmp = tmp .. string.format("%q", val) - elseif type(val) == "boolean" then - tmp = tmp .. (val and "true" or "false") - else - tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" - end - return tmp + if type(val) == "table" then + if isArray(val) then + tmp = tmp .. "\n" + for k, v in pairs(val) do + tmp = tmp .. yamlSerializeTable(v, "METATOOLS_ARRAY_ELEMENT", depth + 1) .. "\n" + end + -- tmp = tmp .. string.rep(" ", depth) + else + tmp = tmp .. "\n" -- Newline is after : for tables. + for k, v in pairs(val) do + tmp = tmp .. yamlSerializeTable(v, k, depth + 1) .. "\n" + end + -- tmp = tmp .. string.rep(" ", depth) + end + elseif type(val) == "number" then + tmp = tmp .. tostring(val) + elseif type(val) == "string" then + tmp = tmp .. string.format("%q", val) + elseif type(val) == "boolean" then + tmp = tmp .. (val and "true" or "false") + else + tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" + end + return tmp end function serializeTable(val, name, skipnewlines, depth) - -- Make a table into a string. - -- (c) 2011 Henrik Ilgen - -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) - -- answered May 21 '11 at 12:14 Henrik Ilgen - -- edited May 13, 2019 at 9:10 - -- on - -- Only the first argument is required. - -- Get the object back from the string via: - -- a = loadstring(s)() - skipnewlines = skipnewlines or false - depth = depth or 0 + -- Make a table into a string. + -- (c) 2011 Henrik Ilgen + -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) + -- answered May 21 '11 at 12:14 Henrik Ilgen + -- edited May 13, 2019 at 9:10 + -- on + -- Only the first argument is required. + -- Get the object back from the string via: + -- a = loadstring(s)() + skipnewlines = skipnewlines or false + depth = depth or 0 - local tmp = string.rep(" ", depth) + local tmp = string.rep(" ", depth) - if name then tmp = tmp .. name .. " = " end + if name then tmp = tmp .. name .. " = " end - if type(val) == "table" then - tmp = tmp .. "{" .. (not skipnewlines and "\n" or "") + if type(val) == "table" then + tmp = tmp .. "{" .. (not skipnewlines and "\n" or "") - for k, v in pairs(val) do - tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "") - end + for k, v in pairs(val) do + tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "") + end - tmp = tmp .. string.rep(" ", depth) .. "}" - elseif type(val) == "number" then - tmp = tmp .. tostring(val) - elseif type(val) == "string" then - tmp = tmp .. string.format("%q", val) - elseif type(val) == "boolean" then - tmp = tmp .. (val and "true" or "false") - else - tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" - end + tmp = tmp .. string.rep(" ", depth) .. "}" + elseif type(val) == "number" then + tmp = tmp .. tostring(val) + elseif type(val) == "string" then + tmp = tmp .. string.format("%q", val) + elseif type(val) == "boolean" then + tmp = tmp .. (val and "true" or "false") + else + tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" + end - return tmp + return tmp end local function token_indices(haystack, needle) @@ -327,10 +327,10 @@ minetest.register_craftitem("metatools:stick",{ -- (same for other variables), -- so API documentation is unclear: -- `get_animation()`: returns `range`, `frame_speed`, `frame_blend` and - -- `frame_loop`. - -- yamlSerializeTable(animation) only gets: - -- y: 65 - -- x: 35 + -- `frame_loop`. + -- yamlSerializeTable(animation) only gets: + -- y: 65 + -- x: 35 -- minetest.chat_send_player( -- username, -- yamlSerializeTable(animation.range, " range") From 1940aa16979d8483d25e4b643591085ad1b254b2 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Wed, 27 Apr 2022 22:27:29 -0400 Subject: [PATCH 19/20] Clean up output. Remove extra newlines from YAML. --- init.lua | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index 4120c09..5c2a393 100644 --- a/init.lua +++ b/init.lua @@ -26,6 +26,14 @@ local function isArray(t) end +-- function string:endswith(ending) + -- from https://gist.github.com/kgriffs/124aae3ac80eefe57199451b823c24ec +-- return ending == "" or self:sub(-#ending) == ending +--end +function endswith(str, ending) + return ending == "" or str:sub(-#ending) == ending +end + function yamlSerializeTable(val, name, depth) -- Make a table into a string. -- (c) 2011 Henrik Ilgen, 2022 Poikilos @@ -46,37 +54,51 @@ function yamlSerializeTable(val, name, depth) else tmp = tmp .. name .. ": " end + -- else: should only occur for a value that is after a name already + -- given, such as for tables. end if type(val) == "table" then + tmp = tmp .. "\n" -- Newline is after : for tables. + -- tmp = tmp .. " # table" .. "\n" -- for debug only if isArray(val) then - tmp = tmp .. "\n" for k, v in pairs(val) do tmp = tmp .. yamlSerializeTable(v, "METATOOLS_ARRAY_ELEMENT", depth + 1) .. "\n" end -- tmp = tmp .. string.rep(" ", depth) else - tmp = tmp .. "\n" -- Newline is after : for tables. for k, v in pairs(val) do tmp = tmp .. yamlSerializeTable(v, k, depth + 1) .. "\n" end -- tmp = tmp .. string.rep(" ", depth) end + while endswith(tmp, "\n\n") do + -- Removing repeated '\n' is necessary since any sub-value + -- (and any more deeply nested value) may be a table and + -- append "\n" (Then this depth appends "\n"). + tmp = string.sub(tmp, ( #tmp - 1 )) + end elseif type(val) == "number" then tmp = tmp .. tostring(val) elseif type(val) == "string" then tmp = tmp .. string.format("%q", val) + -- %q: "surrounds the string with double quotes and properly + -- escapes double quotes, newlines, and some other characters + -- inside the string." + -- - elseif type(val) == "boolean" then tmp = tmp .. (val and "true" or "false") + elseif type(val) == nil then + tmp = tmp .. "null" else tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\"" end return tmp end -function serializeTable(val, name, skipnewlines, depth) +function serializeTable(val, name, depth, skipnewlines) -- Make a table into a string. - -- (c) 2011 Henrik Ilgen + -- (c) 2011 Henrik Ilgen, 2022 Poikilos (switch depth & skipnewlines param order) -- [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) -- answered May 21 '11 at 12:14 Henrik Ilgen -- edited May 13, 2019 at 9:10 @@ -95,7 +117,7 @@ function serializeTable(val, name, skipnewlines, depth) tmp = tmp .. "{" .. (not skipnewlines and "\n" or "") for k, v in pairs(val) do - tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "") + tmp = tmp .. serializeTable(v, k, depth + 1, skipnewlines) .. "," .. (not skipnewlines and "\n" or "") end tmp = tmp .. string.rep(" ", depth) .. "}" @@ -299,11 +321,12 @@ minetest.register_craftitem("metatools:stick",{ username, "[metatools::stick] You pointed at an object (" .. objAsStr .. ")" ) + -- ^ (always?) says "[inserializeable datatype:userdata]", so: local pointedObjRef = pointed_thing.ref -- if pointed_thing.ref.get_hp then minetest.chat_send_player( username, - "[metatools::stick] pointed_thing.ref:get_hp(): " .. pointedObjRef:get_hp() + " pointed_thing.ref:get_hp(): " .. pointedObjRef:get_hp() ) -- end -- minetest.log("action", "[metatools] You pointed at an object: " .. objAsStr) @@ -311,18 +334,24 @@ minetest.register_craftitem("metatools:stick",{ -- INFO: For player name, use user:get_player_name() minetest.chat_send_player( username, - "[metatools::stick] LuaEntity name: " .. luaEntity.name + " LuaEntity.name: " .. luaEntity.name ) -- ^ This is the entity name such as namespace:sheep_black where namespace is a mod name. minetest.chat_send_player( username, - "[metatools::stick] LuaEntity: " .. yamlSerializeTable(luaEntity) + " LuaEntity: " .. yamlSerializeTable(luaEntity, "", 1) ) local animation = pointedObjRef:get_animation() minetest.chat_send_player( username, - "[metatools::stick] LuaEntity.ref:get_animation():" .. yamlSerializeTable(animation) + " pointed_thing.ref:get_animation():" .. yamlSerializeTable(animation) ) + if luaEntity.state then + minetest.chat_send_player( + username, + " luaEntity.state: " .. yamlSerializeTable(luaEntity.state) + ) + end -- Hmm, animation.range, animation['range'] are nil -- (same for other variables), -- so API documentation is unclear: From 5f7c5878b3216c6f177c48f37f67394f332aa9bc Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Fri, 29 Apr 2022 16:10:26 -0400 Subject: [PATCH 20/20] Add a mod.conf. --- description.txt | 1 + mod.conf | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 description.txt create mode 100644 mod.conf diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..b8c505e --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +See metadata for nodes (and Entities in Poikilos' fork!) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..46573ef --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = metatools +depends = +description = See metadata for nodes (and Entities in Poikilos' fork!)