Add support for non-fleshy damage groups, closes #47

This commit is contained in:
stujones11 2017-03-23 00:52:32 +00:00
parent 86fd6b0d7d
commit 11ce84873b
6 changed files with 274 additions and 222 deletions

@ -3,7 +3,9 @@
Depends: default Depends: default
Recommends: sfinv, inventory_plus or unified_inventory (use only one to avoid conflicts) Recommends: sfinv, unified_inventory or smart_inventory (use only one to avoid conflicts)
Supports: player_monoids and armor_monoid
Adds craftable armor that is visible to other players. Each armor item worn contributes to Adds craftable armor that is visible to other players. Each armor item worn contributes to
a player's armor group level making them less vulnerable to weapons. a player's armor group level making them less vulnerable to weapons.
@ -69,13 +71,22 @@ API
Armor Registration: Armor Registration:
minetest.register_tool("your_mod_name:speed_boots", { armor:register_armor(name, def)
armor:register_armor_group(group, base)
Example:
armor:register_armor_group("radiation", 100)
armor:register_armor("mod_name:speed_boots", {
description = "Speed Boots", description = "Speed Boots",
inventory_image = "your_mod_name_speed_boots_inv.png", inventory_image = "mod_name_speed_boots_inv.png",
texture = "your_mod_name_speed_boots.png", texture = "mod_name_speed_boots.png",
groups = {armor_feet=10, physics_speed=0.5, armor_use=2000}, preview = "mod_name_speed_boots_preview.png",
armor_groups = {fleshy=10, radiation=10},
groups = {armor_feet=1, physics_speed=0.5, armor_use=2000},
on_destroy = function(player, item_name) on_destroy = function(player, item_name)
minetest.sound_play("your_mod_name_break_sound", { minetest.sound_play("mod_name_break_sound", {
to_player = player:get_player_name(), to_player = player:get_player_name(),
}) })
end, end,
@ -92,15 +103,15 @@ Durability: armor_use
Notes: Notes:
Elements may be modified by dependent mods, eg shields adds armor_shield. Elements may be modified by dependent mods, eg shields adds armor_shield.
Attributes and physics values are 'stackable', durability is determined
Physics values are 'stackable', durability is determined by the level of armor_use, total uses == approx (65535/armor_use), non-fleshy
by the level of armor_use. total uses == approx (65535/armor_use) damage groups need to be defined in the tool/weapon used against the player
Item Callbacks: Item Callbacks:
on_equip = func(player, stack) on_equip = func(player, stack)
on_unequip = func(player, stack) on_unequip = func(player, stack)
on_destroy = func(player, item_name) on_destroy = func(player, stack)
Global Callbacks: Global Callbacks:

@ -6,13 +6,14 @@ armor = {
timer = 0, timer = 0,
elements = {"head", "torso", "legs", "feet"}, elements = {"head", "torso", "legs", "feet"},
physics = {"jump", "speed", "gravity"}, physics = {"jump", "speed", "gravity"},
attributes = {"heal", "fire", "water"},
formspec = "image[2.5,0;2,4;armor_preview]".. formspec = "image[2.5,0;2,4;armor_preview]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
default.get_hotbar_bg(0, 4.7).. default.get_hotbar_bg(0, 4.7)..
"label[5,1;Level: armor_level]".. "label[5,1;Level: armor_level]"..
"label[5,1.5;Heal: armor_heal]".. "label[5,1.5;Heal: armor_attr_heal]"..
"list[current_player;main;0,4.7;8,1;]".. "list[current_player;main;0,4.7;8,1;]"..
"list[current_player;main;0,5.85;8,3;8]", "list[current_player;main;0,5.85;8,3;8]",
def = {}, def = {},
@ -39,6 +40,7 @@ armor = {
{"default:torch_ceiling", 1, 1}, {"default:torch_ceiling", 1, 1},
{"default:torch_wall", 1, 1}, {"default:torch_wall", 1, 1},
}, },
registered_groups = {["fleshy"]=100},
registered_callbacks = { registered_callbacks = {
on_update = {}, on_update = {},
on_equip = {}, on_equip = {},
@ -69,6 +71,20 @@ armor.config = {
fire_protect = minetest.get_modpath("ethereal") ~= nil fire_protect = minetest.get_modpath("ethereal") ~= nil
} }
-- Armor Registration
armor.register_armor = function(self, name, def)
minetest.register_tool(name, def)
end
armor.register_armor_group = function(self, group, base)
base = base or 100
self.registered_groups[group] = base
if use_armor_monoid then
armor_monoid.register_armor_group(group, base)
end
end
-- Armor callbacks -- Armor callbacks
armor.register_on_update = function(self, func) armor.register_on_update = function(self, func)
@ -125,112 +141,125 @@ armor.update_player_visuals = function(self, player)
end end
armor.set_player_armor = function(self, player) armor.set_player_armor = function(self, player)
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]") local name, player_inv = self:get_valid_player(player, "[set_player_armor]")
if not name then if not name then
return return
end end
local armor_texture = "3d_armor_trans.png"
local armor_level = 0
local armor_heal = 0
local armor_fire = 0
local armor_water = 0
local armor_radiation = 0
local state = 0 local state = 0
local items = 0 local count = 0
local elements = {} local material = {count=1}
local textures = {}
local physics_o = {speed=1,gravity=1,jump=1}
local material = {type=nil, count=1}
local preview = armor:get_preview(name) local preview = armor:get_preview(name)
for _,v in ipairs(self.elements) do local texture = "3d_armor_trans.png"
elements[v] = false local textures = {}
local physics = {}
local attributes = {}
local levels = {}
local groups = {}
local change = {}
for _, phys in pairs(self.physics) do
physics[phys] = 0
end end
for i=1, 6 do for _, attr in pairs(self.attributes) do
local stack = player_inv:get_stack("armor", i) attributes[attr] = 0
local item = stack:get_name() end
for group, base in pairs(self.registered_groups) do
groups[group] = base
change[group] = 1
levels[group] = 0
end
local list = player_inv:get_list("armor")
for i, stack in pairs(list) do
if stack:get_count() == 1 then if stack:get_count() == 1 then
local def = stack:get_definition() local def = stack:get_definition()
for k, v in pairs(elements) do for _, element in pairs(self.elements) do
if v == false then if def.groups["armor_"..element] then
local level = def.groups["armor_"..k] if def.armor_groups then
if level then for group, level in pairs(def.armor_groups) do
local texture = def.texture or item:gsub("%:", "_") if levels[group] then
table.insert(textures, texture..".png") levels[group] = levels[group] + level
preview = preview.."^"..texture.."_preview.png"
armor_level = armor_level + level
state = state + stack:get_wear()
items = items + 1
armor_heal = armor_heal + (def.groups["armor_heal"] or 0)
armor_fire = armor_fire + (def.groups["armor_fire"] or 0)
armor_water = armor_water + (def.groups["armor_water"] or 0)
armor_radiation = armor_radiation + (def.groups["armor_radiation"] or 0)
for kk,vv in ipairs(self.physics) do
local o_value = def.groups["physics_"..vv]
if o_value then
physics_o[vv] = physics_o[vv] + o_value
end end
end end
local mat = string.match(item, "%:.+_(.+)$") else
if material.type then local level = def.groups["armor_"..element]
if material.type == mat then levels["fleshy"] = levels["fleshy"] + level
material.count = material.count + 1
end
else
material.type = mat
end
elements[k] = true
end end
end end
-- DEPRECATED, use armor_groups instead
if def.groups["armor_radiation"] and levels["radiation"] then
levels["radiation"] = def.groups["armor_radiation"]
end
end
local item = stack:get_name()
local tex = def.texture or item:gsub("%:", "_")
local prev = def.preview or tex.."_preview"
tex = tex:gsub(".png$", "")
prev = prev:gsub(".png$", "")
texture = texture.."^"..tex..".png"
preview = preview.."^"..prev..".png"
state = state + stack:get_wear()
count = count + 1
for _, phys in pairs(self.physics) do
local value = def.groups["physics_"..phys] or 0
physics[phys] = physics[phys] + value
end
for _, attr in pairs(self.attributes) do
local value = def.groups["armor_"..attr] or 0
attributes[attr] = attributes[attr] + value
end
local mat = string.match(item, "%:.+_(.+)$")
if material.name then
if material.name == mat then
material.count = material.count + 1
end
else
material.name = mat
end end
end end
end end
if minetest.get_modpath("shields") then for group, level in pairs(levels) do
armor_level = armor_level * 0.9 if level > 0 then
local base = self.registered_groups[group]
if minetest.get_modpath("shields") then
level = level * 0.9
end
if material.name and material.count == #self.elements then
level = level * 1.1
end
level = level * armor.config.level_multiplier
self.def[name].groups[group] = level
if level > base then
level = base
end
groups[group] = base - level
change[group] = groups[group] / base
end
end end
if material.type and material.count == #self.elements then for _, attr in pairs(self.attributes) do
armor_level = armor_level * 1.1 self.def[name][attr] = attributes[attr]
end end
armor_level = armor_level * self.config.level_multiplier for _, phys in pairs(self.physics) do
armor_heal = armor_heal * self.config.heal_multiplier self.def[name][phys] = physics[phys]
armor_radiation = armor_radiation * self.config.radiation_multiplier
if #textures > 0 then
armor_texture = table.concat(textures, "^")
end
local armor_groups = {fleshy=100}
if armor_level > 0 then
armor_groups.level = math.floor(armor_level / 20)
armor_groups.fleshy = 100 - armor_level
armor_groups.radiation = 100 - armor_radiation
end end
if use_armor_monoid then if use_armor_monoid then
armor_monoid.monoid:add_change(player, { armor_monoid.monoid:add_change(player, change, "3d_armor:armor")
fleshy = armor_groups.fleshy / 100
}, "3d_armor:armor")
else else
player:set_armor_groups(armor_groups) player:set_armor_groups(groups)
end end
if use_player_monoids then if use_player_monoids then
player_monoids.speed:add_change(player, physics_o.speed, player_monoids.speed:add_change(player, physics.speed,
"3d_armor:physics") "3d_armor:physics")
player_monoids.jump:add_change(player, physics_o.jump, player_monoids.jump:add_change(player, physics.jump,
"3d_armor:physics") "3d_armor:physics")
player_monoids.gravity:add_change(player, physics_o.gravity, player_monoids.gravity:add_change(player, physics.gravity,
"3d_armor:physics") "3d_armor:physics")
else else
player:set_physics_override(physics_o) player:set_physics_override(physics)
end end
self.textures[name].armor = armor_texture self.textures[name].armor = texture
self.textures[name].preview = preview self.textures[name].preview = preview
self.def[name].level = self.def[name].groups.fleshy or 0
self.def[name].state = state self.def[name].state = state
self.def[name].count = items self.def[name].count = count
self.def[name].level = armor_level
self.def[name].heal = armor_heal
self.def[name].jump = physics_o.jump
self.def[name].speed = physics_o.speed
self.def[name].gravity = physics_o.gravity
self.def[name].fire = armor_fire
self.def[name].water = armor_water
self.def[name].radiation = armor_radiation
self:update_player_visuals(player) self:update_player_visuals(player)
self:run_callbacks("on_update", player) self:run_callbacks("on_update", player)
end end
@ -263,29 +292,28 @@ armor.get_preview = function(self, name)
end end
armor.get_armor_formspec = function(self, name, listring) armor.get_armor_formspec = function(self, name, listring)
if not armor.textures[name] then if not armor.def[name] or not armor.textures[name] then
minetest.log("error", "3d_armor: Player texture["..name.."] is nil [get_armor_formspec]")
return "" return ""
end end
if not armor.def[name] then local formspec = armor.formspec..
minetest.log("error", "3d_armor: Armor def["..name.."] is nil [get_armor_formspec]") "list[detached:"..name.."_armor;armor;0,0.5;2,3;]"
return ""
end
local formspec = armor.formspec.."list[detached:"..name.."_armor;armor;0,0.5;2,3;]"
if listring == true then if listring == true then
formspec = formspec.."listring[current_player;main]".. formspec = formspec.."listring[current_player;main]"..
"listring[detached:"..name.."_armor;armor]" "listring[detached:"..name.."_armor;armor]"
end end
formspec = formspec:gsub("armor_preview", armor.textures[name].preview) formspec = formspec:gsub("armor_preview", armor.textures[name].preview)
formspec = formspec:gsub("armor_level", armor.def[name].level) formspec = formspec:gsub("armor_level", armor.def[name].level)
formspec = formspec:gsub("armor_heal", armor.def[name].heal) for _, attr in pairs(self.attributes) do
formspec = formspec:gsub("armor_fire", armor.def[name].fire) formspec = formspec:gsub("armor_attr_"..attr, armor.def[name][attr])
formspec = formspec:gsub("armor_radiation", armor.def[name].radiation) end
for _, group in pairs(self.attributes) do
formspec = formspec:gsub("armor_group_"..group, armor.def[name][group])
end
return formspec return formspec
end end
armor.update_inventory = function(self, player) armor.update_inventory = function(self, player)
-- DEPRECIATED: Legacy inventory support -- DEPRECATED: Legacy inventory support
end end
armor.set_inventory_stack = function(self, player, i, stack) armor.set_inventory_stack = function(self, player, i, stack)

@ -1,4 +1,4 @@
-- DEPRECIATED, will not be supported in future versions -- DEPRECATED, will not be supported in future versions
-- See README.txt for new configuration options. -- See README.txt for new configuration options.

@ -3,263 +3,264 @@ minetest.register_alias("adminhelmet","3d_armor:helmet_admin")
minetest.register_alias("adminchestplate","3d_armor:chestplate_admin") minetest.register_alias("adminchestplate","3d_armor:chestplate_admin")
minetest.register_alias("adminleggings","3d_armor:leggings_admin") minetest.register_alias("adminleggings","3d_armor:leggings_admin")
minetest.register_tool("3d_armor:helmet_admin", { armor:register_armor("3d_armor:helmet_admin", {
description = "Admin Helmet", description = "Admin Helmet",
inventory_image = "3d_armor_inv_helmet_admin.png", inventory_image = "3d_armor_inv_helmet_admin.png",
groups = {armor_head=1000, armor_heal=1000, armor_use=0, armor_water=1, armor_groups = {fleshy=100},
groups = {armor_head=1, armor_heal=100, armor_use=0, armor_water=1,
not_in_creative_inventory=1}, not_in_creative_inventory=1},
wear = 0,
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)
return return
end, end,
}) })
minetest.register_tool("3d_armor:chestplate_admin", { armor:register_armor("3d_armor:chestplate_admin", {
description = "Admin Chestplate", description = "Admin Chestplate",
inventory_image = "3d_armor_inv_chestplate_admin.png", inventory_image = "3d_armor_inv_chestplate_admin.png",
groups = {armor_torso=1000, armor_heal=1000, armor_use=0, armor_groups = {fleshy=100},
groups = {armor_torso=1, armor_heal=100, armor_use=0,
not_in_creative_inventory=1}, not_in_creative_inventory=1},
wear = 0,
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)
return return
end, end,
}) })
minetest.register_tool("3d_armor:leggings_admin", { armor:register_armor("3d_armor:leggings_admin", {
description = "Admin Leggings", description = "Admin Leggings",
inventory_image = "3d_armor_inv_leggings_admin.png", inventory_image = "3d_armor_inv_leggings_admin.png",
groups = {armor_legs=1000, armor_heal=1000, armor_use=0, armor_groups = {fleshy=100},
groups = {armor_legs=1, armor_heal=100, armor_use=0,
not_in_creative_inventory=1}, not_in_creative_inventory=1},
wear = 0,
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)
return return
end, end,
}) })
minetest.register_tool("3d_armor:boots_admin", { armor:register_armor("3d_armor:boots_admin", {
description = "Admin Boots", description = "Admin Boots",
inventory_image = "3d_armor_inv_boots_admin.png", inventory_image = "3d_armor_inv_boots_admin.png",
groups = {armor_feet=1000, armor_heal=1000, armor_use=0, armor_groups = {fleshy=100},
groups = {armor_feet=1, armor_heal=100, armor_use=0,
not_in_creative_inventory=1}, not_in_creative_inventory=1},
wear = 0,
on_drop = function(itemstack, dropper, pos) on_drop = function(itemstack, dropper, pos)
return return
end, end,
}) })
if armor.materials.wood then if armor.materials.wood then
minetest.register_tool("3d_armor:helmet_wood", { armor:register_armor("3d_armor:helmet_wood", {
description = "Wood Helmet", description = "Wood Helmet",
inventory_image = "3d_armor_inv_helmet_wood.png", inventory_image = "3d_armor_inv_helmet_wood.png",
groups = {armor_head=5, armor_heal=0, armor_use=2000}, armor_groups = {fleshy=5},
wear = 0, groups = {armor_head=1, armor_heal=0, armor_use=2000},
}) })
minetest.register_tool("3d_armor:chestplate_wood", { armor:register_armor("3d_armor:chestplate_wood", {
description = "Wood Chestplate", description = "Wood Chestplate",
inventory_image = "3d_armor_inv_chestplate_wood.png", inventory_image = "3d_armor_inv_chestplate_wood.png",
groups = {armor_torso=10, armor_heal=0, armor_use=2000}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_torso=1, armor_heal=0, armor_use=2000},
}) })
minetest.register_tool("3d_armor:leggings_wood", { armor:register_armor("3d_armor:leggings_wood", {
description = "Wood Leggings", description = "Wood Leggings",
inventory_image = "3d_armor_inv_leggings_wood.png", inventory_image = "3d_armor_inv_leggings_wood.png",
groups = {armor_legs=5, armor_heal=0, armor_use=2000}, armor_groups = {fleshy=5},
wear = 0, groups = {armor_legs=1, armor_heal=0, armor_use=2000},
}) })
minetest.register_tool("3d_armor:boots_wood", { armor:register_armor("3d_armor:boots_wood", {
description = "Wood Boots", description = "Wood Boots",
inventory_image = "3d_armor_inv_boots_wood.png", inventory_image = "3d_armor_inv_boots_wood.png",
groups = {armor_feet=5, armor_heal=0, armor_use=2000}, armor_groups = {fleshy=5},
wear = 0, groups = {armor_feet=1, armor_heal=0, armor_use=2000},
}) })
end end
if armor.materials.cactus then if armor.materials.cactus then
minetest.register_tool("3d_armor:helmet_cactus", { armor:register_armor("3d_armor:helmet_cactus", {
description = "Cactus Helmet", description = "Cactus Helmet",
inventory_image = "3d_armor_inv_helmet_cactus.png", inventory_image = "3d_armor_inv_helmet_cactus.png",
groups = {armor_head=5, armor_heal=0, armor_use=1000}, armor_groups = {fleshy=5},
wear = 0, groups = {armor_head=1, armor_heal=0, armor_use=1000},
}) })
minetest.register_tool("3d_armor:chestplate_cactus", { armor:register_armor("3d_armor:chestplate_cactus", {
description = "Cactus Chestplate", description = "Cactus Chestplate",
inventory_image = "3d_armor_inv_chestplate_cactus.png", inventory_image = "3d_armor_inv_chestplate_cactus.png",
groups = {armor_torso=10, armor_heal=0, armor_use=1000}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_torso=1, armor_heal=0, armor_use=1000},
}) })
minetest.register_tool("3d_armor:leggings_cactus", { armor:register_armor("3d_armor:leggings_cactus", {
description = "Cactus Leggings", description = "Cactus Leggings",
inventory_image = "3d_armor_inv_leggings_cactus.png", inventory_image = "3d_armor_inv_leggings_cactus.png",
groups = {armor_legs=5, armor_heal=0, armor_use=1000}, armor_groups = {fleshy=5},
wear = 0, groups = {armor_legs=1, armor_heal=0, armor_use=1000},
}) })
minetest.register_tool("3d_armor:boots_cactus", { armor:register_armor("3d_armor:boots_cactus", {
description = "Cactus Boots", description = "Cactus Boots",
inventory_image = "3d_armor_inv_boots_cactus.png", inventory_image = "3d_armor_inv_boots_cactus.png",
groups = {armor_feet=5, armor_heal=0, armor_use=1000}, armor_groups = {fleshy=5},
wear = 0, groups = {armor_feet=1, armor_heal=0, armor_use=1000},
}) })
end end
if armor.materials.steel then if armor.materials.steel then
minetest.register_tool("3d_armor:helmet_steel", { armor:register_armor("3d_armor:helmet_steel", {
description = "Steel Helmet", description = "Steel Helmet",
inventory_image = "3d_armor_inv_helmet_steel.png", inventory_image = "3d_armor_inv_helmet_steel.png",
groups = {armor_head=10, armor_heal=0, armor_use=500}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_head=1, armor_heal=0, armor_use=500},
}) })
minetest.register_tool("3d_armor:chestplate_steel", { armor:register_armor("3d_armor:chestplate_steel", {
description = "Steel Chestplate", description = "Steel Chestplate",
inventory_image = "3d_armor_inv_chestplate_steel.png", inventory_image = "3d_armor_inv_chestplate_steel.png",
groups = {armor_torso=15, armor_heal=0, armor_use=500}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_torso=1, armor_heal=0, armor_use=500},
}) })
minetest.register_tool("3d_armor:leggings_steel", { armor:register_armor("3d_armor:leggings_steel", {
description = "Steel Leggings", description = "Steel Leggings",
inventory_image = "3d_armor_inv_leggings_steel.png", inventory_image = "3d_armor_inv_leggings_steel.png",
groups = {armor_legs=15, armor_heal=0, armor_use=500}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_legs=1, armor_heal=0, armor_use=500},
}) })
minetest.register_tool("3d_armor:boots_steel", { armor:register_armor("3d_armor:boots_steel", {
description = "Steel Boots", description = "Steel Boots",
inventory_image = "3d_armor_inv_boots_steel.png", inventory_image = "3d_armor_inv_boots_steel.png",
groups = {armor_feet=10, armor_heal=0, armor_use=500}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_feet=1, armor_heal=0, armor_use=500},
}) })
end end
if armor.materials.bronze then if armor.materials.bronze then
minetest.register_tool("3d_armor:helmet_bronze", { armor:register_armor("3d_armor:helmet_bronze", {
description = "Bronze Helmet", description = "Bronze Helmet",
inventory_image = "3d_armor_inv_helmet_bronze.png", inventory_image = "3d_armor_inv_helmet_bronze.png",
groups = {armor_head=10, armor_heal=6, armor_use=250}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_head=1, armor_heal=6, armor_use=250},
}) })
minetest.register_tool("3d_armor:chestplate_bronze", { armor:register_armor("3d_armor:chestplate_bronze", {
description = "Bronze Chestplate", description = "Bronze Chestplate",
inventory_image = "3d_armor_inv_chestplate_bronze.png", inventory_image = "3d_armor_inv_chestplate_bronze.png",
groups = {armor_torso=15, armor_heal=6, armor_use=250}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_torso=1, armor_heal=6, armor_use=250},
}) })
minetest.register_tool("3d_armor:leggings_bronze", { armor:register_armor("3d_armor:leggings_bronze", {
description = "Bronze Leggings", description = "Bronze Leggings",
inventory_image = "3d_armor_inv_leggings_bronze.png", inventory_image = "3d_armor_inv_leggings_bronze.png",
groups = {armor_legs=15, armor_heal=6, armor_use=250}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_legs=1, armor_heal=6, armor_use=250},
}) })
minetest.register_tool("3d_armor:boots_bronze", { armor:register_armor("3d_armor:boots_bronze", {
description = "Bronze Boots", description = "Bronze Boots",
inventory_image = "3d_armor_inv_boots_bronze.png", inventory_image = "3d_armor_inv_boots_bronze.png",
groups = {armor_feet=10, armor_heal=6, armor_use=250}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_feet=1, armor_heal=6, armor_use=250},
}) })
end end
if armor.materials.diamond then if armor.materials.diamond then
minetest.register_tool("3d_armor:helmet_diamond", { armor:register_armor("3d_armor:helmet_diamond", {
description = "Diamond Helmet", description = "Diamond Helmet",
inventory_image = "3d_armor_inv_helmet_diamond.png", inventory_image = "3d_armor_inv_helmet_diamond.png",
groups = {armor_head=15, armor_heal=12, armor_use=100}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_head=1, armor_heal=12, armor_use=100},
}) })
minetest.register_tool("3d_armor:chestplate_diamond", { armor:register_armor("3d_armor:chestplate_diamond", {
description = "Diamond Chestplate", description = "Diamond Chestplate",
inventory_image = "3d_armor_inv_chestplate_diamond.png", inventory_image = "3d_armor_inv_chestplate_diamond.png",
groups = {armor_torso=20, armor_heal=12, armor_use=100}, armor_groups = {fleshy=20},
wear = 0, groups = {armor_torso=1, armor_heal=12, armor_use=100},
}) })
minetest.register_tool("3d_armor:leggings_diamond", { armor:register_armor("3d_armor:leggings_diamond", {
description = "Diamond Leggings", description = "Diamond Leggings",
inventory_image = "3d_armor_inv_leggings_diamond.png", inventory_image = "3d_armor_inv_leggings_diamond.png",
groups = {armor_legs=20, armor_heal=12, armor_use=100}, armor_groups = {fleshy=20},
wear = 0, groups = {armor_legs=1, armor_heal=12, armor_use=100},
}) })
minetest.register_tool("3d_armor:boots_diamond", { armor:register_armor("3d_armor:boots_diamond", {
description = "Diamond Boots", description = "Diamond Boots",
inventory_image = "3d_armor_inv_boots_diamond.png", inventory_image = "3d_armor_inv_boots_diamond.png",
groups = {armor_feet=15, armor_heal=12, armor_use=100}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_feet=1, armor_heal=12, armor_use=100},
}) })
end end
if armor.materials.gold then if armor.materials.gold then
minetest.register_tool("3d_armor:helmet_gold", { armor:register_armor("3d_armor:helmet_gold", {
description = "Gold Helmet", description = "Gold Helmet",
inventory_image = "3d_armor_inv_helmet_gold.png", inventory_image = "3d_armor_inv_helmet_gold.png",
groups = {armor_head=10, armor_heal=6, armor_use=250}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_head=1, armor_heal=6, armor_use=250},
}) })
minetest.register_tool("3d_armor:chestplate_gold", { armor:register_armor("3d_armor:chestplate_gold", {
description = "Gold Chestplate", description = "Gold Chestplate",
inventory_image = "3d_armor_inv_chestplate_gold.png", inventory_image = "3d_armor_inv_chestplate_gold.png",
groups = {armor_torso=15, armor_heal=6, armor_use=250}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_torso=1, armor_heal=6, armor_use=250},
}) })
minetest.register_tool("3d_armor:leggings_gold", { armor:register_armor("3d_armor:leggings_gold", {
description = "Gold Leggings", description = "Gold Leggings",
inventory_image = "3d_armor_inv_leggings_gold.png", inventory_image = "3d_armor_inv_leggings_gold.png",
groups = {armor_legs=15, armor_heal=6, armor_use=250}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_legs=1, armor_heal=6, armor_use=250},
}) })
minetest.register_tool("3d_armor:boots_gold", { armor:register_armor("3d_armor:boots_gold", {
description = "Gold Boots", description = "Gold Boots",
inventory_image = "3d_armor_inv_boots_gold.png", inventory_image = "3d_armor_inv_boots_gold.png",
groups = {armor_feet=10, armor_heal=6, armor_use=250}, armor_groups = {fleshy=10},
wear = 0, groups = {armor_feet=1, armor_heal=6, armor_use=250},
}) })
end end
if armor.materials.mithril then if armor.materials.mithril then
minetest.register_tool("3d_armor:helmet_mithril", { armor:register_armor("3d_armor:helmet_mithril", {
description = "Mithril Helmet", description = "Mithril Helmet",
inventory_image = "3d_armor_inv_helmet_mithril.png", inventory_image = "3d_armor_inv_helmet_mithril.png",
groups = {armor_head=15, armor_heal=12, armor_use=50}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_head=1, armor_heal=12, armor_use=50},
}) })
minetest.register_tool("3d_armor:chestplate_mithril", { armor:register_armor("3d_armor:chestplate_mithril", {
description = "Mithril Chestplate", description = "Mithril Chestplate",
inventory_image = "3d_armor_inv_chestplate_mithril.png", inventory_image = "3d_armor_inv_chestplate_mithril.png",
groups = {armor_torso=20, armor_heal=12, armor_use=50}, armor_groups = {fleshy=20},
wear = 0, groups = {armor_torso=1, armor_heal=12, armor_use=50},
}) })
minetest.register_tool("3d_armor:leggings_mithril", { armor:register_armor("3d_armor:leggings_mithril", {
description = "Mithril Leggings", description = "Mithril Leggings",
inventory_image = "3d_armor_inv_leggings_mithril.png", inventory_image = "3d_armor_inv_leggings_mithril.png",
groups = {armor_legs=20, armor_heal=12, armor_use=50}, armor_groups = {fleshy=20},
wear = 0, groups = {armor_legs=1, armor_heal=12, armor_use=50},
}) })
minetest.register_tool("3d_armor:boots_mithril", { armor:register_armor("3d_armor:boots_mithril", {
description = "Mithril Boots", description = "Mithril Boots",
inventory_image = "3d_armor_inv_boots_mithril.png", inventory_image = "3d_armor_inv_boots_mithril.png",
groups = {armor_feet=15, armor_heal=12, armor_use=50}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_feet=1, armor_heal=12, armor_use=50},
}) })
end end
if armor.materials.crystal then if armor.materials.crystal then
minetest.register_tool("3d_armor:helmet_crystal", { armor:register_armor("3d_armor:helmet_crystal", {
description = "Crystal Helmet", description = "Crystal Helmet",
inventory_image = "3d_armor_inv_helmet_crystal.png", inventory_image = "3d_armor_inv_helmet_crystal.png",
groups = {armor_head=15, armor_heal=12, armor_use=50, armor_fire=1}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_head=1, armor_heal=12, armor_use=50, armor_fire=1},
}) })
minetest.register_tool("3d_armor:chestplate_crystal", { armor:register_armor("3d_armor:chestplate_crystal", {
description = "Crystal Chestplate", description = "Crystal Chestplate",
inventory_image = "3d_armor_inv_chestplate_crystal.png", inventory_image = "3d_armor_inv_chestplate_crystal.png",
groups = {armor_torso=20, armor_heal=12, armor_use=50, armor_fire=1}, armor_groups = {fleshy=20},
wear = 0, groups = {armor_torso=1, armor_heal=12, armor_use=50, armor_fire=1},
}) })
minetest.register_tool("3d_armor:leggings_crystal", { armor:register_armor("3d_armor:leggings_crystal", {
description = "Crystal Leggings", description = "Crystal Leggings",
inventory_image = "3d_armor_inv_leggings_crystal.png", inventory_image = "3d_armor_inv_leggings_crystal.png",
groups = {armor_legs=20, armor_heal=12, armor_use=50, armor_fire=1}, armor_groups = {fleshy=20},
wear = 0, groups = {armor_legs=1, armor_heal=12, armor_use=50, armor_fire=1},
}) })
minetest.register_tool("3d_armor:boots_crystal", { armor:register_armor("3d_armor:boots_crystal", {
description = "Crystal Boots", description = "Crystal Boots",
inventory_image = "3d_armor_inv_boots_crystal.png", inventory_image = "3d_armor_inv_boots_crystal.png",
groups = {armor_feet=15, armor_heal=12, armor_use=50, physics_speed=1, physics_jump=0.5, armor_fire=1}, armor_groups = {fleshy=15},
wear = 0, groups = {armor_feet=1, armor_heal=12, armor_use=50, physics_speed=1,
physics_jump=0.5, armor_fire=1},
}) })
end end

@ -50,16 +50,17 @@ for material, _ in pairs(armor.materials) do
armor.materials[material] = nil armor.materials[material] = nil
end end
end end
if armor.config.fire_protect then
armor.formspec = armor.formspec.."label[5,2;Fire: armor_fire]"
end
dofile(modpath.."/armor.lua") dofile(modpath.."/armor.lua")
-- Mod Compatibility -- Mod Compatibility
if armor.config.fire_protect then
armor.formspec = armor.formspec.."label[5,2;Fire: armor_fire]"
end
if minetest.get_modpath("technic") then if minetest.get_modpath("technic") then
armor.formspec = armor.formspec.."label[5,2.5;Radiation: armor_radiation]" armor.formspec = armor.formspec.."label[5,2.5;Radiation: armor_group_radiation]"
armor:register_armor_group("radiation")
end end
local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"} local skin_mods = {"skins", "u_skins", "simple_skins", "wardrobe"}
for _, mod in pairs(skin_mods) do for _, mod in pairs(skin_mods) do
@ -167,17 +168,20 @@ minetest.register_on_joinplayer(function(player)
armor:run_callbacks("on_equip", player, stack) armor:run_callbacks("on_equip", player, stack)
end end
armor.def[name] = { armor.def[name] = {
level = 0,
state = 0, state = 0,
count = 0, count = 0,
level = 0, groups = {},
heal = 0,
jump = 1,
speed = 1,
gravity = 1,
fire = 0,
water = 0,
radiation = 0,
} }
for _, phys in pairs(armor.physics) do
armor.def[name][phys] = 1
end
for _, attr in pairs(armor.attributes) do
armor.def[name][attr] = 0
end
for group, _ in pairs(armor.registered_groups) do
armor.def[name].groups[group] = 0
end
local skin = armor:get_player_skin(name) local skin = armor:get_player_skin(name)
armor.textures[name] = { armor.textures[name] = {
skin = skin..".png", skin = skin..".png",
@ -202,6 +206,14 @@ minetest.register_on_joinplayer(function(player)
end end
end) end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
if name then
armor.def[name] = nil
armor.textures[name] = nil
end
end)
if armor.config.drop == true or armor.config.destroy == true then if armor.config.drop == true or armor.config.destroy == true then
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
local name, player_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") local name, player_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
@ -282,7 +294,7 @@ minetest.register_on_player_hpchange(function(player, hp_change)
armor.def[name].state = state armor.def[name].state = state
armor.def[name].count = items armor.def[name].count = items
heal_max = heal_max * armor.config.heal_multiplier heal_max = heal_max * armor.config.heal_multiplier
if heal_max > math.random(100) then if heal_max >= math.random(100) then
hp_change = 0 hp_change = 0
end end
end end

@ -37,7 +37,7 @@ unified_inventory.register_page("armor", {
end end
if minetest.global_exists("technic") then if minetest.global_exists("technic") then
formspec = formspec.."label[5.0,"..(fy + 1.5).. formspec = formspec.."label[5.0,"..(fy + 1.5)..
";Radiation: "..armor.def[name].radiation.."]" ";Radiation: "..armor.def[name].groups["radiation"].."]"
end end
return {formspec=formspec} return {formspec=formspec}
end, end,