mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-22 20:32:22 +01:00
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.
This commit is contained in:
parent
c969676657
commit
93573f22ee
24
util.lua
24
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)
|
local power_available = math.floor(meta.charge / digtron.config.power_ratio)
|
||||||
if power_available ~= 0 then
|
if power_available ~= 0 then
|
||||||
local actual_burned = power_available -- we just take all we have from the battery, since they aren't stackable
|
local actual_burned = power_available -- we just take all we have from the battery, since they aren't stackable
|
||||||
if test ~= true then
|
|
||||||
-- don't bother recording the items if we're just testing, nothing is actually being removed.
|
-- 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
|
if test ~= true then
|
||||||
local properties = itemstack:get_tool_capabilities()
|
-- since we are taking everything, the wear and charge can both be set to 0
|
||||||
-- itemstack = technic.set_RE_wear(itemstack, charge_left, properties.groupcaps.fleshy.uses)
|
itemstack:set_wear(0)
|
||||||
-- we only need half the function, so why bother using it in the first place
|
meta.charge = 0
|
||||||
|
|
||||||
-- 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
|
|
||||||
itemstack:set_metadata(minetest.serialize(meta))
|
itemstack:set_metadata(minetest.serialize(meta))
|
||||||
|
|
||||||
end
|
end
|
||||||
current_burned = current_burned + actual_burned
|
current_burned = current_burned + actual_burned
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user