mojira.dev
MC-124789

Bossbar for health broken

I made a bossbar to display the health of the nearest mob with the following command-
/execute store result bossbar _name of bossbar_ value run data get @e[sort=nearest,limit=1,type=!player] Health

It works for some time then the bar empties. I try to add value to it manually ,it got added but did not show up.

It is resolved when I make the bar visibility to false and then make it visible again

Linked issues

Comments

David Bakle

Can confirm this to be true. The first set of commands is what's expected to work, and the second set is the work around (using command blocks). The commands set the maximum of the bossbar to the max health of the pig, and then set the value for the bossbar as the pig's health. The command output says that it successfully set the values, but it doesn't visibly do it.

/execute store result bossbar minecraft:foo max run data get @e[type=pig,limit=1] Attributes.[0].Base
/execute store result bossbar minecraft:foo value run data get @e[type=pig,limit=1] Health

In order to make this work, I have to add two commands to the beginning to reset the players that can see it. I'm using @s in the first command since I'm instructing the command block to change the players that can see it to itself, which removes anyone who could previously see it. The second command sets the visibility to all players. Setting the bossbar's overall visibility to false then true does not fix the issue.

/bossbar set minecraft:hud players @s
/bossbar set minecraft:hud players @a
/execute store result bossbar minecraft:foo max run data get @e[type=pig,limit=1] Attributes.[0].Base
/execute store result bossbar minecraft:foo value run data get @e[type=pig,limit=1] Health
marcono1234

Possibly duplicates MC-124717, when the pig is dead a max value of 0 is set which is not valid.

user-f2760

You cannot target dead entities with @e though...

marcono1234

No, but the result is likely 0 when it does not find a matching entity

Anonymous

(Unassigned)

Confirmed

/bossbar, bossbar

Minecraft 18w05a

Retrieved