Search in sources :

Example 1 with BaseChunk

use of com.viaversion.viaversion.api.minecraft.chunks.BaseChunk in project ViaVersion by ViaVersion.

the class Chunk1_13Type method read.

@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
    int chunkX = input.readInt();
    int chunkZ = input.readInt();
    boolean fullChunk = input.readBoolean();
    int primaryBitmask = Type.VAR_INT.readPrimitive(input);
    ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input));
    // Read sections
    ChunkSection[] sections = new ChunkSection[16];
    for (int i = 0; i < 16; i++) {
        // Section not set
        if ((primaryBitmask & (1 << i)) == 0)
            continue;
        ChunkSection section = Types1_13.CHUNK_SECTION.read(data);
        sections[i] = section;
        section.getLight().readBlockLight(data);
        if (world.getEnvironment() == Environment.NORMAL) {
            section.getLight().readSkyLight(data);
        }
    }
    int[] biomeData = fullChunk ? new int[256] : null;
    if (fullChunk) {
        if (data.readableBytes() >= 256 * 4) {
            for (int i = 0; i < 256; i++) {
                biomeData[i] = data.readInt();
            }
        } else {
            Via.getPlatform().getLogger().log(Level.WARNING, "Chunk x=" + chunkX + " z=" + chunkZ + " doesn't have biome data!");
        }
    }
    List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
    // Read all the remaining bytes (workaround for #681)
    if (input.readableBytes() > 0) {
        byte[] array = Type.REMAINING_BYTES.read(input);
        if (Via.getManager().isDebug()) {
            Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
        }
    }
    return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
}
Also used : BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 2 with BaseChunk

use of com.viaversion.viaversion.api.minecraft.chunks.BaseChunk in project ViaVersion by ViaVersion.

the class Chunk1_8Type method deserialize.

// Used for normal and bulk chunks
public static Chunk deserialize(final int chunkX, final int chunkZ, final boolean fullChunk, final boolean skyLight, final int bitmask, final byte[] data) throws Exception {
    final ByteBuf input = Unpooled.wrappedBuffer(data);
    final ChunkSection[] sections = new ChunkSection[16];
    int[] biomeData = null;
    // Read blocks
    for (int i = 0; i < sections.length; i++) {
        if ((bitmask & 1 << i) == 0)
            continue;
        sections[i] = Types1_8.CHUNK_SECTION.read(input);
    }
    // Read block light
    for (int i = 0; i < sections.length; i++) {
        if ((bitmask & 1 << i) == 0)
            continue;
        sections[i].getLight().readBlockLight(input);
    }
    // Read sky light
    if (skyLight) {
        for (int i = 0; i < sections.length; i++) {
            if ((bitmask & 1 << i) == 0)
                continue;
            sections[i].getLight().readSkyLight(input);
        }
    }
    // Read biome data
    if (fullChunk) {
        biomeData = new int[256];
        for (int i = 0; i < 256; i++) {
            biomeData[i] = input.readUnsignedByte();
        }
    }
    input.release();
    return new BaseChunk(chunkX, chunkZ, fullChunk, false, bitmask, sections, biomeData, new ArrayList<>());
}
Also used : BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) ByteBuf(io.netty.buffer.ByteBuf) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)

Example 3 with BaseChunk

use of com.viaversion.viaversion.api.minecraft.chunks.BaseChunk in project ViaVersion by ViaVersion.

the class Chunk1_9_3_4Type method read.

@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
    int chunkX = input.readInt();
    int chunkZ = input.readInt();
    boolean fullChunk = input.readBoolean();
    int primaryBitmask = Type.VAR_INT.readPrimitive(input);
    Type.VAR_INT.readPrimitive(input);
    // Read sections
    ChunkSection[] sections = new ChunkSection[16];
    for (int i = 0; i < 16; i++) {
        // Section not set
        if ((primaryBitmask & (1 << i)) == 0)
            continue;
        ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
        sections[i] = section;
        section.getLight().readBlockLight(input);
        if (world.getEnvironment() == Environment.NORMAL) {
            section.getLight().readSkyLight(input);
        }
    }
    int[] biomeData = fullChunk ? new int[256] : null;
    if (fullChunk) {
        for (int i = 0; i < 256; i++) {
            biomeData[i] = input.readByte() & 0xFF;
        }
    }
    List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
    // Read all the remaining bytes (workaround for #681)
    if (input.readableBytes() > 0) {
        byte[] array = Type.REMAINING_BYTES.read(input);
        if (Via.getManager().isDebug()) {
            Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
        }
    }
    return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
}
Also used : BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) ArrayList(java.util.ArrayList) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 4 with BaseChunk

use of com.viaversion.viaversion.api.minecraft.chunks.BaseChunk in project ViaVersion by ViaVersion.

the class Chunk1_9_1_2Type method read.

@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
    int chunkX = input.readInt();
    int chunkZ = input.readInt();
    boolean groundUp = input.readBoolean();
    int primaryBitmask = Type.VAR_INT.readPrimitive(input);
    // Size (unused)
    Type.VAR_INT.readPrimitive(input);
    BitSet usedSections = new BitSet(16);
    ChunkSection[] sections = new ChunkSection[16];
    // Calculate section count from bitmask
    for (int i = 0; i < 16; i++) {
        if ((primaryBitmask & (1 << i)) != 0) {
            usedSections.set(i);
        }
    }
    // Read sections
    for (int i = 0; i < 16; i++) {
        // Section not set
        if (!usedSections.get(i))
            continue;
        ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
        sections[i] = section;
        section.getLight().readBlockLight(input);
        if (world.getEnvironment() == Environment.NORMAL) {
            section.getLight().readSkyLight(input);
        }
    }
    int[] biomeData = groundUp ? new int[256] : null;
    if (groundUp) {
        for (int i = 0; i < 256; i++) {
            biomeData[i] = input.readByte() & 0xFF;
        }
    }
    return new BaseChunk(chunkX, chunkZ, groundUp, false, primaryBitmask, sections, biomeData, new ArrayList<CompoundTag>());
}
Also used : BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) BitSet(java.util.BitSet) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Example 5 with BaseChunk

use of com.viaversion.viaversion.api.minecraft.chunks.BaseChunk in project ViaVersion by ViaVersion.

the class Chunk1_17Type method read.

@Override
public Chunk read(ByteBuf input) throws Exception {
    int chunkX = input.readInt();
    int chunkZ = input.readInt();
    BitSet sectionsMask = BitSet.valueOf(Type.LONG_ARRAY_PRIMITIVE.read(input));
    CompoundTag heightMap = Type.NBT.read(input);
    int[] biomeData = Type.VAR_INT_ARRAY_PRIMITIVE.read(input);
    // data size in bytes
    Type.VAR_INT.readPrimitive(input);
    // Read sections
    ChunkSection[] sections = new ChunkSection[ySectionCount];
    for (int i = 0; i < ySectionCount; i++) {
        // Section not set
        if (!sectionsMask.get(i))
            continue;
        short nonAirBlocksCount = input.readShort();
        ChunkSection section = Types1_16.CHUNK_SECTION.read(input);
        section.setNonAirBlocksCount(nonAirBlocksCount);
        sections[i] = section;
    }
    List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
    // Read all the remaining bytes (workaround for #681)
    if (input.readableBytes() > 0) {
        byte[] array = Type.REMAINING_BYTES.read(input);
        if (Via.getManager().isDebug()) {
            Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
        }
    }
    return new BaseChunk(chunkX, chunkZ, true, false, sectionsMask, sections, biomeData, heightMap, nbtData);
}
Also used : BaseChunk(com.viaversion.viaversion.api.minecraft.chunks.BaseChunk) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) ChunkSection(com.viaversion.viaversion.api.minecraft.chunks.ChunkSection) CompoundTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag)

Aggregations

BaseChunk (com.viaversion.viaversion.api.minecraft.chunks.BaseChunk)11 ChunkSection (com.viaversion.viaversion.api.minecraft.chunks.ChunkSection)11 CompoundTag (com.github.steveice10.opennbt.tag.builtin.CompoundTag)9 ArrayList (java.util.ArrayList)9 Position (com.viaversion.viaversion.api.minecraft.Position)2 Chunk (com.viaversion.viaversion.api.minecraft.chunks.Chunk)2 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)2 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)2 Type (com.viaversion.viaversion.api.type.Type)2 ByteBuf (io.netty.buffer.ByteBuf)2 BitSet (java.util.BitSet)2 StringTag (com.github.steveice10.opennbt.tag.builtin.StringTag)1 ItemRewriter (com.viaversion.viabackwards.api.rewriters.ItemRewriter)1 Protocol1_17_1To1_18 (com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.Protocol1_17_1To1_18)1 BlockEntityIds (com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.data.BlockEntityIds)1 Via (com.viaversion.viaversion.api.Via)1 ParticleMappings (com.viaversion.viaversion.api.data.ParticleMappings)1 EntityTracker (com.viaversion.viaversion.api.data.entity.EntityTracker)1 BlockFace (com.viaversion.viaversion.api.minecraft.BlockFace)1 BlockEntity (com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity)1