From 93573f22ee401e6357d5c9e543bfa4e7360d13bc Mon Sep 17 00:00:00 2001 From: OgelGames Date: Mon, 1 Jun 2020 19:22:28 +1000 Subject: [PATCH] Fix and simplify battery usage (#65) Changes digtron.tap_batteries function so that battery wear and charge is set directly to 0 instead of needlessly calculating it. Fixes a crash that happens if a battery item doesn't define tool capabilities. --- util.lua | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/util.lua b/util.lua index d69ea71..7030184 100644 --- a/util.lua +++ b/util.lua @@ -256,28 +256,12 @@ digtron.tap_batteries = function(battery_positions, target, test) local power_available = math.floor(meta.charge / 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 - -- don't bother recording the items if we're just testing, nothing is actually being removed. - local charge_left = meta.charge - power_available * digtron.config.power_ratio - local properties = itemstack:get_tool_capabilities() - -- itemstack = technic.set_RE_wear(itemstack, charge_left, properties.groupcaps.fleshy.uses) - -- we only need half the function, so why bother using it in the first place - - -- Charge is stored separately, but shown as wear level - -- This calls for recalculating the value. - local charge_level - if charge_left == 0 then - charge_level = 0 - else - charge_level = 65536 - math.floor(charge_left / properties.groupcaps.fleshy.uses * 65535) - if charge_level > 65535 then charge_level = 65535 end - if charge_level < 1 then charge_level = 1 end - end - itemstack:set_wear(charge_level) - - meta.charge = charge_left + -- 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)) - end current_burned = current_burned + actual_burned end