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