If you look on a flowing liquid like water, you notice a flowing animation. This flowing animation has a direction. What I want is this dircection of the animation.
Ideally I wish I could get the direction as an unit vector (x,y,z).
My current code basically just hacks around the fact that I haven't found a clean standard way yet. It only is able to distinguish between the 4 cardinal directions, it doesn't recognize it if the liquid flows diagonally.
This is the code which is supposed to do this (return value is an unit vector, possible are the 4 cardinal directions only):
Code: Select all
local get_flowing_dir = function(self)
local pos = self.object:getpos()
local param2 = minetest.get_node(pos).param2
-- Search for a liquid source, or a flowing liquid node higher than
-- the item's position in the 4 cardinal directions
local posses = {
{x=-1, y=0, z=0},
{x=1, y=0, z=0},
{x=0, y=0, z=-1},
{x=0, y=0, z=1},
}
for _, p in pairs(posses) do
local realpos = vector.add(pos, p)
local name = minetest.get_node(realpos).name
local def = minetest.registered_nodes[name]
local par2 = minetest.get_node(realpos).param2
if def.liquidtype == "source" or (def.liquidtype == "flowing" and par2 > param2) then
-- Node found! Since we looked upwards, the flowing
-- direction is the *opposite* of what we've found
return vector.multiply(p, -1)
end
end
end
If someone knows a standard way to get the flowing direction, that would be great, as I could get rid of some code.