Overlays
Tip
In order to understand Nova's overlays, it might be beneficial for you to read our spigot thread on using the font renderer.
Overlays follow the same concept of using fonts to render images as GUI Textures, but are a bit more difficult to implement for addon developers, as you need to create the font file yourself.
Font files are stored under assets/fonts/
and have this format.
You might also want to take a look at our font for the jetpack energy bar overlay.
Action bar overlay
After creating your font, implement the ActionbarOverlay
interface. There you'll need to provide the component array
to be displayed in the action bar, as well as the width of the entire text. Components to move the text by a specified
amount of pixels can be obtained by calling MoveCharacters#getMovingComponent
.
Example: JetpackOverlay
class JetpackOverlay : ActionbarOverlay {
override var components: Array<BaseComponent> = getCurrentText()
private set
var percentage: Double = 0.0
set(value) {
require(value in 0.0..1.0)
if (field == value) return
field = value
text = getCurrentText()
}
private fun getCurrentText(): Array<BaseComponent> {
val stage = (percentage * 38).toInt()
return ComponentBuilder()
.append(MoveCharacters.getMovingComponent(95))
.append(('\uF000'.code + stage).toChar().toString())
.font("jetpacks:energy_bar")
.create()
}
}
- +1 because the "cursor" always moves one pixel to the left after every character in order to make space between them.
The overlay can now be displayed through the ActionbarOverlayManager
:
Info
Nova intercepts action bar packets and appends the action bar overlay to it.
This means that normal action bar text can still be displayed, even if one or more action bar overlays are active.
Boss bar overlay
Upcoming API-breaking changes
A rework of boss bar overlays is planned for 0.13 or later.
Similar to the action bar overlay, you can also render at boss bar position. For that, you can either extend the
BossBarOverlay
class or use the TextBossBarOverlay
and CenteredTextBossBarOverlay
implementations if you just
need to render text.
Then, register your overlay in the BossBarOverlayManager
:
Info
Nova intercepts all vanilla boss bars and then redraws them using custom characters that have the boss bar texture.
With this approach, vanilla boss bars are just moved below your boss bar overlay.