-- IndustrialTest -- Copyright (C) 2025 mrkubax10 -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . industrialtest.Tool={} function industrialtest.Tool.use(self,itemstack,user,pointed) -- dummy function return false end function industrialtest.Tool.onPlace(self,itemstack,user,pointed) if self:use(itemstack,user,pointed) then local meta=itemstack:get_meta() if not meta:contains("industrialtest.uses") then self:prepareTool(itemstack) end local uses=meta:get_int("industrialtest.uses")-1 if uses==0 then itemstack:set_count(0) minetest.sound_play({name="default_tool_breaks"},{ gain=1, fade=0, pitch=1 },true) return true end meta:set_int("industrialtest.uses",uses) itemstack:set_wear(65535-uses/self.uses*65535) return true end return false end function industrialtest.Tool.prepareTool(self,itemstack) local meta=itemstack:get_meta() meta:set_int("industrialtest.uses",self.uses) end function industrialtest.Tool.createDefinitionTable(self) local def={ description=self.description, inventory_image=self.inventoryImage, tool_capabilities={ full_punch_interval=1, uses=self.uses }, on_place=function(itemstack,user,pointed) if self:onPlace(itemstack,user,pointed) then return itemstack end return nil end, _industrialtest_self=self } if industrialtest.mtgAvailable then def.groups={ flammable=self.flammable } elseif industrialtest.mclAvailable then def.groups={ tool=1 } def._repair_material=self.repairMaterial def._mcl_toollike_wield=true end return def end function industrialtest.Tool.register(self) local def=self:createDefinitionTable() minetest.register_tool(self.name,def) end -- Item callbacks minetest.register_on_player_inventory_action(function(player,action,inventory,info) if action=="put" then local def=info.stack:get_definition() if def and def._industrialtest_self then def._industrialtest_self:prepareTool(info.stack) inventory:set_stack(info.listname,info.index,info.stack) end end end) minetest.register_on_craft(function(itemstack) local def=itemstack:get_definition() if def and def._industrialtest_self then def._industrialtest_self:prepareTool(itemstack) end end)