Exemple #1
0
 public void Write(IPacketWriter writer)
 {
     // this will be revisited once I implement recipes, but for now, all is disabled
     writer.WriteVarInt(0);
     writer.WriteBoolean(false);
     writer.WriteBoolean(false);
     writer.WriteBoolean(false);
     writer.WriteBoolean(false);
     writer.WriteVarInt(0);
     writer.WriteVarInt(0);
 }
Exemple #2
0
 public void Write(IPacketWriter writer)
 {
     writer.WriteInt32(EntityId);
     writer.WriteUInt8(GameMode);
     writer.WriteInt32(Dimension);
     writer.WriteInt64(Seed);
     writer.WriteUInt8(MaxPlayers);
     writer.WriteString(LevelType);
     writer.WriteVarInt(ViewDistance);
     writer.WriteBoolean(ReducedDebugInfo);
     writer.WriteBoolean(!ShowDeathScreen);
 }
Exemple #3
0
        public void WriteOptChat(byte index, Chat?value)
        {
            _writer.WriteUInt8(index);
            _writer.WriteUInt8(5);
            var b = value is null;

            _writer.WriteBoolean(!b);

            if (!b)
            {
                var data = JsonSerializer.SerializeToUtf8Bytes(value);
                _writer.WriteVarInt(data.Length);
                _writer.WriteBytes(data);
            }
        }
Exemple #4
0
        public void Write(IPacketWriter writer)
        {
            writer.WriteBoolean(Present);

            if (Present)
            {
                writer.WriteVarInt(Id);
                writer.WriteUInt8(Count);
                writer.WriteNbt(Nbt);
            }
        }
Exemple #5
0
        public void Write(IPacketWriter writer)
        {
            writer.WriteVarInt((int)Type);
            writer.WriteVarInt(Players.Length);

            foreach (var player in Players)
            {
                writer.WriteGuid(player.Guid);
                switch (Type)
                {
                case InfoType.AddPlayer:
                    writer.WriteString(player.Username);
                    writer.WriteVarInt(0);      // no skin support
                    writer.WriteVarInt(1);      // Gamemode 1
                    writer.WriteVarInt((int)(player.Ping?.TotalMilliseconds ?? -1));
                    writer.WriteBoolean(false); // No display name
                    break;

                case InfoType.UpdateGamemode:
                    writer.WriteVarInt(1);     // Gamemode 1
                    break;

                case InfoType.UpdateLatency:
                    writer.WriteVarInt((int)(player.Ping?.TotalMilliseconds ?? -1));     // No Connection ping
                    break;

                case InfoType.UpdateDisplayName:
                    writer.WriteBoolean(false);     // No display name
                    break;

                case InfoType.RemovePlayer:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(Type));
                }
            }
        }
Exemple #6
0
        public void Write(IPacketWriter writer)
        {
            writer.WriteInt32(Position.X);
            writer.WriteInt32(Position.Z);
            writer.WriteBoolean(true); // Full Chunks only

            var sectionMask = CalculateMask(Chunk.States.Span, Chunk, out var chunksSend, out var chunkNonZeroCount);

            writer.WriteVarInt(sectionMask);

            var rawHeightmap    = CalculateHeightmap(Chunk);
            var packedHeightMap = PackHeightMap(rawHeightmap);
            var compound        = new NbtCompound(new ReadOnlyDictionary <string, INbtTag>(new Dictionary <string, INbtTag>()
            {
                { "MOTION_BLOCKING", new NbtLongArray(packedHeightMap) }
            }));

            const int bitsPerBlock  = 14;
            const int requiredLongs = 16 * 16 * 16 * bitsPerBlock / 8 / sizeof(long);

            writer.WriteNbt(compound);

            WriteBiomes(writer);

            writer.WriteVarInt((chunksSend * (sizeof(short) + sizeof(byte) + 2 + (requiredLongs * sizeof(long)))));

            for (int section = 0; section < 16; section++)
            {
                if ((sectionMask & (1 << section)) == 0)
                {
                    continue;
                }

                writer.WriteInt16(chunkNonZeroCount[section]);

                // log2(maxState) rounded. Direct Pallet.
                writer.WriteUInt8(bitsPerBlock);
                writer.WriteVarInt(requiredLongs);
                Span <ulong> longs     = new ulong[requiredLongs];
                var          bitBuffer = new BitBuffer(longs);

                for (int y = 0; y < 16; y++)
                {
                    for (int x = 0; x < ReadOnlyChunk.Width; x++)
                    {
                        for (int z = 0; z < ReadOnlyChunk.Depth; z++)
                        {
                            bitBuffer.WriteInt32(Chunk[(x, (section * 16) + y, z)].State, 14);
Exemple #7
0
 public void Write(IPacketWriter writer)
 {
     writer.WriteUInt8(Difficulty);
     writer.WriteBoolean(IsLocked);
 }