This commit is contained in:
Andrew Miner
2026-10-26 11:07:59 -06:00
parent bfd7f78a69
commit a822ebbdfd
25 changed files with 178 additions and 181 deletions
+86
View File
@@ -0,0 +1,86 @@
-- Imports -----------------------------------------------------------------------------------------
local core = _G.core
local path = core.get_game_info().path
local C = dofile(path.."/common/constants.lua")
local Region = dofile(path.."/common/region.lua")
-- Private -----------------------------------------------------------------------------------------
local private = {}
--[[
Apply biomes to the given region.
This function will both update the `Region.META..BIOME` table so that each x,z column has an
assigned biome, but it will also update the data within the region to have that biome fully
applied from decorations to fill material.
Args:
region:Region - the region currently being generated
]]--
function private.apply(region)
private.assign_biomes(region)
private.fill_surface(region)
end
--[[
Assigns a specific biome to each position in the region.
Args:
region:Region - the region currently being generated
]]--
function private.assign_biomes(region)
region.iterate_columns(function(x, z)
local terrain_type = region:get_meta(Region.META.TERRAIN_TYPE, x, z)
local terrain = C.TERRAIN_TYPES[terrain_type]
region:set_meta(Region.META.BIOME, x, z, core.get_biome_id(terrain.name))
end)
end
--[[
Replace the upper layers of stone with biome-specific top and filler nodes.
Args:
region:Region - the region currently being generated
]]--
function private.fill_surface(region)
region.iterate_columns(function(x, z)
local biome_id = region:get_meta(Region.META.BIOME, x, z)
local biome_name = core.get_biome_name(biome_id)
local biome = core.registered_biomes[biome_name]
local y = region:get_meta(Region.META.ALTITUDE)
local top_count = biome.depth_top or 0
local filler_count = biome.depth_filler or 0
while y >= region.fill_min.y do
if top_count > 0 then
local content_id = core.get_content_id(biome.node_top)
if content_id then
region:set_content_id(x, y, z, content_id)
end
top_count = top_count - 1
elseif filler_count > 0 then
local content_id = core.get_content_id(biome.node_filler)
if content_id then
region:set_content_id(x, y, z, content_id)
end
filler_count = filler_count - 1
else
break
end
y = y - 1
end
end)
end
-- Export ------------------------------------------------------------------------------------------
return {
apply_to = private.apply
}