diff --git a/init.lua b/init.lua index c01cad8..6bc4cf9 100644 --- a/init.lua +++ b/init.lua @@ -52,6 +52,7 @@ dofile(modpath.."/machines/solar_panel_generator.lua") dofile(modpath.."/machines/wind_mill.lua") dofile(modpath.."/tools/common.lua") +dofile(modpath.."/tools/batpack.lua") dofile(modpath.."/tools/electric_chainsaw.lua") dofile(modpath.."/tools/electric_drill.lua") dofile(modpath.."/tools/electric_hoe.lua") diff --git a/tools/batpack.lua b/tools/batpack.lua new file mode 100644 index 0000000..d24fcdd --- /dev/null +++ b/tools/batpack.lua @@ -0,0 +1,138 @@ +-- IndustrialTest +-- Copyright (C) 2024 mrkubax10 + +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +local S=minetest.get_translator("industrialtest") + +local updateDelta=0 + +local function registerBatpack(config) + if industrialtest.mtgAvailable then + armor:register_armor("industrialtest:"..config.name,{ + description=config.displayName, + inventory_image="industrialtest_"..config.name.."_inv.png", + groups={ + armor_torso=1, + armor_heal=0, + _industrialtest_batpack=1 + }, + _industrialtest_powerStorage=true, + _industrialtest_powerCapacity=config.powerCapacity, + _industrialtest_powerFlow=config.powerFlow + }) + elseif industrialtest.mclAvailable then + minetest.register_tool("industrialtest:"..config.name,{ + description=config.displayName, + inventory_image="industrialtest_"..config.name.."_inv.png", + groups={ + armor=1, + non_combat_armor=1, + armor_torso=1, + non_combat_torso=1, + _industrialtest_batpack=1 + }, + sounds={ + _mcl_armor_equip="mcl_armor_equip_iron", + _mcl_armor_unequip="mcl_armor_unequip_iron" + }, + on_place=mcl_armor.equip_on_use, + on_secondary_use=mcl_armor.equip_on_use, + _mcl_armor_element="torso", + _mcl_armor_texture="industrialtest_"..config.name..".png", + _industrialtest_powerStorage=true, + _industrialtest_powerCapacity=config.powerCapacity, + _industrialtest_powerFlow=config.powerFlow + }) + end +end + +local function onGlobalStep(player,inv,stack,index,def) + if not def.groups or not def.groups._industrialtest_batpack then + return false + end + local wielded=player:get_wielded_item() + local wieldedMeta=wielded:get_meta() + if not industrialtest.api.hasPowerStorage(wieldedMeta) or wieldedMeta:get_int("industrialtest.powerFlow")>def._industrialtest_powerFlow then + return true + end + if industrialtest.api.transferPowerFromItem(stack,wieldedMeta,def._industrialtest_powerFlow)>0 then + industrialtest.api.updateItemPowerText(wielded) + player:set_wielded_item(wielded) + inv:set_stack("armor",index,stack) + end + return true +end + +registerBatpack({ + name="batpack_v", + displayName=S("BatPack"), + powerCapacity=60000, + powerFlow=industrialtest.api.lvPowerFlow +}) +minetest.register_craft({ + type="shaped", + output="industrialtest:batpack_v", + recipe={ + {"industrialtest:re_battery","industrialtest:electronic_circuit","industrialtest:re_battery"}, + {"industrialtest:re_battery",industrialtest.elementKeys.tinIngot,"industrialtest:re_battery"}, + {"industrialtest:re_battery","","industrialtest:re_battery"} + } +}) + +registerBatpack({ + name="lappack_v", + displayName=S("LapPack"), + powerCapacity=300000, + powerFlow=industrialtest.api.hvPowerFlow +}) +minetest.register_craft({ + type="shaped", + output="industrialtest:lappack_v", + recipe={ + {industrialtest.elementKeys.powerCarrier,"industrialtest:electronic_circuit",industrialtest.elementKeys.powerCarrier}, + {industrialtest.elementKeys.powerCarrier,"industrialtest:batpack_v",industrialtest.elementKeys.powerCarrier}, + {industrialtest.elementKeys.powerCarrier,"",industrialtest.elementKeys.powerCarrier} + } +}) + +minetest.register_globalstep(function(dtime) + updateDelta=updateDelta+dtime + if updateDelta