How to change mobs' health with NBT?
-
I am aware this has been asked and answered before, but I can't find a solution that works for me, somehow. Aside from giving the mobs health_boost, that is. But that works per 4 health, so this isn't exactly my prefered choice.
I am currently using a /data merge on a chicken with:
Health:10,Attributes:[{Name:"generic.maxHealth",Base:10}]
Which doesn't work. I thought it might just not regenerate the health above the value it had before merging the data, but healing it doesn't change it, since it still has 4 health.
For the full data merge command:
execute as @e[type=chicken,scores={empowered=1..,lifetime=1..2}] run data merge entity @s {CustomName:"\"Floating Chicken\"",CustomNameVisible:1,Health:10,Attributes:[{Name:"generic.maxHealth",Base:10}],HandDropChances:[0.33F,2F],HandItems:[{id:"minecraft:leather_boots",tag:{Tags:"Airflow",Unbreakable:1,display:{color:16448250,Name:'[{"text":"Airflow","italic":false}]',Lore:['[{"text":"Slows down falling speed while worn","italic":false}]']},AttributeModifiers:[{AttributeName:"generic.armor",Amount:1,Slot:feet,Name:"generic.armor",UUID:[I;-1211110,25079,235157,-50158]},{AttributeName:"generic.max_health",Amount:1,Slot:feet,Name:"generic.max_health",UUID:[I;-1211110,25179,235157,-50358]},{AttributeName:"generic.movement_speed",Amount:0.01,Slot:feet,Operation:1,Name:"generic.movement_speed",UUID:[I;-1211110,25279,235157,-50558]}]},Count:1},{}]}
I am making a simple datapack that causes every mob to sometimes spawn as an empowered mob with higher stats, effects and sometimes special abilities, while also having special drops. This includes almost every mob, except a few such as villagers.
Lifetime is a score that gets increased by 1 per tick to keep track of how long something has been alive. Right now it's only used to change the empowered mobs once instead of constantly, but later I'm planning on using it for things like slimes that regrow in size after being alive for a while.
-
I just realised this has a pretty obvious answer. It isn't NBT as I asked but works perfrectly fine as well. The attribute command allows exactly what I want. I can even reduce health of mobs if I want to. Example:
/attribute minecraft:generic.max_health base set