Exemple #1
0
    public void Serialize(IMinecraftPacket packet, bool fullChunk = false)
    {
        packet.WriteInt32(X);
        packet.WriteInt32(Z);
        packet.WriteBoolean(fullChunk);

        int mask = 0;

        // if full chunk
        using var chunkStream = new MinecraftPacket();
        for (int i = 0; i < Sections.Count(); i++)
        {
            IChunkSection section = Sections.ElementAt(i);

            if (fullChunk || section.IsDirty)
            {
                mask |= 1 << i;
                section.Serialize(chunkStream);
            }
        }

        packet.WriteVarInt32(mask);

        // Heightmap serialization
        var heightmapCompound = new NbtCompound("")
        {
            new NbtLongArray("MOTION_BLOCKING", Heightmap.ToArray()),
            new NbtLongArray("WORLD_SURFACE", WorldSurfaceHeightmap.ToArray())
        };
        var nbtFile = new NbtFile(heightmapCompound);

        packet.WriteBytes(nbtFile.GetBuffer());

        // Biomes
        if (fullChunk)
        {
            packet.WriteVarInt32(1024);

            for (int i = 0; i < 1024; i++)
            {
                packet.WriteVarInt32(0);
            }
        }

        chunkStream.Position = 0;

        packet.WriteVarInt32((int)chunkStream.Length);
        packet.WriteBytes(chunkStream.BaseBuffer);

        packet.WriteVarInt32(0); // block count
        // TODO: foreach block in blocks in chunk as NBT
    }
Exemple #2
0
    private void WriteDimension(Dimension dimension, IMinecraftPacket packet)
    {
        var nbtDimension = NbtSerializer.SerializeCompound(dimension.Element, "");
        var nbtFile      = new NbtFile(nbtDimension);

        packet.WriteBytes(nbtFile.GetBuffer());
    }
Exemple #3
0
    private void WriteDimensionsAndBiomes(IEnumerable <Dimension> dimensions, IEnumerable <Biome> biomes, IMinecraftPacket packet)
    {
        IEnumerable <NbtTag> dimensionsTags = dimensions.Select(x => NbtSerializer.SerializeCompound(x));
        IEnumerable <NbtTag> biomesTags     = biomes.Select(x => NbtSerializer.SerializeCompound(x));

        var nbtCompound = new NbtCompound("")
        {
            new NbtCompound("minecraft:dimension_type")
            {
                new NbtString("type", "minecraft:dimension_type"),
                new NbtList("value", dimensionsTags, NbtTagType.Compound)
            },
            new NbtCompound("minecraft:worldgen/biome")
            {
                new NbtString("type", "minecraft:worldgen/biome"),
                new NbtList("value", biomesTags, NbtTagType.Compound)
            }
        };
        var nbtFile = new NbtFile(nbtCompound);

        packet.WriteBytes(nbtFile.GetBuffer());
    }