Class TintColor
java.lang.Object
net.darkhax.botanypots.common.api.data.display.math.TintColor
Represents the ARGB channels of a color.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic com.mojang.serialization.Codec<TintColor> A codec that can read a TintColor from a component map or hexadecimal string.static com.mojang.serialization.Codec<TintColor> A codec that reads a TintColor from different keys of a map.static com.mojang.serialization.Codec<TintColor> A codec that reads a TintColor from a hexadecimal encoded string.static net.minecraft.network.codec.StreamCodec<io.netty.buffer.ByteBuf, TintColor> Stream codec for networking.static final TintColorA pure white tint color. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintalpha()Gets the alpha value of the color.int[]asArray()Gets the color components as an array.asHex()Represents the color as a hex string.float[]Gets the color components as an array of percentages.intblue()Gets the blue value.static TintColorDecodes a color from a hex string.intgreen()? Gets the green value.intpack()Packs the color into a single integer.intred()Gets the red value.static TintColorunpack(int color) Unpacks a color from a single integer using bit shifting.
-
Field Details
-
WHITE
A pure white tint color. This is used as a default and effectively leaves the original colors unmodified. -
CODEC_ARGB
A codec that reads a TintColor from different keys of a map. -
CODEC_STRING
A codec that reads a TintColor from a hexadecimal encoded string. The casing of the string does not matter and a leading hashtag will be removed if present. -
CODEC
A codec that can read a TintColor from a component map or hexadecimal string. -
STREAM
Stream codec for networking.
-
-
Constructor Details
-
TintColor
public TintColor(int alpha, int red, int green, int blue) - Parameters:
alpha- The value of the alpha channel. An alpha of 0 is fully invisible while 255 is fully opaque.red- The value of the red channel.green- The value of the green channel.blue- The value of the blue channel.
-
-
Method Details
-
asHex
Represents the color as a hex string. The trailing hashtag is not included.- Returns:
- A string that contains a hexadecimal representation of the color.
-
asPercents
public float[] asPercents()Gets the color components as an array of percentages. This can be useful for floating point rendering.- Returns:
- An array of color components as percentages.
-
asArray
public int[] asArray()Gets the color components as an array.- Returns:
- The color components as an array.
-
pack
public int pack()Packs the color into a single integer.- Returns:
- The integer representation of the color.
-
alpha
public int alpha()Gets the alpha value of the color. 0 is fully transparent and 255 is fully opaque.- Returns:
- The value of the alpha channel.
-
red
public int red()Gets the red value.- Returns:
- The value of the red channel.
-
green
public int green()? Gets the green value.- Returns:
- The value of the green channel.
-
blue
public int blue()Gets the blue value.- Returns:
- The value of the blue channel.
-
unpack
Unpacks a color from a single integer using bit shifting.- Parameters:
color- The color to unpack.- Returns:
- A tint based on the bits of the integer.
-
fromHex
Decodes a color from a hex string. The casing does not matter and the hashtag is completely optional.- Parameters:
hexCode- The hex string to decode.- Returns:
- The color that was decoded.
-