mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Address review comments
This commit is contained in:
parent
e65370b845
commit
31a3788ce1
4 changed files with 17 additions and 13 deletions
|
@ -48,9 +48,12 @@ function table.pairs_by_keys(t, f)
|
||||||
return iter
|
return iter
|
||||||
end
|
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
|
local count = #table
|
||||||
return function()
|
if count == 0 then return nil end
|
||||||
|
|
||||||
local idx = math.random(count)
|
local idx = math.random(count)
|
||||||
local res = table[idx]
|
local res = table[idx]
|
||||||
table[idx] = table[count]
|
table[idx] = table[count]
|
||||||
|
@ -58,7 +61,6 @@ function table.pull_random_items(table)
|
||||||
count = count - 1
|
count = count - 1
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local LOGGING_ON = minetest.settings:get_bool("mcl_logging_default", false)
|
local LOGGING_ON = minetest.settings:get_bool("mcl_logging_default", false)
|
||||||
local LOG_MODULE = "[MCL2]"
|
local LOG_MODULE = "[MCL2]"
|
||||||
|
|
|
@ -574,7 +574,7 @@ local function has_room(self, pos)
|
||||||
nodes = nodes,
|
nodes = nodes,
|
||||||
}))
|
}))
|
||||||
]]
|
]]
|
||||||
if n == ( dx * dy * dz ) then
|
if n == dx * dy * dz then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ local function has_room(self, pos)
|
||||||
if not minetest.get_node_boxes then return false end
|
if not minetest.get_node_boxes then return false end
|
||||||
|
|
||||||
-- Check if it's possible for a sub-node space check to succeed
|
-- 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
|
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
|
-- Make sure the entire volume except for the top level is free before checking the top layer
|
||||||
|
|
|
@ -1053,7 +1053,8 @@ local function summon_golem(self)
|
||||||
local p1 = vector.offset(pos, -10, -10, -10)
|
local p1 = vector.offset(pos, -10, -10, -10)
|
||||||
local p2 = 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"})
|
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
|
n.y = n.y + 1
|
||||||
|
|
||||||
local summon = mcl_mobs.spawn(n, "mobs_mc:iron_golem")
|
local summon = mcl_mobs.spawn(n, "mobs_mc:iron_golem")
|
||||||
|
|
|
@ -230,7 +230,8 @@ local function spawn_mobs(pos, elapsed)
|
||||||
local mlig = meta:get_int("MinLight")
|
local mlig = meta:get_int("MinLight")
|
||||||
local xlig = meta:get_int("MaxLight")
|
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
|
-- only if light levels are within range
|
||||||
local lig = minetest.get_node_light(pos2) or 0
|
local lig = minetest.get_node_light(pos2) or 0
|
||||||
if lig >= mlig and lig <= xlig then
|
if lig >= mlig and lig <= xlig then
|
||||||
|
|
Loading…
Reference in a new issue