public static void RecalculateAttributes(IItemStack parent, IWorldAccessor world) { int durability = 0; int maxdurability = 0; ITreeAttribute ToolSlots = parent.Attributes.GetTreeAttribute("toolparts"); foreach (KeyValuePair <string, IAttribute> pair in ToolSlots) { ItemStack stack = pair.Value.GetValue() as ItemStack; stack.ResolveBlockOrItem(world); IModularItem item = (IModularItem)stack.Item; durability += stack.Attributes.GetInt("durability", item != null ? item.GetDurability(stack) : 0); maxdurability += stack.Attributes.GetInt("maxdurability", item != null ? item.GetDurability(stack) : 0); } parent.Attributes.SetInt("maxdurability", maxdurability); if (durability != maxdurability) { parent.Attributes.SetInt("durability", durability); } else { parent.Attributes.RemoveAttribute("durability"); } }