Fix a crash, fine-tune pump mechanics and loop detection.

Crash occurred only when an item entity was in a water flow at the
bottom of a waterfall, and a solid node was placed above the
entity's waterflow, cutting off the waterfall.
Pump loop detection is now more forgiving, just causing pumps to
stall, since its way too easy to accidentally create loops during
normal build process.  Made pumps take a little longer to warm up
than to shut down, to prevent "pulsed" loops.
This commit is contained in:
Aaron Suen 2014-09-02 11:10:14 -04:00
parent 78be4a6470
commit a4e7029dee

View File

@ -320,6 +320,40 @@ function sz_pos:is_empty()
return node and node.name == "air"
end
-- Determine if the node at this position is a fluid, and measure
-- its "depth," up to a certain number of nodes above.
function sz_pos:fluid_depth(recurse)
local def = self:nodedef()
-- Solid nodes have an undefined depth.
if not def or def.walkable then return nil end
-- Non-walkable nodes are considered "air" and have
-- zero depth by default.
local depth = 0
-- Source blocks are 9 ticks deep,
-- since flowing are between 1 and 8.
if def.liquidtype == "source" then
depth = 9
-- Flowing block depth is stored in param2.
elseif def.liquidtype == "flowing" then
local node = self:node_get()
if not node then return 0 end
depth = node.param2 % 8 + 1
end
-- If this node has a full depth, then add the depth of the
-- node above, up to the recursion limit.
if depth >= 8 and recurse and recurse > 0 then
local above = self:add(sz_pos.dirs.u):fluid_depth(recurse - 1)
if above then depth = depth + above end
end
return depth
end
------------------------------------------------------------------------
-- OBJECT HANDLING