Class PaletteStorage

java.lang.Object
net.minestom.server.instance.palette.PaletteStorage

public class PaletteStorage
extends java.lang.Object
Used to efficiently store blocks with an optional palette.

The format used is the one described in the ChunkDataPacket, the reason is that it allows us to write the packet much faster.

  • Constructor Summary

    Constructors 
    Constructor Description
    PaletteStorage​(int bitsPerEntry, int bitsIncrement)
    Creates a new palette storage.
  • Method Summary

    Modifier and Type Method Description
    void clean()
    Loops through all the sections and blocks to find unused array (empty chunk section)
    PaletteStorage copy()  
    int getBitsPerEntry()
    Gets the number of bits that the palette currently take per block.
    short getBlockAt​(int x, int y, int z)  
    short[] getPalette​(int section)
    Gets the palette with the index and the block id as the value.
    long[][] getSectionBlocks()
    Gets the sections of this object, the first array representing the chunk section and the second the block position from getSectionIndex(int, int, int).
    static int getSectionIndex​(int x, int y, int z)
    Gets the index of the block on the section array based on the block position.
    void setBlockAt​(int x, int y, int z, short blockId)  

    Methods inherited from class java.lang.Object

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

    • PaletteStorage

      public PaletteStorage​(int bitsPerEntry, int bitsIncrement)
      Creates a new palette storage.
      Parameters:
      bitsPerEntry - the number of bits used for one entry (block)
      bitsIncrement - the number of bits to add per-block once the palette array is filled
  • Method Details

    • setBlockAt

      public void setBlockAt​(int x, int y, int z, short blockId)
    • getBlockAt

      public short getBlockAt​(int x, int y, int z)
    • getBitsPerEntry

      public int getBitsPerEntry()
      Gets the number of bits that the palette currently take per block.
      Returns:
      the bits per entry
    • getPalette

      public short[] getPalette​(int section)
      Gets the palette with the index and the block id as the value.
      Parameters:
      section - the chunk section to get the palette from
      Returns:
      the palette
    • getSectionBlocks

      public long[][] getSectionBlocks()
      Gets the sections of this object, the first array representing the chunk section and the second the block position from getSectionIndex(int, int, int).
      Returns:
      the section blocks
    • clean

      public void clean()
      Loops through all the sections and blocks to find unused array (empty chunk section)

      Useful after clearing one or multiple sections of a chunk. Can be unnecessarily expensive if the chunk is composed of almost-empty sections since the loop will not stop until a non-air block is discovered.

    • copy

      public PaletteStorage copy()
    • getSectionIndex

      public static int getSectionIndex​(int x, int y, int z)
      Gets the index of the block on the section array based on the block position.
      Parameters:
      x - the chunk X
      y - the chunk Y
      z - the chunk Z
      Returns:
      the section index of the position