optimize water flow functions
This commit is contained in:
parent
9d54ec57c8
commit
dc85729b1a
87
init.lua
87
init.lua
@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
-- Replaces: builtin/item_entity.lua (13th January 2017)
|
-- Replaces: builtin/item_entity.lua (13th January 2017)
|
||||||
|
|
||||||
local abs = math.abs
|
|
||||||
|
|
||||||
-- water flow functions by QwertyMine3, edited by TenPlus1
|
-- water flow functions by QwertyMine3, edited by TenPlus1
|
||||||
local function to_unit_vector(dir_vector)
|
local function to_unit_vector(dir_vector)
|
||||||
|
|
||||||
@ -25,12 +23,6 @@ local function to_unit_vector(dir_vector)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function is_touching(realpos, nodepos, radius)
|
|
||||||
|
|
||||||
return (abs(realpos - nodepos) > (0.5 - radius))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function node_ok(pos)
|
local function node_ok(pos)
|
||||||
|
|
||||||
local node = minetest.get_node_or_nil(pos)
|
local node = minetest.get_node_or_nil(pos)
|
||||||
@ -47,50 +39,35 @@ local function node_ok(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function is_liquid(pos)
|
|
||||||
|
|
||||||
return (minetest.registered_nodes[node_ok(pos).name].groups.liquid)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function quick_flow_logic(node, pos_testing, direction)
|
local function quick_flow_logic(node, pos_testing, direction)
|
||||||
|
|
||||||
if minetest.registered_nodes[node.name].liquidtype == "source" then
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
|
||||||
|
if def.liquidtype == "flowing" then
|
||||||
|
|
||||||
local node_testing = node_ok(pos_testing)
|
local node_testing = node_ok(pos_testing)
|
||||||
local param2_testing = node_testing.param2
|
|
||||||
|
|
||||||
if minetest.registered_nodes[node_testing.name].liquidtype ~= "flowing" then
|
if minetest.registered_nodes[node_testing.name].liquidtype ~= "flowing"
|
||||||
|
and minetest.registered_nodes[node_testing.name].liquidtype ~= "source" then
|
||||||
return 0
|
return 0
|
||||||
else
|
|
||||||
return direction
|
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif minetest.registered_nodes[node.name].liquidtype == "flowing" then
|
|
||||||
|
|
||||||
local node_testing = node_ok(pos_testing)
|
|
||||||
local param2_testing = node_testing.param2
|
local param2_testing = node_testing.param2
|
||||||
|
|
||||||
if minetest.registered_nodes[node_testing.name].liquidtype == "source" then
|
if param2_testing < node.param2 then
|
||||||
return -direction
|
|
||||||
|
|
||||||
elseif minetest.registered_nodes[node_testing.name].liquidtype == "flowing" then
|
if (node.param2 - param2_testing) > 6 then
|
||||||
|
return -direction
|
||||||
|
else
|
||||||
|
return direction
|
||||||
|
end
|
||||||
|
|
||||||
if param2_testing < node.param2 then
|
elseif param2_testing > node.param2 then
|
||||||
|
|
||||||
if (node.param2 - param2_testing) > 6 then
|
if (param2_testing - node.param2) > 6 then
|
||||||
return -direction
|
return direction
|
||||||
else
|
else
|
||||||
return direction
|
return -direction
|
||||||
end
|
|
||||||
|
|
||||||
elseif param2_testing > node.param2 then
|
|
||||||
|
|
||||||
if (param2_testing - node.param2) > 6 then
|
|
||||||
return direction
|
|
||||||
else
|
|
||||||
return -direction
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -114,38 +91,6 @@ local function quick_flow(pos, node)
|
|||||||
|
|
||||||
return to_unit_vector({x = x, y = 0, z = z})
|
return to_unit_vector({x = x, y = 0, z = z})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--if not in water but touching, move centre to touching block
|
|
||||||
--x has higher precedence than z -- if pos changes with x, it affects z
|
|
||||||
local function move_centre(pos, realpos, node, radius)
|
|
||||||
|
|
||||||
if is_touching(realpos.x, pos.x, radius) then
|
|
||||||
|
|
||||||
if is_liquid({x = pos.x - 1, y = pos.y, z = pos.z}) then
|
|
||||||
pos = {x = pos.x - 1, y = pos.y, z = pos.z}
|
|
||||||
node = node_ok(pos)
|
|
||||||
|
|
||||||
elseif is_liquid({x = pos.x + 1, y = pos.y, z = pos.z}) then
|
|
||||||
pos = {x = pos.x + 1, y = pos.y, z = pos.z}
|
|
||||||
node = node_ok(pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_touching(realpos.z, pos.z, radius) then
|
|
||||||
|
|
||||||
if is_liquid({x = pos.x, y = pos.y, z = pos.z - 1}) then
|
|
||||||
pos = {x = pos.x, y = pos.y, z = pos.z - 1}
|
|
||||||
node = node_ok(pos)
|
|
||||||
|
|
||||||
elseif is_liquid({x = pos.x, y = pos.y, z = pos.z + 1}) then
|
|
||||||
pos = {x = pos.x, y = pos.y, z = pos.z + 1}
|
|
||||||
node = node_ok(pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return pos, node
|
|
||||||
end
|
|
||||||
-- END water flow functions
|
-- END water flow functions
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user