Record Class Texture

java.lang.Object
java.lang.Record
io.github.cottonmc.cotton.gui.widget.data.Texture
Record Components:
image - the image of this texture
type - the type of this texture
u1 - the start U-coordinate, between 0 and 1
v1 - the start V-coordinate, between 0 and 1
u2 - the end U-coordinate, between 0 and 1
v2 - the end V-coordinate, between 0 and 1

public record Texture(Identifier image, Texture.Type type, float u1, float v1, float u2, float v2) extends Record
Represents a texture for a widget.

Types

Each texture has a type: it's either a standalone texture file or a sprite on the GUI sprite atlas. Their properties are slightly different.

GUI sprites can use their full range of features such as tiling, stretching and nine-slice drawing modes, while standalone textures are only drawn stretched.

The format of the image ID depends on the type. See the documentation of the individual type constants and the table below for details.

Image IDs for each texture type
Type File path Image ID
STANDALONE assets/my_mod/textures/widget/example.png my_mod:textures/widget/example.png
GUI_SPRITE assets/my_mod/textures/gui/sprites/example.png my_mod:example

Note that the image ID can only be passed to non-Texture overloads of ScreenDrawing.texturedRect() when the type is Texture.Type.STANDALONE. GUI sprites need specialised code for drawing them, and they need to be drawn with specific Texture-accepting methods or DrawContext.

GUI sprite textures don't currently support flipping the texture by flipping UV coordinates.

Since:
3.0.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    A Texture's type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new standalone texture that uses the full image.
    Texture(Identifier image, float u1, float v1, float u2, float v2)
    Constructs a new standalone texture with custom UV values.
    Constructs a new texture that uses the full image.
    Texture(Identifier image, Texture.Type type, float u1, float v1, float u2, float v2)
    Constructs a new texture with custom UV values.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the image record component.
    final String
    Returns a string representation of this record class.
    Returns the value of the type record component.
    float
    u1()
    Returns the value of the u1 record component.
    float
    u2()
    Returns the value of the u2 record component.
    float
    v1()
    Returns the value of the v1 record component.
    float
    v2()
    Returns the value of the v2 record component.
    withUv(float u1, float v1, float u2, float v2)
    Creates a new texture with different UV values.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Texture

      public Texture(Identifier image, Texture.Type type)
      Constructs a new texture that uses the full image.
      Parameters:
      image - the image
      type - the type
      Throws:
      NullPointerException - if the image or the type is null
    • Texture

      public Texture(Identifier image, float u1, float v1, float u2, float v2)
      Constructs a new standalone texture with custom UV values.
      Parameters:
      image - the image of this texture
      u1 - the start U-coordinate, between 0 and 1
      v1 - the start V-coordinate, between 0 and 1
      u2 - the end U-coordinate, between 0 and 1
      v2 - the end V-coordinate, between 0 and 1
      Throws:
      NullPointerException - if the image is null
    • Texture

      public Texture(Identifier image)
      Constructs a new standalone texture that uses the full image.
      Parameters:
      image - the image
      Throws:
      NullPointerException - if the image is null
    • Texture

      public Texture(Identifier image, Texture.Type type, float u1, float v1, float u2, float v2)
      Constructs a new texture with custom UV values.
      Parameters:
      image - the image
      type - the type
      u1 - the left U coordinate
      v1 - the top V coordinate
      u2 - the right U coordinate
      v2 - the bottom V coordinate
      Throws:
      NullPointerException - if the image or the type is null
  • Method Details

    • withUv

      public Texture withUv(float u1, float v1, float u2, float v2)
      Creates a new texture with different UV values.
      Parameters:
      u1 - the left U coordinate
      v1 - the top V coordinate
      u2 - the right U coordinate
      v2 - the bottom V coordinate
      Returns:
      the created texture
    • 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 '=='.
      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.
    • image

      public Identifier image()
      Returns the value of the image record component.
      Returns:
      the value of the image record component
    • type

      public Texture.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • u1

      public float u1()
      Returns the value of the u1 record component.
      Returns:
      the value of the u1 record component
    • v1

      public float v1()
      Returns the value of the v1 record component.
      Returns:
      the value of the v1 record component
    • u2

      public float u2()
      Returns the value of the u2 record component.
      Returns:
      the value of the u2 record component
    • v2

      public float v2()
      Returns the value of the v2 record component.
      Returns:
      the value of the v2 record component