mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-12 10:21:39 +01:00
Cleanup & read section palettes
This commit is contained in:
parent
3562c82e7f
commit
c984ca7a19
@ -10,6 +10,8 @@ import net.minestom.server.utils.clone.PublicCloneable;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static net.minestom.server.instance.Chunk.CHUNK_SECTION_COUNT;
|
||||
import static net.minestom.server.instance.Chunk.CHUNK_SECTION_SIZE;
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class Section implements PublicCloneable<Section> {
|
||||
*
|
||||
* @param newBitsPerEntry the new bits per entry count
|
||||
*/
|
||||
private void resize(int newBitsPerEntry) {
|
||||
public void resize(int newBitsPerEntry) {
|
||||
newBitsPerEntry = fixBitsPerEntry(newBitsPerEntry);
|
||||
|
||||
Section section = new Section(newBitsPerEntry, bitsIncrement);
|
||||
|
@ -172,27 +172,29 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
}
|
||||
|
||||
// Data
|
||||
this.paletteStorage = new PaletteStorage(15, 1);
|
||||
// TODO don't hardcode bitsPerEntry (use packet field instead)
|
||||
this.paletteStorage = new PaletteStorage(8, 1);
|
||||
int blockArrayLength = reader.readVarInt();
|
||||
for (int section = 0; section < CHUNK_SECTION_COUNT; section++) {
|
||||
int test = mask & 1 << section;
|
||||
if (test != 0) {
|
||||
short blockCount = reader.readShort();
|
||||
byte bitsPerEntry = reader.readByte();
|
||||
if (bitsPerEntry < 9) {
|
||||
int paletteSize = reader.readVarInt();
|
||||
for (int i = 0; i < paletteSize; i++) {
|
||||
// TODO fill palette
|
||||
int paletteValue = reader.readVarInt();
|
||||
}
|
||||
boolean hasSection = (mask & 1 << section) != 0;
|
||||
if (!hasSection)
|
||||
continue;
|
||||
short blockCount = reader.readShort();
|
||||
byte bitsPerEntry = reader.readByte();
|
||||
if (bitsPerEntry < 9) {
|
||||
int paletteSize = reader.readVarInt();
|
||||
for (int i = 0; i < paletteSize; i++) {
|
||||
final int paletteValue = reader.readVarInt();
|
||||
paletteStorage.getSections()[section].getPaletteBlockMap().put((short) i, (short) paletteValue);
|
||||
paletteStorage.getSections()[section].getBlockPaletteMap().put((short) paletteValue, (short) i);
|
||||
}
|
||||
}
|
||||
|
||||
int dataLength = reader.readVarInt();
|
||||
long[] data = new long[dataLength];
|
||||
for (int i = 0; i < dataLength; i++) {
|
||||
data[i] = reader.readLong();
|
||||
}
|
||||
paletteStorage.getSectionBlocks()[section] = data;
|
||||
int dataLength = reader.readVarInt();
|
||||
paletteStorage.getSections()[section].resize(bitsPerEntry);
|
||||
long[] data = paletteStorage.getSections()[section].getBlocks();
|
||||
for (int i = 0; i < dataLength; i++) {
|
||||
data[i] = reader.readLong();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user