From d4a65cfb6355fcf362b7ba70f0bd5a2b52249dba Mon Sep 17 00:00:00 2001 From: Thomas--S Date: Sun, 23 Aug 2020 17:51:07 +0200 Subject: [PATCH] Digtron Battery: Fix duplication bug This is done by using `preserve_metadata` instead of a custom `after_dig_node` callback. --- basic_machines/consumer.lua | 1 + digtron/battery.lua | 16 +++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/basic_machines/consumer.lua b/basic_machines/consumer.lua index e7f1c95..e28937e 100644 --- a/basic_machines/consumer.lua +++ b/basic_machines/consumer.lua @@ -233,6 +233,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState on_rightclick = tNode.on_rightclick, after_place_node = after_place_node, after_dig_node = after_dig_node, + preserve_metadata = tNode.preserve_metadata, tubelib2_on_update2 = tubelib2_on_update2, allow_metadata_inventory_put = tNode.allow_metadata_inventory_put, allow_metadata_inventory_move = tNode.allow_metadata_inventory_move, diff --git a/digtron/battery.lua b/digtron/battery.lua index ba09deb..c753081 100644 --- a/digtron/battery.lua +++ b/digtron/battery.lua @@ -140,27 +140,21 @@ techage.register_consumer("digtron_battery", S("Digtron Battery"), { act = tiles end end end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - local node = ItemStack(oldnode.name) - if oldmetadata.inventory then - local total = count_coal(oldmetadata) - local meta = node:get_meta() + preserve_metadata = function(pos, oldnode, oldmetadata, drops) + metadata = M(pos):to_table() + if metadata.inventory then + local total = count_coal(metadata) + local meta = drops[1]:get_meta() meta:set_int("coal", total) local text = S("Digtron Battery").." ("..math.floor(total/TOTAL_MAX * 100).." %)" meta:set_string("description", text) end - local inv = minetest.get_inventory({type="player", name=digger:get_player_name()}) - local left_over = inv:add_item("main", node) - if left_over:get_count() > 0 then - minetest.add_item(pos, node) - end end, on_rightclick = function(pos, node, clicker) techage.set_activeformspec(pos, clicker) local nvm = techage.get_nvm(pos) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) end, - drop = "", node_timer = keep_running, on_receive_fields = on_receive_fields, allow_metadata_inventory_put = allow_metadata_inventory_put,