Merge pull request 'Fix geode crash' (#3304) from fix_geode_crash into master

Reviewed-on: MineClone2/MineClone2#3304
Reviewed-by: Michieal <michieal@noreply.git.minetest.land>
This commit is contained in:
ancientmarinerdev 2023-01-15 22:28:38 +00:00
commit 65fb911e5f
1 changed files with 10 additions and 3 deletions

View File

@ -8,6 +8,7 @@ local adjacents = {
} }
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) local n = minetest.get_node(pos)
if n.name == "mcl_core:bedrock" then return end if n.name == "mcl_core:bedrock" then return end
return minetest.set_node(pos,node) return minetest.set_node(pos,node)
@ -21,10 +22,16 @@ local function makegeode(pos,def,pr)
if calls_remaining ~= 0 then return end if calls_remaining ~= 0 then return end
local calcite = {} local calcite = {}
local nn = minetest.find_nodes_in_area(p1,p2,{"group:material_stone","group:dirt","mcl_core:gravel"}) 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) table.sort(nn,function(a, b)
return vector.distance(pos, a) < vector.distance(pos, b) return vector.distance(pos, a) < vector.distance(pos, b)
end) 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"}) set_node_no_bedrock(nn[i],{name="mcl_amethyst:amethyst_block"})