Raycast: Improve code quality

This commit is contained in:
Lars Mueller 2021-08-14 17:40:44 +02:00
parent 6cc39ef023
commit 0f6f325aa8

@ -16,15 +16,17 @@ function raycast(_pos1, _pos2, objects, liquids)
local direction = modlib.vector.from_minetest(_direction)
local length = vector.distance(_pos1, _pos2)
local function next()
for pointed_thing in raycast do
if pointed_thing.type ~= "node" then
local pointed_thing = raycast:next()
if (not pointed_thing) or pointed_thing.type ~= "node" then
return pointed_thing
end
local _pos = pointed_thing.under
local pos = modlib.vector.from_minetest(_pos)
local node = minetest.get_node(_pos)
local def = minetest.registered_nodes[node.name]
if not (def and def.drawtype == "flowingliquid") then return pointed_thing end
if not (def and def.drawtype == "flowingliquid") then
return pointed_thing
end
local corner_levels = get_liquid_corner_levels(_pos)
local full_corner_levels = true
for _, corner_level in pairs(corner_levels) do
@ -133,7 +135,7 @@ function raycast(_pos1, _pos2, objects, liquids)
return pointed_thing
end
end
end
return next()
end
return setmetatable({next = next}, {__call = next})
end