From afa11c07230831207d4fb0002ecdc4e9927a1eeb Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 2 Nov 2020 15:33:05 +0100 Subject: [PATCH] Unbreaking for armor --- mods/HELP/mcl_tt/depends.txt | 1 + mods/HELP/mcl_tt/snippets_mcl.lua | 8 +++++++- mods/ITEMS/mcl_armor/armor.lua | 4 ++++ mods/ITEMS/mcl_armor/depends.txt | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mods/HELP/mcl_tt/depends.txt b/mods/HELP/mcl_tt/depends.txt index c49c556e0e..12e5a198da 100644 --- a/mods/HELP/mcl_tt/depends.txt +++ b/mods/HELP/mcl_tt/depends.txt @@ -1 +1,2 @@ tt +mcl_enchanting diff --git a/mods/HELP/mcl_tt/snippets_mcl.lua b/mods/HELP/mcl_tt/snippets_mcl.lua index 569dbe6866..6e28035020 100644 --- a/mods/HELP/mcl_tt/snippets_mcl.lua +++ b/mods/HELP/mcl_tt/snippets_mcl.lua @@ -25,7 +25,7 @@ tt.register_snippet(function(itemstring) end return s end) -tt.register_snippet(function(itemstring) +tt.register_snippet(function(itemstring, _, itemstack) local def = minetest.registered_items[itemstring] local s = "" local use = minetest.get_item_group(itemstring, "mcl_armor_uses") @@ -34,6 +34,12 @@ tt.register_snippet(function(itemstring) s = s .. S("Armor points: @1", pts) s = s .. "\n" end + if itemstack then + local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + if unbreaking > 0 then + use = math.floor(use / (0.6 + 0.4 / (unbreaking + 1))) + end + end if use > 0 then s = s .. S("Armor durability: @1", use) end diff --git a/mods/ITEMS/mcl_armor/armor.lua b/mods/ITEMS/mcl_armor/armor.lua index b9aa1b2719..5387aa701b 100644 --- a/mods/ITEMS/mcl_armor/armor.lua +++ b/mods/ITEMS/mcl_armor/armor.lua @@ -518,6 +518,10 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason) if stack:get_count() > 0 then -- Damage armor local use = stack:get_definition().groups["mcl_armor_uses"] or 0 + local unbreaking = mcl_enchanting.get_enchantment(stack, "unbreaking") + if unbreaking > 0 then + use = use / (0.6 + 0.4 / (unbreaking + 1)) + end if use > 0 then local wear = armor_damage * math.floor(65536/use) stack:add_wear(wear) diff --git a/mods/ITEMS/mcl_armor/depends.txt b/mods/ITEMS/mcl_armor/depends.txt index e57f69dfb3..067cf61b11 100644 --- a/mods/ITEMS/mcl_armor/depends.txt +++ b/mods/ITEMS/mcl_armor/depends.txt @@ -3,3 +3,4 @@ mcl_player mcl_fire? ethereal? bakedclay? +mcl_enchanting