on_timer for fluid transfer

This commit is contained in:
Evert Prants 2018-06-23 19:10:08 +03:00
parent 1a1b3caeaa
commit 708b9a3587
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 82 additions and 81 deletions

View File

@ -84,19 +84,11 @@ local function fluid_targets(p_pos, pos)
return targets
end
-----------------------
-- Main Transfer ABM --
-----------------------
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)
function elefluid.transfer_timer_tick(pos, elapsed)
local refresh = true
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local meta1 = nil
local targets = {}
-- Only allow the node directly behind to be a start of a network
@ -109,12 +101,11 @@ minetest.register_abm({
end
-- Retrieve network
minetest.forceload_block(pos)
targets = fluid_targets(pos, tpos)
-- No targets, don't proceed
if #targets == 0 then
return
return true
end
-- Begin transfer
@ -123,18 +114,18 @@ minetest.register_abm({
-- Make sure source node is not air
if not srcnode or srcnode.name == "air" then
return
return true
end
-- Make sure source node is a registered fluid container
if not ele.helpers.get_item_group(srcnode.name, "fluid_container") then
return
return true
end
local srcmeta = minetest.get_meta(srcpos)
local srcdef = minetest.registered_nodes[srcnode.name]
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
local pcapability = ele.helpers.get_node_property(meta, pos, "fluid_pump_capacity")
@ -179,10 +170,19 @@ minetest.register_abm({
end
end
end
end,
})
function elefluid.clear_networks(pos)
-- TODO: Fluid network cache
return refresh
end
function elefluid.refresh_node(pos)
minetest.get_node_timer(pos):start(1.0)
return
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,
})

View File

@ -10,6 +10,7 @@ function elefluid.register_transfer_node(nodename, nodedef)
nodedef.groups["elefluid_transport_source"] = 1
nodedef.paramtype2 = "facedir"
nodedef.legacy_facedir_simple = true
nodedef.on_timer = elefluid.transfer_timer_tick
local orig_construct = nodedef.on_construct
nodedef.on_construct = function (pos)
@ -17,14 +18,14 @@ function elefluid.register_transfer_node(nodename, nodedef)
meta:set_int("fluid_store", 0)
meta:set_string("fluid", "")
elefluid.clear_networks(pos)
elefluid.refresh_node(pos)
if orig_construct then
orig_construct(pos)
end
end
nodedef.after_destruct = elefluid.clear_networks
nodedef.after_destruct = elefluid.refresh_node
-- Default transfer capacity
if not nodedef.ele_fluid_pump_capacity then