diff --git a/init.lua b/init.lua
index d228722..f4d4277 100644
--- a/init.lua
+++ b/init.lua
@@ -66,6 +66,7 @@ dofile(modpath.."/machines/wind_mill.lua")
dofile(modpath.."/tools/common.lua")
dofile(modpath.."/tools/item.lua")
dofile(modpath.."/tools/electric_item.lua")
+dofile(modpath.."/tools/electric_armor.lua")
dofile(modpath.."/tools/fluid_container_item.lua")
dofile(modpath.."/tools/tool.lua")
dofile(modpath.."/tools/gear_tool.lua")
diff --git a/tools/electric_armor.lua b/tools/electric_armor.lua
new file mode 100644
index 0000000..6993fb1
--- /dev/null
+++ b/tools/electric_armor.lua
@@ -0,0 +1,116 @@
+-- IndustrialTest
+-- Copyright (C) 2025 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 .
+
+industrialtest.ElectricArmor={
+ prepare=industrialtest.ElectricItem.prepare
+}
+
+function industrialtest.ElectricArmor.createDefinitionTableForElement(self,element)
+ local def={
+ description=element.description,
+ inventory_image=element.inventoryImage,
+ groups={
+ _industrialtest_electricArmor=1,
+ ["armor_"..element.element]=1
+ },
+ _industrialtest_self=self
+ }
+
+ if industrialtest.mclAvailable then
+ def.groups.armor=1
+ def.groups.non_combat_armor=1
+ def.sounds={
+ _mcl_armor_equip="mcl_armor_equip_iron",
+ _mcl_armor_unequip="mcl_armor_unequip_iron"
+ }
+ def.on_place=mcl_armor.armor_on_use
+ def.on_secondary_use=mcl_armor.armor_on_use
+ def._mcl_armor_element=element.element
+ if type(element.texture)=="string" then
+ def._mcl_armor_texture=element.texture
+ else
+ def._mcl_armor_texture=element.texture[2] or element.texture[1]
+ end
+ end
+
+ return def
+end
+
+function industrialtest.ElectricArmor.register(self)
+ for _,element in ipairs(self.elements) do
+ local def=self:createDefinitionTableForElement(element)
+ local name=self.name.."_"..element.name
+ if industrialtest.mtgAvailable then
+ armor:register_armor(name,def)
+ elseif industrialtest.mclAvailable then
+ minetest.register_tool(name,def)
+ end
+ end
+end
+
+function industrialtest.ElectricArmor.tryReduceDamage(self,itemstack,hpChange)
+ local meta=itemstack:get_meta()
+ local targetReducedDamage=math.floor(math.abs(hpChange)*self:getReducedDamageForItem(itemstack))
+ local powerPerDamage=self:getPowerPerDamageForItem(itemstack)
+ local requiredPower=targetReducedDamage*powerPerDamage
+ local availablePower=math.min(meta:get_int("industrialtest.powerAmount"),requiredPower)
+ return math.floor(availablePower/powerPerDamage)
+end
+
+function industrialtest.ElectricArmor.getReducedDamageForItem(self,itemstack)
+ -- dummy function
+ return 0
+end
+
+function industrialtest.ElectricArmor.getPowerPerDamageForItem(self,itemstack)
+ -- dummy function
+ return 0
+end
+
+minetest.register_on_player_hpchange(function(player,hpChange)
+ if hpChange>0 or not player:is_player() then
+ return hpChange
+ end
+
+ local inv
+ if industrialtest.mtgAvailable then
+ _,inv=armor:get_valid_player(player,"")
+ if not inv then
+ return hpChange
+ end
+ elseif industrialtest.mclAvailable then
+ inv=player:get_inventory()
+ end
+
+ local armorList=inv:get_list("armor")
+ assert(armorList)
+ local result=hpChange
+ for i=1,#armorList do
+ local itemstack=armorList[i]
+ local def=itemstack:get_definition()
+ if def.groups and def.groups._industrialtest_electricArmor and def._industrialtest_self then
+ local reducedDamage=def._industrialtest_self:tryReduceDamage(itemstack,hpChange)
+ minetest.debug(reducedDamage)
+ if reducedDamage>0 then
+ result=result+reducedDamage
+ industrialtest.api.addPowerToItem(itemstack,-reducedDamage*def._industrialtest_self:getPowerPerDamageForItem(itemstack))
+ inv:set_stack("armor",i,itemstack)
+ end
+ end
+ end
+
+ return result
+end,true)
diff --git a/tools/nano_suit.lua b/tools/nano_suit.lua
index 0a4d1d1..44b2d3c 100644
--- a/tools/nano_suit.lua
+++ b/tools/nano_suit.lua
@@ -15,62 +15,66 @@
-- along with this program. If not, see .
local S=minetest.get_translator("industrialtest")
+industrialtest.NanoSuit=table.copy(industrialtest.ElectricArmor)
+industrialtest.internal.unpackTableInto(industrialtest.NanoSuit,{
+ name="industrialtest:nano",
+ elements={
+ {
+ name="helmet",
+ description=S("Nano Helmet"),
+ element="head",
+ inventoryImage="industrialtest_nano_helmet_inv.png",
+ texture="industrialtest_nano_helmet.png"
+ },
+ {
+ name="bodyarmor",
+ description=S("Nano Bodyarmor"),
+ element="torso",
+ inventoryImage="industrialtest_nano_bodyarmor_inv.png",
+ texture="industrialtest_nano_bodyarmor.png"
+ },
+ {
+ name="leggings",
+ description=S("Nano Leggings"),
+ element="legs",
+ inventoryImage="industrialtest_nano_leggings_inv.png",
+ texture="industrialtest_nano_leggings.png"
+ },
+ {
+ name="boots",
+ description=S("Nano Boots"),
+ element="feet",
+ inventoryImage="industrialtest_nano_boots_inv.png",
+ texture={
+ "industrialtest_nano_boots.png",
+ "industrialtest_mcl_nano_boots.png"
+ }
+ }
+ },
+ capacity=1000000,
+ flow=industrialtest.api.evPowerFlow
+})
-local function registerNanoSuitPart(config)
- local groups={
- _industrialtest_nanoSuit=1
- }
- if config.element=="head" then
- groups.armor_head=1
- elseif config.element=="torso" then
- groups.armor_torso=1
- elseif config.element=="legs" then
- groups.armor_legs=1
- elseif config.element=="feet" then
- groups.armor_feet=1
- end
- if industrialtest.mtgAvailable then
- groups.armor_heal=0
- armor:register_armor("industrialtest:"..config.name,{
- description=config.displayName,
- inventory_image="industrialtest_"..config.name.."_inv.png",
- groups=groups,
- _industrialtest_powerStorage=true,
- _industrialtest_powerCapacity=1000000,
- _industrialtest_powerFlow=industrialtest.api.evPowerFlow,
- _industrialtest_damageReduction=config.damageReduction,
- industrialtest_powerPerDamage=5000
- })
- elseif industrialtest.mclAvailable then
- groups.armor=1
- groups.non_combat_armor=1
- minetest.register_tool("industrialtest:"..config.name,{
- description=config.displayName,
- inventory_image="industrialtest_"..config.name.."_inv.png",
- groups=groups,
- 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=config.element,
- _mcl_armor_texture=(config.element=="feet" and "industrialtest_mcl_" or "industrialtest_")..config.name..".png",
- _industrialtest_powerStorage=true,
- _industrialtest_powerCapacity=1000000,
- _industrialtest_powerFlow=industrialtest.api.evPowerFlow,
- _industrialtest_damageReduction=config.damageReduction,
- _industrialtest_powerPerDamage=5000
- })
+function industrialtest.NanoSuit.getReducedDamageForItem(self,itemstack)
+ local def=itemstack:get_definition()
+ if def.groups.armor_head then
+ return 0.12
+ elseif def.groups.armor_torso then
+ return 0.32
+ elseif def.groups.armor_legs then
+ return 0.3
+ elseif def.groups.armor_feet then
+ return 0.24
end
+ return 0
end
-registerNanoSuitPart({
- name="nano_helmet",
- displayName=S("Nano Helmet"),
- element="head",
- damageReduction=0.12
-})
+function industrialtest.NanoSuit.getPowerPerDamageForItem(self,itemstack)
+ return 5000
+end
+
+industrialtest.NanoSuit:register()
+
minetest.register_craft({
type="shaped",
output="industrialtest:nano_helmet",
@@ -80,12 +84,6 @@ minetest.register_craft({
}
})
-registerNanoSuitPart({
- name="nano_bodyarmor",
- displayName=S("Nano Bodyarmor"),
- element="torso",
- damageReduction=0.32
-})
minetest.register_craft({
type="shaped",
output="industrialtest:nano_bodyarmor",
@@ -96,12 +94,6 @@ minetest.register_craft({
}
})
-registerNanoSuitPart({
- name="nano_leggings",
- displayName=S("Nano Leggings"),
- element="legs",
- damageReduction=0.3
-})
minetest.register_craft({
type="shaped",
output="industrialtest:nano_leggings",
@@ -112,12 +104,6 @@ minetest.register_craft({
}
})
-registerNanoSuitPart({
- name="nano_boots",
- displayName=S("Nano Boots"),
- element="feet",
- damageReduction=0.24
-})
minetest.register_craft({
type="shaped",
output="industrialtest:nano_boots",
@@ -126,41 +112,3 @@ minetest.register_craft({
{"industrialtest:carbon_plate","industrialtest:energy_crystal","industrialtest:carbon_plate"}
}
})
-
-minetest.register_on_player_hpchange(function(player,hpChange)
- if hpChange>0 or not player:is_player() then
- return hpChange
- end
-
- local inv
- if industrialtest.mtgAvailable then
- _,inv=armor:get_valid_player(player,"")
- if not inv then
- return hpChange
- end
- elseif industrialtest.mclAvailable then
- inv=player:get_inventory()
- end
-
- local armorList=inv:get_list("armor")
- assert(armorList)
- local result=hpChange
- for i=1,#armorList do
- local stack=armorList[i]
- local def=stack:get_definition()
- if def.groups and def.groups._industrialtest_nanoSuit then
- local meta=stack:get_meta()
- local targetReducedDamage=math.floor(math.abs(hpChange)*def._industrialtest_damageReduction)
- local requiredPower=targetReducedDamage*def._industrialtest_powerPerDamage
- local availablePower=math.min(meta:get_int("industrialtest.powerAmount"),requiredPower)
- local reducedDamage=math.floor(availablePower/def._industrialtest_powerPerDamage)
- if reducedDamage>0 then
- result=result+reducedDamage
- industrialtest.api.addPowerToItem(stack,-reducedDamage*def._industrialtest_powerPerDamage)
- inv:set_stack("armor",i,stack)
- end
- end
- end
-
- return result
-end,true)