2024-03-14 15:58:01 +01:00
|
|
|
-- 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
local S=minetest.get_translator("industrialtest")
|
|
|
|
|
|
|
|
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,
|
2024-03-29 12:06:48 +01:00
|
|
|
_industrialtest_damageReduction=config.damageReduction,
|
|
|
|
industrialtest_powerPerDamage=5000
|
2024-03-14 15:58:01 +01:00
|
|
|
})
|
|
|
|
elseif industrialtest.mclAvailable then
|
|
|
|
groups.armor=1
|
|
|
|
groups.non_combat_armor=1
|
2024-03-17 18:56:54 +01:00
|
|
|
minetest.register_tool("industrialtest:"..config.name,{
|
2024-03-14 15:58:01 +01:00
|
|
|
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,
|
2024-03-21 22:10:16 +01:00
|
|
|
_mcl_armor_texture=(config.element=="feet" and "industrialtest_mcl_" or "industrialtest_")..config.name..".png",
|
2024-03-14 15:58:01 +01:00
|
|
|
_industrialtest_powerStorage=true,
|
|
|
|
_industrialtest_powerCapacity=1000000,
|
|
|
|
_industrialtest_powerFlow=industrialtest.api.evPowerFlow,
|
2024-03-29 12:06:48 +01:00
|
|
|
_industrialtest_damageReduction=config.damageReduction,
|
|
|
|
_industrialtest_powerPerDamage=5000
|
2024-03-14 15:58:01 +01:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
registerNanoSuitPart({
|
|
|
|
name="nano_helmet",
|
|
|
|
displayName=S("Nano Helmet"),
|
|
|
|
element="head",
|
|
|
|
damageReduction=0.12
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
|
|
|
type="shaped",
|
|
|
|
output="industrialtest:nano_helmet",
|
|
|
|
recipe={
|
|
|
|
{"industrialtest:carbon_plate","industrialtest:energy_crystal","industrialtest:carbon_plate"},
|
|
|
|
{"industrialtest:carbon_plate",industrialtest.elementKeys.glass,"industrialtest:carbon_plate"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
registerNanoSuitPart({
|
|
|
|
name="nano_bodyarmor",
|
|
|
|
displayName=S("Nano Bodyarmor"),
|
|
|
|
element="torso",
|
|
|
|
damageReduction=0.32
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
|
|
|
type="shaped",
|
|
|
|
output="industrialtest:nano_bodyarmor",
|
|
|
|
recipe={
|
|
|
|
{"industrialtest:carbon_plate","","industrialtest:carbon_plate"},
|
|
|
|
{"industrialtest:carbon_plate","industrialtest:energy_crystal","industrialtest:carbon_plate"},
|
|
|
|
{"industrialtest:carbon_plate","industrialtest:carbon_plate","industrialtest:carbon_plate"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
registerNanoSuitPart({
|
|
|
|
name="nano_leggings",
|
|
|
|
displayName=S("Nano Leggings"),
|
|
|
|
element="legs",
|
|
|
|
damageReduction=0.3
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
|
|
|
type="shaped",
|
|
|
|
output="industrialtest:nano_leggings",
|
|
|
|
recipe={
|
|
|
|
{"industrialtest:carbon_plate","industrialtest:energy_crystal","industrialtest:carbon_plate"},
|
|
|
|
{"industrialtest:carbon_plate","","industrialtest:carbon_plate"},
|
|
|
|
{"industrialtest:carbon_plate","","industrialtest:carbon_plate"}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
registerNanoSuitPart({
|
|
|
|
name="nano_boots",
|
|
|
|
displayName=S("Nano Boots"),
|
|
|
|
element="feet",
|
|
|
|
damageReduction=0.24
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
|
|
|
type="shaped",
|
|
|
|
output="industrialtest:nano_boots",
|
|
|
|
recipe={
|
|
|
|
{"industrialtest:carbon_plate","","industrialtest:carbon_plate"},
|
|
|
|
{"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)
|
2024-03-29 12:06:48 +01:00
|
|
|
local requiredPower=targetReducedDamage*def._industrialtest_powerPerDamage
|
2024-03-14 15:58:01 +01:00
|
|
|
local availablePower=math.min(meta:get_int("industrialtest.powerAmount"),requiredPower)
|
2024-03-29 12:06:48 +01:00
|
|
|
local reducedDamage=math.floor(availablePower/def._industrialtest_powerPerDamage)
|
2024-03-14 15:58:01 +01:00
|
|
|
if reducedDamage>0 then
|
|
|
|
result=result+reducedDamage
|
2024-03-29 12:06:48 +01:00
|
|
|
industrialtest.api.addPowerToItem(stack,-reducedDamage*def._industrialtest_powerPerDamage)
|
2024-03-14 15:58:01 +01:00
|
|
|
inv:set_stack("armor",i,stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end,true)
|