From 785050d56148c3f339ae22deae40ec235198a75c Mon Sep 17 00:00:00 2001 From: Andrii Date: Thu, 5 Sep 2024 00:14:01 +0300 Subject: [PATCH] Fix on_destruct() and missing 'channel' --- inventory.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/inventory.lua b/inventory.lua index 4eae613..30b95b7 100644 --- a/inventory.lua +++ b/inventory.lua @@ -18,7 +18,8 @@ local function send_and_clear_batch(pos, channel) local pos_hash = minetest.hash_node_position(pos) if #batched_messages[pos_hash] == 1 then -- If there is only one message is the batch, don't send it in a batch - digilines.receptor_send(pos, digilines.rules.default, next(batched_messages[pos_hash])) + digilines.receptor_send(pos, digilines.rules.default, channel, + next(batched_messages[pos_hash])) else digilines.receptor_send(pos, digilines.rules.default, channel, { action = "batch", @@ -29,6 +30,14 @@ local function send_and_clear_batch(pos, channel) last_message_time_for_chest[pos_hash] = nil end +local function flush_batch_for_chest(pos) + if not batched_messages[minetest.hash_node_position(pos)] then + return + end + local channel = minetest.get_meta(pos):get_string("channel") + send_and_clear_batch(pos, channel) +end + -- Sends a message onto the Digilines network. -- pos: the position of the Digilines chest node. -- action: the action string indicating what happened. @@ -235,7 +244,7 @@ minetest.register_node("digilines:chest", { inv:set_size("main", 8*4) end, on_destruct = function(pos) - batched_messages[minetest.hash_node_position(pos)] = nil + flush_batch_for_chest(pos) end, after_place_node = tubescan, after_dig_node = tubescan, @@ -375,11 +384,7 @@ minetest.register_node("digilines:chest", { end, on_timer = function(pos, _) -- Send all the batched messages when enough time since the last message passed - if not batched_messages[minetest.hash_node_position(pos)] then - return - end - local channel = minetest.get_meta(pos):get_string("channel") - send_and_clear_batch(pos, channel) + flush_batch_for_chest(pos) return false end })