1
0
Fork 0

Implement MC's armor durability

This commit is contained in:
Wuzzy 2020-02-17 18:19:04 +01:00
parent 023f70ee1c
commit dcc14d1f3f
2 changed files with 32 additions and 25 deletions

View File

@ -486,25 +486,32 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
end)
end
minetest.register_on_player_hpchange(function(player, hp_change)
minetest.register_on_player_hpchange(function(player, hp_change, reason)
local name, player_inv, armor_inv = armor:get_valid_player(player, "[on_hpchange]")
if name and hp_change < 0 then
-- used for insta kill tools/commands like /kill (doesnt damage armor)
if hp_change < -100 then
-- Armor doesn't protect from set_hp (commands like /kill)
-- and drowning damage.
if reason.type == "set_hp" or reason.type == "drown" then
return hp_change
end
local heal_max = 0
local state = 0
local items = 0
local armor_damage = math.max(1, math.floor(math.abs(hp_change)/4))
for i=1, 6 do
local stack = player_inv:get_stack("armor", i)
if stack:get_count() > 0 then
-- Damage armor
local use = stack:get_definition().groups["armor_use"] or 0
local heal = stack:get_definition().groups["armor_heal"] or 0
if use > 0 then
local wear = armor_damage * math.floor(65536/use)
stack:add_wear(wear)
end
local item = stack:get_name()
stack:add_wear(use)
local heal = stack:get_definition().groups["armor_heal"] or 0
armor_inv:set_stack("armor", i, stack)
player_inv:set_stack("armor", i, stack)
state = state + stack:get_wear()

View File

@ -12,7 +12,7 @@ minetest.register_tool("3d_armor:helmet_leather", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_helmet_leather.png",
groups = {armor_head=5, armor_heal=0, armor_use=100},
groups = {armor_head=5, armor_heal=0, armor_use=56},
_repair_material = "mcl_mobitems:leather",
})
@ -21,7 +21,7 @@ minetest.register_tool("3d_armor:helmet_iron", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_helmet_iron.png",
groups = {armor_head=10, armor_heal=5, armor_use=250},
groups = {armor_head=10, armor_heal=5, armor_use=166},
_repair_material = "mcl_core:iron_ingot",
})
@ -30,7 +30,7 @@ minetest.register_tool("3d_armor:helmet_gold", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_helmet_gold.png",
groups = {armor_head=15, armor_heal=10, armor_use=500},
groups = {armor_head=15, armor_heal=10, armor_use=78},
_repair_material = "mcl_core:gold_ingot",
})
@ -39,7 +39,7 @@ minetest.register_tool("3d_armor:helmet_diamond",{
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_helmet_diamond.png",
groups = {armor_head=20, armor_heal=15, armor_use=750},
groups = {armor_head=20, armor_heal=15, armor_use=364},
_repair_material = "mcl_core:diamond",
})
@ -48,7 +48,7 @@ minetest.register_tool("3d_armor:helmet_chain", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_helmet_chain.png",
groups = {armor_head=15, armor_heal=10, armor_use=500},
groups = {armor_head=15, armor_heal=10, armor_use=166},
_repair_material = "mcl_core:iron_ingot",
})
@ -59,7 +59,7 @@ minetest.register_tool("3d_armor:chestplate_leather", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_chestplate_leather.png",
groups = {armor_torso=15, armor_heal=0, armor_use=100},
groups = {armor_torso=15, armor_heal=0, armor_use=81},
_repair_material = "mcl_mobitems:leather",
})
@ -68,7 +68,7 @@ minetest.register_tool("3d_armor:chestplate_iron", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_chestplate_iron.png",
groups = {armor_torso=20, armor_heal=5, armor_use=250},
groups = {armor_torso=20, armor_heal=5, armor_use=241},
_repair_material = "mcl_core:iron_ingot",
})
@ -77,7 +77,7 @@ minetest.register_tool("3d_armor:chestplate_gold", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_chestplate_gold.png",
groups = {armor_torso=25, armor_heal=10, armor_use=500},
groups = {armor_torso=25, armor_heal=10, armor_use=113},
_repair_material = "mcl_core:gold_ingot",
})
@ -86,7 +86,7 @@ minetest.register_tool("3d_armor:chestplate_diamond",{
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_chestplate_diamond.png",
groups = {armor_torso=30, armor_heal=15, armor_use=750},
groups = {armor_torso=30, armor_heal=15, armor_use=529},
_repair_material = "mcl_core:diamond",
})
@ -95,7 +95,7 @@ minetest.register_tool("3d_armor:chestplate_chain", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_chestplate_chain.png",
groups = {armor_torso=25, armor_heal=10, armor_use=500},
groups = {armor_torso=25, armor_heal=10, armor_use=241},
_repair_material = "mcl_core:iron_ingot",
})
@ -106,7 +106,7 @@ minetest.register_tool("3d_armor:leggings_leather", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_leggings_leather.png",
groups = {armor_legs=10, armor_heal=0, armor_use=100},
groups = {armor_legs=10, armor_heal=0, armor_use=76},
_repair_material = "mcl_mobitems:leather",
})
@ -115,7 +115,7 @@ minetest.register_tool("3d_armor:leggings_iron", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_leggings_iron.png",
groups = {armor_legs=15, armor_heal=5, armor_use=250},
groups = {armor_legs=15, armor_heal=5, armor_use=226},
_repair_material = "mcl_core:iron_ingot",
})
@ -124,7 +124,7 @@ minetest.register_tool("3d_armor:leggings_gold", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_leggings_gold.png",
groups = {armor_legs=20, armor_heal=10, armor_use=500},
groups = {armor_legs=20, armor_heal=10, armor_use=106},
_repair_material = "mcl_core:gold_ingot",
})
@ -133,7 +133,7 @@ minetest.register_tool("3d_armor:leggings_diamond",{
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_leggings_diamond.png",
groups = {armor_legs=25, armor_heal=15, armor_use=750},
groups = {armor_legs=25, armor_heal=15, armor_use=496},
_repair_material = "mcl_core:diamond",
})
@ -142,7 +142,7 @@ minetest.register_tool("3d_armor:leggings_chain", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_leggings_chain.png",
groups = {armor_legs=20, armor_heal=10, armor_use=500},
groups = {armor_legs=20, armor_heal=10, armor_use=226},
_repair_material = "mcl_core:iron_ingot",
})
-- Regisiter Boots
@ -152,7 +152,7 @@ minetest.register_tool("3d_armor:boots_leather", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_boots_leather.png",
groups = {armor_feet=5, armor_heal=0, armor_use=100},
groups = {armor_feet=5, armor_heal=0, armor_use=66},
_repair_material = "mcl_mobitems:leather",
})
@ -161,7 +161,7 @@ minetest.register_tool("3d_armor:boots_iron", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_boots_iron.png",
groups = {armor_feet=10, armor_heal=5, armor_use=250},
groups = {armor_feet=10, armor_heal=5, armor_use=196},
_repair_material = "mcl_core:iron_ingot",
})
@ -170,7 +170,7 @@ minetest.register_tool("3d_armor:boots_gold", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_boots_gold.png",
groups = {armor_feet=15, armor_heal=10, armor_use=500},
groups = {armor_feet=15, armor_heal=10, armor_use=92},
_repair_material = "mcl_core:gold_ingot",
})
@ -179,7 +179,7 @@ minetest.register_tool("3d_armor:boots_diamond",{
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_boots_diamond.png",
groups = {armor_feet=20, armor_heal=15, armor_use=750},
groups = {armor_feet=20, armor_heal=15, armor_use=430},
_repair_material = "mcl_core:diamond",
})
@ -188,7 +188,7 @@ minetest.register_tool("3d_armor:boots_chain", {
_doc_items_longdesc = longdesc,
_doc_items_usagehelp = usage,
inventory_image = "3d_armor_inv_boots_chain.png",
groups = {armor_feet=15, armor_heal=10, armor_use=500},
groups = {armor_feet=15, armor_heal=10, armor_use=196},
_repair_material = "mcl_core:iron_ingot",
})