Fix dungeon margin bug (#4276)

Some mapgen settings used to crash the game.

Reviewed-on: MineClone2/MineClone2#4276
Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com>
Co-authored-by: Bram van den Heuvel <bram.vdh1999@gmail.com>
Co-committed-by: Bram van den Heuvel <bram.vdh1999@gmail.com>
This commit is contained in:
Bram van den Heuvel 2024-05-03 14:05:51 +00:00 committed by the-real-herowl
parent 7d999535e7
commit 69acc5074b
1 changed files with 10 additions and 7 deletions

View File

@ -406,13 +406,16 @@ local function dungeons_nodes(minp, maxp, blockseed)
local pr = PseudoRandom(blockseed) local pr = PseudoRandom(blockseed)
for a=1, attempts do for a=1, attempts do
local dim = dungeonsizes[pr:next(1, #dungeonsizes)] local dim = dungeonsizes[pr:next(1, #dungeonsizes)]
local x = pr:next(minp.x, maxp.x-dim.x-1)
local y = pr:next(ymin , ymax -dim.y-1) if ymin <= ymax - dim.y - 1 then
local z = pr:next(minp.z, maxp.z-dim.z-1) local x = pr:next(minp.x, maxp.x-dim.x-1)
local p1 = {x=x,y=y,z=z} local y = pr:next(ymin , ymax -dim.y-1)
local p2 = {x = x+dim.x+1, y = y+dim.y+1, z = z+dim.z+1} local z = pr:next(minp.z, maxp.z-dim.z-1)
minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2)) local p1 = {x=x,y=y,z=z}
emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr}) local p2 = {x = x+dim.x+1, y = y+dim.y+1, z = z+dim.z+1}
minetest.log("verbose","[mcl_dungeons] size=" ..minetest.pos_to_string(dim) .. ", emerge from "..minetest.pos_to_string(p1) .. " to " .. minetest.pos_to_string(p2))
emerge_area(p1, p2, ecb_spawn_dungeon, {p1=p1, p2=p2, dim=dim, pr=pr})
end
end end
end end