Merge pull request #26 from Thomas--S/digtron_preserve_meta

Digtron Battery: Fix duplication bug
This commit is contained in:
Joachim Stolberg 2020-08-23 18:20:25 +02:00 committed by GitHub
commit 5fbfe95011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -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,

View File

@ -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,