Record Class Color

java.lang.Object
java.lang.Record
net.minestom.server.color.Color
All Implemented Interfaces:
RGBLike

public record Color(int red, int green, int blue) extends Record implements RGBLike
A general purpose class for representing colors.

Colors must be in the range of 0-255.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Color(int rgb)
    Creates a color from an integer.
    Color(int red, int green, int blue)
    Creates an instance of a Color record class.
    Color(@NotNull RGBLike rgbLike)
    Creates a color from an RGB-like color.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the color as an RGB integer.
    int
    Returns the value of the blue record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    Deprecated.
    int
    Deprecated.
    int
    Deprecated.
    int
    Returns the value of the green record component.
    final int
    Returns a hash code value for this object.
    @NotNull Color
    mixWith(@NotNull RGBLike... colors)
    Mixes this color with a series of other colors, as if they were combined in a crafting table.
    int
    red()
    Returns the value of the red record component.
    final String
    Returns a string representation of this record class.
    @NotNull Color
    withBlue(int blue)
     
    @NotNull Color
    withGreen(int green)
     
    @NotNull Color
    withRed(int red)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface net.kyori.adventure.util.RGBLike

    asHSV
  • Constructor Details

    • Color

      public Color(int red, int green, int blue)
      Creates an instance of a Color record class.
      Parameters:
      red - the value for the red record component
      green - the value for the green record component
      blue - the value for the blue record component
    • Color

      public Color(int rgb)
      Creates a color from an integer. This is done by reading each color component from the lowest order 24 bits of the integer, and creating a color from those components.
      Parameters:
      rgb - the integer
    • Color

      public Color(@NotNull @NotNull RGBLike rgbLike)
      Creates a color from an RGB-like color.
      Parameters:
      rgbLike - the color
  • Method Details

    • withRed

      @NotNull public @NotNull Color withRed(int red)
    • withGreen

      @NotNull public @NotNull Color withGreen(int green)
    • withBlue

      @NotNull public @NotNull Color withBlue(int blue)
    • asRGB

      public int asRGB()
      Gets the color as an RGB integer.
      Returns:
      An integer representation of this color, as 0xRRGGBB
    • mixWith

      @NotNull public @NotNull Color mixWith(@NotNull @NotNull RGBLike... colors)
      Mixes this color with a series of other colors, as if they were combined in a crafting table. This function works out the average of each RGB component and then multiplies the components by a scale factor that is calculated from the average of all maximum values divided by the maximum of each average value. This is how Minecraft mixes colors.
      Parameters:
      colors - the colors
    • getRed

      @Deprecated public int getRed()
      Deprecated.
    • getGreen

      @Deprecated public int getGreen()
      Deprecated.
    • getBlue

      @Deprecated public int getBlue()
      Deprecated.
    • 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.
    • red

      public int red()
      Returns the value of the red record component.
      Specified by:
      red in interface RGBLike
      Returns:
      the value of the red record component
    • green

      public int green()
      Returns the value of the green record component.
      Specified by:
      green in interface RGBLike
      Returns:
      the value of the green record component
    • blue

      public int blue()
      Returns the value of the blue record component.
      Specified by:
      blue in interface RGBLike
      Returns:
      the value of the blue record component