Cleanup & read section palettes

This commit is contained in:
themode 2021-03-15 06:06:41 +01:00 committed by jglrxavpok
parent 3562c82e7f
commit c984ca7a19
3 changed files with 22 additions and 18 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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();
}
}