Compare commits

...

2 Commits

Author SHA1 Message Date
62246bf91b Make sure that pointed thing is node when using treetap 2025-04-28 12:53:19 +02:00
8d48b3f9f5 Refactor wrench 2025-04-28 12:53:03 +02:00
3 changed files with 63 additions and 43 deletions

View File

@ -53,6 +53,29 @@ function industrialtest.Tool.onPlace(self,itemstack,user,pointed)
return false
end
function industrialtest.Tool.onUse(self,itemstack,user,pointed)
if self:hitUse(itemstack,user,pointed) then
local meta=itemstack:get_meta()
if not meta:contains("industrialtest.uses") then
self:prepare(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.prepare(self,itemstack)
local meta=itemstack:get_meta()
meta:set_int("industrialtest.uses",self.uses)

View File

@ -19,6 +19,9 @@ if industrialtest.mods.mclRubber then
end
local function onTreetapUse(user,pointed)
if pointed.type~="node" or not user or not user:is_player() then
return false
end
local node=minetest.get_node_or_nil(pointed.under)
if not node then
return false
@ -47,7 +50,7 @@ industrialtest.internal.unpackTableInto(industrialtest.Treetap,{
})
function industrialtest.Treetap.use(self,itemstack,user,pointed)
return pointed.type=="node" and user and user:is_player() and onTreetapUse(user,pointed)
return onTreetapUse(user,pointed)
end
industrialtest.Treetap:register()
@ -73,7 +76,7 @@ industrialtest.internal.unpackTableInto(industrialtest.ElectricTreetap,{
})
function industrialtest.ElectricTreetap.use(self,itemstack,user,pointed)
return user and user:is_player() and onTreetapUse(user,pointed)
return onTreetapUse(user,pointed)
end
function industrialtest.ElectricTreetap.getOpPower(self,itemstack)

View File

@ -16,6 +16,9 @@
local S=minetest.get_translator("industrialtest")
local function onWrenchUse(user,pointed)
if pointed.type~="node" or not user or not user:is_player() then
return false
end
local node=minetest.get_node_or_nil(pointed.under)
if not node then
return false
@ -37,29 +40,22 @@ local function onWrenchUse(user,pointed)
return true
end
local definition={
industrialtest.Wrench=table.copy(industrialtest.Tool)
industrialtest.internal.unpackTableInto(industrialtest.Wrench,{
name="industrialtest:wrench",
define={onUse=true},
description=S("Wrench"),
inventory_image="industrialtest_wrench.png",
tool_capabilities={
full_punch_interval=1,
uses=200
},
on_use=function(itemstack,user,pointed)
if pointed.type=="node" and user and user:is_player() and onWrenchUse(user,pointed) then
industrialtest.api.afterToolUse(itemstack)
return itemstack
end
return nil
end,
_industrialtest_tool=true
}
if industrialtest.mclAvailable then
definition.groups={
tool=1
}
definition._mcl_toollike_wield=true
inventoryImage="industrialtest_wrench.png",
uses=200,
repairMaterial=industrialtest.elementKeys.bronzeIngot
})
function industrialtest.Wrench.hitUse(self,itemstack,user,pointed)
return onWrenchUse(user,pointed)
end
minetest.register_tool("industrialtest:wrench",definition)
industrialtest.Wrench:register()
minetest.register_craft({
type="shaped",
output="industrialtest:wrench",
@ -70,28 +66,26 @@ minetest.register_craft({
}
})
definition={
industrialtest.ElectricWrench=table.copy(industrialtest.ElectricTool)
industrialtest.internal.unpackTableInto(industrialtest.ElectricWrench,{
name="industrialtest:electric_wrench",
define={onUse=true},
description=S("Electric Wrench"),
inventory_image="industrialtest_electric_wrench.png",
on_use=function(itemstack,user,pointed)
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=20 and user and user:is_player() and onWrenchUse(user,pointed) then
industrialtest.api.addPowerToItem(itemstack,-20)
return itemstack
end
return nil
end,
_industrialtest_powerStorage=true,
_industrialtest_powerCapacity=10000,
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
}
if industrialtest.mclAvailable then
definition.groups={
tool=1
}
definition._mcl_toollike_wield=true
inventoryImage="industrialtest_electric_wrench.png",
capacity=10000,
flow=industrialtest.api.lvPowerFlow
})
function industrialtest.ElectricWrench.getOpPower(self,itemstack)
return 50
end
minetest.register_tool("industrialtest:electric_wrench",definition)
function industrialtest.ElectricWrench.hitUse(self,itemstack,user,pointed)
return onWrenchUse(user,pointed)
end
industrialtest.ElectricWrench:register()
minetest.register_craft({
type="shapeless",
output="industrialtest:electric_wrench",