From a999c5d845bd759c6d83b356c7b39e67473dc452 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 10 Apr 2021 15:57:16 +0100 Subject: More cProtocol cleanup * Alpha sort functions * Simplify hand handling * Fix left handed mode client-side display --- src/Protocol/Protocol_1_13.cpp | 666 ++++++++++++++++++++--------------------- 1 file changed, 333 insertions(+), 333 deletions(-) (limited to 'src/Protocol/Protocol_1_13.cpp') diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index a802f0074..400dd62b1 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -238,257 +238,7 @@ void cProtocol_1_13::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) -bool cProtocol_1_13::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) -{ - if (m_State != 3) - { - return Super::HandlePacket(a_ByteBuffer, a_PacketType); - } - - // Game - switch (a_PacketType) - { - case 0x00: HandleConfirmTeleport(a_ByteBuffer); return true; - case 0x05: HandlePacketTabComplete(a_ByteBuffer); return true; - case 0x02: HandlePacketChatMessage(a_ByteBuffer); return true; - case 0x03: HandlePacketClientStatus(a_ByteBuffer); return true; - case 0x04: HandlePacketClientSettings(a_ByteBuffer); return true; - case 0x06: break; // Confirm transaction - not used in Cuberite - case 0x07: HandlePacketEnchantItem(a_ByteBuffer); return true; - case 0x08: HandlePacketWindowClick(a_ByteBuffer); return true; - case 0x09: HandlePacketWindowClose(a_ByteBuffer); return true; - case 0x0a: HandlePacketPluginMessage(a_ByteBuffer); return true; - case 0x0d: HandlePacketUseEntity(a_ByteBuffer); return true; - case 0x0e: HandlePacketKeepAlive(a_ByteBuffer); return true; - case 0x0f: HandlePacketPlayer(a_ByteBuffer); return true; - case 0x10: HandlePacketPlayerPos(a_ByteBuffer); return true; - case 0x11: HandlePacketPlayerPosLook(a_ByteBuffer); return true; - case 0x12: HandlePacketPlayerLook(a_ByteBuffer); return true; - case 0x13: HandlePacketVehicleMove(a_ByteBuffer); return true; - case 0x14: HandlePacketBoatSteer(a_ByteBuffer); return true; - case 0x15: break; // Pick item - not yet implemented - case 0x16: break; // Craft Recipe Request - not yet implemented - case 0x17: HandlePacketPlayerAbilities(a_ByteBuffer); return true; - case 0x18: HandlePacketBlockDig(a_ByteBuffer); return true; - case 0x19: HandlePacketEntityAction(a_ByteBuffer); return true; - case 0x1a: HandlePacketSteerVehicle(a_ByteBuffer); return true; - case 0x1b: HandlePacketCraftingBookData(a_ByteBuffer); return true; - case 0x1d: break; // Resource pack status - not yet implemented - case 0x1e: HandlePacketAdvancementTab(a_ByteBuffer); return true; - case 0x20: HandlePacketSetBeaconEffect(a_ByteBuffer); return true; - case 0x21: HandlePacketSlotSelect(a_ByteBuffer); return true; - case 0x24: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; - case 0x26: HandlePacketUpdateSign(a_ByteBuffer); return true; - case 0x27: HandlePacketAnimation(a_ByteBuffer); return true; - case 0x28: HandlePacketSpectate(a_ByteBuffer); return true; - case 0x29: HandlePacketBlockPlace(a_ByteBuffer); return true; - case 0x2a: HandlePacketUseItem(a_ByteBuffer); return true; - } - - return Super::HandlePacket(a_ByteBuffer, a_PacketType); -} - - - - - -void cProtocol_1_13::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) -{ - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); - - // If the plugin channel is recognized vanilla, handle it directly: - if (Channel.substr(0, 15) == "minecraft:brand") - { - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Brand); - m_Client->SetClientBrand(Brand); - - // Send back our brand, including the length: - m_Client->SendPluginMessage("minecraft:brand", "\x08""Cuberite"); - return; - } - - ContiguousByteBuffer Data; - - // Read the plugin message and relay to clienthandle: - VERIFY(a_ByteBuffer.ReadSome(Data, a_ByteBuffer.GetReadableSpace())); // Always succeeds - m_Client->HandlePluginMessage(Channel, Data); -} - - - - - -void cProtocol_1_13::HandlePacketSetBeaconEffect(cByteBuffer & a_ByteBuffer) -{ - HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect1); - HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect2); - m_Client->HandleBeaconSelection(Effect1, Effect2); -} - - - - - -cProtocol::Version cProtocol_1_13::GetProtocolVersion() -{ - return Version::v1_13; -} - - - - - -UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) -{ - switch (a_PacketType) - { - case pktAttachEntity: return 0x46; - case pktBlockChanges: return 0x0f; - case pktCameraSetTo: return 0x3c; - case pktChatRaw: return 0x0e; - case pktCollectEntity: return 0x4f; - case pktDestroyEntity: return 0x35; - case pktDisconnectDuringGame: return 0x1b; - case pktEditSign: return 0x2c; - case pktEntityEffect: return 0x53; - case pktEntityEquipment: return 0x42; - case pktEntityHeadLook: return 0x39; - case pktEntityLook: return 0x2a; - case pktEntityMeta: return 0x3f; - case pktEntityProperties: return 0x52; - case pktEntityRelMove: return 0x28; - case pktEntityRelMoveLook: return 0x29; - case pktEntityStatus: return 0x1c; - case pktEntityVelocity: return 0x41; - case pktExperience: return 0x43; - case pktExplosion: return 0x1e; - case pktGameMode: return 0x20; - case pktHeldItemChange: return 0x3d; - case pktInventorySlot: return 0x17; - case pktJoinGame: return 0x25; - case pktKeepAlive: return 0x21; - case pktLeashEntity: return 0x40; - case pktMapData: return 0x26; - case pktParticleEffect: return 0x24; - case pktPlayerAbilities: return 0x2e; - case pktPlayerList: return 0x30; - case pktPlayerListHeaderFooter: return 0x4e; - case pktPlayerMoveLook: return 0x32; - case pktPluginMessage: return 0x19; - case pktRemoveEntityEffect: return 0x36; - case pktRespawn: return 0x38; - case pktScoreboardObjective: return 0x45; - case pktSoundEffect: return 0x1a; - case pktSoundParticleEffect: return 0x23; - case pktSpawnPosition: return 0x49; - case pktTabCompletionResults: return 0x10; - case pktTeleportEntity: return 0x50; - case pktTimeUpdate: return 0x4a; - case pktTitle: return 0x4b; - case pktUnloadChunk: return 0x1f; - case pktUnlockRecipe: return 0x32; - case pktUpdateHealth: return 0x44; - case pktUpdateScore: return 0x48; - case pktUpdateSign: return GetPacketID(pktUpdateBlockEntity); - case pktUseBed: return 0x33; - case pktWindowClose: return 0x13; - case pktWindowItems: return 0x15; - case pktWindowOpen: return 0x14; - case pktWindowProperty: return 0x16; - default: return Super::GetPacketID(a_PacketType); - } -} - - - - - -signed char cProtocol_1_13::GetProtocolEntityStatus(const EntityAnimation a_Animation) const -{ - switch (a_Animation) - { - case EntityAnimation::DolphinShowsHappiness: return 38; - default: return Super::GetProtocolEntityStatus(a_Animation); - } -} - - - - - -UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType) -{ - switch (a_MobType) - { - // Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong) - case mtInvalidType: return 27; - case mtBat: return 3; - case mtCat: return 48; - case mtBlaze: return 4; - case mtCaveSpider: return 6; - case mtChicken: return 7; - case mtCod: return 8; - case mtCow: return 9; - case mtCreeper: return 10; - case mtDonkey: return 11; - case mtDolphin: return 12; - case mtDrowned: return 14; - case mtElderGuardian: return 15; - case mtEnderDragon: return 17; - case mtEnderman: return 18; - case mtEndermite: return 19; - case mtEvoker: return 21; - case mtGhast: return 26; - case mtGiant: return 27; - case mtGuardian: return 28; - case mtHorse: return 29; - case mtHusk: return 30; - case mtIllusioner: return 31; - case mtIronGolem: return 80; - case mtLlama: return 36; - case mtMagmaCube: return 38; - case mtMule: return 46; - case mtMooshroom: return 47; - case mtOcelot: return 48; - case mtParrot: return 50; - case mtPhantom: return 90; - case mtPig: return 51; - case mtPufferfish: return 52; - case mtPolarBear: return 54; - case mtRabbit: return 56; - case mtSalmon: return 57; - case mtSheep: return 58; - case mtShulker: return 59; - case mtSilverfish: return 61; - case mtSkeleton: return 62; - case mtSkeletonHorse: return 63; - case mtSlime: return 64; - case mtSnowGolem: return 66; - case mtSpider: return 69; - case mtSquid: return 70; - case mtStray: return 71; - case mtTropicalFish: return 72; - case mtTurtle: return 73; - case mtVex: return 78; - case mtVillager: return 79; - case mtVindicator: return 81; - case mtWitch: return 82; - case mtWither: return 83; - case mtWitherSkeleton: return 84; - case mtWolf: return 86; - case mtZombie: return 87; - case mtZombiePigman: return 53; - case mtZombieHorse: return 88; - case mtZombieVillager: return 89; - default: return 0; - } -} - - - - - -UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata) +UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata) const { const UInt8 Entity = 6; const UInt8 Living = Entity + 5; @@ -608,87 +358,337 @@ UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata) case EntityMetadata::MinecartFurnacePowered: return Minecart; case EntityMetadata::TNTPrimedFuseTime: return Entity; - case EntityMetadata::EntityPose: - case EntityMetadata::AreaEffectCloudParticleParameter1: - case EntityMetadata::AreaEffectCloudParticleParameter2: - case EntityMetadata::AbstractSkeletonArmsSwinging: - case EntityMetadata::ZombieUnusedWasType: break; + case EntityMetadata::EntityPose: + case EntityMetadata::AreaEffectCloudParticleParameter1: + case EntityMetadata::AreaEffectCloudParticleParameter2: + case EntityMetadata::AbstractSkeletonArmsSwinging: + case EntityMetadata::ZombieUnusedWasType: break; + } + UNREACHABLE("Retrieved invalid metadata for protocol"); +} + + + + + +UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadataType a_FieldType) const +{ + switch (a_FieldType) + { + case EntityMetadataType::Byte: return 0; + case EntityMetadataType::VarInt: return 1; + case EntityMetadataType::Float: return 2; + case EntityMetadataType::String: return 3; + case EntityMetadataType::Chat: return 4; + case EntityMetadataType::OptChat: return 5; + case EntityMetadataType::Item: return 6; + case EntityMetadataType::Boolean: return 7; + case EntityMetadataType::Rotation: return 8; + case EntityMetadataType::Position: return 9; + case EntityMetadataType::OptPosition: return 10; + case EntityMetadataType::Direction: return 11; + case EntityMetadataType::OptUUID: return 12; + case EntityMetadataType::OptBlockID: return 13; + case EntityMetadataType::NBT: return 14; + case EntityMetadataType::Particle: return 15; + case EntityMetadataType::VillagerData: return 16; + case EntityMetadataType::OptVarInt: return 17; + case EntityMetadataType::Pose: return 18; + } + UNREACHABLE("Translated invalid metadata type for protocol"); +} + + + + + +std::pair cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolID) const +{ + return PaletteUpgrade::ToItem(Palette_1_13::ToItem(a_ProtocolID)); +} + + + + + +UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) const +{ + switch (a_PacketType) + { + case pktAttachEntity: return 0x46; + case pktBlockChanges: return 0x0f; + case pktCameraSetTo: return 0x3c; + case pktChatRaw: return 0x0e; + case pktCollectEntity: return 0x4f; + case pktDestroyEntity: return 0x35; + case pktDisconnectDuringGame: return 0x1b; + case pktEditSign: return 0x2c; + case pktEntityEffect: return 0x53; + case pktEntityEquipment: return 0x42; + case pktEntityHeadLook: return 0x39; + case pktEntityLook: return 0x2a; + case pktEntityMeta: return 0x3f; + case pktEntityProperties: return 0x52; + case pktEntityRelMove: return 0x28; + case pktEntityRelMoveLook: return 0x29; + case pktEntityStatus: return 0x1c; + case pktEntityVelocity: return 0x41; + case pktExperience: return 0x43; + case pktExplosion: return 0x1e; + case pktGameMode: return 0x20; + case pktHeldItemChange: return 0x3d; + case pktInventorySlot: return 0x17; + case pktJoinGame: return 0x25; + case pktKeepAlive: return 0x21; + case pktLeashEntity: return 0x40; + case pktMapData: return 0x26; + case pktParticleEffect: return 0x24; + case pktPlayerAbilities: return 0x2e; + case pktPlayerList: return 0x30; + case pktPlayerListHeaderFooter: return 0x4e; + case pktPlayerMoveLook: return 0x32; + case pktPluginMessage: return 0x19; + case pktRemoveEntityEffect: return 0x36; + case pktRespawn: return 0x38; + case pktScoreboardObjective: return 0x45; + case pktSoundEffect: return 0x1a; + case pktSoundParticleEffect: return 0x23; + case pktSpawnPosition: return 0x49; + case pktTabCompletionResults: return 0x10; + case pktTeleportEntity: return 0x50; + case pktTimeUpdate: return 0x4a; + case pktTitle: return 0x4b; + case pktUnloadChunk: return 0x1f; + case pktUnlockRecipe: return 0x32; + case pktUpdateHealth: return 0x44; + case pktUpdateScore: return 0x48; + case pktUpdateSign: return GetPacketID(pktUpdateBlockEntity); + case pktUseBed: return 0x33; + case pktWindowClose: return 0x13; + case pktWindowItems: return 0x15; + case pktWindowOpen: return 0x14; + case pktWindowProperty: return 0x16; + default: return Super::GetPacketID(a_PacketType); + } +} + + + + + +UInt32 cProtocol_1_13::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const +{ + return Palette_1_13::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); +} + + + + + +signed char cProtocol_1_13::GetProtocolEntityStatus(const EntityAnimation a_Animation) const +{ + switch (a_Animation) + { + case EntityAnimation::DolphinShowsHappiness: return 38; + default: return Super::GetProtocolEntityStatus(a_Animation); } - UNREACHABLE("Retrieved invalid metadata for protocol"); } -UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadataType a_FieldType) +UInt32 cProtocol_1_13::GetProtocolItemType(short a_ItemID, short a_ItemDamage) const { - switch (a_FieldType) + return Palette_1_13::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); +} + + + + + +UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType) const +{ + switch (a_MobType) { - case EntityMetadataType::Byte: return 0; - case EntityMetadataType::VarInt: return 1; - case EntityMetadataType::Float: return 2; - case EntityMetadataType::String: return 3; - case EntityMetadataType::Chat: return 4; - case EntityMetadataType::OptChat: return 5; - case EntityMetadataType::Item: return 6; - case EntityMetadataType::Boolean: return 7; - case EntityMetadataType::Rotation: return 8; - case EntityMetadataType::Position: return 9; - case EntityMetadataType::OptPosition: return 10; - case EntityMetadataType::Direction: return 11; - case EntityMetadataType::OptUUID: return 12; - case EntityMetadataType::OptBlockID: return 13; - case EntityMetadataType::NBT: return 14; - case EntityMetadataType::Particle: return 15; - case EntityMetadataType::VillagerData: return 16; - case EntityMetadataType::OptVarInt: return 17; - case EntityMetadataType::Pose: return 18; + // Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong) + case mtInvalidType: return 27; + case mtBat: return 3; + case mtCat: return 48; + case mtBlaze: return 4; + case mtCaveSpider: return 6; + case mtChicken: return 7; + case mtCod: return 8; + case mtCow: return 9; + case mtCreeper: return 10; + case mtDonkey: return 11; + case mtDolphin: return 12; + case mtDrowned: return 14; + case mtElderGuardian: return 15; + case mtEnderDragon: return 17; + case mtEnderman: return 18; + case mtEndermite: return 19; + case mtEvoker: return 21; + case mtGhast: return 26; + case mtGiant: return 27; + case mtGuardian: return 28; + case mtHorse: return 29; + case mtHusk: return 30; + case mtIllusioner: return 31; + case mtIronGolem: return 80; + case mtLlama: return 36; + case mtMagmaCube: return 38; + case mtMule: return 46; + case mtMooshroom: return 47; + case mtOcelot: return 48; + case mtParrot: return 50; + case mtPhantom: return 90; + case mtPig: return 51; + case mtPufferfish: return 52; + case mtPolarBear: return 54; + case mtRabbit: return 56; + case mtSalmon: return 57; + case mtSheep: return 58; + case mtShulker: return 59; + case mtSilverfish: return 61; + case mtSkeleton: return 62; + case mtSkeletonHorse: return 63; + case mtSlime: return 64; + case mtSnowGolem: return 66; + case mtSpider: return 69; + case mtSquid: return 70; + case mtStray: return 71; + case mtTropicalFish: return 72; + case mtTurtle: return 73; + case mtVex: return 78; + case mtVillager: return 79; + case mtVindicator: return 81; + case mtWitch: return 82; + case mtWither: return 83; + case mtWitherSkeleton: return 84; + case mtWolf: return 86; + case mtZombie: return 87; + case mtZombiePigman: return 53; + case mtZombieHorse: return 88; + case mtZombieVillager: return 89; + default: return 0; } - UNREACHABLE("Translated invalid metadata type for protocol"); } -std::pair cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolID) +UInt32 cProtocol_1_13::GetProtocolStatisticType(Statistic a_Statistic) const { - return PaletteUpgrade::ToItem(Palette_1_13::ToItem(a_ProtocolID)); + return Palette_1_13::From(a_Statistic); } -UInt32 cProtocol_1_13::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +cProtocol::Version cProtocol_1_13::GetProtocolVersion() const { - return Palette_1_13::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); + return Version::v1_13; } -UInt32 cProtocol_1_13::GetProtocolItemType(short a_ItemID, short a_ItemDamage) +bool cProtocol_1_13::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { - return Palette_1_13::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); + if (m_State != 3) + { + return Super::HandlePacket(a_ByteBuffer, a_PacketType); + } + + // Game + switch (a_PacketType) + { + case 0x00: HandleConfirmTeleport(a_ByteBuffer); return true; + case 0x05: HandlePacketTabComplete(a_ByteBuffer); return true; + case 0x02: HandlePacketChatMessage(a_ByteBuffer); return true; + case 0x03: HandlePacketClientStatus(a_ByteBuffer); return true; + case 0x04: HandlePacketClientSettings(a_ByteBuffer); return true; + case 0x06: break; // Confirm transaction - not used in Cuberite + case 0x07: HandlePacketEnchantItem(a_ByteBuffer); return true; + case 0x08: HandlePacketWindowClick(a_ByteBuffer); return true; + case 0x09: HandlePacketWindowClose(a_ByteBuffer); return true; + case 0x0a: HandlePacketPluginMessage(a_ByteBuffer); return true; + case 0x0d: HandlePacketUseEntity(a_ByteBuffer); return true; + case 0x0e: HandlePacketKeepAlive(a_ByteBuffer); return true; + case 0x0f: HandlePacketPlayer(a_ByteBuffer); return true; + case 0x10: HandlePacketPlayerPos(a_ByteBuffer); return true; + case 0x11: HandlePacketPlayerPosLook(a_ByteBuffer); return true; + case 0x12: HandlePacketPlayerLook(a_ByteBuffer); return true; + case 0x13: HandlePacketVehicleMove(a_ByteBuffer); return true; + case 0x14: HandlePacketBoatSteer(a_ByteBuffer); return true; + case 0x15: break; // Pick item - not yet implemented + case 0x16: break; // Craft Recipe Request - not yet implemented + case 0x17: HandlePacketPlayerAbilities(a_ByteBuffer); return true; + case 0x18: HandlePacketBlockDig(a_ByteBuffer); return true; + case 0x19: HandlePacketEntityAction(a_ByteBuffer); return true; + case 0x1a: HandlePacketSteerVehicle(a_ByteBuffer); return true; + case 0x1b: HandlePacketCraftingBookData(a_ByteBuffer); return true; + case 0x1d: break; // Resource pack status - not yet implemented + case 0x1e: HandlePacketAdvancementTab(a_ByteBuffer); return true; + case 0x20: HandlePacketSetBeaconEffect(a_ByteBuffer); return true; + case 0x21: HandlePacketSlotSelect(a_ByteBuffer); return true; + case 0x24: HandlePacketCreativeInventoryAction(a_ByteBuffer); return true; + case 0x26: HandlePacketUpdateSign(a_ByteBuffer); return true; + case 0x27: HandlePacketAnimation(a_ByteBuffer); return true; + case 0x28: HandlePacketSpectate(a_ByteBuffer); return true; + case 0x29: HandlePacketBlockPlace(a_ByteBuffer); return true; + case 0x2a: HandlePacketUseItem(a_ByteBuffer); return true; + } + + return Super::HandlePacket(a_ByteBuffer, a_PacketType); } -UInt32 cProtocol_1_13::GetProtocolStatisticType(Statistic a_Statistic) +void cProtocol_1_13::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) { - return Palette_1_13::From(a_Statistic); + HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); + + // If the plugin channel is recognized vanilla, handle it directly: + if (Channel.substr(0, 15) == "minecraft:brand") + { + HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Brand); + m_Client->SetClientBrand(Brand); + + // Send back our brand, including the length: + m_Client->SendPluginMessage("minecraft:brand", "\x08""Cuberite"); + return; + } + + ContiguousByteBuffer Data; + + // Read the plugin message and relay to clienthandle: + VERIFY(a_ByteBuffer.ReadSome(Data, a_ByteBuffer.GetReadableSpace())); // Always succeeds + m_Client->HandlePluginMessage(Channel, Data); +} + + + + + +void cProtocol_1_13::HandlePacketSetBeaconEffect(cByteBuffer & a_ByteBuffer) +{ + HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect1); + HANDLE_READ(a_ByteBuffer, ReadVarInt32, UInt32, Effect2); + m_Client->HandleBeaconSelection(Effect1, Effect2); } -bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) +bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) const { HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemID); if (ItemID == -1) @@ -724,35 +724,7 @@ bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t -void cProtocol_1_13::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) -{ - short ItemType = a_Item.m_ItemType; - ASSERT(ItemType >= -1); // Check validity of packets in debug runtime - if (ItemType <= 0) - { - // Fix, to make sure no invalid values are sent. - ItemType = -1; - } - - if (a_Item.IsEmpty()) - { - a_Pkt.WriteBEInt16(-1); - return; - } - - // Normal item - a_Pkt.WriteBEInt16(static_cast(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage))); - a_Pkt.WriteBEInt8(a_Item.m_ItemCount); - - // TODO: NBT - a_Pkt.WriteBEInt8(0); -} - - - - - -void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const EntityMetadata a_Metadata, const EntityMetadataType a_FieldType) +void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const EntityMetadata a_Metadata, const EntityMetadataType a_FieldType) const { a_Pkt.WriteBEUInt8(GetEntityMetadataID(a_Metadata)); // Index a_Pkt.WriteBEUInt8(GetEntityMetadataID(a_FieldType)); // Type @@ -762,7 +734,7 @@ void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const EntityMetada -void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) +void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) const { // Common metadata: Int8 Flags = 0; @@ -809,7 +781,7 @@ void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_ a_Pkt.WriteBEUInt8(static_cast(Player.GetSkinParts())); WriteEntityMetadata(a_Pkt, EntityMetadata::PlayerMainHand, EntityMetadataType::Byte); - a_Pkt.WriteBEUInt8(static_cast(Player.GetMainHand())); + a_Pkt.WriteBEUInt8(Player.IsLeftHanded() ? 0 : 1); break; } case cEntity::etPickup: @@ -953,7 +925,35 @@ void cProtocol_1_13::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_ -void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) +void cProtocol_1_13::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) const +{ + short ItemType = a_Item.m_ItemType; + ASSERT(ItemType >= -1); // Check validity of packets in debug runtime + if (ItemType <= 0) + { + // Fix, to make sure no invalid values are sent. + ItemType = -1; + } + + if (a_Item.IsEmpty()) + { + a_Pkt.WriteBEInt16(-1); + return; + } + + // Normal item + a_Pkt.WriteBEInt16(static_cast(GetProtocolItemType(a_Item.m_ItemType, a_Item.m_ItemDamage))); + a_Pkt.WriteBEInt8(a_Item.m_ItemCount); + + // TODO: NBT + a_Pkt.WriteBEInt8(0); +} + + + + + +void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mob) const { // Living Enitiy Metadata if (a_Mob.HasCustomName()) @@ -1444,45 +1444,45 @@ void cProtocol_1_13_1::SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSk -cProtocol::Version cProtocol_1_13_1::GetProtocolVersion() +std::pair cProtocol_1_13_1::GetItemFromProtocolID(UInt32 a_ProtocolID) const { - return Version::v1_13_1; + return PaletteUpgrade::ToItem(Palette_1_13_1::ToItem(a_ProtocolID)); } -std::pair cProtocol_1_13_1::GetItemFromProtocolID(UInt32 a_ProtocolID) +UInt32 cProtocol_1_13_1::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const { - return PaletteUpgrade::ToItem(Palette_1_13_1::ToItem(a_ProtocolID)); + return Palette_1_13_1::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); } -UInt32 cProtocol_1_13_1::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +UInt32 cProtocol_1_13_1::GetProtocolItemType(short a_ItemID, short a_ItemDamage) const { - return Palette_1_13_1::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); + return Palette_1_13_1::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); } -UInt32 cProtocol_1_13_1::GetProtocolItemType(short a_ItemID, short a_ItemDamage) +UInt32 cProtocol_1_13_1::GetProtocolStatisticType(Statistic a_Statistic) const { - return Palette_1_13_1::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); + return Palette_1_13_1::From(a_Statistic); } -UInt32 cProtocol_1_13_1::GetProtocolStatisticType(Statistic a_Statistic) +cProtocol::Version cProtocol_1_13_1::GetProtocolVersion() const { - return Palette_1_13_1::From(a_Statistic); + return Version::v1_13_1; } @@ -1492,7 +1492,7 @@ UInt32 cProtocol_1_13_1::GetProtocolStatisticType(Statistic a_Statistic) //////////////////////////////////////////////////////////////////////////////// // cProtocol_1_13_2: -cProtocol::Version cProtocol_1_13_2::GetProtocolVersion() +cProtocol::Version cProtocol_1_13_2::GetProtocolVersion() const { return Version::v1_13_2; } @@ -1501,7 +1501,7 @@ cProtocol::Version cProtocol_1_13_2::GetProtocolVersion() -bool cProtocol_1_13_2::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) +bool cProtocol_1_13_2::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) const { HANDLE_PACKET_READ(a_ByteBuffer, ReadBool, bool, Present); if (!Present) @@ -1538,7 +1538,7 @@ bool cProtocol_1_13_2::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size -void cProtocol_1_13_2::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) +void cProtocol_1_13_2::WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) const { short ItemType = a_Item.m_ItemType; ASSERT(ItemType >= -1); // Check validity of packets in debug runtime -- cgit v1.2.3