Add rubber tree related items

This commit is contained in:
2023-03-15 18:10:54 +01:00
parent 1b502bf944
commit 63bdb0e0e6
4 changed files with 119 additions and 2 deletions

31
api.lua
View File

@@ -49,6 +49,37 @@ industrialtest.api.preparePowerStorageItem=function(itemstack)
industrialtest.api.updateItemPowerText(itemstack)
return true
end
industrialtest.api.prepareToolItem=function(itemstack)
local def=minetest.registered_tools[itemstack:get_name()]
if not def or not def._industrialtest_tool or not def.tool_capabilities or not def.tool_capabilities.uses then
return false
end
local meta=itemstack:get_meta()
meta:set_int("industrialtest.uses",def.tool_capabilities.uses)
return true
end
industrialtest.api.afterToolUse=function(itemstack)
local meta=itemstack:get_meta()
local def=minetest.registered_tools[itemstack:get_name()]
if not def or not def._industrialtest_tool or not def.tool_capabilities or not def.tool_capabilities.uses then
return
end
if not meta:contains("industrialtest.uses") then
industrialtest.prepareToolItem(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
end
meta:set_int("industrialtest.uses",uses)
itemstack:set_wear(65535-uses/def.tool_capabilities.uses*65535)
end
industrialtest.api.isFullyCharged=function(meta)
return meta:get_int("industrialtest.powerAmount")>=meta:get_int("industrialtest.powerCapacity")
end