Class BlockColorIndex

java.lang.Object
com.hypixel.hytale.builtin.buildertools.BlockColorIndex

public final class BlockColorIndex extends Object
Index of solid block colors for fast color-to-block matching. Uses LAB color space for perceptually accurate matching. Lazily initialized on first access. TODO: When refactoring type replace related logic, maybe generalize this class to be an index that groups blocks by their variants and color. That way looking up variants of a block is better.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    findBlockForLerpedColor(int rA, int gA, int bA, int rB, int gB, int bB, float t)
    Interpolates between two colors and finds the closest block.
    int
    findClosestBlock(int r, int g, int b)
    Finds the closest matching block for the given RGB color.
    int
    findClosestVariant(int sourceBlockId, String suffix)
    Finds the block whose id ends with the given shape suffix and whose colour is closest to the source block.
    int
    findDarkerVariant(int blockId, float darkenAmount)
    Finds a darker variant of the given block.
    int
    findLighterVariant(int blockId, float lightenAmount)
    Finds a lighter variant of the given block.
    int
    getBlockColor(int blockId)
    Gets the RGB color of a block.
    boolean
    Checks if the index has any entries.
    boolean
    isExcludedQuality(int blockId)
     

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BlockColorIndex

      public BlockColorIndex()
  • Method Details

    • isExcludedQuality

      public boolean isExcludedQuality(int blockId)
    • findClosestBlock

      public int findClosestBlock(int r, int g, int b)
      Finds the closest matching block for the given RGB color.
      Returns:
      block ID or -1 if no match found
    • findClosestVariant

      public int findClosestVariant(int sourceBlockId, @Nonnull String suffix)
      Finds the block whose id ends with the given shape suffix and whose colour is closest to the source block.
      Returns:
      block id of the closest same-shape block, or -1 if none has a usable colour
    • findDarkerVariant

      public int findDarkerVariant(int blockId, float darkenAmount)
      Finds a darker variant of the given block.
      Parameters:
      blockId - the source block ID
      darkenAmount - how much to darken (0.0 - 1.0)
      Returns:
      block ID of a darker variant, or the original if none found
    • findLighterVariant

      public int findLighterVariant(int blockId, float lightenAmount)
      Finds a lighter variant of the given block.
      Parameters:
      blockId - the source block ID
      lightenAmount - how much to lighten (0.0 - 1.0)
      Returns:
      block ID of a lighter variant, or the original if none found
    • getBlockColor

      public int getBlockColor(int blockId)
      Gets the RGB color of a block.
      Returns:
      packed RGB (0xRRGGBB) or -1 if not found
    • findBlockForLerpedColor

      public int findBlockForLerpedColor(int rA, int gA, int bA, int rB, int gB, int bB, float t)
      Interpolates between two colors and finds the closest block.
      Parameters:
      t - interpolation factor (0.0 = colorA, 1.0 = colorB)
    • isEmpty

      public boolean isEmpty()
      Checks if the index has any entries.