elepower/elepower_fapi/transfer_node.lua
2018-06-18 22:31:46 +03:00

100 lines
2.1 KiB
Lua

-- Nodes for transferring fluids
-- All units are in millibuckets (1 bucket)
-- This is the node that takes fluid from another node.
function elefluid.register_transfer_node(nodename, nodedef)
if not nodedef.groups then
nodedef.groups = {}
end
nodedef.groups["elefluid_transport_source"] = 1
nodedef.paramtype2 = "facedir"
local orig_construct = nodedef.on_construct
nodedef.on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_int("fluid_store", 0)
meta:set_string("fluid", "")
elefluid.clear_networks(pos)
if orig_construct then
orig_construct(pos)
end
end
nodedef.after_destruct = elefluid.clear_networks
-- Default transfer capacity
if not nodedef.ele_fluid_pump_capacity then
nodedef.ele_fluid_pump_capacity = 1000
end
minetest.register_node(nodename, nodedef)
end
-- This is the node that allows for fluid transfer.
function elefluid.register_transfer_duct(nodename, nodedef)
if not nodedef.groups then
nodedef.groups = {}
end
nodedef.groups["elefluid_transport"] = 1
-- Duct node density
local cd = 1/7
if nodedef.ele_duct_density then
cd = nodedef.ele_duct_density
end
-- Default values, including the nodebox
local defaults = {
drawtype = "nodebox",
node_box = {
type = "connected",
fixed = {
{-cd, -cd, -cd, cd, cd, cd}
},
connect_front = {
{-cd, -cd, -1/2, cd, cd, -cd}
},
connect_back = {
{-cd, -cd, cd, cd, cd, 1/2}
},
connect_top = {
{-cd, cd, -cd, cd, 1/2, cd}
},
connect_bottom = {
{-cd, -1/2, -cd, cd, -cd, cd}
},
connect_left = {
{-1/2, -cd, -cd, cd, cd, cd}
},
connect_right = {
{cd, -cd, -cd, 1/2, cd, cd}
},
},
paramtype = "light",
connect_sides = { "top", "bottom", "front", "left", "back", "right" },
is_ground_content = false,
connects_to = {
"group:elefluid_transport",
"group:elefluid_transport_source",
"group:fluid_container",
"group:fluidity_tank"
},
}
for k,v in pairs(defaults) do
if not nodedef[k] then
nodedef[k] = v
end
end
nodedef.on_construct = elefluid.clear_networks
nodedef.after_destruct = elefluid.clear_networks
minetest.register_node(nodename, nodedef)
end