Mapgen: write SuperUltraSigmaMapgen part 8

This commit is contained in:
Van
2025-11-25 19:39:39 +03:00
parent 96cf459719
commit e61ea85c9a
9 changed files with 64 additions and 49 deletions

View File

@@ -43,6 +43,7 @@ local Cavern = require('MapGen.Layer.Cavern')
---@field cavernsNoiseInitialized boolean TODO: описание ---@field cavernsNoiseInitialized boolean TODO: описание
---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work. ---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work.
---@field nodeIDs table<string, number> ---@field nodeIDs table<string, number>
---@field waterLevel number
local MapGen = { local MapGen = {
layersByName = {}, layersByName = {},
layersList = {}, layersList = {},
@@ -51,12 +52,13 @@ local MapGen = {
isRunning = false, isRunning = false,
} }
---@param nodeIDs table<string, number> ---@param nodeIDs table<string, number>
---@return MapGen ---@return MapGen
function MapGen:new(nodeIDs) function MapGen:new(nodeIDs, waterLevel)
---@type MapGen ---@type MapGen
local instance = setmetatable({ local instance = setmetatable({
nodeIDs = nodeIDs, nodeIDs = nodeIDs,
waterLevel = waterLevel or 0,
}, {__index = self}) }, {__index = self})
return instance return instance
@@ -226,7 +228,7 @@ function MapGen:initPeaksMultinoise()
self.peaksMultinoiseInitialized = true self.peaksMultinoiseInitialized = true
end end
---TODO: описаение ---TODO: описание
function MapGen:initCavernsNoise() function MapGen:initCavernsNoise()
---@param layer MapGen.Layer ---@param layer MapGen.Layer
for _, layer in ipairs(self.layersList) do for _, layer in ipairs(self.layersList) do
@@ -280,26 +282,27 @@ end
---@param z number ---@param z number
local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z) local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z)
local ids = mapGenerator.nodeIDs local ids = mapGenerator.nodeIDs
local waterLevel = mapGenerator.waterLevel
local m = math.random(-5, 5) local m = math.random(-5, 5)
temp = mathMin(100, mathMax(0, temp + m)) temp = mathMin(100, mathMax(0, temp + m))
humidity = mathMin(100, mathMax(0, humidity + m)) humidity = mathMin(100, mathMax(0, humidity + m))
--height = mathMin(layer.maxY, mathMax(layer.minY, y + m)) --_height = mathMin(layer.maxY, mathMax(layer.minY, y + m))
---@type MapGen.Layer.Biome ---@type MapGen.Layer.Biome
local biome = layer.biomesDiagram[y][mathRound(temp)][mathRound(humidity)] local biome = layer.biomesDiagram[y][mathRound(temp)][mathRound(humidity)]
if y > height and y > 0 then if y > height and y > waterLevel then
data[index] = ids.air data[index] = ids.air
elseif y > height and y <= 0 then elseif y > height and y <= waterLevel then
data[index] = ids.water data[index] = ids.water
elseif y <= height then elseif y <= height then
if isCavern(layer, x, y, z) then if isCavern(layer, x, y, z) then
data[index] = ids.air data[index] = ids.air
elseif y == height and y >= 0 then elseif y == height and y >= waterLevel then
biome.generateSoil(mapGenerator, biome, data, index, x, y, z) biome.generateSoil(mapGenerator, biome, data, index, x, y, z)
elseif y == height and y < 0 then elseif y == height and y < waterLevel then
biome.generateBottom(mapGenerator, biome, data, index, x, y, z) biome.generateBottom(mapGenerator, biome, data, index, x, y, z)
else else
biome.generateRock(mapGenerator, biome, data, index, x, y, z) biome.generateRock(mapGenerator, biome, data, index, x, y, z)
@@ -614,6 +617,9 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed)
voxelManip:calc_lighting() voxelManip:calc_lighting()
voxelManip:update_liquids() voxelManip:update_liquids()
core.generate_ores(voxelManip, minPos, maxPos)
core.generate_decorations(voxelManip, minPos, maxPos)
--voxelManip:write_to_map() -- Async edit --voxelManip:write_to_map() -- Async edit
end end

View File

@@ -43,42 +43,6 @@ function Layer:addPeak(peak)
table.insert(self.peaksList, peak) table.insert(self.peaksList, peak)
end end
---Returns a list of tables of the form `{peak, weight}`.
---
---Maybe return an empty table.
---@param xPos number
---@param yPos number
---@param zPos number
---@return {peak : MapGen.Peak, weight : number}[] | table, number
function Layer:getPeaksByPos(xPos, yPos, zPos, radius)
---@type MapGen.Peak[]
local peaks = {}
--- @type vector
local peakPos
---@type number
local distance
---@type number
local weight
---@type number
local totalWeight = 0
---@param peak MapGen.Peak
for _, peak in ipairs(self.peaksList) do
peakPos = peak.getPeakPos()
distance = mathSqrt((xPos - peakPos.x)^2 + (yPos - peakPos.y)^2 + (zPos - peakPos.z)^2)
if distance <= radius then
weight = 1 / distance --/ radius
table.insert(peaks, {peak = peak, weight = weight})
totalWeight = totalWeight + weight
end
end
return peaks, totalWeight
end
---@param height number ---@param height number
---@param biomesList MapGen.Layer.Biome[] ---@param biomesList MapGen.Layer.Biome[]
---@return string[], MapGen.Layer.Biome[] ---@return string[], MapGen.Layer.Biome[]

View File

@@ -60,7 +60,8 @@ local mapGenerator = MapGen:new({
-- Liquids -- Liquids
water = id("liquids:water_source"), water = id("liquids:water_source"),
}) }, 10
)
mapGenerator:RegisterLayer("world", -1000, 500) mapGenerator:RegisterLayer("world", -1000, 500)

View File

@@ -2,3 +2,22 @@
-- The Mapgen environment is isolated from the main enviroment. -- The Mapgen environment is isolated from the main enviroment.
core.register_mapgen_script(core.get_modpath(core.get_current_modname())..'/MapGenerator.lua') core.register_mapgen_script(core.get_modpath(core.get_current_modname())..'/MapGenerator.lua')
core.register_ore({
ore_type = "scatter",
ore = "soils:rocky_soil_baren",
wherein = "rocks:sylite",
clust_scarcity = 8*8*8,
clust_num_ores = 8,
clust_size = 3,
y_min = -31000,
y_max = 64,
})
core.register_decoration({
deco_type = "simple",
place_on = "soils:clay_soil_baren",
sidelen = 8,
fill_ratio = 0.1,
decoration = "plants:plants",
})

View File

@@ -0,0 +1,23 @@
core.register_node(":plants:plants", {
description = 'Plant',
drawtype = "plantlike",
tiles = { "test_plant.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "meshoptions",
place_param2 = 3,
waving = 1,
walkable = false,
buildable_to = true,
groups = {dig_immediate = 2},
selection_box = {
type = "fixed",
fixed = { -0.15, -0.5, -0.15, 0.15, 0.2, 0.15 },
},
on_construct = function(pos)
local node = core.get_node(pos)
node.param2 = 3
end,
})

View File

@@ -0,0 +1,2 @@
name = smc__game__items__plants
depends = smc__core__node, smc__core__tilesheet

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -1,2 +1,2 @@
name = smc__game__items__rocks name = smc__game__items__rocks
depends = smc__core__node depends = smc__core__node, smc__core__tilesheet

View File

@@ -1,2 +1,2 @@
name = smc__game__items__soils name = smc__game__items__soils
depends = smc__core__node depends = smc__core__node, smc__core__tilesheet