From 40c624c8327972965e9f4f11ee9fcc0c1df1f718 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Wed, 20 May 2015 17:04:50 +0200 Subject: [PATCH] Added dumpnodes mod - Added dumpnodes mod, creating /dumpnodes command which can be used by admins to drop the nodenames and top tiles' images for every node on the server in the aim of beginning a process designed to generate automatically the colors.txt file needed by minetestmapper --- mods/dumpnodes/init.lua | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 mods/dumpnodes/init.lua diff --git a/mods/dumpnodes/init.lua b/mods/dumpnodes/init.lua new file mode 100644 index 00000000..10b7ba9e --- /dev/null +++ b/mods/dumpnodes/init.lua @@ -0,0 +1,50 @@ +local function nd_get_tiles(nd) + if nd.tiles then + return nd.tiles + elseif nd.tile_images then + return nd.tile_images + end + return nil +end + +minetest.register_chatcommand("dumpnodes", { + params = "", + description = "", + privs = {server = true}, + func = function(plname, param) + local n = 0 + local ntbl = {} + for nn, nd in pairs(minetest.registered_nodes) do + local prefix, name = nn:match('(.*):(.*)') + if prefix == nil or name == nil or prefix == '' or name == '' then + -- nothing + else + if ntbl[prefix] == nil then + ntbl[prefix] = {} + end + ntbl[prefix][name] = nd + end + end + local out, err = io.open('nodes.txt', 'wb') + if not out then + return minetest.chat_send_player(plname, 'io.open: ' .. err) + end + for prefix, i in pairs(ntbl) do + out:write('# ' .. prefix .. '\n') + for name, nd in pairs(i) do + if nd.drawtype ~= 'airlike' and nd_get_tiles(nd) ~= nil then + local tl = nd_get_tiles(nd)[1] + if type(tl) == 'table' then + tl = tl.name + end + tl = (tl .. '^'):match('(.-)^') + out:write(prefix .. ':' .. name .. ' ' .. tl .. '\n') + n = n + 1 + end + end + out:write('\n') + end + out:close() + minetest.chat_send_player(plname, n .. " nodes dumped.") + end, +})