Page 1 of 1

[mod] Display All Installed Nodes (for design and building)

PostPosted: Sun Feb 22, 2015 13:23
by dgm5555
The code excludes lava water and fire from display (else it obscures your view, or combusts everything)
just paste it into an init.lua file in a directory of your choice, or extract the zip file
https://dl.dropboxusercontent.com/u/21225632/displayallnodes.zip
BTW in 0.4.11 debug (F5) tells which node you're pointing at if you want to identify them

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
local displayAllNodes = function(pos)
   local nodeCount = 0
   -- key is node name, eg default:stone   value is definition table
   for key, value in pairs(minetest.registered_nodes) do
      print (key)         
      nodeCount = nodeCount + 1
   end

   local manip = minetest.get_voxel_manip()
   minetest.chat_send_all("placing".. nodeCount.. " nodes")

   local curY = pos.y + math.sqrt(nodeCount * 2)
   local curX = pos.x
   local curZ = pos.z
   local startX = pos.x
   local startZ = pos.z
   local curRowMax = 1
   local rowCount = 1

   for key, value in pairs(minetest.registered_nodes) do         

      if ((string.find(key,"lava") == nil) and (string.find(key,"fire")) == nil and (string.find(key,"water") == nil) and (string.find(key,"air") == nil)) then
         local p = {x=curX, y=curY, z=curZ}
         manip:read_from_map(p, p)
         minetest.env:add_node(p, {name=key})
         -- use the voxelmanip to fix lighting problems
         manip:calc_lighting()

         rowCount = rowCount + 1
      
         if rowCount > curRowMax then
            rowCount = 1
            curRowMax = curRowMax + 1   --2
            --startX = startX - 1
            startZ = startZ - 1
            curY = curY - 1
            curX = startX
            curZ = startZ
         else
            curX = curX + 1
            curZ = curZ + 1
         end
      end
   end
   return true
end

minetest.register_chatcommand("/dan", {
   params = "",
   description = "Display All registered Nodes",
   func = function(name, param)
      local pos = minetest.get_player_by_name(name):getpos()
      pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)

      displayAllNodes(pos)
      return true
   end,
})



In the foreground is minetest_game, and the background is with moreblocks included
Image
Image



EDIT: This was my original post, left for posterity

I'd really like a mod which can place every registered node in a game so I can view them.
I'm considering making one, but don't know how to list all registered nodes.
I know there is minetest.registered_nodes[nodename], but that's indexed by name. As a start, I want a list I can iterate through to return the names.
Does anyone know how to do that (or can supply code to get me more or less of the way along)?

Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 13:42
by rubenwardy
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
for key, value in ipairs(minetest.registered_nodes) do
      -- key is node name, eg default:stone
      -- value is definition table
end

Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 16:54
by Bas080
I could use this when working on my OCD texture/nodebox-pack. Could you place the node in a slanted/diagonal fassion. The same way you often see when texture packs are presented? Or was that not your intention for this mod?

Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 18:20
by dgm5555
This is my code to create the chat command ('/dan')
It should create an inverted pyramid starting above the players head and going out and down, but
Unfortunately the for loop doesn't work, it returns a node count of 0, so I'm no further on...

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
local displayAllNodes = function(pos)
   local nodeCount = 0
   -- key is node name, eg default:stone   value is definition table
   for key, value in ipairs(minetest.registered_nodes) do
      print (key)         
      nodeCount = nodeCount + 1
   end

   local manip = minetest.get_voxel_manip()
   minetest.chat_send_all("placing".. nodeCount.. " nodes")

   local curY = pos.y + math.sqrt(nodeCount * 2)
   local curX = pos.x
   local curZ = pos.z
   local startX = pos.x
   local startZ = pos.z
   local curRowMax = 1

   for key, value in ipairs(minetest.registered_nodes) do         

      local p = {x=curX, y=curY, z=curZ}
      manip:read_from_map(p, p)
      minetest.env:add_node(p, {name=key})

      local rowCount = rowCount + 1
      
      if rowCount > curRowMax then
         rowCount = 1
         curRowMax = curRowMax + 2
         startX = startX - 1
         startZ = startZ - 1
         curY = curY - 1
         curX = startX
         curZ = startZ
      else
         curX = curX + 1
         curZ = curZ + 1
      end
   end
   return true
end

minetest.register_chatcommand("/dan", {
   params = "",
   description = "Display All registered Nodes",
   func = function(name, param)
      local pos = minetest.get_player_by_name(name):getpos()
      pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)

      displayAllNodes(pos)
      return true
   end,
})


Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 19:13
by rubenwardy
try pairs rather than ipairs, maybe (ipair cancels when it gets to nil)

Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 20:41
by dgm5555
That worked. thanks - and dropped a pillar of lava on my head :-(
The code now excludes lava and water from display
just paste it into an init.lua file in a directory of your choice
BTW in 0.4.11 debug (F5) tells which node you're pointing at if you want to identify them

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
local displayAllNodes = function(pos)
   local nodeCount = 0
   -- key is node name, eg default:stone   value is definition table
   for key, value in pairs(minetest.registered_nodes) do
      print (key)         
      nodeCount = nodeCount + 1
   end

   local manip = minetest.get_voxel_manip()
   minetest.chat_send_all("placing".. nodeCount.. " nodes")

   local curY = pos.y + math.sqrt(nodeCount * 2)
   local curX = pos.x
   local curZ = pos.z
   local startX = pos.x
   local startZ = pos.z
   local curRowMax = 1
   local rowCount = 1

   for key, value in pairs(minetest.registered_nodes) do         

      if ((string.find(key,"lava") == nil) and (string.find(key,"fire")) == nil and (string.find(key,"water") == nil) and (string.find(key,"air") == nil)) then
         local p = {x=curX, y=curY, z=curZ}
         manip:read_from_map(p, p)
         minetest.env:add_node(p, {name=key})

         rowCount = rowCount + 1
      
         if rowCount > curRowMax then
            rowCount = 1
            curRowMax = curRowMax + 1   --2
            --startX = startX - 1
            startZ = startZ - 1
            curY = curY - 1
            curX = startX
            curZ = startZ
         else
            curX = curX + 1
            curZ = curZ + 1
         end
      end
   end
   return true
end

minetest.register_chatcommand("/dan", {
   params = "",
   description = "Display All registered Nodes",
   func = function(name, param)
      local pos = minetest.get_player_by_name(name):getpos()
      pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)

      displayAllNodes(pos)
      return true
   end,
})



In the foreground is minetest_game, and the background is with moreblocks included
Image
Image

Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 20:45
by ExeterDad
Strangely beautiful.

Re: How can I list or place all installed nodes?

PostPosted: Sun Feb 22, 2015 21:20
by rubenwardy
BTW, you could write

local function display_all_nodes()

It does the same - assigns the function to a local variable.

Re: [mod] Display All Installed Nodes (for design and buildi

PostPosted: Sat Mar 21, 2015 08:47
by Hybrid Dog
it tells me "placing3616 nodes", these nodes appear but then saplings and other stuff grows
Image

Re: [mod] Display All Installed Nodes (for design and buildi

PostPosted: Sun Mar 22, 2015 07:37
by dgm5555
the mod just places blocks. if they've got abms (which i would have thought saplings probably have) they will then do whatever they'd normally do after being placed (eg grow.)