extend stdmin.lua & add module base:generation/ores

This commit is contained in:
MihailRis
2024-10-14 07:38:54 +03:00
parent 4c3ce8c174
commit a1407a1d1f
4 changed files with 97 additions and 89 deletions
@@ -1,31 +1,10 @@
local _, dir = parse_path(__DIR__)
ores = file.read_combined_list(dir.."/ores.json")
local function place_ores(placements, x, z, w, d, seed, hmap, chunk_height)
local BLOCKS_PER_CHUNK = w * d * chunk_height
for _, ore in ipairs(ores) do
local count = BLOCKS_PER_CHUNK / ore.rarity
-- average count is less than 1
local addchance = math.fmod(count, 1.0)
if math.random() < addchance then
count = count + 1
end
for i=1,count do
local sx = math.random() * w
local sz = math.random() * d
local sy = math.random() * (chunk_height * 0.5)
if sy < hmap:at(sx, sz) * chunk_height - 6 then
table.insert(placements, {ore.struct, {sx, sy, sz}, math.random()*4, -1})
end
end
end
end
local ores = require "base:generation/ores"
ores.load(dir)
function place_structures(x, z, w, d, seed, hmap, chunk_height)
local placements = {}
place_ores(placements, x, z, w, d, seed, hmap, chunk_height)
ores.place(placements, x, z, w, d, seed, hmap, chunk_height)
return placements
end
@@ -0,0 +1,29 @@
local ores = {}
function ores.load(directory)
ores.ores = file.read_combined_list(directory.."/ores.json")
end
function ores.place(placements, x, z, w, d, seed, hmap, chunk_height)
local BLOCKS_PER_CHUNK = w * d * chunk_height
for _, ore in ipairs(ores.ores) do
local count = BLOCKS_PER_CHUNK / ore.rarity
-- average count is less than 1
local addchance = math.fmod(count, 1.0)
if math.random() < addchance then
count = count + 1
end
for i=1,count do
local sx = math.random() * w
local sz = math.random() * d
local sy = math.random() * (chunk_height * 0.5)
if sy < hmap:at(sx, sz) * chunk_height - 6 then
table.insert(placements, {ore.struct, {sx, sy, sz}, math.random()*4, -1})
end
end
end
end
return ores