use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection in project ViaVersion by ViaVersion.
the class ConnectionData method connectBlocks.
public static void connectBlocks(UserConnection user, Chunk chunk) {
long xOff = chunk.getX() << 4;
long zOff = chunk.getZ() << 4;
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
boolean willConnect = false;
for (int p = 0; p < section.getPaletteSize(); p++) {
int id = section.getPaletteEntry(p);
if (ConnectionData.connects(id)) {
willConnect = true;
break;
}
}
if (!willConnect)
continue;
long yOff = i << 4;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z);
ConnectionHandler handler = ConnectionData.getConnectionHandler(block);
if (handler != null) {
block = handler.connect(user, new Position((int) (xOff + x), (short) (yOff + y), (int) (zOff + z)), block);
section.setFlatBlock(x, y, z, block);
}
}
}
}
}
}
use of com.viaversion.viaversion.api.minecraft.chunks.ChunkSection 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.ChunkSection 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