Record Class SectionType<S extends Section>

java.lang.Object
java.lang.Record
de.Keyle.MyPet.api.gui.SectionType<S>
Type Parameters:
S - the section record this type describes
Record Components:
id - the type id as it appears in menu JSON
sectionClass - the record class decoded instances have
renderer - draws the section and handles clicks on its slots
codec - reads and writes the section's JSON form

public record SectionType<S extends Section>(String id, Class<S extends Section> sectionClass, SectionRenderer<S extends Section> renderer, JsonCodec<S extends Section> codec) extends Record
Pairs a section's type id with its concrete record class, renderer, and codec. Built-in types are static fields on type-holder classes that call register(java.lang.String, java.lang.Class<S>, de.Keyle.MyPet.api.gui.SectionRenderer<S>, de.Keyle.MyPet.api.gui.JsonCodec<S>) from a static initializer; the registry forces those classes to load at plugin OnLoad.
  • Constructor Details

    • SectionType

      public SectionType(String id, Class<S> sectionClass, SectionRenderer<S> renderer, JsonCodec<S> codec)
      Creates an instance of a SectionType record class.
      Parameters:
      id - the value for the id record component
      sectionClass - the value for the sectionClass record component
      renderer - the value for the renderer record component
      codec - the value for the codec record component
  • Method Details

    • register

      public static <S extends Section> SectionType<S> register(String id, Class<S> sectionClass, SectionRenderer<S> renderer, JsonCodec<S> codec)
      Builds a section type and registers it in one step, so a type-holder class can assign the result straight to a static final field.
      Type Parameters:
      S - the section record this type describes
      Parameters:
      id - the type id as it appears in menu JSON
      sectionClass - the record class decoded instances have
      renderer - draws the section and handles clicks on its slots
      codec - reads and writes the section's JSON form
      Returns:
      the newly registered type
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • sectionClass

      public Class<S> sectionClass()
      Returns the value of the sectionClass record component.
      Returns:
      the value of the sectionClass record component
    • renderer

      public SectionRenderer<S> renderer()
      Returns the value of the renderer record component.
      Returns:
      the value of the renderer record component
    • codec

      public JsonCodec<S> codec()
      Returns the value of the codec record component.
      Returns:
      the value of the codec record component