1
Command Block Help / Health Modifying Armor
I'm trying to make armor that add hearts to the player wearing them. I've added effects to armor using commands like:
/give @p minecraft:iron_helmet{Unbreakable:1,ticket:1016a,display:{Name:'[{"text":"NVG","italics":"true","color":"dark_aqua"}]'}}
Repeat
/tag @a[tag=NVG] remove NVG
Chain
/tag @a[nbt={Inventory:[{Slot:103b,tag:{ticket:1016a}}]}] add NVG
Repeat
/effect give @a[tag=NVG] minecraft:night_vision 11 0 true
However for Health Boost it can't be given every tick, otherwise it will reset the bonus hearts effectively doing nothing. So, I've considered doing something like this:
Repeat
/execute unless entity @a[tag=HealthBoost,nbt={ActiveEffects:[{Id:21b}]}] run effect give @a[tag=HealthBoost] minecraft:health_boost 86400 1 true
However, by itself this makes it so that the player would only have to put on the tag giving armor once a day, and if I have a command that removes health boost on players without the tag that means players would be unable to get health boosts from other means.
Another solution I've seen is by adding generic.max_health modifiers to armor, using commands like this:
/give @p minecraft:chainmail_helmet{AttributeModifiers:[{AttributeName:"generic.max_Health",Name:"generic.max_Health",Amount:1,Operation:0,UUIDLeast:816652,UUIDMost:485609}]} 1
But I haven't gotten it to work. I've played with the syntax a little, too, but I'm not sure how it should be.
The best solution I can think of right now is making it so that instead of lasting a day the effect lasts a minute, then resets so it's simply more convenient to keep it on, or have a distance check on tagged armor so that if players are near them or have them in their inventory but not worn their health boost is cleared. That seems woefully inelegant and obtuse, though.
/give @p minecraft:iron_helmet{Unbreakable:1,ticket:1016a,display:{Name:'[{"text":"NVG","italics":"true","color":"dark_aqua"}]'}}
Repeat
/tag @a[tag=NVG] remove NVG
Chain
/tag @a[nbt={Inventory:[{Slot:103b,tag:{ticket:1016a}}]}] add NVG
Repeat
/effect give @a[tag=NVG] minecraft:night_vision 11 0 true
However for Health Boost it can't be given every tick, otherwise it will reset the bonus hearts effectively doing nothing. So, I've considered doing something like this:
Repeat
/execute unless entity @a[tag=HealthBoost,nbt={ActiveEffects:[{Id:21b}]}] run effect give @a[tag=HealthBoost] minecraft:health_boost 86400 1 true
However, by itself this makes it so that the player would only have to put on the tag giving armor once a day, and if I have a command that removes health boost on players without the tag that means players would be unable to get health boosts from other means.
Another solution I've seen is by adding generic.max_health modifiers to armor, using commands like this:
/give @p minecraft:chainmail_helmet{AttributeModifiers:[{AttributeName:"generic.max_Health",Name:"generic.max_Health",Amount:1,Operation:0,UUIDLeast:816652,UUIDMost:485609}]} 1
But I haven't gotten it to work. I've played with the syntax a little, too, but I'm not sure how it should be.
The best solution I can think of right now is making it so that instead of lasting a day the effect lasts a minute, then resets so it's simply more convenient to keep it on, or have a distance check on tagged armor so that if players are near them or have them in their inventory but not worn their health boost is cleared. That seems woefully inelegant and obtuse, though.
2
If you're using this on (I think) 1.14+, UUIDMost and Least have been decrepated and instead made into 4 integer elements of an array.
The command would be:
The command would be:
/give @p chainmail_helmet{AttributeModifiers:[{AttributeName:"generic.max_health",Name:"generic.max_health",Amount:1,Operation:0,UUID:[I;-984824647,1029064462,-1728717498,-591411252]}]} 1Awesome, that works!
