Lighting seems to work properly, alignment is proper. Separated the simple
mapgen code into multi_mapgen_simple mod and registered with multi_map_core which now properly calls the registered mapgen
This commit is contained in:
parent
d5d4520b2e
commit
18f6b8f3cc
|
@ -9,8 +9,8 @@ multi_map.map_max = 30927
|
||||||
multi_map.half_layer_height = multi_map.layer_height / 2
|
multi_map.half_layer_height = multi_map.layer_height / 2
|
||||||
multi_map.current_layer = nil
|
multi_map.current_layer = nil
|
||||||
|
|
||||||
multi_map.bedrock = "multi_map:bedrock"
|
multi_map.bedrock = "multi_map_core:bedrock"
|
||||||
multi_map.skyrock = "multi_map:skyrock"
|
multi_map.skyrock = "multi_map_core:skyrock"
|
||||||
|
|
||||||
multi_map.generate_bedrock = true
|
multi_map.generate_bedrock = true
|
||||||
multi_map.generate_skyrock = true
|
multi_map.generate_skyrock = true
|
||||||
|
@ -36,15 +36,12 @@ function multi_map.append_generator(generator)
|
||||||
table.insert(multi_map.generators, generator)
|
table.insert(multi_map.generators, generator)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, content_id, light_data, light_level)
|
function multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, content_id)
|
||||||
for z = minp.z, maxp.z do
|
for z = minp.z, maxp.z do
|
||||||
for y = minp.y, maxp.y do
|
for y = minp.y, maxp.y do
|
||||||
local vi = area:index(minp.x, y, z)
|
local vi = area:index(minp.x, y, z)
|
||||||
for x = minp.x, maxp.x do
|
for x = minp.x, maxp.x do
|
||||||
vm_data[vi] = content_id
|
vm_data[vi] = content_id
|
||||||
if light_data then
|
|
||||||
light_data[vi] = light_level
|
|
||||||
end
|
|
||||||
vi = vi + 1
|
vi = vi + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,6 +56,8 @@ multi_map.c_water = nil
|
||||||
multi_map.c_bedrock = nil
|
multi_map.c_bedrock = nil
|
||||||
multi_map.c_skyrock = nil
|
multi_map.c_skyrock = nil
|
||||||
|
|
||||||
|
minetest.set_mapgen_params({mgname = "singlenode"})
|
||||||
|
|
||||||
minetest.register_on_mapgen_init(function(mapgen_params)
|
minetest.register_on_mapgen_init(function(mapgen_params)
|
||||||
if multi_map.number_of_layers * multi_map.layer_height > multi_map.map_height then
|
if multi_map.number_of_layers * multi_map.layer_height > multi_map.map_height then
|
||||||
minetest.log("error", "Number of layers for the given layer height exceeds map height!")
|
minetest.log("error", "Number of layers for the given layer height exceeds map height!")
|
||||||
|
@ -66,14 +65,14 @@ minetest.register_on_mapgen_init(function(mapgen_params)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_generated(function(minp, maxp)
|
minetest.register_on_generated(function(minp, maxp)
|
||||||
-- if firstrun then
|
if firstrun then
|
||||||
multi_map.c_stone = minetest.get_content_id("default:stone")
|
multi_map.c_stone = minetest.get_content_id("default:stone")
|
||||||
multi_map.c_air = minetest.get_content_id("air")
|
multi_map.c_air = minetest.get_content_id("air")
|
||||||
multi_map.c_water = minetest.get_content_id("default:water_source")
|
multi_map.c_water = minetest.get_content_id("default:water_source")
|
||||||
multi_map.c_bedrock = minetest.get_content_id(multi_map.bedrock)
|
multi_map.c_bedrock = minetest.get_content_id(multi_map.bedrock)
|
||||||
multi_map.c_skyrock = minetest.get_content_id(multi_map.skyrock)
|
multi_map.c_skyrock = minetest.get_content_id(multi_map.skyrock)
|
||||||
firstrun = false
|
firstrun = false
|
||||||
-- end
|
end
|
||||||
|
|
||||||
multi_map.set_current_layer(minp.y)
|
multi_map.set_current_layer(minp.y)
|
||||||
local sidelen = maxp.x - minp.x + 1
|
local sidelen = maxp.x - minp.x + 1
|
||||||
|
@ -97,38 +96,23 @@ minetest.register_on_generated(function(minp, maxp)
|
||||||
multi_map.map_min + (multi_map.layer_height * (multi_map.current_layer + 1)) - 160 == minp.y
|
multi_map.map_min + (multi_map.layer_height * (multi_map.current_layer + 1)) - 160 == minp.y
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
print("Generating skyrock at y = "..minp.y)
|
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||||
local vm_data = vm:get_data()
|
local vm_data = vm:get_data()
|
||||||
|
|
||||||
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_skyrock)
|
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_skyrock)
|
||||||
|
vm:set_lighting({day=15, night=0})
|
||||||
vm:set_data(vm_data)
|
vm:set_data(vm_data)
|
||||||
vm:calc_lighting(false)
|
vm:calc_lighting(false)
|
||||||
vm:write_to_map(false)
|
vm:write_to_map(false)
|
||||||
else
|
else
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
for i,f in ipairs(multi_map.generators) do
|
||||||
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
f(multi_map.current_layer, minp, maxp, offset_minp, offset_maxp)
|
||||||
local vm_data = vm:get_data()
|
|
||||||
local light_data = vm:get_light_data()
|
|
||||||
print(offset_minp.y)
|
|
||||||
if offset_minp.y >= 0 then
|
|
||||||
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_air)
|
|
||||||
vm:set_lighting({day=15, night=0})
|
|
||||||
else
|
|
||||||
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_stone, light_data, 0)
|
|
||||||
end
|
end
|
||||||
vm:set_data(vm_data)
|
|
||||||
vm:calc_lighting()
|
|
||||||
vm:write_to_map()
|
|
||||||
|
|
||||||
-- for i,f in ipairs(multi_map.generators) do
|
|
||||||
-- f(multi_map.current_layer, minp, maxp, offset_minp, offset_maxp)
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_node("multi_map:skyrock", {
|
minetest.register_node("multi_map_core:skyrock", {
|
||||||
description = "Multi Map Impenetrable Skyblock",
|
description = "Multi Map Impenetrable Skyblock",
|
||||||
drawtype = "airlike",
|
drawtype = "airlike",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
|
@ -140,7 +124,7 @@ minetest.register_node("multi_map:skyrock", {
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("multi_map:bedrock", {
|
minetest.register_node("multi_map_core:bedrock", {
|
||||||
description = "Multi Map Impenetrable Bedrock",
|
description = "Multi Map Impenetrable Bedrock",
|
||||||
drawtype = "normal",
|
drawtype = "normal",
|
||||||
tiles ={"multi_map_bedrock.png"},
|
tiles ={"multi_map_bedrock.png"},
|
||||||
|
|
|
@ -1,252 +1,16 @@
|
||||||
-- levels 0.2.6
|
|
||||||
-- bugfixes: rename luxoff to luxore, remove 'local' from nobj_s
|
|
||||||
|
|
||||||
-- Parameters
|
|
||||||
|
|
||||||
local TERSCA = 96
|
|
||||||
local TSPIKE = 1.2
|
|
||||||
local SPIKEAMP = 2000
|
|
||||||
local TSTONE = 0.04
|
|
||||||
local STABLE = 2
|
|
||||||
|
|
||||||
local FLOATPER = 512
|
|
||||||
local FLOATFAC = 2
|
|
||||||
local FLOATOFF = -0.2
|
|
||||||
|
|
||||||
local YSURFMAX = 256
|
|
||||||
local YSAND = 4
|
|
||||||
local YWATER = 1
|
|
||||||
local YSURFCEN = 0
|
|
||||||
local YSURFMIN = -256
|
|
||||||
|
|
||||||
local YUNDERCEN = -512
|
|
||||||
local YLAVA = -528
|
|
||||||
local UNDERFAC = 0.0001
|
|
||||||
local UNDEROFF = -0.2
|
|
||||||
local LUXCHA = 1 / 9 ^ 3
|
|
||||||
|
|
||||||
-- Noise parameters
|
|
||||||
|
|
||||||
-- 3D noise
|
|
||||||
|
|
||||||
local np_terrain = {
|
|
||||||
offset = 0,
|
|
||||||
scale = 1,
|
|
||||||
spread = {x=384, y=192, z=384},
|
|
||||||
seed = 5900033,
|
|
||||||
octaves = 5,
|
|
||||||
persist = 0.63,
|
|
||||||
lacunarity = 2.0,
|
|
||||||
--flags = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
-- 2D noise
|
|
||||||
|
|
||||||
local np_spike = {
|
|
||||||
offset = 0,
|
|
||||||
scale = 1,
|
|
||||||
spread = {x=128, y=128, z=128},
|
|
||||||
seed = -188900,
|
|
||||||
octaves = 3,
|
|
||||||
persist = 0.5,
|
|
||||||
lacunarity = 2.0,
|
|
||||||
flags = "noeased"
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Nodes
|
|
||||||
|
|
||||||
minetest.register_node("mm_testauri_mountains:grass", {
|
|
||||||
description = "Grass",
|
|
||||||
tiles = {"default_grass.png", "default_dirt.png", "default_grass.png"},
|
|
||||||
groups = {crumbly=3},
|
|
||||||
sounds = default.node_sound_dirt_defaults({
|
|
||||||
footstep = {name="default_grass_footstep", gain=0.25},
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("mm_testauri_mountains:dirt", {
|
|
||||||
description = "Dirt",
|
|
||||||
tiles = {"default_dirt.png"},
|
|
||||||
groups = {crumbly=3},
|
|
||||||
sounds = default.node_sound_dirt_defaults(),
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("mm_testauri_mountains:luxore", {
|
|
||||||
description = "Lux Ore",
|
|
||||||
tiles = {"levels_luxore.png"},
|
|
||||||
paramtype = "light",
|
|
||||||
light_source = 14,
|
|
||||||
groups = {cracky=3},
|
|
||||||
sounds = default.node_sound_glass_defaults(),
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Stuff
|
|
||||||
|
|
||||||
local floatper = math.pi / FLOATPER
|
|
||||||
|
|
||||||
-- Set mapgen parameters
|
|
||||||
|
|
||||||
minetest.register_on_mapgen_init(function(mgparams)
|
|
||||||
minetest.set_mapgen_params({mgname="singlenode", flags="nolight"})
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Initialize noise objects to nil
|
|
||||||
|
|
||||||
local nobj_terrain = nil
|
|
||||||
local nobj_spike = nil
|
|
||||||
|
|
||||||
-- On generated function
|
|
||||||
|
|
||||||
function generate(current_layer, minp, maxp, offset_minp, offset_maxp)
|
function generate(current_layer, minp, maxp, offset_minp, offset_maxp)
|
||||||
-- local t0 = 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 ox1 = offset_maxp.x
|
|
||||||
local oy1 = offset_maxp.y
|
|
||||||
local oz1 = offset_maxp.z
|
|
||||||
local ox0 = offset_minp.x
|
|
||||||
local oy0 = offset_minp.y
|
|
||||||
local oz0 = offset_minp.z
|
|
||||||
-- print ("[levels] chunk minp ("..x0.." "..y0.." "..z0..")")
|
|
||||||
|
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
|
||||||
local data = vm:get_data()
|
local vm_data = vm:get_data()
|
||||||
|
if offset_minp.y >= 0 then
|
||||||
local c_stone = minetest.get_content_id("default:stone")
|
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_air)
|
||||||
local c_sand = minetest.get_content_id("default:sand")
|
vm:set_lighting({day=15, night=0})
|
||||||
local c_water = minetest.get_content_id("default:water_source")
|
else
|
||||||
local c_lava = minetest.get_content_id("default:lava_source")
|
multi_map.generate_singlenode_chunk(minp, maxp, area, vm_data, multi_map.c_stone)
|
||||||
|
|
||||||
local c_grass = minetest.get_content_id("mm_testauri_mountains:grass")
|
|
||||||
local c_dirt = minetest.get_content_id("mm_testauri_mountains:dirt")
|
|
||||||
local c_luxore = minetest.get_content_id("mm_testauri_mountains:luxore")
|
|
||||||
|
|
||||||
local sidelen = x1 - x0 + 1
|
|
||||||
local ystride = sidelen + 32
|
|
||||||
--local zstride = ystride ^ 2
|
|
||||||
local chulens3d = {x=sidelen, y=sidelen+17, z=sidelen}
|
|
||||||
local chulens2d = {x=sidelen, y=sidelen, z=1}
|
|
||||||
local minpos3d = {x=x0, y=y0-16, z=z0}
|
|
||||||
local minpos2d = {x=x0, y=z0}
|
|
||||||
|
|
||||||
nobj_terrain = nobj_terrain or minetest.get_perlin_map(np_terrain, chulens3d)
|
|
||||||
nobj_spike = nobj_spike or minetest.get_perlin_map(np_spike, chulens2d)
|
|
||||||
|
|
||||||
local nvals_terrain = nobj_terrain:get3dMap_flat(minpos3d)
|
|
||||||
local nvals_spike = nobj_spike:get2dMap_flat(minpos2d)
|
|
||||||
|
|
||||||
local ni3d = 1
|
|
||||||
local ni2d = 1
|
|
||||||
local stable = {}
|
|
||||||
local under = {}
|
|
||||||
for z = oz0, oz1 do
|
|
||||||
for x = ox0, ox1 do
|
|
||||||
local si = x - ox0 + 1
|
|
||||||
stable[si] = 0
|
|
||||||
end
|
|
||||||
for y = oy0 - 16, oy1 + 1 do
|
|
||||||
local vi = area:index(x0, y, z)
|
|
||||||
for x = ox0, ox1 do
|
|
||||||
local si = x - ox0 + 1
|
|
||||||
local viu = vi - ystride
|
|
||||||
|
|
||||||
local n_terrain = nvals_terrain[ni3d]
|
|
||||||
local n_spike = nvals_spike[ni2d]
|
|
||||||
local spikeoff = 0
|
|
||||||
if n_spike > TSPIKE then
|
|
||||||
spikeoff = (n_spike - TSPIKE) ^ 4 * SPIKEAMP
|
|
||||||
end
|
|
||||||
local grad = (YSURFCEN - y) / TERSCA + spikeoff
|
|
||||||
if y > YSURFMAX then
|
|
||||||
grad = math.max(
|
|
||||||
-FLOATFAC * math.abs(math.cos((y - YSURFMAX) * floatper)),
|
|
||||||
grad
|
|
||||||
)
|
|
||||||
elseif y < YSURFMIN then
|
|
||||||
grad = math.min(
|
|
||||||
UNDERFAC * (y - YUNDERCEN) ^ 2 + UNDEROFF,
|
|
||||||
grad
|
|
||||||
)
|
|
||||||
end
|
|
||||||
local density = n_terrain + grad
|
|
||||||
|
|
||||||
if y < oy0 then
|
|
||||||
if density >= TSTONE then
|
|
||||||
stable[si] = stable[si] + 1
|
|
||||||
elseif density <= 0 then
|
|
||||||
stable[si] = 0
|
|
||||||
end
|
|
||||||
if y == oy0 - 1 then
|
|
||||||
local nodid = data[vi]
|
|
||||||
if nodid == c_stone
|
|
||||||
or nodid == c_sand
|
|
||||||
or nodid == c_grass
|
|
||||||
or nodid == c_dirt
|
|
||||||
or nodid == c_luxore then
|
|
||||||
stable[si] = STABLE
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif y >= oy0 and y <= oy1 then
|
|
||||||
if density >= TSTONE then
|
|
||||||
if math.random() < LUXCHA and y < YSURFMIN
|
|
||||||
and density < 0.01 and data[viu] == c_stone then
|
|
||||||
data[vi] = c_luxore
|
|
||||||
else
|
|
||||||
data[vi] = c_stone
|
|
||||||
end
|
|
||||||
stable[si] = stable[si] + 1
|
|
||||||
under[si] = 0
|
|
||||||
elseif density > 0 and density < TSTONE
|
|
||||||
and stable[si] >= STABLE and y > YSURFMIN then
|
|
||||||
if y <= YSAND then
|
|
||||||
data[vi] = c_sand
|
|
||||||
under[si] = 0
|
|
||||||
else
|
|
||||||
data[vi] = c_dirt
|
|
||||||
under[si] = 1
|
|
||||||
end
|
|
||||||
elseif y > YSURFMIN and y <= YWATER then
|
|
||||||
data[vi] = c_water
|
|
||||||
stable[si] = 0
|
|
||||||
under[si] = 0
|
|
||||||
elseif y <= YLAVA then
|
|
||||||
data[vi] = c_lava
|
|
||||||
stable[si] = 0
|
|
||||||
under[si] = 0
|
|
||||||
else -- air, possibly just above surface
|
|
||||||
if under[si] == 1 then
|
|
||||||
data[viu] = c_grass
|
|
||||||
end
|
|
||||||
stable[si] = 0
|
|
||||||
under[si] = 0
|
|
||||||
end
|
|
||||||
elseif y == oy1 + 1 then
|
|
||||||
if density <= 0 and y > YWATER then -- air, possibly just above surface
|
|
||||||
if under[si] == 1 then
|
|
||||||
data[viu] = c_grass
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
ni3d = ni3d + 1
|
|
||||||
ni2d = ni2d + 1
|
|
||||||
vi = vi + 1
|
|
||||||
end
|
|
||||||
ni2d = ni2d - sidelen
|
|
||||||
end
|
|
||||||
ni2d = ni2d + sidelen
|
|
||||||
end
|
end
|
||||||
|
vm:set_data(vm_data)
|
||||||
vm:set_data(data)
|
vm:calc_lighting(false)
|
||||||
vm:calc_lighting()
|
vm:write_to_map(false)
|
||||||
vm:write_to_map(data)
|
|
||||||
vm:update_liquids()
|
|
||||||
|
|
||||||
-- local chugent = math.ceil((os.clock() - t0) * 1000)
|
|
||||||
-- print ("[levels] "..chugent.." ms")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
multi_map.append_generator(generate)
|
||||||
|
|
Loading…
Reference in New Issue