Search in sources :

Example 46 with ChunkSection

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);
                    }
                }
            }
        }
    }
}
Also used : Position(com.viaversion.viaversion.api.minecraft.Position) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Example 47 with ChunkSection

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;
}
Also used : ChunkSectionImpl(com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Example 48 with 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;
}
Also used : ChunkSectionImpl(com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Aggregations

ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)48 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)20 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)19 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)19 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)18 ArrayList (java.util.ArrayList)16 Type (com.viaversion.viaversion.api.type.Type)14 ByteBuf (io.netty.buffer.ByteBuf)13 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)12 BlockRewriter (com.viaversion.viaversion.rewriter.BlockRewriter)12 BaseChunk (com.viaversion.viaversion.api.minecraft.chunks.BaseChunk)11 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)10 Position (com.viaversion.viaversion.api.minecraft.Position)8 BlockChangeRecord (com.viaversion.viaversion.api.minecraft.BlockChangeRecord)7 CompoundTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag)7 List (java.util.List)7 StringTag (com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag)6 Tag (com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag)6 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)5 Via (com.viaversion.viaversion.api.Via)5