How do i Make a Bossbar that will Decrease when i Die?

I recently found out about the new Minecraft snapshot that adds new uses to boss health bars. I was wondering if there was a way to make a bossbar that will decrease by 1 every time i die, and when i die 9 times (when the bar depletes all the way) it will set my gamemode to hardcore, therefore causing me to only be able to die 10 times before my game gets deleted. If so, can someone tell me how to create this command?


Solution 1:

From the wiki on Hardcore mode:

It is normally impossible to toggle Hardcore mode once the world has been created, though it is possible to use external programs such as NBTExplorer to change it by setting the hardcore tag to either 1 (hardcore) or 0 (normal).

There is no command to change the world to hardcore mode so what you are asking for is not currently possible.


Just for fun and since I have never played with 1.13 before today, I built a system which will do what you want except it changes the difficulty to hard when you die the 9th time instead of hardcore mode. Anyone who sees anything that could be done better, feel free to educate me.

First, a handful of manual commands to enter into chat.

Create an objective to track the number of deaths:

/scoreboard objectives add Deaths deathCount

Create the bossbar:

/bossbar create minecraft:deaths "Deaths"

Set the maximum value of the bar to 10:

/bossbar set minecraft:deaths max 10

Set bossbar to a notched style for easy counting:

/bossbar set minecraft:deaths style notched_10

Apply bossbar to yourself:

/bossbar set minecraft:deaths players @a

Now for the command blocks

First command block is a Repeat Unconditional Always active block with the command:

execute store result bossbar minecraft:deaths value run scoreboard players get @p Deaths

Second command block is a Chain Unconditional Always active block with the command:

execute if score @p Deaths matches 9 run difficulty hard