From e61ea85c9a4ece23674606905b88cd581a3706fa Mon Sep 17 00:00:00 2001 From: Vanic Date: Tue, 25 Nov 2025 19:39:39 +0300 Subject: [PATCH] Mapgen: write SuperUltraSigmaMapgen part 8 --- mods/CORE/MapGen/src/MapGen.lua | 24 +++++++----- mods/CORE/MapGen/src/MapGen/Layer.lua | 36 ------------------ .../ENVIRONMENT/MapGenerator/MapGenerator.lua | 3 +- mods/ENVIRONMENT/MapGenerator/init.lua | 21 +++++++++- mods/GAME/ITEMS/Plants/init.lua | 23 +++++++++++ mods/GAME/ITEMS/Plants/mod.conf | 2 + .../GAME/ITEMS/Plants/textures/test_plant.png | Bin 0 -> 1221 bytes mods/GAME/ITEMS/Rocks/mod.conf | 2 +- mods/GAME/ITEMS/Soils/mod.conf | 2 +- 9 files changed, 64 insertions(+), 49 deletions(-) create mode 100644 mods/GAME/ITEMS/Plants/init.lua create mode 100644 mods/GAME/ITEMS/Plants/mod.conf create mode 100644 mods/GAME/ITEMS/Plants/textures/test_plant.png diff --git a/mods/CORE/MapGen/src/MapGen.lua b/mods/CORE/MapGen/src/MapGen.lua index 4aec3e8..1c393b5 100644 --- a/mods/CORE/MapGen/src/MapGen.lua +++ b/mods/CORE/MapGen/src/MapGen.lua @@ -43,6 +43,7 @@ local Cavern = require('MapGen.Layer.Cavern') ---@field cavernsNoiseInitialized boolean TODO: описание ---@field isRunning boolean A static field that guarantees that only one instance of the `MapGen` class will work. ---@field nodeIDs table +---@field waterLevel number local MapGen = { layersByName = {}, layersList = {}, @@ -51,12 +52,13 @@ local MapGen = { isRunning = false, } ----@param nodeIDs table +---@param nodeIDs table ---@return MapGen -function MapGen:new(nodeIDs) +function MapGen:new(nodeIDs, waterLevel) ---@type MapGen local instance = setmetatable({ - nodeIDs = nodeIDs, + nodeIDs = nodeIDs, + waterLevel = waterLevel or 0, }, {__index = self}) return instance @@ -226,7 +228,7 @@ function MapGen:initPeaksMultinoise() self.peaksMultinoiseInitialized = true end ----TODO: описаение +---TODO: описание function MapGen:initCavernsNoise() ---@param layer MapGen.Layer for _, layer in ipairs(self.layersList) do @@ -280,26 +282,27 @@ end ---@param z number local function generateNode(mapGenerator, layer, height, temp, humidity, data, index, x, y, z) local ids = mapGenerator.nodeIDs + local waterLevel = mapGenerator.waterLevel local m = math.random(-5, 5) temp = mathMin(100, mathMax(0, temp + 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 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 - elseif y > height and y <= 0 then + elseif y > height and y <= waterLevel then data[index] = ids.water elseif y <= height then if isCavern(layer, x, y, z) then 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) - elseif y == height and y < 0 then + elseif y == height and y < waterLevel then biome.generateBottom(mapGenerator, biome, data, index, x, y, z) else biome.generateRock(mapGenerator, biome, data, index, x, y, z) @@ -614,6 +617,9 @@ function MapGen:onMapGenerated(voxelManip, minPos, maxPos, blockseed) voxelManip:calc_lighting() voxelManip:update_liquids() + core.generate_ores(voxelManip, minPos, maxPos) + core.generate_decorations(voxelManip, minPos, maxPos) + --voxelManip:write_to_map() -- Async edit end diff --git a/mods/CORE/MapGen/src/MapGen/Layer.lua b/mods/CORE/MapGen/src/MapGen/Layer.lua index c15343b..61487c0 100644 --- a/mods/CORE/MapGen/src/MapGen/Layer.lua +++ b/mods/CORE/MapGen/src/MapGen/Layer.lua @@ -43,42 +43,6 @@ function Layer:addPeak(peak) table.insert(self.peaksList, peak) 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 biomesList MapGen.Layer.Biome[] ---@return string[], MapGen.Layer.Biome[] diff --git a/mods/ENVIRONMENT/MapGenerator/MapGenerator.lua b/mods/ENVIRONMENT/MapGenerator/MapGenerator.lua index 676b936..b80aca5 100644 --- a/mods/ENVIRONMENT/MapGenerator/MapGenerator.lua +++ b/mods/ENVIRONMENT/MapGenerator/MapGenerator.lua @@ -60,7 +60,8 @@ local mapGenerator = MapGen:new({ -- Liquids water = id("liquids:water_source"), -}) +}, 10 +) mapGenerator:RegisterLayer("world", -1000, 500) diff --git a/mods/ENVIRONMENT/MapGenerator/init.lua b/mods/ENVIRONMENT/MapGenerator/init.lua index d38c4ff..2d05db5 100644 --- a/mods/ENVIRONMENT/MapGenerator/init.lua +++ b/mods/ENVIRONMENT/MapGenerator/init.lua @@ -1,4 +1,23 @@ -- World generation runs in the mapgen environment (separate thread) -- The Mapgen environment is isolated from the main enviroment. -core.register_mapgen_script(core.get_modpath(core.get_current_modname())..'/MapGenerator.lua') \ No newline at end of file +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", +}) \ No newline at end of file diff --git a/mods/GAME/ITEMS/Plants/init.lua b/mods/GAME/ITEMS/Plants/init.lua new file mode 100644 index 0000000..74b46be --- /dev/null +++ b/mods/GAME/ITEMS/Plants/init.lua @@ -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, +}) + diff --git a/mods/GAME/ITEMS/Plants/mod.conf b/mods/GAME/ITEMS/Plants/mod.conf new file mode 100644 index 0000000..8ca2cbf --- /dev/null +++ b/mods/GAME/ITEMS/Plants/mod.conf @@ -0,0 +1,2 @@ +name = smc__game__items__plants +depends = smc__core__node, smc__core__tilesheet \ No newline at end of file diff --git a/mods/GAME/ITEMS/Plants/textures/test_plant.png b/mods/GAME/ITEMS/Plants/textures/test_plant.png new file mode 100644 index 0000000000000000000000000000000000000000..2427ecfc48cbc7c359d0bcc5d1934c0cd309d370 GIT binary patch literal 1221 zcmd^7F-w9`6uqBVnx-iZVnIeiLpcPMRJ16HN+>1`xrEZt(2!s)Q6%NkRBjPL(9#yP zMO#BeL~GE{P*VnCWJH)`?>xEkCH{jhyzkw2-#z!7d*8Pciv~@GZUYgS!XbZL>=rD2 zyZAcGwUpSDOg!jQ9&X&5;-FphM!ZC4yT)p&O`Q7{Lh%UE+5k~DM^q7^>g5qC)IMO%1lDOb$TO>Hw7_66@{4fK>Nbe#Gr_sUzi7&5Qjmw+SEUq