Exemple #1
0
        public void FinishReading()
        {
            using (MemoryStream ms = new MemoryStream(Data))
                using (MinecraftStream stream = new MinecraftStream(ms))
                {
                    byte index = 0;
                    do
                    {
                        index = (byte)stream.ReadByte();
                        if (index == 0xff)
                        {
                            break;
                        }

                        MetadataType  type = (MetadataType)stream.ReadVarInt();
                        MetaDataEntry meta = null;
                        switch (type)
                        {
                        case MetadataType.Byte:
                            meta = new MetadataByte(index, (byte)stream.ReadByte());
                            break;

                        case MetadataType.Varint:
                            meta = new MetadataVarInt(index, stream.ReadVarInt());
                            break;

                        case MetadataType.Float:
                            meta = new MetadataFloat(index, stream.ReadFloat());
                            break;

                        case MetadataType.String:
                            meta = new MetadataString(index, stream.ReadString());
                            break;

                        case MetadataType.Chat:
                            meta = new MetadataChat(index, stream.ReadChatObject());
                            break;

                        case MetadataType.OptChat:
                            var hasData = stream.ReadBool();
                            meta = new MetadataOptChat(index, hasData, hasData ? stream.ReadChatObject() : null);
                            break;

                        case MetadataType.Slot:
                            meta = new MetadataSlot(index, stream.ReadSlot());
                            break;

                        case MetadataType.Boolean:
                            meta = new MetadataBool(index, stream.ReadBool());
                            break;

                        case MetadataType.Rotation:
                            meta = new MetadataRotation(index, new Vector3(stream.ReadFloat(), stream.ReadFloat(), stream.ReadFloat()));
                            break;

                        case MetadataType.Position:
                            meta = new MetadataPosition(index, stream.ReadPosition());
                            break;

                        case MetadataType.OptPosition:
                        {
                            bool hasPosition = stream.ReadBool();

                            meta = new MetadataOptPosition(
                                index, hasPosition, hasPosition ? stream.ReadPosition() : (Vector3?)null);
                        }

                        break;

                        case MetadataType.Direction:
                            meta = new MetadataDirection(index, (API.Utils.Direction)stream.ReadVarInt());                         // stream.ReadVarInt();
                            break;

                        case MetadataType.OptUUID:
                        {
                            var hasUUID = stream.ReadBool();
                            meta = new MetadataOptUUID(index, hasUUID, hasUUID ? new UUID(stream.ReadUuid().ToByteArray()) : null);                        // stream.ReadUuid();
                        }
                        break;

                        case MetadataType.OptBlockID:
                            stream.ReadVarInt();
                            break;

                        case MetadataType.NBT:
                            meta = new MetadataNbt(index, stream.ReadNbtCompound());
                            break;

                        case MetadataType.Particle:
                            break;

                        case MetadataType.VillagerData:
                            meta = new MetadataVillagerData(
                                index, (MetadataVillagerData.VillagerTypes)stream.ReadVarInt(), (MetadataVillagerData.VillagerProfession)stream.ReadVarInt(), (MetadataVillagerData.VillagerLevel)stream.ReadVarInt());
                            break;

                        case MetadataType.OptVarInt:
                            stream.ReadVarInt();
                            break;

                        case MetadataType.Pose:
                            stream.ReadVarInt();
                            break;
                        }

                        if (meta != null)
                        {
                            Entries.Add(meta);
                        }
                    } while (index != 0xff);
                }
        }
        public void FinishReading()
        {
            using (MemoryStream ms = new MemoryStream(Data))
                using (MinecraftStream stream = new MinecraftStream(ms))
                {
                    byte index = 0;
                    do
                    {
                        index = (byte)stream.ReadByte();
                        if (index == 0xff)
                        {
                            break;
                        }

                        MetadataType  type = (MetadataType)stream.ReadVarInt();
                        MetaDataEntry meta = null;
                        switch (type)
                        {
                        case MetadataType.Byte:
                            meta = new MetadataByte(index, (byte)stream.ReadByte());
                            break;

                        case MetadataType.Varint:
                            meta = new MetadataVarInt(index, stream.ReadVarInt());
                            break;

                        case MetadataType.Float:
                            meta = new MetadataFloat(index, stream.ReadFloat());
                            break;

                        case MetadataType.String:
                            meta = new MetadataString(index, stream.ReadString());
                            break;

                        case MetadataType.Chat:
                            meta = new MetadataChat(index, stream.ReadChatObject());
                            break;

                        case MetadataType.OptChat:
                            var hasData = stream.ReadBool();
                            meta = new MetadataOptChat(index, hasData, hasData ? stream.ReadChatObject() : null);
                            break;

                        case MetadataType.Slot:
                            meta = new MetadataSlot(index, stream.ReadSlot());
                            break;

                        case MetadataType.Boolean:
                            meta = new MetadataBool(index, stream.ReadBool());
                            break;

                        case MetadataType.Rotation:
                            stream.ReadFloat();
                            stream.ReadFloat();
                            stream.ReadFloat();
                            break;

                        case MetadataType.Position:
                            stream.ReadPosition();
                            break;

                        case MetadataType.OptPosition:
                            if (stream.ReadBool())
                            {
                                stream.ReadPosition();
                            }
                            break;

                        case MetadataType.Direction:
                            stream.ReadVarInt();
                            break;

                        case MetadataType.OptUUID:
                            if (stream.ReadBool())
                            {
                                stream.ReadUuid();
                            }
                            break;

                        case MetadataType.OptBlockID:
                            stream.ReadVarInt();
                            break;

                        case MetadataType.NBT:
                            stream.ReadNbtCompound();
                            break;

                        case MetadataType.Particle:
                            break;

                        case MetadataType.VillagerData:
                            stream.ReadVarInt();
                            stream.ReadVarInt();
                            stream.ReadVarInt();
                            break;

                        case MetadataType.OptVarInt:
                            stream.ReadVarInt();
                            break;

                        case MetadataType.Pose:
                            stream.ReadVarInt();
                            break;
                        }

                        if (meta != null)
                        {
                            Entries.Add(meta);
                        }
                    } while (index != 0xff);
                }
        }