You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've had technic.get_RE_charge, technic.set_RE_charge and technic.use_RE_charge available for some time (since 2022), those are also used in various mods already.
Around 2024 minetest-mods/technic added technic.get_charge and technic.set_charge which have compatible interface with Technic Plus counterparts.
For consistency would be good to also add technic.use_charge, preferably even attempt to bring last one also to minetest-mods/technic. Function itself is fairly simple, basically just a shortcut wrapper around get/set functions.
Should then probably also prefer technic.get_charge, technic.set_charge and technic.use_charge by replacing their .*_RE.* counterparts in documentation.
This would give significantly better API compatibility for power tools.
The text was updated successfully, but these errors were encountered:
- if technic.plus then- replacer.get_charge = technic.get_RE_charge- replacer.set_charge = technic.set_RE_charge- else- -- technic still stores data serialized, so this is the nearest we get to current standard- function replacer.get_charge(itemstack)- local meta = deserialize(itemstack:get_meta():get_string(''))- if (not meta) or (not meta.charge) then- return 0- end- return meta.charge- end-- function replacer.set_charge(itemstack, charge, maximum)- technic.set_RE_wear(itemstack, charge, maximum)- local meta = itemstack:get_meta()- local data = deserialize(meta:get_string(''))- if (not data) or (not data.charge) then- data = { charge = 0 }- end- data.charge = charge- meta:set_string('', serialize(data))- end- end+ replacer.get_charge = technic.get_charge+ replacer.set_charge = technic.set_charge
-- Technic Plus
if technic.use_charge ~= nil then
if not technic.use_charge(itemstack, technic_charge_per_use) then
reload = true
end
else
- -- Technic Plus- local meta = itemstack:get_meta()- local old_metadata = minetest.deserialize(meta:get_string(""))- local charge = nil+ local charge = technic.get_charge(itemstack)- if old_metadata then- charge = old_metadata.charge- end- -- Technic- if not charge then- charge = meta:get_int("technic:charge")- end-
if charge < technic_charge_per_use then
reload = true
- else- if not technic.creative_mode then+ elseif not technic.creative_mode then- charge = charge - technic_charge_per_use- technic.set_RE_wear(itemstack, charge, technic_charge)- if old_metadata and old_metadata.charge then- old_metadata.charge = charge- meta:set_string("", minetest.serialize(old_metadata))- else- meta:set_int("technic:charge", charge)- end- end+ technic.set_charge(itemstack, charge - technic_charge_per_use)
end
end
We've had
technic.get_RE_charge
,technic.set_RE_charge
andtechnic.use_RE_charge
available for some time (since 2022), those are also used in various mods already.Around 2024 minetest-mods/technic added
technic.get_charge
andtechnic.set_charge
which have compatible interface with Technic Plus counterparts.For consistency would be good to also add
technic.use_charge
, preferably even attempt to bring last one also to minetest-mods/technic. Function itself is fairly simple, basically just a shortcut wrapper around get/set functions.Should then probably also prefer
technic.get_charge
,technic.set_charge
andtechnic.use_charge
by replacing their.*_RE.*
counterparts in documentation.This would give significantly better API compatibility for power tools.
The text was updated successfully, but these errors were encountered: