Record Class UnpackedColour

java.lang.Object
java.lang.Record
top.girlkisser.lazuli.api.colour.UnpackedColour
Record Components:
r - Red value from 0 to 255.
g - Green value from 0 to 255.
b - Blue value from 0 to 255.
a - Alpha value from 0 to 255.

public record UnpackedColour(int r, int g, int b, int a) extends Record
Represents an RGBA colour in an unpacked form.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<UnpackedColour>
     
    static final com.mojang.serialization.Codec<UnpackedColour>
    A codec for colours allowing a variety of formats: - RGB(A) as an object ({"r":255,"g":100,"b":150,"a":255}) - RGBA as a list ([255, 100, 150, 255]) - RGB as a list ([255, 100, 150]) - Hex (RGBA) codes as a string ("#rrggbbaa") - Hex (RGB) codes as a string ("#rrggbb") - Packed colours as an integer (16777215)
    static final com.mojang.serialization.Codec<UnpackedColour>
     
    static final com.mojang.serialization.Codec<UnpackedColour>
     
    static final com.mojang.serialization.Codec<UnpackedColour>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    UnpackedColour(int packedColour)
    Creates an unpacked colour from the packed colour (expects ARGB32).
    UnpackedColour(int r, int g, int b)
    Creates an unpacked colour using the provided R, G, and B values (0-255).
    UnpackedColour(int r, int g, int b, int a)
    Creates an instance of a UnpackedColour record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    a()
    Returns the value of the a record component.
    int
    b()
    Returns the value of the b record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    g()
    Returns the value of the g record component.
    final int
    Returns a hash code value for this object.
    modulateAlpha(net.minecraft.util.RandomSource random, int variance)
    Add random.nextInt(-variance, variance) to the alpha value.
    modulateRGB(net.minecraft.util.RandomSource random, int variance)
    Add random.nextInt(-variance, variance) to the R, G, and B values.
    int
    Gets the colour as a packed integer in ARGB32 format.
    int
    r()
    Returns the value of the r record component.
    net.minecraft.util.ColorRGBA
    Converts the unpacked colour to a ColorRGBA.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • CODEC

      public static final com.mojang.serialization.Codec<UnpackedColour> CODEC
    • LIST_CODEC

      public static final com.mojang.serialization.Codec<UnpackedColour> LIST_CODEC
    • STRING_CODEC

      public static final com.mojang.serialization.Codec<UnpackedColour> STRING_CODEC
    • PACKED_CODEC

      public static final com.mojang.serialization.Codec<UnpackedColour> PACKED_CODEC
    • FLEXIBLE_CODEC

      public static final com.mojang.serialization.Codec<UnpackedColour> FLEXIBLE_CODEC
      A codec for colours allowing a variety of formats: - RGB(A) as an object ({"r":255,"g":100,"b":150,"a":255}) - RGBA as a list ([255, 100, 150, 255]) - RGB as a list ([255, 100, 150]) - Hex (RGBA) codes as a string ("#rrggbbaa") - Hex (RGB) codes as a string ("#rrggbb") - Packed colours as an integer (16777215)
  • Constructor Details

    • UnpackedColour

      public UnpackedColour(int r, int g, int b)
      Creates an unpacked colour using the provided R, G, and B values (0-255).
      Parameters:
      r - Red value from 0 to 255.
      g - Green value from 0 to 255.
      b - Blue value from 0 to 255.
    • UnpackedColour

      public UnpackedColour(int packedColour)
      Creates an unpacked colour from the packed colour (expects ARGB32).
      Parameters:
      packedColour - The packed colour.
    • UnpackedColour

      public UnpackedColour(int r, int g, int b, int a)
      Creates an instance of a UnpackedColour record class.
      Parameters:
      r - the value for the r record component
      g - the value for the g record component
      b - the value for the b record component
      a - the value for the a record component
  • Method Details

    • pack

      public int pack()
      Gets the colour as a packed integer in ARGB32 format.
      Returns:
      The packed colour.
    • toColorRGBA

      public net.minecraft.util.ColorRGBA toColorRGBA()
      Converts the unpacked colour to a ColorRGBA.
      Returns:
      The ColorRGBA.
    • modulateRGB

      public UnpackedColour modulateRGB(net.minecraft.util.RandomSource random, int variance)
      Add random.nextInt(-variance, variance) to the R, G, and B values.
      Parameters:
      random - The random source to use.
      variance - How much to vary the ranges.
      Returns:
      A UnpackedColour with the new values.
    • modulateAlpha

      public UnpackedColour modulateAlpha(net.minecraft.util.RandomSource random, int variance)
      Add random.nextInt(-variance, variance) to the alpha value.
      Parameters:
      random - The random source to use.
      variance - How much to vary the range.
      Returns:
      A UnpackedColour with the new value.
    • 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 '=='.
      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.
    • r

      public int r()
      Returns the value of the r record component.
      Returns:
      the value of the r record component
    • g

      public int g()
      Returns the value of the g record component.
      Returns:
      the value of the g record component
    • b

      public int b()
      Returns the value of the b record component.
      Returns:
      the value of the b record component
    • a

      public int a()
      Returns the value of the a record component.
      Returns:
      the value of the a record component