Implement Electric Treetap

This commit is contained in:
mrkubax10 2023-03-23 15:24:39 +01:00
parent da3d99164b
commit 72f9c22903
1 changed files with 49 additions and 14 deletions

View File

@ -16,6 +16,21 @@
local S=minetest.get_translator("industrialtest")
local function onTreetapUse(user,pointed)
local node=minetest.get_node_or_nil(pointed.under)
if not node then
return false
end
-- Note: if more nodes from which treetap can extract will be added then they shouldn't be added here
-- Instead they should have additional entry in definition which will denote that treetap can be used on them
if node.name=="industrialtest:rubber_wood_with_rubber" then
local inv=user:get_inventory()
inv:add_item("main",ItemStack("industrialtest:sticky_resin"))
minetest.set_node(pointed.under,{name="industrialtest:rubber_wood"})
return true
end
return false
end
local definition={
description=S("Treetap"),
inventory_image="industrialtest_treetap.png",
@ -24,20 +39,9 @@ local definition={
uses=50
},
on_place=function(itemstack,user,pointed)
if pointed.type=="node" and user and user:is_player() then
local node=minetest.get_node_or_nil(pointed.under)
if not node then
return nil
end
-- Note: if more nodes from which treetap can extract will be added then they shouldn't be added here
-- Instead they should have additional entry in definition which will denote that treetap can be used on them
if node.name=="industrialtest:rubber_wood_with_rubber" then
local inv=user:get_inventory()
inv:add_item("main",ItemStack("industrialtest:sticky_resin"))
minetest.set_node(pointed.under,{name="industrialtest:rubber_wood"})
industrialtest.api.afterToolUse(itemstack)
return itemstack
end
if pointed.type=="node" and user and user:is_player() and onTreetapUse(user,pointed) then
industrialtest.api.afterToolUse(itemstack)
return itemstack
end
return nil
end,
@ -64,3 +68,34 @@ minetest.register_craft({
{"group:wood","",""}
}
})
definition={
description=S("Electric Treetap"),
inventory_image="industrialtest_electric_treetap.png",
on_place=function(itemstack,user,pointed)
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=50 and user and user:is_player() and onTreetapUse(user,pointed) then
industrialtest.api.addPowerToItem(itemstack,-50)
return itemstack
end
return nil
end,
_industrialtest_powerStorage=true,
_industrialtest_powerCapacity=7000,
_industrialtest_powerFlow=industrialtest.api.lvPowerFlow
}
if industrialtest.mclAvailable then
definition.groups={
tool=1
}
definition._mcl_toollike_wield=true
end
minetest.register_tool("industrialtest:electric_treetap",definition)
minetest.register_craft({
type="shapeless",
output="industrialtest:electric_treetap",
recipe={
"industrialtest:treetap",
"industrialtest:electronic_circuit",
"industrialtest:re_battery"
}
})