83 lines
2.5 KiB
Lua
83 lines
2.5 KiB
Lua
-- Imports -----------------------------------------------------------------------------------------
|
|
|
|
-- Since we're in the mapgen environment, we can't count on the mod loading process. Instead, we
|
|
-- have to load everything we need from other mods manually.
|
|
|
|
local core = _G["core"]
|
|
local api = _G["jvmi_biomes"]
|
|
|
|
local path = core.get_modpath("jvmi_constants")
|
|
dofile(path.."/constants.lua")
|
|
local C = _G["jvmi_constants"]
|
|
|
|
path = core.get_modpath("jvmi_mapgen")
|
|
dofile(path.."/init.lua")
|
|
local mapgen = _G["jvmi_mapgen"]
|
|
local Region = mapgen.Region
|
|
|
|
|
|
-- Private -----------------------------------------------------------------------------------------
|
|
|
|
local private = {}
|
|
|
|
--[[
|
|
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
|
|
|
|
|
|
-- API Implementations -----------------------------------------------------------------------------
|
|
|
|
function api.apply_biomes(region)
|
|
private.assign_biomes(region)
|
|
|
|
private.fill_surface(region)
|
|
end
|