Added caverns

This commit is contained in:
npx 2016-05-23 23:23:53 +02:00
parent e0560df2ee
commit 42406d1759
3 changed files with 99 additions and 6 deletions

87
caverns.lua Normal file
View File

@ -0,0 +1,87 @@
-- Parameters
local YMIN = -31000 -- Cave realm limits
local YMAX = -30000
local TCAVE = 0 -- Cave threshold: 1 = small rare caves,
-- 0.5 = 1/3rd ground volume, 0 = 1/2 ground volume.
local BLEND = 64 -- Cave blend distance near YMIN, YMAX
-- 3D noise for caves
local np_cave = {
offset = 0,
scale = 1,
spread = {x = 512, y = 256, z = 512}, -- squashed 3:1
seed = 59033,
octaves = 6,
persist = 0.63
}
-- Stuff
local yblmin = YMIN + BLEND * 1.5
local yblmax = YMAX - BLEND * 1.5
-- Initialize noise objects to nil
local nobj_cave = nil
-- On generated function
minetest.register_on_generated(function(minp, maxp, seed)
if minp.y > YMAX or maxp.y < YMIN then
return
end
local t1 = os.clock()
local x1 = maxp.x
local y1 = maxp.y
local z1 = maxp.z
local x0 = minp.x
local y0 = minp.y
local z0 = minp.z
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
local sidelen = x1 - x0 + 1
local chulens = {x = sidelen, y = sidelen, z = sidelen}
local minposxyz = {x = x0, y = y0, z = z0}
nobj_cave = nobj_cave or minetest.get_perlin_map(np_cave, chulens)
local nvals_cave = nobj_cave:get3dMap_flat(minposxyz)
local nixyz = 1
for z = z0, z1 do -- for each xy plane progressing northwards
for y = y0, y1 do -- for each x row progressing upwards
local tcave
if y < yblmin then
tcave = TCAVE + ((yblmin - y) / BLEND) ^ 2
elseif y > yblmax then
tcave = TCAVE + ((y - yblmax) / BLEND) ^ 2
else
tcave = TCAVE
end
local vi = area:index(x0, y, z)
for x = x0, x1 do -- for each node do
if nvals_cave[nixyz] > tcave then
data[vi] = c_air
end
nixyz = nixyz + 1
vi = vi + 1
end
end
end
vm:set_data(data)
vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
vm:write_to_map(data)
local chugent = math.ceil((os.clock() - t1) * 1000)
print ("[subterrain] " .. chugent .. " ms")
end)

View File

@ -1,4 +1,10 @@
--Nssb
local path = minetest.get_modpath("nssb")
--Mobs
dofile(path.."/caverns.lua")
--Materials
minetest.register_node("nssb:mossy_stone_brick", {
description = "Mossy Stone Brick",
@ -699,8 +705,8 @@ for i=1,8 do
clust_scarcity = 1,
clust_num_ores = 1,
clust_size = 1,
y_min = -31000,
y_max = -30997,
y_min = -30999,
y_max = -30001,
})
end
@ -712,8 +718,8 @@ for i=1,8 do
clust_scarcity = 1,
clust_num_ores = 1,
clust_size = 1,
y_min = -30503,
y_max = -30999,
y_min = -30999,
y_max = -30001,
})
end
@ -727,7 +733,7 @@ local function replace(old, new)
clust_num_ores = 1,
clust_size = 1,
y_min = -30999,
y_max = -30501,
y_max = -30001,
})
end
end
@ -754,5 +760,5 @@ minetest.register_ore({
clust_num_ores = 200,
clust_size = 10,
y_min = -30999,
y_max = -30501,
y_max = -30001,
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 717 B

After

Width:  |  Height:  |  Size: 756 B