forked from Apancore.Studio/simple-makes-complex
Mapgen: write SuperUltraSigmaMapgen part 6.5
This commit is contained in:
@@ -208,17 +208,13 @@ end
|
|||||||
---TODO: описание
|
---TODO: описание
|
||||||
---@param layerName string
|
---@param layerName string
|
||||||
---@param cavernName string
|
---@param cavernName string
|
||||||
---@param minY number
|
---@param def MapGen.Layer.CavernDef
|
||||||
---@param maxY number
|
function MapGen:registerCavern(layerName, cavernName, def)
|
||||||
---@param smoothDistance number
|
|
||||||
---@param noiseParams NoiseParams
|
|
||||||
---@param groups? table<string, number>
|
|
||||||
function MapGen:registerCavern(layerName, cavernName, minY, maxY, smoothDistance, noiseParams, groups)
|
|
||||||
local layer = self.layersByName[layerName]
|
local layer = self.layersByName[layerName]
|
||||||
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
assert(layer ~= nil, ('There is no layer named `%s` registered.'):format(layerName))
|
||||||
assert(layer.cavernsByName[cavernName] == nil, ('A cavern named `%s` already exists in the `%s` layer.'):format(cavernName, layerName))
|
assert(layer.cavernsByName[cavernName] == nil, ('A cavern named `%s` already exists in the `%s` layer.'):format(cavernName, layerName))
|
||||||
|
|
||||||
local cavern = Cavern:new(cavernName, minY, maxY, smoothDistance, noiseParams, groups)
|
local cavern = Cavern:new(cavernName, def)
|
||||||
|
|
||||||
layer.cavernsByName[cavernName] = cavern
|
layer.cavernsByName[cavernName] = cavern
|
||||||
table.insert(layer.cavernsList, cavern)
|
table.insert(layer.cavernsList, cavern)
|
||||||
@@ -322,7 +318,7 @@ end
|
|||||||
---@return boolean
|
---@return boolean
|
||||||
local function isCavern(layer, x, y, z)
|
local function isCavern(layer, x, y, z)
|
||||||
for _, cavern in ipairs(layer.cavernsList) do
|
for _, cavern in ipairs(layer.cavernsList) do
|
||||||
if cavern:isCavern(x, y, z, 0.2) then
|
if cavern:isCavern(x, y, z) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -646,6 +642,8 @@ function MapGen:onMapGenerated(minPos, maxPos, blockseed)
|
|||||||
-- local param2_data = voxelManip:get_param2_data()
|
-- local param2_data = voxelManip:get_param2_data()
|
||||||
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
local area = VoxelArea:new({MinEdge = eMin, MaxEdge = eMax})
|
||||||
|
|
||||||
|
data[area:index(0,50,0)] = core.get_content_id('rocks:malachite')
|
||||||
|
|
||||||
local index
|
local index
|
||||||
-- Initial generation: landscape
|
-- Initial generation: landscape
|
||||||
for z = minPos.z, maxPos.z do
|
for z = minPos.z, maxPos.z do
|
||||||
@@ -653,10 +651,12 @@ function MapGen:onMapGenerated(minPos, maxPos, blockseed)
|
|||||||
for y = minPos.y, maxPos.y do
|
for y = minPos.y, maxPos.y do
|
||||||
index = area:index(x, y, z)
|
index = area:index(x, y, z)
|
||||||
|
|
||||||
|
if data[index] == core.CONTENT_AIR then
|
||||||
generatorHandler(self, data, index, x, y, z)
|
generatorHandler(self, data, index, x, y, z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- We make changes back to LVM and recalculate light & liquids
|
-- We make changes back to LVM and recalculate light & liquids
|
||||||
voxelManip:set_data(data)
|
voxelManip:set_data(data)
|
||||||
|
|||||||
@@ -6,43 +6,56 @@ local mathMin, mathMax, mathAbs
|
|||||||
---@field minY number
|
---@field minY number
|
||||||
---@field maxY number
|
---@field maxY number
|
||||||
---@field smoothDistance number
|
---@field smoothDistance number
|
||||||
|
---@field threshold number
|
||||||
---@field getNoise fun():ValueNoise
|
---@field getNoise fun():ValueNoise
|
||||||
---@field initNoise fun()
|
---@field initNoise fun()
|
||||||
---@field getGroups fun():table<string, number>
|
---@field getGroups fun():table<string, number>
|
||||||
local Cavern = {}
|
local Cavern = {}
|
||||||
|
|
||||||
|
---Definition table for the `MapGen.Layer.Cavern`.
|
||||||
|
---
|
||||||
|
---**Only for EmmyLua.**
|
||||||
|
---@class MapGen.Layer.CavernDef
|
||||||
|
---@field minY number
|
||||||
|
---@field maxY number
|
||||||
|
---@field noiseParams NoiseParams
|
||||||
|
---@field smoothDistance number
|
||||||
|
---@field threshold number?
|
||||||
|
---@field groups table<string, number>?
|
||||||
|
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param minY number
|
---@param def MapGen.Layer.CavernDef
|
||||||
---@param maxY number
|
|
||||||
---@param smoothDistance number
|
|
||||||
---@param noiseParams NoiseParams
|
|
||||||
---@param groups? table<string, number>
|
|
||||||
---@return MapGen.Layer.Cavern
|
---@return MapGen.Layer.Cavern
|
||||||
function Cavern:new(name, minY, maxY, smoothDistance, noiseParams, groups)
|
function Cavern:new(name, def)
|
||||||
assert(maxY > minY, 'maxY there should be more minY')
|
assert(def.maxY > def.minY, 'maxY there should be more minY')
|
||||||
assert(smoothDistance < mathAbs(maxY - minY)/2, 'The smoothing distance cannot be greater than half the distance between minY and maxY')
|
assert(def.smoothDistance < mathAbs(def.maxY - def.minY)/2, 'The smoothing distance cannot be greater than half the distance between minY and maxY')
|
||||||
|
|
||||||
---@type NoiseParams
|
---@type NoiseParams
|
||||||
local _noiseParams = noiseParams
|
local _noiseParams = def.noiseParams
|
||||||
|
|
||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
---@type ValueNoise
|
---@type ValueNoise
|
||||||
local _noise = {}-- note: must be nil until luanti mapgen objects are loaded.
|
local _noise = {} -- note: must be nil until luanti mapgen objects are loaded.
|
||||||
|
|
||||||
|
if def.threshold == nil then
|
||||||
|
def.threshold = 0.0
|
||||||
|
end
|
||||||
|
|
||||||
local _groups
|
local _groups
|
||||||
|
|
||||||
if groups == nil then
|
if def.groups == nil then
|
||||||
_groups = {}
|
_groups = {}
|
||||||
else
|
else
|
||||||
_groups = groups
|
_groups = def.groups
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type MapGen.Layer.Cavern
|
---@type MapGen.Layer.Cavern
|
||||||
local instance = setmetatable({
|
local instance = setmetatable({
|
||||||
name = name,
|
name = name,
|
||||||
minY = minY,
|
minY = def.minY,
|
||||||
maxY = maxY,
|
maxY = def.maxY,
|
||||||
smoothDistance = smoothDistance,
|
smoothDistance = def.smoothDistance,
|
||||||
|
threshold = def.threshold,
|
||||||
}, {__index = self})
|
}, {__index = self})
|
||||||
|
|
||||||
function instance:getNoise()
|
function instance:getNoise()
|
||||||
@@ -54,7 +67,7 @@ function Cavern:new(name, minY, maxY, smoothDistance, noiseParams, groups)
|
|||||||
minetest.log('warning', 'Cavern noise has already been initialized. Re-initialization is not recommended.')
|
minetest.log('warning', 'Cavern noise has already been initialized. Re-initialization is not recommended.')
|
||||||
end
|
end
|
||||||
|
|
||||||
_noise = core.get_value_noise(noiseParams)
|
_noise = core.get_value_noise(_noiseParams)
|
||||||
end
|
end
|
||||||
|
|
||||||
function instance:getGroups()
|
function instance:getGroups()
|
||||||
@@ -79,27 +92,18 @@ end
|
|||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
---@param z number
|
---@param z number
|
||||||
---@param threshold number?
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function Cavern:isCavern(x, y, z, threshold)
|
function Cavern:isCavern(x, y, z)
|
||||||
local minY, maxY = self.minY, self.maxY
|
local minY, maxY = self.minY, self.maxY
|
||||||
|
|
||||||
if y > maxY or y < minY then
|
if y > maxY or y < minY then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if threshold == nil then
|
|
||||||
threshold = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local noise = self:getNoise()
|
local noise = self:getNoise()
|
||||||
local weight = calcCavernWeight(y, self.smoothDistance, minY, maxY)
|
local weight = calcCavernWeight(y, self.smoothDistance, minY, maxY)
|
||||||
|
|
||||||
if y == -15 then
|
return noise:get_3d({x = x, y = y, z = z}) * weight > self.threshold
|
||||||
print('is', weight)
|
|
||||||
end
|
|
||||||
|
|
||||||
return noise:get_3d({x = x, y = y, z = z}) * weight > threshold
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Cavern
|
return Cavern
|
||||||
@@ -126,3 +126,22 @@ mapGenerator:registerBiome('world', "biome2", 100, 100, {
|
|||||||
}, 1)
|
}, 1)
|
||||||
|
|
||||||
mapGenerator:run()
|
mapGenerator:run()
|
||||||
|
|
||||||
|
minetest.register_ore({
|
||||||
|
ore_type = "blob",
|
||||||
|
ore = "soils:clay_soil_baren",
|
||||||
|
wherein = {"rocks:iyellite", "rocks:falmyte"},
|
||||||
|
clust_scarcity = 16 * 16 * 16,
|
||||||
|
clust_size = 5,
|
||||||
|
y_max = 0,
|
||||||
|
y_min = -3100,
|
||||||
|
noise_threshold = 0.0,
|
||||||
|
noise_params = {
|
||||||
|
offset = 1,
|
||||||
|
scale = 0.5,
|
||||||
|
spread = {x = 5, y = 5, z = 5},
|
||||||
|
seed = 2316,
|
||||||
|
octaves = 1,
|
||||||
|
persist = 0.0
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user