use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl in project ViaVersion by ViaVersion.
the class ChunkSectionType1_13 method read.
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
// Reaad bits per block
int bitsPerBlock = buffer.readUnsignedByte();
int originalBitsPerBlock = bitsPerBlock;
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
// Read palette
ChunkSection chunkSection;
if (bitsPerBlock != GLOBAL_PALETTE) {
int paletteLength = Type.VAR_INT.readPrimitive(buffer);
chunkSection = new ChunkSectionImpl(true, paletteLength);
for (int i = 0; i < paletteLength; i++) {
chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
}
} else {
chunkSection = new ChunkSectionImpl(true);
}
// Read blocks
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
if (blockData.length > 0) {
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
if (blockData.length != expectedLength) {
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
}
for (int i = 0; i < blockData.length; i++) {
blockData[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData, bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
}
return chunkSection;
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl in project ViaVersion by ViaVersion.
the class ChunkSectionType1_16 method read.
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
// Reaad bits per block
int bitsPerBlock = buffer.readUnsignedByte();
int originalBitsPerBlock = bitsPerBlock;
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
// Read palette
ChunkSection chunkSection;
if (bitsPerBlock != GLOBAL_PALETTE) {
int paletteLength = Type.VAR_INT.readPrimitive(buffer);
chunkSection = new ChunkSectionImpl(false, paletteLength);
for (int i = 0; i < paletteLength; i++) {
chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
}
} else {
chunkSection = new ChunkSectionImpl(false);
}
// Read blocks
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
if (blockData.length > 0) {
char valuesPerLong = (char) (64 / bitsPerBlock);
int expectedLength = (ChunkSection.SIZE + valuesPerLong - 1) / valuesPerLong;
if (blockData.length != expectedLength) {
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
}
for (int i = 0; i < blockData.length; i++) {
blockData[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, blockData, bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
}
return chunkSection;
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl in project ViaVersion by ViaVersion.
the class ChunkSectionType1_8 method read.
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
ChunkSection chunkSection = new ChunkSectionImpl(true);
// 0 index needs to be air in 1.9
chunkSection.addPaletteEntry(0);
ByteBuf littleEndianView = buffer.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < ChunkSection.SIZE; i++) {
int mask = littleEndianView.readShort();
int type = mask >> 4;
int data = mask & 0xF;
chunkSection.setBlockWithData(i, type, data);
}
return chunkSection;
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl in project ViaVersion by ViaVersion.
the class ChunkSectionType1_18 method read.
@Override
public ChunkSection read(final ByteBuf buffer) throws Exception {
final ChunkSection chunkSection = new ChunkSectionImpl();
chunkSection.setNonAirBlocksCount(buffer.readShort());
chunkSection.addPalette(PaletteType.BLOCKS, blockPaletteType.read(buffer));
chunkSection.addPalette(PaletteType.BIOMES, biomePaletteType.read(buffer));
return chunkSection;
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl in project ViaVersion by ViaVersion.
the class ChunkSectionType1_9 method read.
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
// Reaad bits per block
int bitsPerBlock = buffer.readUnsignedByte();
int originalBitsPerBlock = bitsPerBlock;
if (bitsPerBlock == 0) {
bitsPerBlock = GLOBAL_PALETTE;
}
if (bitsPerBlock < 4) {
bitsPerBlock = 4;
}
if (bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
// Read palette
int paletteLength = Type.VAR_INT.readPrimitive(buffer);
ChunkSection chunkSection = bitsPerBlock != GLOBAL_PALETTE ? new ChunkSectionImpl(true, paletteLength) : new ChunkSectionImpl(true);
for (int i = 0; i < paletteLength; i++) {
if (bitsPerBlock != GLOBAL_PALETTE) {
chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
} else {
Type.VAR_INT.readPrimitive(buffer);
}
}
// Read blocks
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
if (blockData.length > 0) {
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
if (blockData.length != expectedLength) {
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
}
for (int i = 0; i < blockData.length; i++) {
blockData[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData, bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
}
return chunkSection;
}
Aggregations