Return the surface world.

This commit is contained in:
Duane Robertson 2016-05-19 22:14:31 -05:00
parent 0ad60d974b
commit 6f25d3c388
2 changed files with 178 additions and 202 deletions

View file

@ -10,64 +10,45 @@ if not mobs or not mobs.mod then
end end
--fun_caves.ores = {}
minetest.register_on_mapgen_init(function(mgparams) minetest.register_on_mapgen_init(function(mgparams)
minetest.set_mapgen_params({mgname="singlenode", flags="nolight"}) --minetest.set_mapgen_params({mgname="singlenode", flags="nolight"})
minetest.set_mapgen_params({flags="nocaves,nodungeons"})
--local ores = {}
--for id, ore_table in pairs(minetest.registered_ores) do
-- local ore = table.copy(ore_table)
-- local ore2 = table.copy(ore_table)
-- table.insert(fun_caves.ores, ore2)
-- ore.y_min = -31000
-- ore.y_max = 31000
-- table.insert(ores, ore)
-- print(dump(ore))
--end
--minetest.clear_registered_ores()
end) end)
fun_caves.ores = {} --function fun_caves.set_ores(biome, y)
if default then -- local ores = fun_caves.ores
if default.register_ores then --
default.register_ores() -- --print("generating ores based on biome: "..biome)
end -- local y_factor = (math.abs(biome) - 0.4) * -2000
if default.register_blobs then -- --print("y_factor: "..y_factor)
default.register_blobs() --
end -- minetest.clear_registered_ores()
if default.register_biomes then -- for id, ore_table in pairs(ores) do
default.register_biomes() -- local ore = table.copy(ore_table)
end -- if ore.y_max >= y_factor and y <= ore.y_max then
if default.register_decorations then -- --if ore.y_max >= y_factor then
default.register_decorations() -- --print("using ore: "..ore.ore..", y_max: "..ore.y_max)
end -- ore.y_min = -31000
if flowers.register_decorations then -- ore.y_max = 31000
flowers.register_decorations() -- minetest.register_ore(ore)
end -- end
-- end
local ores = {} --end
for id, ore_table in pairs(minetest.registered_ores) do
local ore = table.copy(ore_table)
local ore2 = table.copy(ore_table)
table.insert(fun_caves.ores, ore2)
ore.y_min = -31000
ore.y_max = 31000
table.insert(ores, ore)
end
minetest.clear_registered_ores()
for _, ore in pairs(ores) do
minetest.register_ore(ore)
end
end
function fun_caves.set_ores(biome)
local ores = fun_caves.ores
--print("generating ores based on biome: "..biome)
local y_factor = (math.abs(biome) - 0.4) * -2000
--print("y_factor: "..y_factor)
minetest.clear_registered_ores()
for id, ore_table in pairs(ores) do
local ore = table.copy(ore_table)
if ore.y_max >= y_factor then
--print("using ore: "..ore.ore..", y_max: "..ore.y_max)
ore.y_min = -31000
ore.y_max = 31000
minetest.register_ore(ore)
end
end
end
-- Check if the table contains an element. -- Check if the table contains an element.
@ -130,12 +111,12 @@ dofile(fun_caves.path .. "/mapgen.lua")
dofile(fun_caves.path .. "/mobs.lua") dofile(fun_caves.path .. "/mobs.lua")
minetest.register_on_newplayer(fun_caves.respawn) --minetest.register_on_newplayer(fun_caves.respawn)
minetest.register_on_respawnplayer(fun_caves.respawn) --minetest.register_on_respawnplayer(fun_caves.respawn)
-- Inserting helps to ensure that fun_caves operates first. -- Inserting helps to ensure that fun_caves operates first.
table.insert(minetest.registered_on_generateds, 1, fun_caves.generate) table.insert(minetest.registered_on_generateds, 1, fun_caves.generate)
minetest.register_on_joinplayer(function(player) --minetest.register_on_joinplayer(function(player)
player:set_sky("#000000", "plain", {}) -- player:set_sky("#000000", "plain", {})
end) --end)

View file

@ -11,7 +11,7 @@ local node = fun_caves.node
local data = {} local data = {}
local p2data = {} -- vm rotation data buffer local p2data = {} -- vm rotation data buffer
local lightmap = {} local lightmap = {}
local vm, emin, emax, area, csize local vm, emin, emax, area, noise_area, csize
local div_sz_x, div_sz_z, minp, maxp, terrain, cave local div_sz_x, div_sz_z, minp, maxp, terrain, cave
if fun_caves.world then if fun_caves.world then
@ -162,8 +162,10 @@ function fun_caves.generate(p_minp, p_maxp, seed)
vm, emin, emax = minetest.get_mapgen_object("voxelmanip") vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
vm:get_data(data) vm:get_data(data)
--p2data = vm:get_param2_data() --p2data = vm:get_param2_data()
local heightmap = minetest.get_mapgen_object("heightmap")
area = VoxelArea:new({MinEdge = emin, MaxEdge = emax}) area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
csize = vector.add(vector.subtract(maxp, minp), 1) csize = vector.add(vector.subtract(maxp, minp), 1)
noise_area = VoxelArea:new({MinEdge={x=0,y=0,z=0}, MaxEdge=vector.subtract(csize, 1)})
-- Deal with memory issues. This, of course, is supposed to be automatic. -- Deal with memory issues. This, of course, is supposed to be automatic.
local mem = math.floor(collectgarbage("count")/1024) local mem = math.floor(collectgarbage("count")/1024)
@ -188,38 +190,26 @@ function fun_caves.generate(p_minp, p_maxp, seed)
for x = minp.x, maxp.x do for x = minp.x, maxp.x do
index = index + 1 index = index + 1
local dx = x - minp.x local dx = x - minp.x
index3d = dz * csize.y * csize.x + dx + 1 index3d = noise_area:index(dx, 0, dz)
local ivm = area:index(x, minp.y, z) local ivm = area:index(x, minp.y, z)
for y = minp.y, maxp.y do for y = minp.y, maxp.y do
local dy = y - minp.y if y <= heightmap[index] - 10 or (y <= heightmap[index] and data[ivm] == node("default:stone")) then
if cave_1[index3d] * cave_2[index3d] > 0.05 then
data[ivm] = node("air")
end
local n1 = cave_2[index3d] local biome_val = biome_n[index3d]
local n2 = cave_1[index3d] biome_avg = biome_avg + biome_val
biome_ct = biome_ct + 1
if n1 * n2 > 0.05 then
data[ivm] = node("air")
else
data[ivm] = node("default:stone")
end end
local biome_val = biome_n[index3d]
biome_avg = biome_avg + biome_val
biome_ct = biome_ct + 1
ivm = ivm + area.ystride ivm = ivm + area.ystride
index3d = index3d + csize.x index3d = index3d + csize.x
end end
end end
end end
vm:set_data(data)
biome_avg = biome_avg / biome_ct
fun_caves.set_ores(biome_avg)
minetest.generate_ores(vm, minp, maxp)
vm:get_data(data)
local noise_area = VoxelArea:new({MinEdge={x=0,y=0,z=0}, MaxEdge=vector.subtract(csize, 1)})
local index = 0 local index = 0
local index3d = 0 local index3d = 0
for z = minp.z, maxp.z do for z = minp.z, maxp.z do
@ -232,140 +222,145 @@ function fun_caves.generate(p_minp, p_maxp, seed)
local ivm = area:index(x, maxp.y, z) local ivm = area:index(x, maxp.y, z)
for y = maxp.y, minp.y, -1 do for y = maxp.y, minp.y, -1 do
local ivm_below = ivm - area.ystride if y <= heightmap[index] - 20 then
local ivm_above = ivm + area.ystride local ivm_below = ivm - area.ystride
local dy = y - minp.y local ivm_above = ivm + area.ystride
local dy = y - minp.y
------------------- -------------------
local stone_type = node("default:stone") local stone_type = node("default:stone")
local stone_depth = 1 local stone_depth = 1
local biome_val = biome_n[index3d] local biome_val = biome_n[index3d]
------------------- if y > heightmap[index] - 500 then
--biome_val = 0.3 biome_val = biome_val / math.max(1, math.log(500 - (heightmap[index] - y)))
------------------- end
if biome_val < -0.6 then -------------------
if true then --biome_val = 0.3
stone_type = node("default:ice") -------------------
if biome_val < -0.6 then
if true then
stone_type = node("default:ice")
stone_depth = 2
else
stone_type = node("fun_caves:thinice")
stone_depth = 2
end
elseif biome_val < -0.5 then
stone_type = node("fun_caves:stone_with_lichen")
elseif biome_val < -0.3 then
stone_type = node("fun_caves:stone_with_moss")
elseif biome_val < -0.0 then
stone_type = node("fun_caves:stone_with_lichen")
elseif biome_val < 0.2 then
stone_type = node("fun_caves:stone_with_algae")
elseif biome_val < 0.35 then
stone_type = node("fun_caves:stone_with_salt")
stone_depth = 2
if data[ivm] == node("default:stone") then
data[ivm] = stone_type
end
elseif biome_val < 0.5 then
stone_type = node("default:sand")
stone_depth = 2
elseif biome_val < 0.6 then
stone_type = node("default:coalblock")
stone_depth = 2 stone_depth = 2
else else
stone_type = node("fun_caves:thinice") stone_type = node("fun_caves:hot_cobble")
stone_depth = 2
end
elseif biome_val < -0.5 then
stone_type = node("fun_caves:stone_with_lichen")
elseif biome_val < -0.3 then
stone_type = node("fun_caves:stone_with_moss")
elseif biome_val < -0.0 then
stone_type = node("fun_caves:stone_with_lichen")
elseif biome_val < 0.2 then
stone_type = node("fun_caves:stone_with_algae")
elseif biome_val < 0.35 then
stone_type = node("fun_caves:stone_with_salt")
stone_depth = 2
if data[ivm] == node("default:stone") then
data[ivm] = stone_type
end
elseif biome_val < 0.5 then
stone_type = node("default:sand")
stone_depth = 2
elseif biome_val < 0.6 then
stone_type = node("default:coalblock")
stone_depth = 2
else
stone_type = node("fun_caves:hot_cobble")
end
-- "glow"
if data[ivm] == node("air") then
-- Change stone per biome.
if data[ivm_below] == node("default:stone") or (stone_type == node("fun_caves:stone_with_salt") and data[ivm_below] ~= node("fun_caves:stone_with_salt") and data[ivm_below] ~= node("air")) then
data[ivm_below] = stone_type
if stone_type == node("fun_caves:stone_with_salt") and math.random(500) == 1 then
data[ivm_below - area.ystride] = node("fun_caves:radioactive_ore")
elseif stone_depth == 2 then
data[ivm_below - area.ystride] = stone_type
end
end
if data[ivm_above] == node("default:stone") or (stone_type == node("fun_caves:stone_with_salt") and data[ivm_above] ~= node("fun_caves:stone_with_salt") and data[ivm_above] ~= node("air")) then
data[ivm_above] = stone_type
if stone_type == node("fun_caves:stone_with_salt") and math.random(500) == 1 then
data[ivm_above - area.ystride] = node("fun_caves:radioactive_ore")
elseif stone_depth == 2 then
data[ivm_above + area.ystride] = stone_type
end
end
if (data[ivm_above] == node("fun_caves:stone_with_lichen") or data[ivm_above] == node("fun_caves:stone_with_moss")) and math.random(1,50) == 1 then
data[ivm_above] = node("fun_caves:glowing_fungal_stone")
end end
-- "glow"
if data[ivm] == node("air") then if data[ivm] == node("air") then
local sr = math.random(1,1000) -- Change stone per biome.
if data[ivm_below] == node("default:stone") or (stone_type == node("fun_caves:stone_with_salt") and data[ivm_below] ~= node("fun_caves:stone_with_salt") and data[ivm_below] ~= node("air")) then
data[ivm_below] = stone_type
if stone_type == node("fun_caves:stone_with_salt") and math.random(500) == 1 then
data[ivm_below - area.ystride] = node("fun_caves:radioactive_ore")
elseif stone_depth == 2 then
data[ivm_below - area.ystride] = stone_type
end
end
if data[ivm_above] == node("default:stone") or (stone_type == node("fun_caves:stone_with_salt") and data[ivm_above] ~= node("fun_caves:stone_with_salt") and data[ivm_above] ~= node("air")) then
data[ivm_above] = stone_type
if stone_type == node("fun_caves:stone_with_salt") and math.random(500) == 1 then
data[ivm_above - area.ystride] = node("fun_caves:radioactive_ore")
elseif stone_depth == 2 then
data[ivm_above + area.ystride] = stone_type
end
end
-- fluids if (data[ivm_above] == node("fun_caves:stone_with_lichen") or data[ivm_above] == node("fun_caves:stone_with_moss")) and math.random(1,50) == 1 then
if (data[ivm_below] == node("default:stone") or data[ivm_below] == node("fun_caves:hot_cobble")) and sr < 3 then data[ivm_above] = node("fun_caves:glowing_fungal_stone")
end
if data[ivm] == node("air") then
local sr = math.random(1,1000)
-- fluids
if (data[ivm_below] == node("default:stone") or data[ivm_below] == node("fun_caves:hot_cobble")) and sr < 3 then
data[ivm] = node("default:lava_source") data[ivm] = node("default:lava_source")
elseif data[ivm_below] == node("fun_caves:stone_with_moss") and sr < 3 then elseif data[ivm_below] == node("fun_caves:stone_with_moss") and sr < 3 then
data[ivm] = node("default:water_source") data[ivm] = node("default:water_source")
-- hanging down -- hanging down
elseif data[ivm_above] == node("default:ice") and sr < 80 then elseif data[ivm_above] == node("default:ice") and sr < 80 then
data[ivm] = node("fun_caves:icicle_down") data[ivm] = node("fun_caves:icicle_down")
elseif (data[ivm_above] == node("fun_caves:stone_with_lichen") or data[ivm_above] == node("fun_caves:stone_with_moss") or data[ivm_above] == node("fun_caves:stone_with_algae") or data[ivm_above] == node("default:stone")) and sr < 80 then elseif (data[ivm_above] == node("fun_caves:stone_with_lichen") or data[ivm_above] == node("fun_caves:stone_with_moss") or data[ivm_above] == node("fun_caves:stone_with_algae") or data[ivm_above] == node("default:stone")) and sr < 80 then
if data[ivm_above] == node("fun_caves:stone_with_algae") then if data[ivm_above] == node("fun_caves:stone_with_algae") then
data[ivm] = node("fun_caves:stalactite_slimy") data[ivm] = node("fun_caves:stalactite_slimy")
elseif data[ivm_above] == node("fun_caves:stone_with_moss") then elseif data[ivm_above] == node("fun_caves:stone_with_moss") then
data[ivm] = node("fun_caves:stalactite_mossy") data[ivm] = node("fun_caves:stalactite_mossy")
else else
data[ivm] = node("fun_caves:stalactite") data[ivm] = node("fun_caves:stalactite")
end end
-- standing up -- standing up
elseif data[ivm_below] == node("fun_caves:hot_cobble") and sr < 20 then elseif data[ivm_below] == node("fun_caves:hot_cobble") and sr < 20 then
if sr < 10 then if sr < 10 then
data[ivm] = node("fun_caves:hot_spike") data[ivm] = node("fun_caves:hot_spike")
else else
data[ivm] = node("fun_caves:hot_spike_"..(math.ceil(sr / 3) - 2)) data[ivm] = node("fun_caves:hot_spike_"..(math.ceil(sr / 3) - 2))
end end
elseif data[ivm_below] == node("default:coalblock") and sr < 20 then elseif data[ivm_below] == node("default:coalblock") and sr < 20 then
data[ivm] = node("fun_caves:constant_flame") data[ivm] = node("fun_caves:constant_flame")
elseif data[ivm_below] == node("default:ice") and sr < 80 then elseif data[ivm_below] == node("default:ice") and sr < 80 then
data[ivm] = node("fun_caves:icicle_up") data[ivm] = node("fun_caves:icicle_up")
elseif (data[ivm_below] == node("fun_caves:stone_with_lichen") or data[ivm_below] == node("fun_caves:stone_with_algae") or data[ivm_below] == node("default:stone") or data[ivm_below] == node("fun_caves:stone_with_moss")) and sr < 80 then elseif (data[ivm_below] == node("fun_caves:stone_with_lichen") or data[ivm_below] == node("fun_caves:stone_with_algae") or data[ivm_below] == node("default:stone") or data[ivm_below] == node("fun_caves:stone_with_moss")) and sr < 80 then
if data[ivm_below] == node("fun_caves:stone_with_algae") then if data[ivm_below] == node("fun_caves:stone_with_algae") then
data[ivm] = node("fun_caves:stalagmite_slimy") data[ivm] = node("fun_caves:stalagmite_slimy")
elseif data[ivm_below] == node("fun_caves:stone_with_moss") then elseif data[ivm_below] == node("fun_caves:stone_with_moss") then
data[ivm] = node("fun_caves:stalagmite_mossy") data[ivm] = node("fun_caves:stalagmite_mossy")
elseif data[ivm_below] == node("fun_caves:stone_with_lichen") or data[ivm_above] == node("default:stone") then elseif data[ivm_below] == node("fun_caves:stone_with_lichen") or data[ivm_above] == node("default:stone") then
data[ivm] = node("fun_caves:stalagmite") data[ivm] = node("fun_caves:stalagmite")
end end
elseif data[ivm_below] == node("fun_caves:stone_with_moss") and sr < 90 then elseif data[ivm_below] == node("fun_caves:stone_with_moss") and sr < 90 then
data[ivm_below] = node("fun_caves:glowing_fungal_stone") data[ivm_below] = node("fun_caves:glowing_fungal_stone")
-- vegetation -- vegetation
elseif (data[ivm_below] == node("fun_caves:stone_with_lichen") or data[ivm_below] == node("fun_caves:stone_with_algae")) and biome_val >= -0.5 then elseif (data[ivm_below] == node("fun_caves:stone_with_lichen") or data[ivm_below] == node("fun_caves:stone_with_algae")) and biome_val >= -0.5 then
if sr < 110 then if sr < 110 then
data[ivm] = node("flowers:mushroom_red") data[ivm] = node("flowers:mushroom_red")
elseif sr < 140 then elseif sr < 140 then
data[ivm] = node("flowers:mushroom_brown") data[ivm] = node("flowers:mushroom_brown")
elseif air_count > 1 and sr < 160 then elseif air_count > 1 and sr < 160 then
data[ivm_above] = node("fun_caves:huge_mushroom_cap") data[ivm_above] = node("fun_caves:huge_mushroom_cap")
data[ivm] = node("fun_caves:giant_mushroom_stem") data[ivm] = node("fun_caves:giant_mushroom_stem")
elseif air_count > 2 and sr < 170 then elseif air_count > 2 and sr < 170 then
data[ivm + 2 * area.ystride] = node("fun_caves:giant_mushroom_cap") data[ivm + 2 * area.ystride] = node("fun_caves:giant_mushroom_cap")
data[ivm_above] = node("fun_caves:giant_mushroom_stem") data[ivm_above] = node("fun_caves:giant_mushroom_stem")
data[ivm] = node("fun_caves:giant_mushroom_stem") data[ivm] = node("fun_caves:giant_mushroom_stem")
elseif air_count > 5 and sr < 180 then elseif air_count > 5 and sr < 180 then
fun_caves.make_fungal_tree(data, area, ivm, math.random(2,math.min(air_count, 12)), node(fun_caves.fungal_tree_leaves[math.random(1,#fun_caves.fungal_tree_leaves)]), node("fun_caves:fungal_tree_fruit")) fun_caves.make_fungal_tree(data, area, ivm, math.random(2,math.min(air_count, 12)), node(fun_caves.fungal_tree_leaves[math.random(1,#fun_caves.fungal_tree_leaves)]), node("fun_caves:fungal_tree_fruit"))
data[ivm_below] = node("dirt") data[ivm_below] = node("dirt")
elseif sr < 300 then elseif sr < 300 then
data[ivm_below] = node("dirt") data[ivm_below] = node("dirt")
end end
if data[ivm] ~= node("air") then if data[ivm] ~= node("air") then
data[ivm_below] = node("dirt") data[ivm_below] = node("dirt")
end
end end
end end
end
if data[ivm] == node("air") then if data[ivm] == node("air") then
air_count = air_count + 1 air_count = air_count + 1
end
end end
end end