Move some common tool functionality to separate files for further usage

This commit is contained in:
2025-04-06 22:07:38 +02:00
parent 25680ace72
commit ae123446ad
6 changed files with 151 additions and 90 deletions

View File

@@ -164,20 +164,6 @@ function industrialtest.api.updateItemPowerText(itemstack)
itemstack:set_wear(65535-meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*65534)
end
-- \brief Adds power storage to item depending on it's definition
-- \param itemstack ItemStack to which item storage should be added
-- \returns true if power storage was successfully added, false otherwise
function industrialtest.api.preparePowerStorageItem(itemstack)
local meta=itemstack:get_meta()
local def=minetest.registered_tools[itemstack:get_name()]
if industrialtest.api.hasPowerStorage(meta) or not def or not def._industrialtest_powerStorage or not def._industrialtest_powerCapacity or not def._industrialtest_powerFlow then
return false
end
industrialtest.api.addPowerStorage(meta,def._industrialtest_powerCapacity,def._industrialtest_powerFlow,"n/a")
industrialtest.api.updateItemPowerText(itemstack)
return true
end
-- \brief Adds power to itemstack. Function checks if itemstack has power storage.
-- \param itemstack ItemStack to which add power
-- \param amount How much power to add