mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 15:07:36 +02: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
|
for (int i = 0; i < 16; i++) { // TODO: variable section count
|
||||||
final Section section = Objects.requireNonNullElseGet(sectionMap.get(i), Section::new);
|
final Section section = Objects.requireNonNullElseGet(sectionMap.get(i), Section::new);
|
||||||
final Palette blockPalette = section.blockPalette();
|
final Palette blockPalette = section.blockPalette();
|
||||||
writer.writeShort((short) blockPalette.count());
|
writer.writeShort((short) blockPalette.size());
|
||||||
blockPalette.write(writer); // Blocks
|
blockPalette.write(writer); // Blocks
|
||||||
section.biomePalette().write(writer); // Biomes
|
section.biomePalette().write(writer); // Biomes
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* <p>
|
* <p>
|
||||||
* 0 is the default value.
|
* 0 is the default value.
|
||||||
*/
|
*/
|
||||||
public interface Palette extends Writeable {
|
public sealed interface Palette extends Writeable permits PaletteImpl {
|
||||||
static Palette blocks() {
|
static Palette blocks() {
|
||||||
return new PaletteImpl(16 * 16 * 16, 8, 8, 2);
|
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);
|
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.
|
* Returns the number of bits used per entry.
|
||||||
*/
|
*/
|
||||||
int bitsPerEntry();
|
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();
|
int maxBitsPerEntry();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of entries in this palette.
|
* Returns the maximum number of entries in this palette.
|
||||||
*/
|
*/
|
||||||
int size();
|
int maxSize();
|
||||||
|
|
||||||
long[] data();
|
|
||||||
|
|
||||||
@NotNull Palette clone();
|
@NotNull Palette clone();
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import static net.minestom.server.instance.Chunk.CHUNK_SECTION_SIZE;
|
import static net.minestom.server.instance.Chunk.CHUNK_SECTION_SIZE;
|
||||||
|
|
||||||
final class PaletteImpl implements Palette {
|
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 =
|
private static final int[] MAGIC_MASKS =
|
||||||
{0, 0, 0, 0,
|
{0, 1, 3, 7,
|
||||||
15, 31, 63, 127, 255,
|
15, 31, 63, 127, 255,
|
||||||
511, 1023, 2047, 4095,
|
511, 1023, 2047, 4095,
|
||||||
8191, 16383, 32767};
|
8191, 16383, 32767};
|
||||||
@ -104,7 +104,7 @@ final class PaletteImpl implements Palette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count() {
|
public int size() {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ final class PaletteImpl implements Palette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int maxSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user