From eed94c485319ba62b98fd7130be9ac3ac3813f23 Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Tue, 16 Jan 2024 18:38:24 +0100 Subject: [PATCH] Implement Solar Helmet It can charge equipped electric tools from environment light. --- compatibility.lua | 2 + init.lua | 1 + tools/solar_helmet.lua | 115 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 tools/solar_helmet.lua diff --git a/compatibility.lua b/compatibility.lua index 5c8b6f8..201ad76 100644 --- a/compatibility.lua +++ b/compatibility.lua @@ -538,6 +538,7 @@ if industrialtest.mclAvailable then industrialtest.elementKeys.copperBlock="mcl_copper:block" industrialtest.elementKeys.stoneWithCopper="mcl_copper:stone_with_copper" industrialtest.elementKeys.ironPickaxe="mcl_tools:pick_iron" + industrialtest.elementKeys.ironHelmet="mcl_tools:helmet_iron" industrialtest.elementKeys.ironBoots="mcl_armor:boots_iron" industrialtest.elementKeys.lavaSource="mcl_core:lava_source" industrialtest.elementKeys.waterSource="mcl_core:water_source" @@ -764,6 +765,7 @@ elseif industrialtest.mtgAvailable then industrialtest.elementKeys.stoneWithTin="default:stone_with_tin" industrialtest.elementKeys.bronzeBlock="default:bronzeblock" industrialtest.elementKeys.ironPickaxe="default:pick_steel" + industrialtest.elementKeys.ironHelmet="3d_armor:helmet_steel" industrialtest.elementKeys.ironBoots="3d_armor:boots_steel" industrialtest.elementKeys.lavaSource="default:lava_source" industrialtest.elementKeys.waterSource="default:water_source" diff --git a/init.lua b/init.lua index 314d851..8f8a981 100644 --- a/init.lua +++ b/init.lua @@ -58,6 +58,7 @@ dofile(modpath.."/tools/electric_drill.lua") dofile(modpath.."/tools/electric_hoe.lua") dofile(modpath.."/tools/electric_saber.lua") dofile(modpath.."/tools/jetpack.lua") +dofile(modpath.."/tools/solar_helmet.lua") dofile(modpath.."/tools/static_boots.lua") dofile(modpath.."/tools/treetap.lua") dofile(modpath.."/tools/wrench.lua") diff --git a/tools/solar_helmet.lua b/tools/solar_helmet.lua new file mode 100644 index 0000000..6493507 --- /dev/null +++ b/tools/solar_helmet.lua @@ -0,0 +1,115 @@ +-- 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 onGlobalStep(player,inv,stack) + if stack:get_name()~="industrialtest:solar_helmet" then + return false + end + local amount=math.floor(minetest.get_node_light(player:get_pos())/2) + if amount==0 then + return true + end + local armorList=inv:get_list("armor") + for i=1,#armorList do + local meta=armorList[i]:get_meta() + if industrialtest.api.hasPowerStorage(meta) and not industrialtest.api.isFullyCharged(meta) then + industrialtest.api.addPowerToItem(armorList[i],amount) + inv:set_stack("armor",i,armorList[i]) + break + end + end + return true +end + +if industrialtest.mtgAvailable then + armor:register_armor("industrialtest:solar_helmet",{ + description=S("Solar Helmet"), + inventory_image="industrialtest_solar_helmet_inv.png", + groups={ + armor_head=1, + armor_heal=0 + } + }) +elseif industrialtest.mclAvailable then + minetest.register_tool("industrialtest:solar_helmet",{ + description=S("Solar Helmet"), + inventory_image="industrialtest_solar_helmet_inv.png", + groups={ + armor=1, + non_combat_armor=1, + armor_head=1, + non_combat_feet=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="head", + _mcl_armor_texture="industrialtest_solar_helmet.png" + }) +end +minetest.register_craft({ + type="shaped", + output="industrialtest:solar_helmet", + recipe={ + {industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot,industrialtest.elementKeys.ironIngot}, + {industrialtest.elementKeys.ironIngot,"industrialtest:solar_panel",industrialtest.elementKeys.ironIngot}, + {"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"} + } +}) +minetest.register_craft({ + type="shaped", + output="industrialtest:solar_helmet", + recipe={ + {"",industrialtest.elementKeys.ironHelmet,""}, + {"","industrialtest:solar_panel",""}, + {"industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable","industrialtest:insulated_copper_cable"} + } +}) + +minetest.register_globalstep(function(dtime) + updateDelta=updateDelta+dtime + if updateDelta