on_timer for fluid transfer
This commit is contained in:
parent
1a1b3caeaa
commit
708b9a3587
@ -84,19 +84,11 @@ local function fluid_targets(p_pos, pos)
|
|||||||
return targets
|
return targets
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------
|
function elefluid.transfer_timer_tick(pos, elapsed)
|
||||||
-- Main Transfer ABM --
|
local refresh = true
|
||||||
-----------------------
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"group:elefluid_transport_source"},
|
|
||||||
label = "elepower Fluid Transfer Tick",
|
|
||||||
interval = 1,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
local meta1 = nil
|
local meta1 = nil
|
||||||
|
|
||||||
local targets = {}
|
local targets = {}
|
||||||
|
|
||||||
-- Only allow the node directly behind to be a start of a network
|
-- Only allow the node directly behind to be a start of a network
|
||||||
@ -109,12 +101,11 @@ minetest.register_abm({
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Retrieve network
|
-- Retrieve network
|
||||||
minetest.forceload_block(pos)
|
|
||||||
targets = fluid_targets(pos, tpos)
|
targets = fluid_targets(pos, tpos)
|
||||||
|
|
||||||
-- No targets, don't proceed
|
-- No targets, don't proceed
|
||||||
if #targets == 0 then
|
if #targets == 0 then
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Begin transfer
|
-- Begin transfer
|
||||||
@ -123,18 +114,18 @@ minetest.register_abm({
|
|||||||
|
|
||||||
-- Make sure source node is not air
|
-- Make sure source node is not air
|
||||||
if not srcnode or srcnode.name == "air" then
|
if not srcnode or srcnode.name == "air" then
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Make sure source node is a registered fluid container
|
-- Make sure source node is a registered fluid container
|
||||||
if not ele.helpers.get_item_group(srcnode.name, "fluid_container") then
|
if not ele.helpers.get_item_group(srcnode.name, "fluid_container") then
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local srcmeta = minetest.get_meta(srcpos)
|
local srcmeta = minetest.get_meta(srcpos)
|
||||||
local srcdef = minetest.registered_nodes[srcnode.name]
|
local srcdef = minetest.registered_nodes[srcnode.name]
|
||||||
local buffers = fluid_lib.get_node_buffers(srcpos)
|
local buffers = fluid_lib.get_node_buffers(srcpos)
|
||||||
if not buffers then return nil end
|
if not buffers then return true end
|
||||||
|
|
||||||
-- Limit the amount of fluid pumped per cycle
|
-- Limit the amount of fluid pumped per cycle
|
||||||
local pcapability = ele.helpers.get_node_property(meta, pos, "fluid_pump_capacity")
|
local pcapability = ele.helpers.get_node_property(meta, pos, "fluid_pump_capacity")
|
||||||
@ -179,10 +170,19 @@ minetest.register_abm({
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
function elefluid.clear_networks(pos)
|
return refresh
|
||||||
-- TODO: Fluid network cache
|
end
|
||||||
|
|
||||||
|
function elefluid.refresh_node(pos)
|
||||||
|
minetest.get_node_timer(pos):start(1.0)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Fluid Transfer Tick",
|
||||||
|
name = "elepower_fapi:fluid_transfer_tick",
|
||||||
|
nodenames = {"group:elefluid_transport_source"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = elefluid.refresh_node,
|
||||||
|
})
|
||||||
|
@ -10,6 +10,7 @@ function elefluid.register_transfer_node(nodename, nodedef)
|
|||||||
nodedef.groups["elefluid_transport_source"] = 1
|
nodedef.groups["elefluid_transport_source"] = 1
|
||||||
nodedef.paramtype2 = "facedir"
|
nodedef.paramtype2 = "facedir"
|
||||||
nodedef.legacy_facedir_simple = true
|
nodedef.legacy_facedir_simple = true
|
||||||
|
nodedef.on_timer = elefluid.transfer_timer_tick
|
||||||
|
|
||||||
local orig_construct = nodedef.on_construct
|
local orig_construct = nodedef.on_construct
|
||||||
nodedef.on_construct = function (pos)
|
nodedef.on_construct = function (pos)
|
||||||
@ -17,14 +18,14 @@ function elefluid.register_transfer_node(nodename, nodedef)
|
|||||||
meta:set_int("fluid_store", 0)
|
meta:set_int("fluid_store", 0)
|
||||||
meta:set_string("fluid", "")
|
meta:set_string("fluid", "")
|
||||||
|
|
||||||
elefluid.clear_networks(pos)
|
elefluid.refresh_node(pos)
|
||||||
|
|
||||||
if orig_construct then
|
if orig_construct then
|
||||||
orig_construct(pos)
|
orig_construct(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
nodedef.after_destruct = elefluid.clear_networks
|
nodedef.after_destruct = elefluid.refresh_node
|
||||||
|
|
||||||
-- Default transfer capacity
|
-- Default transfer capacity
|
||||||
if not nodedef.ele_fluid_pump_capacity then
|
if not nodedef.ele_fluid_pump_capacity then
|
||||||
|
Loading…
Reference in New Issue
Block a user