More work being done. And... bugs.

This commit is contained in:
DesertMermaid 2024-12-11 14:47:15 -08:00
parent 0242488c9e
commit a260c4a33a
20 changed files with 1102 additions and 80 deletions

View file

@ -11,58 +11,145 @@
-- with this program; if not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
vox_mapgen_core = { }
vox_mapgen_core = {}
-- Also run...
dofile(minetest.get_modpath("vox_mapgen_core").."/ores.lua")
-- -------------------------------------------------------------- --
-- Configuration: Noise Parameters
-- -------------------------------------------------------------- --
local noise_heat = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 1234,
octaves = 3,
persistence = 0.5,
lacunarity = 2.0,
}
-- Disable minetest dungeons. We're making our own with blackjack and hookers.
minetest.set_mapgen_setting("mg_flags", "dungeons", false)
local noise_humidity = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 5678,
octaves = 3,
persistence = 0.5,
lacunarity = 2.0,
}
-- Some adjustments based on different generators.
-- For now we allow v7, and haven't looked at the other generators.
if mg_name == "v7" then
minetest.set_mapgen_setting("mg7_cavern_threshold", 0.2, true)
minetest.set_mapgen_setting("mg_flags", "dungeons", false)
end
local noise_altitude = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 91011,
octaves = 3,
persistence = 0.5,
lacunarity = 2.0,
}
-- And some superflat tweaks.
if superflat then
-- Disable caves
minetest.set_mapgen_setting("mg_flags", "caves", false)
-- Disable dungeons
minetest.set_mapgen_setting("mg_flags", "dungeons", false)
-- Disable decorations
minetest.set_mapgen_setting("mg_flags", "decoration", false)
minetest.set_mapgen_setting("mgflat_spflags", "nocaves,nohills", true)
end
local biome_size_noise = {
offset = 0,
scale = 10,
spread = {x = 2000, y = 2000, z = 2000},
seed = 78910,
octaves = 2,
persistence = 0.4,
lacunarity = 2.0,
}
-- Generate flat bedrock at the lowest point of the world, -10000.
local function generate_bedrock(minp, maxp, data)
local vi = 0
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
for y = -10000, -10000 do
local c_air = minetest.get_content_id("air")
data[vi] = c_air
vi = vi + 1
end
-- Apply noise parameters to the map generator
minetest.register_on_mapgen_init(function(mapgen_params)
minetest.set_mapgen_setting_noiseparams("heat", noise_heat, true)
minetest.set_mapgen_setting_noiseparams("humidity", noise_humidity, true)
minetest.set_mapgen_setting_noiseparams("altitude", noise_altitude, true)
end)
-- -------------------------------------------------------------- --
-- Biome Assignment Logic
-- -------------------------------------------------------------- --
local function get_biome(heat, humidity, altitude)
if heat > 70 and humidity < 30 then
return "desert"
elseif heat > 70 and humidity > 50 then
if altitude > 100 then
return "volcanic_fields"
end
return "savannah"
elseif heat > 50 and humidity > 70 then
return "tropical_rainforest"
elseif heat < 30 and humidity > 60 then
return "boreal_forest"
elseif heat < 10 and humidity > 40 then
return "frozen_tundra"
elseif altitude > 256 then
return "jade_cliffs"
else
return "grassland" -- Default biome
end
end
-- Put air/void beneath bedrock
local function generate_void(minp, maxp, data)
local vi = 0
local function blend_biomes(current_biome, neighbor_biome, distance)
if distance < 10 and math.random() < 0.5 then
return neighbor_biome
end
return current_biome
end
-- -------------------------------------------------------------- --
-- Map Generation Logic
-- -------------------------------------------------------------- --
minetest.register_on_generated(function(minp, maxp, seed)
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
local data = vm:get_data()
-- Generate noise maps
local heat_map = minetest.get_perlin_map(noise_heat, {x = maxp.x - minp.x + 1, y = maxp.z - minp.z + 1})
local humidity_map = minetest.get_perlin_map(noise_humidity, {x = maxp.x - minp.x + 1, y = maxp.z - minp.z + 1})
local altitude_map = minetest.get_perlin_map(noise_altitude, {x = maxp.x - minp.x + 1, y = maxp.z - minp.z + 1})
local biome_size_map = minetest.get_perlin_map(biome_size_noise, {x = maxp.x - minp.x + 1, y = maxp.z - minp.z + 1})
local heat = heat_map:get_2d_map_flat({x = minp.x, y = minp.z})
local humidity = humidity_map:get_2d_map_flat({x = minp.x, y = minp.z})
local altitude = altitude_map:get_2d_map_flat({x = minp.x, y = minp.z})
local biome_sizes = biome_size_map:get_2d_map_flat({x = minp.x, y = minp.z})
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
for y = -10001, -31000 do
local c_air = minetest.get_content_id("air")
data[vi] = c_air
vi = vi + 1
local index2d = (z - minp.z) * (maxp.x - minp.x + 1) + (x - minp.x + 1)
local h = heat[index2d]
local hum = humidity[index2d]
local alt = altitude[index2d]
local biome_size = biome_sizes[index2d]
local current_biome = get_biome(h, hum, alt)
local neighbor_biome = get_biome(h + 5, hum + 5, alt)
current_biome = blend_biomes(current_biome, neighbor_biome, biome_size)
-- Fetch biome properties
local node_top = core.get_biome_top_node(current_biome) or "vox_worldblocks:grass"
local node_filler = core.get_biome_filler_node(current_biome) or "vox_worldblocks:dirt"
local depth_top = core.get_biome_depth_top(current_biome) or 1
local depth_filler = core.get_biome_depth_filler(current_biome) or 3
for y = minp.y, maxp.y do
local vi = area:index(x, y, z)
if y == minp.y then
data[vi] = minetest.get_content_id("vox_worldblocks:bedrock")
elseif y < -10001 then
data[vi] = minetest.get_content_id("air")
elseif y <= minp.y + depth_top then
data[vi] = minetest.get_content_id(node_top)
elseif y <= minp.y + depth_top + depth_filler then
data[vi] = minetest.get_content_id(node_filler)
else
data[vi] = minetest.get_content_id("air")
end
end
end
end
end
vm:set_data(data)
vm:write_to_map()
end)

View file

@ -0,0 +1,42 @@
# Biome Registry Template
```lua
core.register_biome({
name = "temperate_forest",
node_top = "vox_worldblocks:grass", -- Top surface block
depth_top = 1, -- Depth of the top block
node_filler = "vox_worldblocks:dirt", -- Subsurface block
depth_filler = 3, -- Depth of filler layer
node_stone = "vox_worldblocks:stone", -- Base stone layer
node_riverbed = "vox_worldblocks:sand", -- Riverbed material
depth_riverbed = 2, -- Depth of riverbed material
node_river_water = "vox_worldblocks:water_source", -- Water source
heat_point = 45, -- Climate heat level
humidity_point = 70, -- Climate humidity level
height_min = 1, -- Minimum height for the biome
height_max = 128, -- Maximum height for the biome
decorations = {"flowers:rose", "flowers:tulip"}, -- Decoration nodes
biome_group = "temperate", -- Biome category (for climate/weather)
})
```
OLD:
```lua
core.register_biome({
name = "grassland",
node_top = "grass",
depth_top = 1,
node_filler = "vox_main:dirt",
node_stone = "vox_main:stone",
depth_filler = 3,
node_riverbed = "vox_main:sand",
node_river_water = "vox_main:water_source",
depth_riverbed = 2,
height_min = 1,
height_max = 256,
heat_point = 35,
humidity_point = 50
})
```

View file

@ -15,4 +15,5 @@ vox_overworld = {}
dofile(core.get_modpath(core.get_current_modname()) .. "/registry.lua")
-- Ensure vox_mapgen_core is loaded
--local mapgen_core = assert(vox_mapgen_core, "vox_mapgen_core must be loaded before vox_overworld")

View file

@ -2,27 +2,190 @@
-- Voxelis - Voxel survival sandbox for Luanti
-- Copyright (C) 2024 Mad Star Studio LLC
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------
core.register_biome({
-- -------------------------------------------------------------- --
-- BIOMES
-- -------------------------------------------------------------- --
-- Helper Function: Register Default Biome Properties
local function register_biome(params)
-- Set defaults for biome parameters
params.node_river_water = params.node_river_water or "vox_worldblocks:water_source"
params.depth_riverbed = params.depth_riverbed or 2
params.height_min = params.height_min or 1
params.height_max = params.height_max or 256
params.node_stone = params.node_stone or "vox_worldblocks:stone"
core.register_biome(params)
end
-- Grasslands
register_biome({
name = "grassland",
node_top = "grass",
node_top = "vox_worldblocks:grass",
depth_top = 1,
node_filler = "vox_main:dirt",
node_stone = "vox_main:stone",
node_filler = "vox_worldblocks:dirt",
depth_filler = 3,
node_riverbed = "vox_main:sand",
node_river_water = "vox_main:water_source",
depth_riverbed = 2,
height_min = 1,
height_max = 256,
heat_point = 35,
humidity_point = 50
humidity_point = 50,
})
-- Desert
register_biome({
name = "desert",
node_top = "vox_worldblocks:sand",
depth_top = 2,
node_filler = "vox_worldblocks:sandstone",
depth_filler = 5,
heat_point = 80,
humidity_point = 20,
})
-- Boreal Forest
register_biome({
name = "boreal_forest",
node_top = "vox_worldblocks:grass",
depth_top = 1,
node_filler = "vox_worldblocks:dirt",
depth_filler = 4,
heat_point = 20,
humidity_point = 60,
})
-- Frozen Tundra
register_biome({
name = "frozen_tundra",
node_top = "vox_worldblocks:snow",
depth_top = 1,
node_filler = "vox_worldblocks:packed_snow",
depth_filler = 3,
node_riverbed = "vox_worldblocks:ice",
heat_point = 5,
humidity_point = 40,
height_max = 150,
})
-- Rocky Badlands
register_biome({
name = "rocky_badlands",
node_top = "vox_worldblocks:stone",
depth_top = 2,
node_filler = "vox_worldblocks:gravel",
depth_filler = 4,
heat_point = 50,
humidity_point = 30,
height_min = 50,
height_max = 180,
})
-- Savannah
register_biome({
name = "savannah",
node_top = "vox_worldblocks:grass",
depth_top = 1,
node_filler = "vox_worldblocks:dirt",
depth_filler = 3,
heat_point = 70,
humidity_point = 30,
height_max = 512,
})
-- Mangrove Forest
register_biome({
name = "mangrove_forest",
node_top = "vox_worldblocks:grass",
depth_top = 1,
node_filler = "vox_worldblocks:mud",
depth_filler = 3,
node_riverbed = "vox_worldblocks:mud",
heat_point = 75,
humidity_point = 80,
height_min = -5,
height_max = 100,
})
-- Volcanic Fields
register_biome({
name = "volcanic_fields",
node_top = "vox_worldblocks:volcanic_rock",
depth_top = 1,
node_filler = "vox_worldblocks:basalt",
depth_filler = 5,
node_riverbed = "vox_worldblocks:lava_source",
node_river_water = "vox_worldblocks:lava_source",
heat_point = 90,
humidity_point = 10,
height_min = 50,
height_max = 512,
})
-- Salt Flats
register_biome({
name = "salt_flats",
node_top = "vox_worldblocks:salt_crystal",
depth_top = 2,
node_filler = "vox_worldblocks:sand",
depth_filler = 3,
heat_point = 80,
humidity_point = 20,
height_max = 100,
})
-- Jade Cliffs
register_biome({
name = "jade_cliffs",
node_top = "vox_worldblocks:grass",
depth_top = 1,
node_filler = "vox_worldblocks:stone",
depth_filler = 5,
node_stone = "vox_worldblocks:granite",
node_riverbed = "vox_worldblocks:gravel",
heat_point = 55,
humidity_point = 65,
height_min = 128,
height_max = 1024,
})
-- Painted Canyons
register_biome({
name = "painted_canyons",
node_top = "vox_worldblocks:terracotta_red",
depth_top = 1,
node_filler = "vox_worldblocks:terracotta_orange",
depth_filler = 4,
node_riverbed = "vox_worldblocks:terracotta_yellow",
heat_point = 65,
humidity_point = 25,
height_min = 10,
height_max = 256,
})
-- Iceberg Fields
register_biome({
name = "iceberg_fields",
node_top = "vox_worldblocks:ice",
depth_top = 1,
node_filler = "vox_worldblocks:snow",
depth_filler = 3,
node_riverbed = "vox_worldblocks:ice",
heat_point = -10,
humidity_point = 50,
height_min = -100,
height_max = 100,
})
-- Black Sand Beach
register_biome({
name = "black_sand_beach",
node_top = "vox_worldblocks:basalt",
depth_top = 2,
node_filler = "vox_worldblocks:sand",
depth_filler = 3,
heat_point = 65,
humidity_point = 80,
height_min = -5,
height_max = 5,
})