Reuse palette code

This commit is contained in:
TheMode 2021-06-18 14:50:10 +02:00
parent 7032645c63
commit d7fd079288
1 changed files with 6 additions and 4 deletions

View File

@ -94,7 +94,7 @@ public class Palette implements PublicCloneable<Palette> {
final long value = block >> bitIndex & clear;
final boolean isCurrentAir = Block.fromStateId(hasPalette ? paletteBlockMap.get((short) value) : (short) value).isAir();
final boolean isCurrentAir = Block.fromStateId(fromPalette((short) value)).isAir();
block |= clear << bitIndex;
block ^= clear << bitIndex;
@ -124,9 +124,7 @@ public class Palette implements PublicCloneable<Palette> {
final long value = blocks[index] >> bitIndex & MAGIC_MASKS[bitsPerEntry];
// Change to palette value and return
return hasPalette ?
paletteBlockMap.get((short) value) :
(short) value;
return fromPalette((short) value);
}
/**
@ -252,6 +250,10 @@ public class Palette implements PublicCloneable<Palette> {
return 1 << bitsPerEntry;
}
private short fromPalette(short value) {
return hasPalette ? paletteBlockMap.get(value) : value;
}
private static Short2ShortLinkedOpenHashMap createPaletteBlockMap() {
Short2ShortLinkedOpenHashMap map = new Short2ShortLinkedOpenHashMap(CHUNK_SECTION_SIZE);
map.put((short) 0, (short) 0);