Misc style

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-05-10 04:10:57 +02:00
parent 37ba3c7893
commit 27c4c99949

View File

@ -50,7 +50,7 @@ final class FlexiblePalette implements SpecializedPalette, Cloneable {
@Override
public int get(int x, int y, int z) {
final int bitsPerEntry = this.bitsPerEntry;
final int sectionIndex = getSectionIndex(x, y, z);
final int sectionIndex = getSectionIndex(dimension(), x, y, z);
final int valuesPerLong = 64 / bitsPerEntry;
final int index = sectionIndex / valuesPerLong;
final int bitIndex = (sectionIndex - index * valuesPerLong) * bitsPerEntry;
@ -76,21 +76,18 @@ final class FlexiblePalette implements SpecializedPalette, Cloneable {
final long[] values = this.values;
// Change to palette value
final int valuesPerLong = 64 / bitsPerEntry;
final int sectionIndex = getSectionIndex(x, y, z);
final int sectionIndex = getSectionIndex(dimension(), x, y, z);
final int index = sectionIndex / valuesPerLong;
final int bitIndex = (sectionIndex - index * valuesPerLong) * bitsPerEntry;
final long block = values[index];
final long clear = (1L << bitsPerEntry) - 1;
final long oldBlock = block >> bitIndex & clear;
if (oldBlock == value)
return; // Trying to place the same block
values[index] = block & ~(clear << bitIndex) | (value & clear) << bitIndex;
// Check if block count needs to be updated
final boolean currentAir = oldBlock == 0;
if (currentAir != (value == 0)) {
if (currentAir) count++;
else count--;
this.count += currentAir ? 1 : -1;
}
}
@ -141,6 +138,7 @@ final class FlexiblePalette implements SpecializedPalette, Cloneable {
}
}
}
assert index == maxSize();
// Update palette content
if (fillValue < 0) {
updateAll(cache);
@ -169,6 +167,7 @@ final class FlexiblePalette implements SpecializedPalette, Cloneable {
cache[index] = newValue != value ? getPaletteIndex(newValue) : value;
if (newValue != 0) count.setPlain(count.getPlain() + 1);
});
assert arrayIndex.getPlain() == maxSize();
// Update palette content
updateAll(cache);
this.count = count.getPlain();
@ -311,8 +310,8 @@ final class FlexiblePalette implements SpecializedPalette, Cloneable {
return bitsPerEntry <= maxBitsPerEntry();
}
int getSectionIndex(int x, int y, int z) {
final int dimensionMask = dimension() - 1;
static int getSectionIndex(int dimension, int x, int y, int z) {
final int dimensionMask = dimension - 1;
y &= dimensionMask;
z &= dimensionMask;
x &= dimensionMask;