1
0
Fork 0

Address review comments

This commit is contained in:
teknomunk 2024-09-13 20:24:34 -05:00
parent e65370b845
commit 31a3788ce1
4 changed files with 17 additions and 13 deletions

View File

@ -48,16 +48,18 @@ function table.pairs_by_keys(t, f)
return iter
end
function table.pull_random_items(table)
-- Removes one element randomly selected from the array section of the table and
-- returns it, or nil if there are no elements in the array section of the table
function table.remove_random_element(table)
local count = #table
return function()
if count == 0 then return nil end
local idx = math.random(count)
local res = table[idx]
table[idx] = table[count]
table[count] = nil
count = count - 1
return res
end
end
local LOGGING_ON = minetest.settings:get_bool("mcl_logging_default", false)

View File

@ -574,7 +574,7 @@ local function has_room(self, pos)
nodes = nodes,
}))
]]
if n == ( dx * dy * dz ) then
if n == dx * dy * dz then
return true
end
@ -582,7 +582,7 @@ local function has_room(self, pos)
if not minetest.get_node_boxes then return false end
-- Check if it's possible for a sub-node space check to succeed
local needed_in_bottom_section = (dx * dz * ( dy - 1))
local needed_in_bottom_section = dx * ( dy - 1) * dz
if n < needed_in_bottom_section then return false end
-- Make sure the entire volume except for the top level is free before checking the top layer

View File

@ -1053,7 +1053,8 @@ local function summon_golem(self)
local p1 = vector.offset(pos, -10, -10, -10)
local p2 = vector.offset(pos, 10, 10, 10)
local nn = minetest.find_nodes_in_area_under_air(p1, p2,{"group:solid","group:water"})
for n in table.pull_random_items(nn) do
while #nn > 0 do
local n = table.remove_random_element(nn)
n.y = n.y + 1
local summon = mcl_mobs.spawn(n, "mobs_mc:iron_golem")

View File

@ -230,7 +230,8 @@ local function spawn_mobs(pos, elapsed)
local mlig = meta:get_int("MinLight")
local xlig = meta:get_int("MaxLight")
for pos2 in table.pull_random_items(air) do
while #air > 0 do
local pos2 = table.remove_random_element(air)
-- only if light levels are within range
local lig = minetest.get_node_light(pos2) or 0
if lig >= mlig and lig <= xlig then