Interface Palette
public sealed interface Palette
Palette is a data storage with three storage models used to store blocks and biomes
Single Value Mode
Indirect Mode
Direct Mode
You can optimize for space/speed using
Single Value Mode
(bitsPerEntry == 0): All blocks have the same value.
No arrays allocated, value stored in count field.
Indirect Mode
(bitsPerEntry <= maxBitsPerEntry): Uses palette compression.
Values array stores palette indices, paletteToValueList and valueToPaletteMap
provide bidirectional mapping between indices and block values.
Direct Mode
(bitsPerEntry > maxBitsPerEntry): Stores block values directly.
No palette structures, values array contains actual block values using directBits.
You can optimize for space/speed using
optimize(Optimization)-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interfacestatic interfacestatic interfacestatic enumAn optimization mode to use withoptimize(Optimization) -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final NetworkBuffer.Type<Palette> -
Method Summary
Modifier and TypeMethodDescriptionbooleanany(int value) Checks if the palette contains the given value.static Palettebiomes()static Palettebiomes(int bitsPerEntry) static NetworkBuffer.Type<Palette> biomeSerializer(int biomeCount) intReturns the number of bits used per entry.static Paletteblocks()static Paletteblocks(int bitsPerEntry) clone()booleanCompare palettes content independently of their storage format.voidEfficiently copies values from another palette starting at position (0, 0, 0).voidEfficiently copies values from another palette with the given offset.intcount()Returns the number of entries in this palette.intcount(int value) Returns the number of entries in this palette that match the given value.intstatic Paletteempty(int dimension, int minBitsPerEntry, int maxBitsPerEntry, int directBits) voidfill(int value) intget(int x, int y, int z) voidgetAll(Palette.EntryConsumer consumer) voidgetAllPresent(Palette.EntryConsumer consumer) intheight(int x, int z, Palette.EntryPredicate predicate) long @Nullable []Gets the value array if it has one, otherwise returns null (i.e.default booleanisEmpty()voidload(int[] palette, long[] values) default intmaxSize()Returns the maximum number of entries in this palette.voidoffset(int offset) voidoptimize(Palette.Optimization focus) Attempts to optimize the currentPalette
If plausible the only optimization will be performed is converting to a single value regardless ofPalette.OptimizationintpaletteIndexToValue(int value) voidreplace(int oldValue, int newValue) voidreplace(int x, int y, int z, IntUnaryOperator operator) voidreplaceAll(Palette.EntryFunction function) static NetworkBuffer.Type<Palette> serializer(int dimension, int minIndirect, int maxIndirect, int directBits) voidset(int x, int y, int z, int value) voidsetAll(Palette.EntrySupplier supplier) intGets the single value of this palette if it is a single value palette, otherwise returns -1.static Palettesized(int dimension, int minBitsPerEntry, int maxBitsPerEntry, int directBits, int bitsPerEntry) intvalueToPaletteIndex(int value)
-
Field Details
-
BLOCK_DIMENSION
static final int BLOCK_DIMENSION- See Also:
-
BLOCK_PALETTE_MIN_BITS
static final int BLOCK_PALETTE_MIN_BITS- See Also:
-
BLOCK_PALETTE_MAX_BITS
static final int BLOCK_PALETTE_MAX_BITS- See Also:
-
BLOCK_PALETTE_DIRECT_BITS
static final int BLOCK_PALETTE_DIRECT_BITS- See Also:
-
BIOME_DIMENSION
static final int BIOME_DIMENSION- See Also:
-
BIOME_PALETTE_MIN_BITS
static final int BIOME_PALETTE_MIN_BITS- See Also:
-
BIOME_PALETTE_MAX_BITS
static final int BIOME_PALETTE_MAX_BITS- See Also:
-
BIOME_PALETTE_DIRECT_BITS
- See Also:
-
BLOCK_SERIALIZER
-
-
Method Details
-
blocks
-
biomes
-
blocks
-
biomes
-
empty
-
sized
static Palette sized(int dimension, int minBitsPerEntry, int maxBitsPerEntry, int directBits, int bitsPerEntry) -
get
int get(int x, int y, int z) -
getAll
-
getAllPresent
-
height
-
set
void set(int x, int y, int z, int value) -
fill
void fill(int value) -
load
void load(int[] palette, long[] values) -
offset
void offset(int offset) -
replace
void replace(int oldValue, int newValue) -
setAll
-
replace
-
replaceAll
-
copyFrom
Efficiently copies values from another palette with the given offset.Both palettes must have the same dimension.
- Parameters:
source- the source palette to copy fromoffsetX- the X offset to apply when copyingoffsetY- the Y offset to apply when copyingoffsetZ- the Z offset to apply when copying
-
copyFrom
Efficiently copies values from another palette starting at position (0, 0, 0).Both palettes must have the same dimension.
This is a convenience method equivalent to calling
copyFrom(source, 0, 0, 0).- Parameters:
source- the source palette to copy from
-
count
int count()Returns the number of entries in this palette. -
count
int count(int value) Returns the number of entries in this palette that match the given value.- Parameters:
value- the value to count- Returns:
- the number of entries matching the value
-
isEmpty
default boolean isEmpty() -
any
boolean any(int value) Checks if the palette contains the given value.- Parameters:
value- the value to check- Returns:
- true if the palette contains the value, false otherwise
-
bitsPerEntry
int bitsPerEntry()Returns the number of bits used per entry. -
dimension
int dimension() -
maxSize
default int maxSize()Returns the maximum number of entries in this palette. -
optimize
Attempts to optimize the currentPalette
If plausible the only optimization will be performed is converting to a single value regardless ofPalette.Optimization- Parameters:
focus- the optimization focus
-
compare
Compare palettes content independently of their storage format.- Parameters:
palette- the palette to compare with- Returns:
- true if the palettes are equivalent, false otherwise
-
clone
Palette clone() -
paletteIndexToValue
-
valueToPaletteIndex
-
singleValue
Gets the single value of this palette if it is a single value palette, otherwise returns -1. -
indexedValues
-
biomeSerializer
-
serializer
static NetworkBuffer.Type<Palette> serializer(int dimension, int minIndirect, int maxIndirect, int directBits)
-