Skip to content

Prism Documentation

Grend edited this page Jul 30, 2022 · 6 revisions

Developer Documentation

Class Documentation

item.ItemColors

This class allows you to easily extract the name color of the given item stack. Name colors can be specified in many different ways, and this class should be able to handle them all.
Call the getColorForItem(ItemStack item, TextColor defaultColor) method to get the name color. This method checks the following, in order, to extract the name color:

  • ItemStack DisplayName style color
  • Item Name style color
  • Item HoverName style color
  • Item HoverName color-code specified color
  • Item HoverName single-character embedded color (uses first found)

If no color has been found yet:

  • Color of first line of fully-rendered tooltip
  • Default color

text.DynamicColor

This class extends from Minecraft's TextColor class. To achieve this, Prism makes TextColor no longer a final class. This means that anywhere TextColor is used, you may use a DynamicColor instead to add functionality.

  • Animation
    You can create an animated color by using one of the constructors that takes a list of colors:
    DynamicColor(List<IColor> values, float duration), DynamicColor(List<IColor> values, float duration, String name)
    This will result in a color that smoothly fades from one color in the provided list to the next, completing the full list in the given duration (in seconds). Once the last color is displayed, it will fade back to the starting color and repeat the process.

  • Factory methods
    There are many factory methods to quickly and easily create colors given color components. These factory methods all have int and float versions, where the int versions take values from 0-255 (except hue, which is 0-359) and the float versions take values from 0.0 to 1.0:

    • fromRGB
    • fromARGB
    • fromHSV
    • fromAHSV
  • Component getters
    Convenient getters to easily access components of a color in RGB or HSV color models. For animated colors, these will retrieve the currently-displayed color's components.

    • alpha()
    • red()
    • green()
    • blue()
    • hue()
    • saturation()
    • value() - Note that the getValue() method will instead retrieve the (current) underlying color's full ARGB int value, don't confuse the two.

util.ColorUtil

This class contains many utility methods, most of which are used elsewhere throughout the library.

  • Color Model conversion methods
    There are several methods that convert from HSV to RGB and vice-versa, accepting either integer or float component variants. Methods that convert to RGB or ARGB return an integer value representing the full color. Methods that convert to HSV or AHSV return an array of floats containing HSV or AHSV components in the range 0.0 - 1.0. All methods that don't accept an alpha value assume full (0xFF / 1.0) alpha.

    • HSVtoRGB
    • AHSVtoARGB
    • RGBtoHSV
    • ARGBtoAHSV
  • Component combiner methods
    These methods simply accept either ARGB or RGB components and return the full color as an integer value.

    • combineARGB
    • combineRGB

util.ConfigHelper

The ConfigHelper class contains helpful methods when adding configuration options for mods that utilize Prism.

  • colorFormatDocumentation()
    This function returns a list of ColorFormatDocumentation records, each of which hold a name, description, and list of examples. Each of these records describes one accepted format that Prism understands for describing a color. These records can be used to add automatic documentation to any mod's configuration page to describe accepted color formats for color options. See the Color Format Options section for a list of currently-supported options.
  • parseColor(Object value)
    This function parses the given object (expected to be a String or Number) and returns an IColor instance (which may be a TextColor or DynamicColor, depending on the object given). See the Color Format Options section for a list of currently-supported options.

util.ImageAnalysis

This class provides analysis functionality for images.

  • getDominantColor(ResourceLocation imageLocation, Rect2i region), getDominantColor(BufferedImage image)
    Currently the only function in the class, these functions analyze the given image or portion of an image, and return the "dominant" color of that image. The dominant color is the most common color in the image with a few stipulations--bright and high-alpha colors are prioritized, very dark and low-alpha colors are ignored, and similar colors are grouped together.

util.WebColors

This class allows convenient access to HTML-standard web colors.

  • getColor(String colorName)
    Provided a case-insensitive string, will return the matching web color as a DynamicColor instance. If no web color matches the given string, null is returned.

Color Format Options

When parsing configuration options, Prism has many accepted formats. This section documents the current selection of available formats.

  • Hex color code
    A hex color code is preceded by # or 0x and must be quoted. Supports 3, 4, 6, or 8-digit codes (RGB, ARRGB, RRGGBB, AARRGGBB).
  • Decimal color code
    A decimal color code is the same thing as a hex color code, but in decimal format. May or may not be quoted.
  • Minecraft color name
    One of the standard 16 Minecraft color names, must be quoted. See here for a list of all Minecraft colors. (Use the parenthesized name with underscores.)
  • Web color name
    One of the standard 140 web/HTML colors, must be quoted. See here for a full list of web colors. Note, if a web color has the same name as a Minecraft color, the Minecraft color will be used.
  • Modifiers
    Colors specified in any of the above formats (only when quoted) can be altered by including one or more "modifier" after the definition.
    Modifiers are specified with the format <+, -, or =><h, s, v, r, g, b, or a><amount>, with valid amounts being in the range 0 to 255 for all types except hue, which accepts 0 to 359. The letters represent the following:
    • h - hue
    • s - saturation
    • v - value
    • r - red
    • g - green
    • b - blue
    • a - alpha
  • Animated color
    Animated colors fade from one definition to another in sequence. They are specified with the format "<duration in seconds>_<list of color definitions separated by underscores>".

Examples

  • "#D2A"
  • "#CC00E2EE"
  • 4278251143
  • "dark_purple"
  • "gold"
  • "red+h15"
  • "#F4C-r150+v10=a40"
  • "10_black_#7FFF00"
  • "5.5_gold_orange_orangered"
  • "20_mediumspringgreen_mediumspringgreen+h30"