diff --git a/nodes/node_battery_holder.lua b/nodes/node_battery_holder.lua index c869a0f..4dc6474 100644 --- a/nodes/node_battery_holder.lua +++ b/nodes/node_battery_holder.lua @@ -67,28 +67,11 @@ local def = { -- Allow all items with energy storage to be placed in the inventory allow_metadata_inventory_put = function(pos, listname, _, stack, player) if listname == "batteries" then - if not minetest.global_exists("technic") then - return 0 - end - - local node_name = stack:get_name() - - -- Allow all items with energy storage from technic mod - if technic.power_tools[node_name] ~= nil then - local meta = stack:get_metadata() - local md = minetest.deserialize(meta) - -- And specifically if they hold any charge - -- Disregard empty batteries, the player should know better - if md and md.charge > 0 then - if digtron.check_protected_and_record(pos, player) then - return 0 - end - return stack:get_count() - else + if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then + if digtron.check_protected_and_record(pos, player) then return 0 end - else - return 0 + return stack:get_count() end end return 0 @@ -116,12 +99,9 @@ local def = { return inv:add_item("batteries", stack) end, can_insert = function(pos, _, stack) - local meta = stack:get_metadata() - local md = minetest.deserialize(meta) - -- And specifically if they hold any charge -- Disregard empty batteries, the player should know better - if md and md.charge > 0 then - meta = minetest.get_meta(pos) + if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then + local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:room_for_item("batteries", stack) end diff --git a/util.lua b/util.lua index 5b0a8d6..9d53c78 100644 --- a/util.lua +++ b/util.lua @@ -262,17 +262,14 @@ digtron.tap_batteries = function(battery_positions, target, test) end for _, itemstack in pairs(invlist) do - local meta = minetest.deserialize(itemstack:get_metadata()) - if (meta ~= nil) then - local power_available = math.floor(meta.charge / digtron.config.power_ratio) + if minetest.global_exists("technic") then + local power_available = math.floor(technic.get_charge(itemstack) / digtron.config.power_ratio) if power_available ~= 0 then local actual_burned = power_available -- we just take all we have from the battery, since they aren't stackable -- don't bother recording the items if we're just testing, nothing is actually being removed. if test ~= true then -- since we are taking everything, the wear and charge can both be set to 0 - itemstack:set_wear(0) - meta.charge = 0 - itemstack:set_metadata(minetest.serialize(meta)) + technic.set_charge(itemstack, 0) end current_burned = current_burned + actual_burned end