Skip to content

Commit 059ec55

Browse files
authored
Restore technic.charge_tools for compatibility (#403)
1 parent b56f042 commit 059ec55

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

technic/machines/compat/tools.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,22 @@ function technic.set_RE_wear(stack, charge)
118118
minetest.log("warning", "Use of deprecated function technic.set_RE_wear with stack: "..stack:get_name())
119119
compat_set_RE_wear(stack, charge)
120120
end
121+
122+
-- Old utility function to recharge tools
123+
local function charge_tools(meta, batt_charge, charge_step)
124+
local src_stack = meta:get_inventory():get_stack("src", 1)
125+
local def = src_stack:get_definition()
126+
if not def or not def.technic_max_charge or src_stack:is_empty() then
127+
return batt_charge, false
128+
end
129+
local new_charge = math.min(def.technic_max_charge, def.technic_get_charge(src_stack) + charge_step)
130+
def.technic_set_charge(src_stack, new_charge)
131+
meta:get_inventory():set_stack("src", 1, src_stack)
132+
return batt_charge, (def.technic_max_charge == new_charge)
133+
end
134+
135+
function technic.charge_tools(...)
136+
minetest.log("warning", "Use of deprecated function technic.charge_tools")
137+
technic.charge_tools = charge_tools
138+
return charge_tools(...)
139+
end

0 commit comments

Comments
 (0)