Skip to content

Boss bars

A BossBar is the bar across the top of the screen. It has a name, a fill fraction from 0.0F to 1.0F, a color, and an overlay style:

java
BossBar bar = BossBar.bossBar(
        Component.text("Boss"),  // name
        1.0F,                    // progress percentage
        BossBar.Color.RED,       // color
        BossBar.Overlay.PROGRESS // variant
);

audience.showBossBar(bar);
audience.hideBossBar(bar);

Overlay.PROGRESS draws a solid bar:

A boss bar using the progress overlay

The NOTCHED_ variants divide it into 6, 10, 12, or 20 segments:

A boss bar using a notched overlay

Updating a bar

A BossBar is mutable and tracks its viewers. Changes are sent to every current viewer, so the bar does not need to be shown again:

java
bar.progress(0.5F);
bar.color(BossBar.Color.YELLOW);
bar.name(Component.text("Boss fight (half health)"));

Flags enable the vanilla boss effects, all disabled by default:

java
bar.addFlag(BossBar.Flag.DARKEN_SCREEN);
bar.addFlag(BossBar.Flag.PLAY_BOSS_MUSIC);
bar.addFlag(BossBar.Flag.CREATE_WORLD_FOG);

The manager

MinecraftServer#getBossBarManager() provides two operations the audience API does not:

java
// remove a bar from all of its viewers
MinecraftServer.getBossBarManager().destroyBossBar(bar);

// the bars a player is currently shown
Collection<BossBar> bars = MinecraftServer.getBossBarManager().getPlayerBossBars(player);