How do you change a boss bar in minecraft by a certain value instead of directly
I can't find it anywhere on the internet, but all I want to do is change a boss bar by a certain amount, instead of directly changing it with the value sub command. Is there a way to simply add an amount to the existing value? ie. Add 1 to bossbar, instead of set bossbar to 2.
Math operations cannot be performed on bossbar values. However, what you can do is use Minecraft's scoreboard system, which provides many helpful math operations.
Try this solution and see if it works:
Setup
Use the following command to create a scoreboard objective:
scoreboard objectives add bossbars dummy
Creates a scoreboard objective where you can store bossbar values. The dummy
means it is not affected by a statistic. (You can change bossbars
to anything you want, but don't change dummy
or it will break!)
Next you need to set a value. Use this command:
scoreboard players set $finalBattle 0
Replace $finalBattle
with something that will make it easy for others to know what this score refers to. For example, $finalBattle
could refer to the bossbar for the final battle of the game.
Usage
Put this command on repeat:
execute store result bossbar YourBossbarName value run scoreboard players get $finalBattle bossbar
Replace $finalBattle
and bossbar
with the names you set them to earlier. This will repeatedly query the score in the scoreboard and set the bossbar's value to it.
Now, increase/decrease the value in the scoreboard and watch it immediately update on the bossbar!
scoreboard players add finalBattle bossbar 1
Add 1 to finalBattle
's score of objective bossbar
.
Note: If you need multiplication, division, or modulus, your commands will be more complicated, but it is possible! Comment below if you would like that.