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

Post Reply
dgm5555
Member
Posts: 245
Joined: Tue Apr 08, 2014 19:45

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

by dgm5555 » Post

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/212 ... lnodes.zip
BTW in 0.4.11 debug (F5) tells which node you're pointing at if you want to identify them

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)?
Last edited by dgm5555 on Sun Mar 01, 2015 17:58, edited 3 times in total.

User avatar
rubenwardy
Moderator
Posts: 7098
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: London, United Kingdom
Contact:

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

by rubenwardy » Post

Code: Select all

for key, value in ipairs(minetest.registered_nodes) do
      -- key is node name, eg default:stone
      -- value is definition table
end
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Bas080
Member
Posts: 398
Joined: Mon May 21, 2012 15:54
GitHub: bas080
IRC: bas080
In-game: bas080
Location: Netherlands

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

by Bas080 » Post

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?

dgm5555
Member
Posts: 245
Joined: Tue Apr 08, 2014 19:45

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

by dgm5555 » Post

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...

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,
})


User avatar
rubenwardy
Moderator
Posts: 7098
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: London, United Kingdom
Contact:

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

by rubenwardy » Post

try pairs rather than ipairs, maybe (ipair cancels when it gets to nil)
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

dgm5555
Member
Posts: 245
Joined: Tue Apr 08, 2014 19:45

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

by dgm5555 » Post

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

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
Last edited by dgm5555 on Sun Feb 22, 2015 20:57, edited 2 times in total.

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

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

by ExeterDad » Post

Strangely beautiful.

User avatar
rubenwardy
Moderator
Posts: 7098
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: London, United Kingdom
Contact:

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

by rubenwardy » Post

BTW, you could write

local function display_all_nodes()

It does the same - assigns the function to a local variable.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Hybrid Dog
Member
Posts: 2865
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog
Location: Europe, in the EU where the GDPR applies!

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

by Hybrid Dog » Post

it tells me "placing3616 nodes", these nodes appear but then saplings and other stuff grows
Image
Attachments
afshdkjn.png
afshdkjn.png (329.33 KiB) Viewed 1651 times

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

dgm5555
Member
Posts: 245
Joined: Tue Apr 08, 2014 19:45

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

by dgm5555 » Post

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.)

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests