Skip to content

Commit

Permalink
Fix on_destruct() and missing 'channel'
Browse files Browse the repository at this point in the history
  • Loading branch information
andriyndev committed Sep 4, 2024
1 parent 4278dc5 commit 785050d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
})
Expand Down

0 comments on commit 785050d

Please sign in to comment.