From 72f9c22903b855a8b6b7f0dc84e2ee71e206a8bf Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Thu, 23 Mar 2023 15:24:39 +0100 Subject: [PATCH] Implement Electric Treetap --- tools.lua | 63 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/tools.lua b/tools.lua index 2355522..63a0e87 100644 --- a/tools.lua +++ b/tools.lua @@ -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" + } +}) \ No newline at end of file