mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2025-01-10 18:47:31 +01:00
use helper function for cleaner code
This commit is contained in:
parent
0529480318
commit
0ccf9186c0
@ -530,6 +530,35 @@ local function get_water_spawn(p)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- helper to check a single node p
|
||||||
|
local function check_room_helper(p, fly_in, fly_in_air, headroom, check_headroom)
|
||||||
|
local node = get_node(p)
|
||||||
|
local nam = node.name
|
||||||
|
-- fast-track very common air case:
|
||||||
|
if fly_in_air and nam == "air" then return true end
|
||||||
|
local n_def = registered_nodes[nam]
|
||||||
|
if not n_def then return false end -- don't spawn in ignore
|
||||||
|
|
||||||
|
-- Fast-track common cases:
|
||||||
|
-- if fly_in "air", also include other non-walkable non-liquid nodes:
|
||||||
|
if fly_in_air and n_def and not n_def.walkable and n_def.liquidtype == "none" then return true end
|
||||||
|
-- other things we can fly in
|
||||||
|
if fly_in[nam] then return true end
|
||||||
|
-- negative checks: need full node
|
||||||
|
if not check_headroom then return false end
|
||||||
|
-- solid block always overlaps
|
||||||
|
if n_def.node_box == "regular" then return false end
|
||||||
|
-- perform sub-node checks in top layer
|
||||||
|
local boxes = minetest.get_node_boxes("collision_box", p, node)
|
||||||
|
for i = 1,#boxes do
|
||||||
|
-- headroom is measured from the bottom, hence +0.5
|
||||||
|
if boxes[i][2] + 0.5 < headroom then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local FLY_IN_AIR = { air = true }
|
local FLY_IN_AIR = { air = true }
|
||||||
local function has_room(self, pos)
|
local function has_room(self, pos)
|
||||||
local cb = self.spawnbox or self.collisionbox
|
local cb = self.spawnbox or self.collisionbox
|
||||||
@ -557,31 +586,9 @@ local function has_room(self, pos)
|
|||||||
p.z = z
|
p.z = z
|
||||||
for x = p1.x,p2.x do
|
for x = p1.x,p2.x do
|
||||||
p.x = x
|
p.x = x
|
||||||
local node = get_node(p)
|
if not check_room_helper(p, fly_in, fly_in_air, headroom, check_headroom) then
|
||||||
local nam = node.name
|
|
||||||
local n_def = registered_nodes[nam]
|
|
||||||
-- Fast-track common cases:
|
|
||||||
local continue = nam == "ignore" or (nam == "air" and fly_in_air) or not n_def
|
|
||||||
-- if fly_in "air", also include other non-walkable non-liquid nodes:
|
|
||||||
continue = continue or (fly_in_air and n_def and not n_def.walkable and n_def.liquidtype == "none")
|
|
||||||
-- other things we can fly in
|
|
||||||
continue = continue or not not fly_in[nam]
|
|
||||||
if not continue then
|
|
||||||
if not check_headroom then
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if n_def.node_box == "regular" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
-- perform sub-node checks in top layer
|
|
||||||
local boxes = minetest.get_node_boxes("collision_box", p, node)
|
|
||||||
for i = 1,#boxes do
|
|
||||||
-- headroom is measured from the bottom, hence +0.5
|
|
||||||
if boxes[i][2] + 0.5 < headroom then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user