Class TextOffset

java.lang.Object
com.github.darksoulq.abyssallib.server.resource.util.TextOffset

public class TextOffset extends Object
Utility for generating invisible font-based glyph offsets to fine-tune horizontal text alignment.

This class uses a custom font provider to register glyphs with specific advance widths. By appending these characters to a string, text following them is shifted horizontally without rendering any visible characters.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.kyori.adventure.text.Component
    getOffset(int pixelOffset)
    Converts a pixel offset into a sequence of invisible glyphs that shift text left or right.
    static String
    getOffsetMinimessage(int pixelOffset)
    Converts a pixel offset into a MiniMessage string containing invisible glyphs.
    static void
    Initializes the offset font provider and registers all necessary glyphs.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TextOffset

      public TextOffset()
  • Method Details

    • init

      @Internal public static void init(Namespace ns)
      Initializes the offset font provider and registers all necessary glyphs.

      This method registers an "offset" font within the given namespace and creates texture glyphs that are moved far off-screen (-9000 height) to ensure invisibility.

      Parameters:
      ns - The Namespace context where the font and textures will be registered.
    • getOffset

      public static net.kyori.adventure.text.Component getOffset(int pixelOffset)
      Converts a pixel offset into a sequence of invisible glyphs that shift text left or right.
      Parameters:
      pixelOffset - The number of pixels to offset the text (positive for right, negative for left).
      Returns:
      A Component containing the invisible offset glyphs in the custom font.
    • getOffsetMinimessage

      public static String getOffsetMinimessage(int pixelOffset)
      Converts a pixel offset into a MiniMessage string containing invisible glyphs.

      The method uses a greedy algorithm to decompose the target pixelOffset into the fewest possible number of predefined glyph widths.

      Parameters:
      pixelOffset - The number of pixels to offset the text.
      Returns:
      A MiniMessage-formatted String using the abyssallib:offset font.