ボスバーで、エンダードラゴンやウィザーなどのように体力を表示する方法。
Java版、1.19で確認(おそらく1.16以降は同様に可能)
エンダーマンでの例が下記。
1. ボスバーの名前を決める
/bossbar add enderman "Enderman"
2.ボスバーの上限を決める。
これはモブ毎に異なるため調べる必要がある。例えばエンダーマンなら40。
/bossbar set minecraft:enderman max 40
3.ボスバーを表示する
/bossbar set minecraft:enderman players @a
4.ボスバーにモブの体力を反映させる
コマンドブロック:Repeat, Unconditional, Always active
で下記を入れる。
/execute as @e[type=enderman, limit=1] store result bossbar minecraft:enderman value run data get entity @s Health
上記では、最後の1撃を与える前の状態で止まってしまうことが判明。
解消方法
エンダーマンをカウントし、0になったらボスバーも0になるようにする。
/scoreboard objectives add Count dummy
Command block: Repeat, Uncondional, Always active
/execute store result score enderman Count if entity @e[type=enderman]
Command block: Repeat, Uncondional, Always active
/execute if score enderman Count matches 0 run scoreboard players set enderman health 0
Command block: Chain, Conditional, Always active
/execute if score enderman Count matches 0 run bossbar set enderman value 0