paramat, you should try to use the new functions to set multiple nodes that were added today: it is now insanely fast (less than a few seconds for a full chunck). I am doing a mod that creates multiple realms at y=20000, and it went at least 100 times faster with the new version. Here is the code: (it is WTFPL, and if there are unused variabled, it is because it is base on your code
Code: Select all
local ONGEN = true -- (true / false) -- Enable / disable moonrealm generation.
local YMIN = 19000 -- Approx bottom.
local YMAX = 20000 -- Approx top.
local GRAD = 40 -- 40 -- Surface generating noise gradient. Controls height of hills.
local STOTHR = 0.15 -- 0.15 -- Stone noise threshold. Controls maximum depth of dust.
local DUSDIS = 40 -- 40 -- Dust thinning distance in nodes.
local DUSAVY = 20 -- 20 -- Average y where dust starts to thin, relative to minp.y.
local DUSAMP = 20 -- 20 -- Amplitude of that thinning level.
local DUSRAN = 2 -- 2 -- +- Randomness of that thinning level.
local CAVOFF = 0.015 -- 0.015 -- Cave offset. Size of underground caves.
local CAVDIS = 56 -- 56 -- Cave thinning distance in nodes.
local ATMALP = 32 -- 32 -- Alpha of above ground atmosphere
local ATMTHR3 = 0.1 -- 0.1 -- Atmosphere noise thresholds. Controls smooth transition from orange tinted air to normal air underground -- .
local ATMTHR4 = 0.2 -- 0.2 --
local ATMTHR5 = 0.3 -- 0.3 --
local DEBUG = true
-- Perlin noise for terrain.
local SEEDDIFF1 = 46894686546
local OCTAVES1 = 6 -- 6 -- Add 1 to this if you increase scale, add another 1 each time scale has doubled.
local PERSISTENCE1 = 0.55 -- 0.55 --
local SCALE1 = 256 -- 256 -- Largest scale of noise pattern.
-- Perlin noise for caves.
local SEEDDIFF2 = 9294207
local OCTAVES2 = 6 -- 6 -- Add 1 to this if you increase scale, add another 1 each time scale has doubled.
local PERSISTENCE2 = 0.5 -- 0.5 --
local SCALE2 = 256 -- 256 -- Largest scale of noise pattern.
-- Perlin noise for dust thinning line.
local SEEDDIFF3 = 93561
local OCTAVES3 = 4 -- 4 -- Add 1 to this if you increase scale, add another 1 each time scale has doubled.
local PERSISTENCE3 = 0.5 -- 0.5 --
local SCALE3 = 256 -- 256 -- Largest scale of noise pattern.
local yminq = (80 * math.floor((YMIN + 32) / 80)) - 32
local ymaxq = (80 * math.floor((YMAX + 32) / 80)) + 47
minetest.register_node("realms:barrier", {
drawtype = "normal",
tiles = {"realms_barrier"},
paramtype = "light",
sunlight_propagates = true,
pointable = false,
diggable = false,
})
local function replace(old, new)
for i=1,16 do
minetest.register_ore({
ore_type = "scatter",
ore = new,
wherein = old,
clust_scarcity = 1,
clust_num_ores = 1,
clust_size = 1,
height_min = yminq,
height_max = ymaxq - 80,
})
end
end
if ONGEN then
replace("air", "default:stone")
end
-- On generated function.
function ces()
local s={}
for i=1,80 do
s[i]={}
for j=1,80 do
s[i][j]={}
for k=1,80 do
s[i][j][k]={name="air"}
end
end
end
return s
end
function flatten(scm)
local s2={}
local s2i=1
for _,a in ipairs(scm) do
for __,b in ipairs(a) do
for ___,c in ipairs(b) do
s2[s2i]=c
s2i=s2i+1
end
end
end
return s2
end
function add_to_scm(scm, pos, s)
for p, node in pairs(s) do
if p.x+pos.x>=1 and p.x+pos.x<=80 and p.y+pos.y>=1 and p.y+pos.y<=80 and p.z+pos.z>=1 and p.z+pos.z<=80 then
scm[p.z+pos.z][p.y+pos.y][p.x+pos.x]=node
end
end
end
treeschm = {[{x=0,y=0,z=0}]={name="default:tree"},
[{x=0,y=1,z=0}]={name="default:tree"},
[{x=0,y=2,z=0}]={name="default:tree"},
[{x=0,y=3,z=0}]={name="default:tree"},
[{x=0,y=4,z=0}]={name="default:tree"},
[{x=1,y=5,z=0}]={name="default:leaves"},
[{x=-1,y=5,z=0}]={name="default:leaves"},
[{x=1,y=5,z=1}]={name="default:leaves"},
[{x=1,y=5,z=-1}]={name="default:leaves"},
[{x=-1,y=5,z=1}]={name="default:leaves"},
[{x=-1,y=5,z=-1}]={name="default:leaves"},
[{x=0,y=5,z=0}]={name="default:leaves"},
[{x=0,y=5,z=1}]={name="default:leaves"},
[{x=0,y=5,z=-1}]={name="default:leaves"},
[{x=1,y=6,z=0}]={name="default:leaves"},
[{x=-1,y=6,z=0}]={name="default:leaves"},
[{x=0,y=6,z=1}]={name="default:leaves"},
[{x=0,y=6,z=-1}]={name="default:leaves"},
[{x=0,y=6,z=0}]={name="default:leaves"},
}
for y=2,4 do
for x=-2,2 do
for z=-2,2 do
if x~=0 or z~=0 then
treeschm[{x=x,y=y,z=z}]={name="default:leaves"}
end
end
end
end
if ONGEN then
minetest.register_on_generated(function(minp, maxp, seed)
minetest.place_schematic(minp, {size={x=1,y=1,z=1},data={{name="default:mese"}}})
local env = minetest.env
local scm = ces()
if maxp.y == ymaxq then
math.randomseed(seed)
--local pr=PseudoRandom(seed)
local perlin1 = env:get_perlin(SEEDDIFF1, OCTAVES1, PERSISTENCE1, SCALE1)
local perlin2 = env:get_perlin(SEEDDIFF2, OCTAVES2, PERSISTENCE2, SCALE2)
--local perlin3 = env:get_perlin(pr:next(1,1000), pr:next(2,6), pr:next(1,1000)/500, pr:next(50,1000))
local water_level = math.random(20,60)
local sea,treeproba
if math.random()<=0.05 then
sea="default:lava_source"
treeproba=0
else
sea="default:water_source"
treeproba = (math.exp(2*math.random())-1)/50
end
for x=1,79 do
print(x)
for z=1,79 do
local surf=math.floor(40+25*perlin1:get2d({x=minp.x+x,y=minp.z+z}))
local top=math.floor(3+2*perlin2:get2d({x=minp.x+x,y=minp.z+z}))
if top>=surf then top=surf-1 end
if surf>80 then surf=80 end
for y=1, surf-top do
--minetest.set_node({x=x,y=y,z=z},{name="default:stone"})
scm[z][y][x]={name="default:stone"}
end
for y=surf-top, surf-1 do
--minetest.set_node({x=x,y=y,z=z},{name="default:dirt"})
scm[z][y][x]={name="default:dirt"}
end
--minetest.set_node({x=x,y=surf,z=z},{name="default:dirt_with_grass"})
scm[z][surf][x]={name="default:dirt_with_grass"}
if surf<water_level then
for yw=surf+1,water_level do
--minetest.set_node({x=x,y=yw,z=z},{name=sea})
scm[z][yw][x]={name=sea}
end
else
if math.random()<=treeproba then
add_to_scm(scm, {x=x,y=surf+1,z=z}, treeschm)
end
end
end
end
for y=1,80 do
for x=1,80 do
--minetest.set_node({x=x,y=y,z=minp.z},{name="realms:barrier"})
--minetest.set_node({x=x,y=y,z=maxp.z},{name="realms:barrier"})
scm[1][y][x]={name="realms:barrier"}
scm[80][y][x]={name="realms:barrier"}
end
for z=2,79 do
--minetest.set_node({x=minp.x,y=y,z=z},{name="realms:barrier"})
--minetest.set_node({x=maxp.x,y=y,z=z},{name="realms:barrier"})
scm[z][y][1]={name="realms:barrier"}
scm[z][y][80]={name="realms:barrier"}
end
end
minetest.place_schematic(minp, {size={x=80,y=80,z=80},data=flatten(scm)})
elseif minp.y>=yminq and maxp.y<ymaxq then
for y=minp.y,maxp.y do
for x=minp.x,maxp.x do
minetest.set_node({x=x,y=y,z=minp.z},{name="realms:barrier"})
minetest.set_node({x=x,y=y,z=maxp.z},{name="realms:barrier"})
end
for z=minp.z+1,maxp.z-1 do
minetest.set_node({x=minp.x,y=y,z=z},{name="realms:barrier"})
minetest.set_node({x=maxp.x,y=y,z=z},{name="realms:barrier"})
end
end
end
end)
end