Unbreaking for armor

This commit is contained in:
Elias Fleckenstein 2020-11-02 15:33:05 +01:00
parent a516eccd6d
commit afa11c0723
4 changed files with 13 additions and 1 deletions

View file

@ -1 +1,2 @@
tt
mcl_enchanting

View file

@ -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

View file

@ -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)

View file

@ -3,3 +3,4 @@ mcl_player
mcl_fire?
ethereal?
bakedclay?
mcl_enchanting