aboutsummaryrefslogtreecommitdiff
path: root/init.lua
blob: 6b1b4beb337e02470a9ee61dc674719dd35c8f97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local channel = minetest.mod_channel_join("randomblocks")

local nodes = {}

minetest.register_on_mods_loaded(function()
	for nodename, nodedef in pairs(minetest.registered_nodes) do
		if nodedef.node_placement_prediction ~= "" and nodename ~= "ignore" and nodename ~= "air" then
			table.insert(nodes, nodename)
		end
	end
end)

minetest.register_on_modchannel_message(function(channel_name, _, message)
	if channel_name == "randomblocks" then
		local pos = minetest.string_to_pos(message)
		if pos then
			local node = minetest.get_node(pos)
			if node and node.name ~= "air" and node.name ~= "ignore" and node.name ~= "mcl_core:obsidian" and node.name ~= "mcl_core:bedrock" and node.name ~= "mcl_portals:nether_portal" then
				minetest.set_node(pos, {name = nodes[math.random(#nodes)]})
			end
		end
	end
end)