Record Class WrittenBookContent

java.lang.Object
java.lang.Record
fr.fidorial.item.component.WrittenBookContent
Record Components:
title - the title
author - the author
generation - how many times the book was copied, from 0 (original) to 3
pages - the pages
resolved - whether the selectors, scores and NBT the pages hold were already resolved
All Implemented Interfaces:
BookLike

public record WrittenBookContent(Component title, Component author, int generation, List<Component> pages, boolean resolved) extends Record implements BookLike
The contents of a signed book, under minecraft:written_book_content.

As a BookLike, it can be opened directly with Audience.openBook(BookLike).

The client only knows the title and author as plain text: they are flattened when the book is sent or saved, and the title is cut to 32 characters.

Since:
0.1.0
  • Field Details

    • MAX_TITLE_LENGTH

      public static final int MAX_TITLE_LENGTH
      The longest title, in plain text characters, the client accepts.
      See Also:
    • MAX_PAGES

      public static final int MAX_PAGES
      The most pages a written book holds.
      See Also:
    • MAX_GENERATION

      public static final int MAX_GENERATION
      The highest generation, a copy of a copy.
      See Also:
  • Constructor Details

    • WrittenBookContent

      public WrittenBookContent(Component title, Component author, int generation, List<Component> pages, boolean resolved)
      Creates an instance of a WrittenBookContent record class.
      Parameters:
      title - the value for the title record component
      author - the value for the author record component
      generation - the value for the generation record component
      pages - the value for the pages record component
      resolved - the value for the resolved record component
  • Method Details

    • of

      public static WrittenBookContent of(BookLike book)
      Converts an Adventure book, keeping its title, author and pages as they are.
      Parameters:
      book - the book
      Returns:
      the contents of an original, already resolved written book
    • asBook

      public Book asBook()
      Specified by:
      asBook in interface BookLike
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • title

      public Component title()
      Returns the value of the title record component.
      Returns:
      the value of the title record component
    • author

      public Component author()
      Returns the value of the author record component.
      Returns:
      the value of the author record component
    • generation

      public int generation()
      Returns the value of the generation record component.
      Returns:
      the value of the generation record component
    • pages

      public List<Component> pages()
      Returns the value of the pages record component.
      Returns:
      the value of the pages record component
    • resolved

      public boolean resolved()
      Returns the value of the resolved record component.
      Returns:
      the value of the resolved record component