Package net.kamkeyke.raccooncore.util
Class ColorUtils
java.lang.Object
net.kamkeyke.raccooncore.util.ColorUtils
Utility methods for reading, writing and mixing item colors stored via NBT,
following the same
display.color convention vanilla uses for dyeable
leather items.
Also resolves a DyeColor from colored block-item variants (wool,
terracotta, concrete, ...) and mixes dyes together the same way vanilla does
for leather armor.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetColor(net.minecraft.world.item.ItemStack stack, int fallbackColor) Reads the custom color stored in the item'sdisplay.colorNBT tag.static Optional<net.minecraft.world.item.DyeColor>getWoolColor(net.minecraft.world.item.ItemStack stack) static booleanhasColor(net.minecraft.world.item.ItemStack stack) static intMixes an existing color (or none) with one or more dye stacks.static net.minecraft.world.item.ItemresolveVariant(net.minecraft.world.item.DyeColor color, String modIdFromBlock, String suffix) Resolves a vanilla colored-block-item variant for a givenDyeColorand suffix (e.g.static voidsetColor(net.minecraft.world.item.ItemStack stack, int rgb) Stores an RGB color (0xRRGGBB) in the stack'sdisplay.colorNBT tag.static inttoRgb(net.minecraft.world.item.DyeColor color) Converts aDyeColorinto a packed0xRRGGBBvalue.
-
Constructor Details
-
ColorUtils
public ColorUtils()
-
-
Method Details
-
resolveVariant
public static net.minecraft.world.item.Item resolveVariant(net.minecraft.world.item.DyeColor color, String modIdFromBlock, String suffix) Resolves a vanilla colored-block-item variant for a givenDyeColorand suffix (e.g."_wool","_terracotta","_concrete").Use for suffixes other than wool, which already has a lookup table cached.
-
getWoolColor
public static Optional<net.minecraft.world.item.DyeColor> getWoolColor(net.minecraft.world.item.ItemStack stack) - Returns:
- the
DyeColormatching the given stack, if it is a wool item.
-
toRgb
public static int toRgb(net.minecraft.world.item.DyeColor color) Converts aDyeColorinto a packed0xRRGGBBvalue. -
getColor
public static int getColor(net.minecraft.world.item.ItemStack stack, int fallbackColor) Reads the custom color stored in the item'sdisplay.colorNBT tag.- Parameters:
fallbackColor- value returned when the stack has no custom color set
-
hasColor
public static boolean hasColor(net.minecraft.world.item.ItemStack stack) - Returns:
trueif the stack has a custom color set viasetColor(net.minecraft.world.item.ItemStack, int).
-
setColor
public static void setColor(net.minecraft.world.item.ItemStack stack, int rgb) Stores an RGB color (0xRRGGBB) in the stack'sdisplay.colorNBT tag. -
mixColors
Mixes an existing color (or none) with one or more dye stacks. Colors with a higher combined count dominate super-linearly (seeMIX_POWER), and results close enough to a pureDyeColorsnap to it exactly instead of leaving a faint residue.- Parameters:
baseColor- -1 if the item has no color yet, otherwise its current RGB colordyes- dye item stacks being applied (stack count is honored)
-