Class FoliosText

java.lang.Object
net.ixdarklord.folios.api.client.page.FoliosText

public final class FoliosText extends Object
Text written for a book, set out in lines to a width. It is a small part of Markdown, so long text reads well in a JSON file:
  • A line is a line; an empty line starts a new paragraph.
  • # Heading and ## Smaller heading; --- alone is a dividing rule.
  • - item (or * item) is a bullet, 1. item a numbered one; two spaces before nest it.
  • > text is set apart as a note.
  • **bold**, *italic* (or _italic_), __underlined__, ~~struck~~, `code`.
  • [label](target) links to an entry (entry:id, entry:id#marker or the bare id), a category (category:id), an item's page (item:minecraft:diamond) or a web page (https://...).
  • Tags in braces: {#FF8800}coloured{/} colours text; {key:key.jump} names the key bound to something; {player} is the reader's name; {item:minecraft:diamond} an item's name, linking to its page when the book has one; {entry:tools/scribe#scribe} a link with the entry's name; {flag:mymod:hard_mode|on text|off text} text by a flag; {lang:key|first|second} a translation, itself read as this markup, its %s filled from the rest. A tag that doesn't parse is shown as written.
  • A backslash keeps the next character as it is: \*, {@code \{}.</li> </ul> Text that is a translation key as a whole is translated first. In JSON, a text field takes either a string of this markup or {@code {"translate": "key", "with": [...], "fallback": "..."}} ({@link #CODEC}), so a book can keep all its words in lang files.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    What a line is part of, which decides how it is drawn.
    static final record 
    One line, at (x, y) from the text's top left.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<String>
    Text as JSON writes it: a string of this markup, or {"translate": "key", "with": ["first"], "fallback": "text"} for a translation (the arguments and fallback are markup too).
    static final int
     
    static final String
    The insertion text of a link's characters starts with this; the rest is where it goes.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    draw(FoliosPainter painter, int x, int y)
    Draws the text with its top left at (x, y), its links pressable.
    static boolean
    Whether the language has text for a translation key.
    int
    From the top of the first line to the bottom of the last.
    static <T> T
    in(FoliosBook book, Supplier<T> read)
    Runs something with a book as the one text is read for: its {entry:...} tags take its entries' names, and {item:...} links to its pages.
    static net.minecraft.network.chat.Component
    One line of marked-up text (a title or a label) as a component; block marks are kept as written.
    static boolean
    Whether text comes to nothing once read (a translation with an empty fallback and no key, say).
    boolean
     
     
    Where each line starts down the text, top first, each once: where a window of it can start.
    static FoliosText
    of(net.minecraft.client.gui.Font font, String raw, int width)
    Reads marked-up text and sets it out in lines no wider than width.
    static FoliosText
    of(net.minecraft.client.gui.Font font, String raw, int width, @Nullable FoliosAlign align)
    As of(Font, String, int), its lines aligned: null or FoliosAlign.LEFT as written.
    static String
    Text without its marks, for searching.
    static String
    read(com.google.gson.JsonElement json)
    Text from JSON, as CODEC reads it.
    static String
    The text a raw string stands for: its translation if it is a translation key, with each {lang:...} put in its place.
    split(int firstHeight, int nextHeight)
    Splits the text into pieces that fit: the first firstHeight tall, the rest nextHeight.
    static String
    translation(String key, List<String> with, @Nullable String fallback)
    Markup for a translation, {lang:key|with...}, with what to show if there is no such key (null to show the key).
    int
    The width it was set out to.
    int
    width(net.minecraft.client.gui.Font font)
    The widest line.
    window(int from, int height)
    The lines that lie whole between from and from + height down the text, starting again at y 0.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LINE_HEIGHT

      public static final int LINE_HEIGHT
      See Also:
    • CODEC

      public static final com.mojang.serialization.Codec<String> CODEC
      Text as JSON writes it: a string of this markup, or {"translate": "key", "with": ["first"], "fallback": "text"} for a translation (the arguments and fallback are markup too). Either way it is read as a string of markup.
  • Method Details

    • lines

      public List<FoliosText.Line> lines()
    • height

      public int height()
      From the top of the first line to the bottom of the last.
    • width

      public int width()
      The width it was set out to.
    • isEmpty

      public boolean isEmpty()
    • read

      public static String read(com.google.gson.JsonElement json)
      Text from JSON, as CODEC reads it.
    • translation

      public static String translation(String key, List<String> with, @Nullable @Nullable String fallback)
      Markup for a translation, {lang:key|with...}, with what to show if there is no such key (null to show the key).
    • hasTranslation

      public static boolean hasTranslation(String key)
      Whether the language has text for a translation key.
    • isBlank

      public static boolean isBlank(String raw)
      Whether text comes to nothing once read (a translation with an empty fallback and no key, say).
    • in

      public static <T> T in(FoliosBook book, Supplier<T> read)
      Runs something with a book as the one text is read for: its {entry:...} tags take its entries' names, and {item:...} links to its pages. A book sets itself while it lays out its pages and searches them.
    • resolve

      public static String resolve(String raw)
      The text a raw string stands for: its translation if it is a translation key, with each {lang:...} put in its place.
    • inline

      public static net.minecraft.network.chat.Component inline(String raw)
      One line of marked-up text (a title or a label) as a component; block marks are kept as written.
    • plain

      public static String plain(String raw)
      Text without its marks, for searching.
    • of

      public static FoliosText of(net.minecraft.client.gui.Font font, String raw, int width)
      Reads marked-up text and sets it out in lines no wider than width.
    • of

      public static FoliosText of(net.minecraft.client.gui.Font font, String raw, int width, @Nullable @Nullable FoliosAlign align)
      As of(Font, String, int), its lines aligned: null or FoliosAlign.LEFT as written. A paragraph written ->like this<- is centred, and ->like this right-aligned, whatever the rest is.
    • split

      public List<FoliosText> split(int firstHeight, int nextHeight)
      Splits the text into pieces that fit: the first firstHeight tall, the rest nextHeight. A heading is never left alone at the foot of a piece. Each piece's lines start again at y 0.
    • lineTops

      public List<Integer> lineTops()
      Where each line starts down the text, top first, each once: where a window of it can start.
    • window

      public FoliosText window(int from, int height)
      The lines that lie whole between from and from + height down the text, starting again at y 0.
    • draw

      public void draw(FoliosPainter painter, int x, int y)
      Draws the text with its top left at (x, y), its links pressable.
    • width

      public int width(net.minecraft.client.gui.Font font)
      The widest line.