From 38732e801d7a0cd16f1efbdba2a429c9151886f1 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Fri, 13 Jan 2023 00:25:52 +0000 Subject: [PATCH] Fix geode crash --- mods/MAPGEN/mcl_structures/geode.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mods/MAPGEN/mcl_structures/geode.lua b/mods/MAPGEN/mcl_structures/geode.lua index 95f9b0e81..56453ee60 100644 --- a/mods/MAPGEN/mcl_structures/geode.lua +++ b/mods/MAPGEN/mcl_structures/geode.lua @@ -7,7 +7,8 @@ local adjacents = { vector.new(0,-1,0) } -local function set_node_no_bedrock(pos,node) +local function set_node_no_bedrock(pos, node) + if not pos then return end local n = minetest.get_node(pos) if n.name == "mcl_core:bedrock" then return end return minetest.set_node(pos,node) @@ -21,12 +22,18 @@ local function makegeode(pos,def,pr) if calls_remaining ~= 0 then return end local calcite = {} local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone","group:dirt","mcl_core:gravel"}) + + if not nn or #nn < 2 then + minetest.log("action", "Not enough valid space to generate geode at pos: " .. minetest.pos_to_string(pos)) + return + end + table.sort(nn,function(a, b) return vector.distance(pos, a) < vector.distance(pos, b) end) - if not nn[1] then return end + --if not nn[1] then return end - for i=1,pr:next(1,math.max(2,#nn - math.ceil(#nn/5) )) do + for i=1,pr:next(1, math.max(2, #nn - math.ceil(#nn/5) )) do set_node_no_bedrock(nn[i],{name="mcl_amethyst:amethyst_block"}) end