AbstractFontRenderer

abstract class AbstractFontRenderer

Draws text with minecraft font markup.

The FormattedCharSequence overloads are the primitives and draw the sequence as it is: no sanitizeForeignInput, so text that came from a server has to be sanitized by the caller. The Component overloads do it for you, at the price of an extra pass per call (flatten the component, match the protected names) - pass a sequence once the text is settled, or when it is measured before it is drawn, to pay that only once.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard

Properties

Link copied to clipboard
abstract val height: Float
Link copied to clipboard

Scales this renderer's text metrics to vanilla's 9px GUI font line height.

Link copied to clipboard
abstract val size: Float

Functions

Link copied to clipboard
context(ctx: WorldRenderEnvironment)
inline fun draw(text: Component, parameters: AbstractFontRenderer.DrawParameters.() -> Unit = {}): Float

context(ctx: WorldRenderEnvironment)
inline fun draw(text: FormattedCharSequence, parameters: AbstractFontRenderer.DrawParameters.() -> Unit = {}): Float
context(ctx: GuiGraphicsExtractor)
inline fun draw(text: FormattedCharSequence, parameters: AbstractFontRenderer.DrawParameters.() -> Unit = {}): Float

Draws text as it is - unlike the Component overloads, it is not sanitized.

context(ctx: WorldRenderEnvironment)
abstract fun draw(text: FormattedCharSequence, parameters: AbstractFontRenderer.DrawParameters): Float

Draws text with minecraft font markup on GUI with WorldRenderEnvironment.

context(ctx: GuiGraphicsExtractor)
inline fun draw(text: Component, parameters: AbstractFontRenderer.DrawParameters.() -> Unit = {}): Float

Draws a Component, degenerating its legacy formatting and applying sanitizeForeignInput first. Pass a FormattedCharSequence when the text is already prepared.

context(ctx: GuiGraphicsExtractor)
abstract fun draw(text: FormattedCharSequence, parameters: AbstractFontRenderer.DrawParameters): Float

Draws text with minecraft font markup on GUI with GuiGraphicsExtractor.

fun draw(ctx: GuiGraphicsExtractor, text: Component, x: Float, y: Float, color: Color4b = Color4b.WHITE, shadow: Boolean = false, scale: Float = scaleToVanillaFont, horizontalAnchor: HorizontalAnchor? = null, verticalAnchor: VerticalAnchor? = null): Float

Draws text on the GUI at x/y in GUI pixels; scale 1 is this font's own size, the default matches vanilla's. For Kotlin the context overloads with DrawParameters do the same.

Link copied to clipboard
abstract fun getStringWidth(text: FormattedCharSequence, shadow: Boolean = false): Float

Approximates the width of a text. Accurate except for obfuscated (§k) formatting

fun getStringWidth(text: Component, scale: Float = scaleToVanillaFont, shadow: Boolean = false): Float

Width of text in GUI pixels at scale, the default being vanilla's size.