local getNode = minetest.env:get_node
Inocudom wrote:What effects will this have on RAM and CPU usage?
--[[
You can copy, use this in your mods, an change it, as long as you give me credit as the original coder. [Jordan4Ibanez]
]]--
num_nodes = {}
thickness = {}
function minetest.generate_nodes(node_id,base_block,node_table,node_thickness)
thickness[node_id] = node_thickness
num_nodes[node_id] = 0
for k,v in pairs(node_table) do
num_nodes[node_id] = num_nodes[node_id] + 1
end
minetest.register_on_generated(function(minp, maxp, blockseed)
local testing_node = minetest.env:find_node_near({x=(minp.x + maxp.x)/2,y=(minp.y + maxp.y)/2,z=(minp.z + maxp.z)/2}, 40, base_block)
if testing_node == nil then
return
end
--let's find the lowest point of air
baser = nil
for y = minp.y, maxp.y do
for x = minp.x, maxp.x do
for z = minp.z, maxp.z do
local get_node = minetest.env.get_node
local test = get_node(minetest.env, {x=x,y=y,z=z}).name
if test == "air" then
baser = y - 1
break
end
end
if baser ~= nil then
break
end
z=0
end
if baser ~= nil then
break
end
x=0
end
print(dump(baser))
for x = minp.x,maxp.x do
for z = minp.z,maxp.z do
for y = baser,maxp.y do
local get_node = minetest.env.get_node
local test = get_node(minetest.env, {x=x,y=y,z=z}).name
--local test = minetest.env:get_node({x=x,y=y,z=z}).name
if test == base_block then
if minetest.env:get_node({x=x,y=y+1,z=z}).name == "air" then
if math.random()*100 < thickness[node_id] then
local noding = node_table[math.random(0,num_nodes[node_id])]
if noding ~= nil then
local set_node = minetest.env.set_node
local setter = set_node(minetest.env, {x=x,y=y+1,z=z}, {name=noding})
--minetest.env:set_node({x=x,y=y+1,z=z}, {name=noding})
end
end
end
y = minp.y
z = z + 1
--Cancel search nodes
elseif test == "default:water_source" or test == "default:sand" or test == "default:clay" or test == "air" then
y = minp.y
z = z + 1
end
end
end
z=0
end
end)
end
minetest.generate_nodes("normal","default:dirt_with_grass",{"default:grass_1","default:grass_2","default:grass_3","default:grass_4","default:grass_5"},25)minetest.generate_nodes("normal","default:dirt_with_grass",{"default:grass_1","default:grass_2","default:grass_3","default:grass_4","default:grass_5"},25)
Sokomine wrote:It might be intresting to know the average ground height in a chunk (as far as that can be determined) and how smooth the terrain is without having to actually look for the surface. Even my rather small trader huts usually need a support platform (which looks for the ground in a similar way like this algorithm) because most areas are not smooth enough. Knowing where the surface is might also be very intresting for mobs. Maybe this could be made available inside the engine?
Users browsing this forum: No registered users and 24 guests