diff --git a/tools.lua b/tools.lua index a3a31bd..2fe8386 100644 --- a/tools.lua +++ b/tools.lua @@ -639,6 +639,137 @@ minetest.register_craft({ } }) +local registeredElectricSabers={} +local function registerElectricSaber(config) + local definition={ + description=S(config.displayName), + inventory_image="industrialtest_"..config.name..".png", + _industrialtest_powerStorage=true, + _industrialtest_powerCapacity=10000, + _industrialtest_powerFlow=industrialtest.api.lvPowerFlow + } + if industrialtest.mtgAvailable then + definition.groups={ + sword=1 + } + definition.tool_capabilities={ + full_punch_interval=0.5, + max_drop_level=config.maxDropLevel, + groupcaps={ + snappy={ + times=config.inactiveTimes, + maxlevel=config.maxLevel + } + }, + damage_groups={fleshy=config.inactiveDamage} + } + elseif industrialtest.mclAvailable then + definition.groups={ + weapon=1, + sword=1, + dig_speed_class=config.digSpeedClass + } + definition.tool_capabilities={ + full_punch_interval=0.5, + max_drop_level=config.maxDropLevel, + damage_groups={fleshy=config.inactiveDamage} + } + definition.after_use=function() + -- Hack to make sure that saber won't be destroyed when has 0 EU in MCL + return nil + end + definition._mcl_toollike_wield=true + definition._mcl_diggroups={ + swordy={ + speed=config.inactiveDigSpeed, + level=config.digLevel, + uses=-1 + }, + swordy_cobweb={ + speed=config.inactiveDigSpeed, + level=config.digLevel, + uses=-1 + } + } + end + minetest.register_tool("industrialtest:"..config.name,definition) + definition=table.copy(definition) + if industrialtest.mtgAvailable then + definition.tool_capabilities.groupcaps.snappy.times=config.activeTimes + definition.tool_capabilities.damage_groups.fleshy=config.activeDamage + elseif industrialtest.mclAvailable then + definition.tool_capabilities.damage_groups.fleshy=config.activeDamage + definition._mcl_diggroups.swordy.speed=config.activeDigSpeed + definition._mcl_diggroups.swordy_cobweb.speed=config.activeDigSpeed + end + definition.groups.not_in_creative_inventory=1 + definition.after_use=function() + return nil + end + minetest.register_tool("industrialtest:"..config.name.."_active",definition) + registeredElectricSabers["industrialtest:"..config.name]=true +end +definition={ + name="electric_saber", + displayName="Electric Saber" +} +if industrialtest.mtgAvailable then + definition.maxDropLevel=1 + definition.inactiveTimes={[1]=10,[2]=5.6,[3]=4} + definition.maxLevel=3 + definition.inactiveDamage=1 + definition.activeTimes={[1]=2.0,[2]=0.8,[3]=0.4} + definition.activeDamage=6 +elseif industrialtest.mclAvailable then + definition.digSpeedClass=4 + definition.maxDropLevel=4 + definition.inactiveDamage=1 + definition.inactiveDigSpeed=1 + definition.digLevel=4 + definition.activeDamage=6 + definition.activeDigSpeed=7 +end +registerElectricSaber(definition) +minetest.register_craft({ + type="shaped", + output="industrialtest:electric_saber", + recipe={ + {"industrialtest:refined_iron_ingot"}, + {"industrialtest:refined_iron_ingot"}, + {"industrialtest:re_battery"} + } +}) +definition={ + name="diamond_electric_saber", + displayName="Diamond Electric Saber" +} +if industrialtest.mtgAvailable then + definition.maxDropLevel=1 + definition.inactiveTimes={[1]=10,[2]=5.6,[3]=4} + definition.maxLevel=3 + definition.inactiveDamage=1 + definition.activeTimes={[1]=2.0,[2]=0.8,[3]=0.4} + definition.activeDamage=9 +elseif industrialtest.mclAvailable then + definition.digSpeedClass=5 + definition.maxDropLevel=5 + definition.inactiveDamage=1 + definition.inactiveDigSpeed=1 + definition.digLevel=5 + definition.activeDamage=9 + definition.activeDigSpeed=9 +end +registerElectricSaber(definition) +minetest.register_craft({ + type="shapeless", + output="industrialtest:diamond_electric_saber", + recipe={ + "industrialtest:electric_saber", + industrialtest.elementKeys.diamond, + industrialtest.elementKeys.diamond + } +}) + -- Tool callbacks minetest.register_on_punchnode(function(pos,node,user,pointed) if user then @@ -670,6 +801,29 @@ minetest.register_on_punchnode(function(pos,node,user,pointed) user:set_wielded_item(itemstack) end end + elseif registeredElectricSabers[itemstack:get_name()] then + 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.snappy) or (industrialtest.mclAvailable and def.groups and (def.groups.swordy or def.groups.swordy_cobweb)) then + itemstack:set_name(itemstack:get_name().."_active") + user:set_wielded_item(itemstack) + end + end end end end) +minetest.register_on_punchplayer(function(player,hitter) + local itemstack=hitter:get_wielded_item() + if registeredElectricSabers[itemstack:get_name()] then + local meta=itemstack:get_meta() + if meta:get_int("industrialtest.powerAmount")>=20 then + industrialtest.api.addPowerToItem(itemstack,-20) + hitter:set_wielded_item(itemstack) + local def=minetest.registered_tools[itemstack:get_name().."_active"] + player:set_hp(player:get_hp()-def.tool_capabilites.damage_groups.fleshy) + return true + end + end + return false +end)