Class DataPaletteImpl
java.lang.Object
com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl
- All Implemented Interfaces:
DataPalette
-
Constructor Summary
ConstructorsConstructorDescriptionDataPaletteImpl(int valuesLength) DataPaletteImpl(int valuesLength, int initialSize) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddId(int id) Adds a new id to the palette.voidclear()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.voidforEachMatchingCoordinate(IntPredicate idPredicate, IntConsumer coordinateConsumer) Runs over all section coordinate indices that match the given predicate.intidAt(int sectionCoordinate) Returns the value of the given chunk coordinate.intidByIndex(int index) Returns the id assigned to the given palette index.intindex(int x, int y, int z) Returns the packet section index of the given coordinates.intpaletteIndexAt(int packedCoordinate) Returns the palette index of the given section index.voidreplaceId(int oldId, int newId) Replaces an id in the palette.voidreplaceIds(IntUnaryOperator mapper) Replaces every id in the palette by applying the given mapper.voidsetIdAt(int sectionCoordinate, int id) Set a value in the chunk section.voidsetIdByIndex(int index, int id) Assigns an id assigned to the given palette index.voidsetPaletteIndexAt(int sectionCoordinate, int index) Sets the index of the given section coordinate.voidsetPaletteIndexes(long[] data, int bitsPerValue, int valuesPerLong) Stores palette indexes from a compact long array, replacing all current values.intsize()Returns the size of the palette.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:DataPaletteReturns the packet section index of the given coordinates.- Specified by:
indexin interfaceDataPalette- Parameters:
x- xy- yz- z- Returns:
- packed section index of the given coordinates
-
idAt
public int idAt(int sectionCoordinate) Description copied from interface:DataPaletteReturns the value of the given chunk coordinate.- Specified by:
idAtin interfaceDataPalette- 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:DataPaletteSet a value in the chunk section. This method does not update non-air blocks count.- Specified by:
setIdAtin interfaceDataPalette- Parameters:
sectionCoordinate- section index within the sectionid- id value
-
paletteIndexAt
public int paletteIndexAt(int packedCoordinate) Description copied from interface:DataPaletteReturns the palette index of the given section index.- Specified by:
paletteIndexAtin interfaceDataPalette- Parameters:
packedCoordinate- section index- Returns:
- palette index of the given section index
-
setPaletteIndexAt
public void setPaletteIndexAt(int sectionCoordinate, int index) Description copied from interface:DataPaletteSets the index of the given section coordinate.- Specified by:
setPaletteIndexAtin interfaceDataPalette- Parameters:
sectionCoordinate- section indexindex- 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 arraybitsPerValue- bits per valuevaluesPerLong- packked values per long
-
createPackedValues
public long[] createPackedValues(int bitsPerValue, int entries, boolean rawIds) Description copied from interface:DataPalettePacks the section values into a compact long array as used by the protocol.- Specified by:
createPackedValuesin interfaceDataPalette- Parameters:
bitsPerValue- bits used per valueentries- number of valuesrawIds- 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:DataPaletteReturns the size of the palette.- Specified by:
sizein interfaceDataPalette- Returns:
- palette size
-
idByIndex
public int idByIndex(int index) Description copied from interface:DataPaletteReturns the id assigned to the given palette index.- Specified by:
idByIndexin interfaceDataPalette- Parameters:
index- palette index- Returns:
- id assigned to the given palette index
-
setIdByIndex
public void setIdByIndex(int index, int id) Description copied from interface:DataPaletteAssigns an id assigned to the given palette index.- Specified by:
setIdByIndexin interfaceDataPalette- Parameters:
index- palette indexid- id value
-
replaceId
public void replaceId(int oldId, int newId) Description copied from interface:DataPaletteReplaces an id in the palette.- Specified by:
replaceIdin interfaceDataPalette- Parameters:
oldId- old idnewId- new id
-
replaceIds
Description copied from interface:DataPaletteReplaces every id in the palette by applying the given mapper.- Specified by:
replaceIdsin interfaceDataPalette- Parameters:
mapper- function from old id to new id
-
addId
public void addId(int id) Description copied from interface:DataPaletteAdds a new id to the palette.- Specified by:
addIdin interfaceDataPalette- Parameters:
id- id value
-
forEachMatchingCoordinate
Description copied from interface:DataPaletteRuns over all section coordinate indices that match the given predicate.- Specified by:
forEachMatchingCoordinatein interfaceDataPalette- Parameters:
idPredicate- predicate to test idscoordinateConsumer- consumer to run over applicable coordinate indices (not ids!)- See Also:
-
clear
public void clear()Description copied from interface:DataPaletteClears the palette.- Specified by:
clearin interfaceDataPalette
-