elepower/elepower_fapi/transfer_node.lua

101 lines
2.2 KiB
Lua
Raw Normal View History

2018-06-18 16:15:15 +00:00
-- 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"
nodedef.legacy_facedir_simple = true
2018-06-23 16:10:08 +00:00
nodedef.on_timer = elefluid.transfer_timer_tick
2018-06-18 16:15:15 +00:00
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", "")
2018-06-23 16:10:08 +00:00
elefluid.refresh_node(pos)
2018-06-18 16:15:15 +00:00
if orig_construct then
orig_construct(pos)
end
end
2018-06-23 16:10:08 +00:00
nodedef.after_destruct = elefluid.refresh_node
2018-06-18 16:15:15 +00:00
-- 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",
2018-06-24 09:10:47 +00:00
"group:fluid_container"
2018-06-18 16:15:15 +00:00
},
}
for k,v in pairs(defaults) do
if not nodedef[k] then
nodedef[k] = v
end
end
2018-06-24 09:10:47 +00:00
-- nodedef.on_construct = elefluid.refresh_node
-- nodedef.after_destruct = elefluid.refresh_node
2018-06-18 16:15:15 +00:00
minetest.register_node(nodename, nodedef)
end