mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 19:47:44 +01:00
Improve palette interface
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
9dd1e4a550
commit
00e5e6b2cc
@ -177,7 +177,7 @@ public class DynamicChunk extends Chunk {
|
||||
for (int i = 0; i < 16; i++) { // TODO: variable section count
|
||||
final Section section = Objects.requireNonNullElseGet(sectionMap.get(i), Section::new);
|
||||
final Palette blockPalette = section.blockPalette();
|
||||
writer.writeShort((short) blockPalette.count());
|
||||
writer.writeShort((short) blockPalette.size());
|
||||
blockPalette.write(writer); // Blocks
|
||||
section.biomePalette().write(writer); // Biomes
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <p>
|
||||
* 0 is the default value.
|
||||
*/
|
||||
public interface Palette extends Writeable {
|
||||
public sealed interface Palette extends Writeable permits PaletteImpl {
|
||||
static Palette blocks() {
|
||||
return new PaletteImpl(16 * 16 * 16, 8, 8, 2);
|
||||
}
|
||||
@ -21,21 +21,31 @@ public interface Palette extends Writeable {
|
||||
|
||||
void set(int x, int y, int z, int value);
|
||||
|
||||
int count();
|
||||
/**
|
||||
* Returns the number of entries in this palette.
|
||||
*/
|
||||
int size();
|
||||
|
||||
/**
|
||||
* Returns the number of bits used per entry.
|
||||
*/
|
||||
int bitsPerEntry();
|
||||
|
||||
/**
|
||||
* Returns the payload of this palette.
|
||||
* <p>
|
||||
* The size of each element is defined by {@link #bitsPerEntry()}.
|
||||
*
|
||||
* @return the palette payload
|
||||
*/
|
||||
long[] data();
|
||||
|
||||
int maxBitsPerEntry();
|
||||
|
||||
/**
|
||||
* Returns the number of entries in this palette.
|
||||
* Returns the maximum number of entries in this palette.
|
||||
*/
|
||||
int size();
|
||||
|
||||
long[] data();
|
||||
int maxSize();
|
||||
|
||||
@NotNull Palette clone();
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import static net.minestom.server.instance.Chunk.CHUNK_SECTION_SIZE;
|
||||
|
||||
final class PaletteImpl implements Palette {
|
||||
// Magic values generated with "Integer.MAX_VALUE >> (31 - bitsPerIndex)" for bitsPerIndex between 4 and 15
|
||||
// Magic values generated with "Integer.MAX_VALUE >> (31 - bitsPerIndex)" for bitsPerIndex between 1 and 16
|
||||
private static final int[] MAGIC_MASKS =
|
||||
{0, 0, 0, 0,
|
||||
{0, 1, 3, 7,
|
||||
15, 31, 63, 127, 255,
|
||||
511, 1023, 2047, 4095,
|
||||
8191, 16383, 32767};
|
||||
@ -104,7 +104,7 @@ final class PaletteImpl implements Palette {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count() {
|
||||
public int size() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ final class PaletteImpl implements Palette {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
public int maxSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user