From 90c9779bf09044de7ffed7bebb9223781886af74 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Sat, 8 Apr 2023 19:09:15 +0200 Subject: [PATCH] Implement Electric Chainsaw --- machines.lua | 2 +- tools.lua | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) diff --git a/machines.lua b/machines.lua index 1baccd0..439f9a3 100644 --- a/machines.lua +++ b/machines.lua @@ -331,7 +331,7 @@ registerMachine({ local shouldUpdateFormspec=flowTransferred local shouldRerunTimer=(afterFlow and meta:get_int("industrialtest.powerAmount")>0) if chargedSlot:get_count()>0 and not industrialtest.api.isFullyCharged(chargedSlot:get_meta()) and meta:get_int("industrialtest.powerAmount")>0 then - industrialtest.api.transferPowerToItem(meta,chargedSlot,powerFlow) + industrialtest.api.transferPowerToItem(meta,chargedSlot,chargedSlot:get_meta():get_int("industrialtest.powerFlow")) inv:set_stack("charged",1,chargedSlot) shouldUpdateFormspec=true shouldRerunTimer=true diff --git a/tools.lua b/tools.lua index d954078..a2d84e8 100644 --- a/tools.lua +++ b/tools.lua @@ -184,3 +184,129 @@ minetest.register_craft({ "industrialtest:re_battery" } }) + +local registeredElectricChainsaws={} +local function registerElectricChainsaw(config) + local definition={ + description=S(config.displayName), + inventory_image="industrialtest_"..config.name..".png", + _industrialtest_powerStorage=true, + _industrialtest_powerCapacity=7000, + _industrialtest_powerFlow=industrialtest.api.lvPowerFlow + } + if industrialtest.mtgAvailable then + definition.tool_capabilities={ + full_punch_interval=0.5, + max_drop_level=config.maxDropLevel, + groupcaps={ + choppy={ + times=config.inactiveTimes, + maxlevel=config.maxLevel + } + } + } + definition.groups={ + axe=1 + } + elseif industrialtest.mclAvailable then + definition.tool_capabilities={ + full_punch_interval=0.5, + max_drop_level=config.maxDropLevel, + } + definition.groups={ + dig_speed_class=config.digSpeedClass, + } + definition.after_use=function(itemstack) + -- Hack to make sure that chainsaw won't be destroyed when has 0 EU in MCL + return nil + end + definition._mcl_diggroups={ + axey={ + speed=config.inactiveDigSpeed, + level=config.digLevel, + uses=-1 + } + } + definition._mcl_toollike_wield=true + end + minetest.register_tool("industrialtest:"..config.name,definition) + definition=table.copy(definition) + if industrialtest.mtgAvailable then + definition.tool_capabilities.groupcaps.choppy.times=config.activeTimes + elseif industrialtest.mclAvailable then + definition._mcl_diggroups.axey.speed=config.activeDigSpeed + end + definition.groups.not_in_creative_inventory=1 + definition.on_use=nil + definition.after_use=function(itemstack,user,node,digparams) + industrialtest.api.addPowerToItem(itemstack,-20) + itemstack:set_name("industrialtest:"..config.name) + return itemstack + end + minetest.register_tool("industrialtest:"..config.name.."_active",definition) + registeredElectricChainsaws["industrialtest:"..config.name]=true +end +minetest.register_on_punchnode(function(pos,node,user,pointed) + if user and registeredElectricChainsaws[user:get_wielded_item():get_name()] then + local itemstack=user:get_wielded_item() + local meta=itemstack:get_meta() + if meta:get_int("industrialtest.powerAmount")>=20 then + local def=minetest.registered_nodes[node.name] + if (industrialtest.mtgAvailable and def.groups and def.groups.choppy) or (industrialtest.mclAvailable and def.groups and def.groups.axey) then + itemstack:set_name(itemstack:get_name().."_active") + user:set_wielded_item(itemstack) + end + end + end +end) +definition={ + name="electric_chainsaw", + displayName="Electric Chainsaw" +} +if industrialtest.mtgAvailable then + definition.maxDropLevel=1 + definition.inactiveTimes={[1]=10,[2]=5.6,[3]=4} + definition.maxLevel=2 + definition.activeTimes={[1]=2.2,[2]=1.1,[3]=0.7} +elseif industrialtest.mclAvailable then + definition.digSpeedClass=4 + definition.maxDropLevel=4 + definition.inactiveDigSpeed=1 + definition.digLevel=4 + definition.activeDigSpeed=7 +end +registerElectricChainsaw(definition) +minetest.register_craft({ + type="shaped", + output="industrialtest:electric_chainsaw", + recipe={ + {"","industrialtest:refined_iron_ingot","industrialtest:refined_iron_ingot"}, + {"industrialtest:refined_iron_ingot","industrialtest:electronic_circuit","industrialtest:refined_iron_ingot"}, + {"industrialtest:re_battery","industrialtest:refined_iron_ingot",""} + } +}) +definition={ + name="diamond_electric_chainsaw", + displayName="Diamond Electric Chainsaw" +} +if industrialtest.mtgAvailable then + definition.maxDropLevel=1 + definition.inactiveTimes={[1]=10,[2]=5.6,[3]=4} + definition.maxLevel=3 + definition.activeTimes={[1]=2.0,[2]=0.8,[3]=0.4} +elseif industrialtest.mclAvailable then + definition.digSpeedClass=5 + definition.maxDropLevel=5 + definition.inactiveDigSpeed=1 + definition.digLevel=5 + definition.activeDigSpeed=9 +end +registerElectricChainsaw(definition) +minetest.register_craft({ + type="shaped", + output="industrialtest:diamond_electric_chainsaw", + recipe={ + {"",industrialtest.elementKeys.diamond,""}, + {industrialtest.elementKeys.diamond,"industrialtest:electric_chainsaw",industrialtest.elementKeys.diamond} + } +})