how to implement this in most optimized way?
version: 1.20.6
what i have
i have this datapack where i replaced vanilla health with my own health system that is based on scoreboards. then i also have "accessories" that i will later on call just "armor" its from 9 to 13 container in player's inventory. and i want the armor to modify health based on its nbt data. here instead of checking for my inventory slots every tick i decided to use
inventory_changedadvancement instead, and when the "armor" is there i take values from it and add onto heatlh.max scoreboard of the player. that works wonderfully!problem
but now here is a problem. how do i check for when the player unequips armor, and subtract the health values stored in the unequiped armor from health.max? i need to make it as optimized as possible and multiplayer friendly. the only solutions i can think of are complex data manipulations with saving everything in data storages and then manipulating all that to achieve what i want.
what i want
what i want from you: please help me brainstorm this and find out the best solution to the problem