Fix palette resizing

This commit is contained in:
themode 2021-12-20 01:15:59 +01:00 committed by TheMode
parent 9174742429
commit cf43d2c70a

View File

@ -19,9 +19,9 @@ final class PaletteImpl implements Palette, Cloneable {
private final int dimension;
private final int size;
private final int maxBitsPerEntry;
private final int bitsIncrement;
private int bitsPerEntry;
private final int bitsIncrement;
private int valuesPerLong;
private boolean hasPalette;
@ -39,9 +39,9 @@ final class PaletteImpl implements Palette, Cloneable {
this.dimension = dimension;
this.size = dimension * dimension * dimension;
this.maxBitsPerEntry = maxBitsPerEntry;
this.bitsIncrement = bitsIncrement;
this.bitsPerEntry = bitsPerEntry;
this.bitsIncrement = bitsIncrement;
this.valuesPerLong = Long.SIZE / bitsPerEntry;
this.hasPalette = bitsPerEntry <= maxBitsPerEntry;
@ -180,7 +180,7 @@ final class PaletteImpl implements Palette, Cloneable {
private void resize(int newBitsPerEntry) {
newBitsPerEntry = fixBitsPerEntry(newBitsPerEntry);
PaletteImpl palette = new PaletteImpl(size, maxBitsPerEntry, newBitsPerEntry, bitsIncrement);
PaletteImpl palette = new PaletteImpl(dimension, maxBitsPerEntry, newBitsPerEntry, bitsIncrement);
for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
for (int x = 0; x < Chunk.CHUNK_SIZE_X; x++) {
for (int z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
@ -189,16 +189,16 @@ final class PaletteImpl implements Palette, Cloneable {
}
}
this.paletteToValueList = palette.paletteToValueList;
this.lastPaletteIndex = palette.lastPaletteIndex;
this.bitsPerEntry = palette.bitsPerEntry;
this.valuesPerLong = palette.valuesPerLong;
this.hasPalette = palette.hasPalette;
this.lastPaletteIndex = palette.lastPaletteIndex;
this.count = palette.count;
this.values = palette.values;
this.count = palette.count;
this.paletteToValueList = palette.paletteToValueList;
this.valueToPaletteMap = palette.valueToPaletteMap;
}
private int getPaletteIndex(int value) {
@ -209,7 +209,7 @@ final class PaletteImpl implements Palette, Cloneable {
if (lastPaletteIndex >= maxPaletteSize(bitsPerEntry)) {
// Palette is full, must resize
resize(bitsPerEntry + bitsIncrement);
if (!hasPalette) return value;
return getPaletteIndex(value);
}
final int paletteIndex = lastPaletteIndex++;
this.paletteToValueList.add(value);