From 69acc5074b9f5ac72c2c9496a710c158e0eadeae Mon Sep 17 00:00:00 2001 From: Bram van den Heuvel Date: Fri, 3 May 2024 14:05:51 +0000 Subject: [PATCH] Fix dungeon margin bug (#4276) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some mapgen settings used to crash the game. Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/4276 Reviewed-by: Mikita Wiśniewski Co-authored-by: Bram van den Heuvel Co-committed-by: Bram van den Heuvel --- mods/MAPGEN/mcl_dungeons/init.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index c115c35c3..479052d2c 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -406,13 +406,16 @@ local function dungeons_nodes(minp, maxp, blockseed) local pr = PseudoRandom(blockseed) for a=1, attempts do 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) - local z = pr:next(minp.z, maxp.z-dim.z-1) - local p1 = {x=x,y=y,z=z} - 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}) + + if ymin <= ymax - dim.y - 1 then + local x = pr:next(minp.x, maxp.x-dim.x-1) + local y = pr:next(ymin , ymax -dim.y-1) + local z = pr:next(minp.z, maxp.z-dim.z-1) + local p1 = {x=x,y=y,z=z} + 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