Skip to content

TextTexture

Since 2.2.1

TextTexture renders a translated string as a GUI texture. It supports multiple display modes (centred, left-aligned, scrolling, hidden-until-hover), word-wrapping, a background colour, and an optional live-update supplier.

Registry name: text_texture

INFO

Extends TransformTexture — supports rotate(), scale(), transform().


Usage

java
// Static centred text
IGuiTexture label = new TextTexture("Hello World");

// Left-aligned, coloured, with shadow
IGuiTexture info = new TextTexture("Info", 0xFFFFDD44)
    .setType(TextTexture.TextType.LEFT)
    .setDropShadow(true);

// Scrolling text, word-wrap at 80 px
IGuiTexture scroll = new TextTexture("Long description that scrolls…")
    .setType(TextTexture.TextType.ROLL_ALWAYS)
    .setWidth(80)
    .setRollSpeed(1.5f);

// Dynamic — updates every game tick
IGuiTexture dynamic = new TextTexture(() -> "Ticks: " + level.getGameTime());

Text Types

TypeAlignmentOverflow behaviour
NORMALCentreAll lines shown stacked.
LEFTLeftAll lines shown stacked.
RIGHTRightAll lines shown stacked.
HIDECentreFirst line shown; full text scrolls when hovered.
LEFT_HIDELeftFirst line shown; full text scrolls when hovered.
ROLLCentreFirst line shown; scrolls when hovered and text overflows.
LEFT_ROLLLeftFirst line shown; scrolls when hovered.
ROLL_ALWAYSCentreAlways scrolls regardless of hover.
LEFT_ROLL_ALWAYSLeftAlways scrolls regardless of hover.

Fields

NameTypeDescription
textStringThe displayed string (translated via LocalizationUtils).
colorintText colour (ARGB). Default: -1 (white).
backgroundColorintBackground fill colour. 0 = none.
widthintMaximum line width for word-wrapping in pixels.
rollSpeedfloatScroll speed for rolling modes. Default: 1.0.
dropShadowbooleanWhether to draw a drop shadow. Default: false (constructor with String sets it to true).
typeTextTypeDisplay mode. Default: NORMAL.
supplierSupplier<String> (nullable)When set, text is updated every game tick from this supplier.

Methods

MethodReturnsDescription
setColor(int)TextTextureSets the text colour.
setBackgroundColor(int)TextTextureSets the background fill colour.
setDropShadow(boolean)TextTextureEnables or disables drop shadow.
setWidth(int)TextTextureSets the word-wrap width and reflows lines.
setType(TextType)TextTextureSets the display mode.
setRollSpeed(float)TextTextureSets the scroll speed for rolling modes.
setSupplier(Supplier<String>)TextTextureRegisters a live text supplier updated each tick.
updateText(String)voidImmediately updates the text and reflows lines.
copy()TextTextureReturns a deep copy.

Released under the MIT License.