Class DataPaletteImpl

java.lang.Object
com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl
All Implemented Interfaces:
DataPalette

public final class DataPaletteImpl extends Object implements DataPalette
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataPaletteImpl(int valuesLength)
     
    DataPaletteImpl(int valuesLength, int initialSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addId(int id)
    Adds a new id to the palette.
    void
    Clears the palette.
    long[]
    createPackedValues(int bitsPerValue, int entries, boolean rawIds)
    Packs the section values into a compact long array as used by the protocol.
    void
    forEachMatchingCoordinate(IntPredicate idPredicate, IntConsumer coordinateConsumer)
    Runs over all section coordinate indices that match the given predicate.
    int
    idAt(int sectionCoordinate)
    Returns the value of the given chunk coordinate.
    int
    idByIndex(int index)
    Returns the id assigned to the given palette index.
    int
    index(int x, int y, int z)
    Returns the packet section index of the given coordinates.
    int
    paletteIndexAt(int packedCoordinate)
    Returns the palette index of the given section index.
    void
    replaceId(int oldId, int newId)
    Replaces an id in the palette.
    void
    Replaces every id in the palette by applying the given mapper.
    void
    setIdAt(int sectionCoordinate, int id)
    Set a value in the chunk section.
    void
    setIdByIndex(int index, int id)
    Assigns an id assigned to the given palette index.
    void
    setPaletteIndexAt(int sectionCoordinate, int index)
    Sets the index of the given section coordinate.
    void
    setPaletteIndexes(long[] data, int bitsPerValue, int valuesPerLong)
    Stores palette indexes from a compact long array, replacing all current values.
    int
    Returns the size of the palette.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.viaversion.viaversion.api.minecraft.chunks.DataPalette

    idAt, setIdAt
  • Constructor Details

    • DataPaletteImpl

      public DataPaletteImpl(int valuesLength)
    • DataPaletteImpl

      public DataPaletteImpl(int valuesLength, int initialSize)
  • Method Details

    • index

      public int index(int x, int y, int z)
      Description copied from interface: DataPalette
      Returns the packet section index of the given coordinates.
      Specified by:
      index in interface DataPalette
      Parameters:
      x - x
      y - y
      z - z
      Returns:
      packed section index of the given coordinates
    • idAt

      public int idAt(int sectionCoordinate)
      Description copied from interface: DataPalette
      Returns the value of the given chunk coordinate.
      Specified by:
      idAt in interface DataPalette
      Parameters:
      sectionCoordinate - section index within the section
      Returns:
      section state of the given index
    • setIdAt

      public void setIdAt(int sectionCoordinate, int id)
      Description copied from interface: DataPalette
      Set a value in the chunk section. This method does not update non-air blocks count.
      Specified by:
      setIdAt in interface DataPalette
      Parameters:
      sectionCoordinate - section index within the section
      id - id value
    • paletteIndexAt

      public int paletteIndexAt(int packedCoordinate)
      Description copied from interface: DataPalette
      Returns the palette index of the given section index.
      Specified by:
      paletteIndexAt in interface DataPalette
      Parameters:
      packedCoordinate - section index
      Returns:
      palette index of the given section index
    • setPaletteIndexAt

      public void setPaletteIndexAt(int sectionCoordinate, int index)
      Description copied from interface: DataPalette
      Sets the index of the given section coordinate.
      Specified by:
      setPaletteIndexAt in interface DataPalette
      Parameters:
      sectionCoordinate - section index
      index - palette index
    • setPaletteIndexes

      public void setPaletteIndexes(long[] data, int bitsPerValue, int valuesPerLong)
      Stores palette indexes from a compact long array, replacing all current values. The data is kept packed unless written to; reads extract bits the slow way, since almost all work will use replaceIds or will only have a few reads.

      Only valid for local palettes (bitsPerValue <= 8).

      Parameters:
      data - compact long array
      bitsPerValue - bits per value
      valuesPerLong - packked values per long
    • createPackedValues

      public long[] createPackedValues(int bitsPerValue, int entries, boolean rawIds)
      Description copied from interface: DataPalette
      Packs the section values into a compact long array as used by the protocol.
      Specified by:
      createPackedValues in interface DataPalette
      Parameters:
      bitsPerValue - bits used per value
      entries - number of values
      rawIds - whether to pack raw ids instead of palette indexes (direct palette)
      Returns:
      compact long array of the values
    • size

      public int size()
      Description copied from interface: DataPalette
      Returns the size of the palette.
      Specified by:
      size in interface DataPalette
      Returns:
      palette size
    • idByIndex

      public int idByIndex(int index)
      Description copied from interface: DataPalette
      Returns the id assigned to the given palette index.
      Specified by:
      idByIndex in interface DataPalette
      Parameters:
      index - palette index
      Returns:
      id assigned to the given palette index
    • setIdByIndex

      public void setIdByIndex(int index, int id)
      Description copied from interface: DataPalette
      Assigns an id assigned to the given palette index.
      Specified by:
      setIdByIndex in interface DataPalette
      Parameters:
      index - palette index
      id - id value
    • replaceId

      public void replaceId(int oldId, int newId)
      Description copied from interface: DataPalette
      Replaces an id in the palette.
      Specified by:
      replaceId in interface DataPalette
      Parameters:
      oldId - old id
      newId - new id
    • replaceIds

      public void replaceIds(IntUnaryOperator mapper)
      Description copied from interface: DataPalette
      Replaces every id in the palette by applying the given mapper.
      Specified by:
      replaceIds in interface DataPalette
      Parameters:
      mapper - function from old id to new id
    • addId

      public void addId(int id)
      Description copied from interface: DataPalette
      Adds a new id to the palette.
      Specified by:
      addId in interface DataPalette
      Parameters:
      id - id value
    • forEachMatchingCoordinate

      public void forEachMatchingCoordinate(IntPredicate idPredicate, IntConsumer coordinateConsumer)
      Description copied from interface: DataPalette
      Runs over all section coordinate indices that match the given predicate.
      Specified by:
      forEachMatchingCoordinate in interface DataPalette
      Parameters:
      idPredicate - predicate to test ids
      coordinateConsumer - consumer to run over applicable coordinate indices (not ids!)
      See Also:
    • clear

      public void clear()
      Description copied from interface: DataPalette
      Clears the palette.
      Specified by:
      clear in interface DataPalette