diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-04-10 16:57:16 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2021-04-12 23:35:07 +0200 |
commit | a999c5d845bd759c6d83b356c7b39e67473dc452 (patch) | |
tree | c8da72f5192293648f30b3228e7563fa7c79d13e /src/Protocol/Protocol_1_13.cpp | |
parent | Add animations for shield/item block & break (diff) | |
download | cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.tar cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.tar.gz cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.tar.bz2 cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.tar.lz cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.tar.xz cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.tar.zst cuberite-a999c5d845bd759c6d83b356c7b39e67473dc452.zip |
Diffstat (limited to 'src/Protocol/Protocol_1_13.cpp')
-rw-r--r-- | src/Protocol/Protocol_1_13.cpp | 566 |
1 files changed, 283 insertions, 283 deletions
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,107 +238,180 @@ void cProtocol_1_13::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) -bool cProtocol_1_13::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) +UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata) const { - if (m_State != 3) - { - return Super::HandlePacket(a_ByteBuffer, a_PacketType); - } + const UInt8 Entity = 6; + const UInt8 Living = Entity + 5; + const UInt8 Insentient = Living + 1; + const UInt8 Ageable = Insentient + 1; + const UInt8 AbstractHorse = Ageable + 2; + const UInt8 ChestedHorse = AbstractHorse + 1; + const UInt8 TameableAnimal = Ageable + 2; + const UInt8 Minecart = Entity + 6; - // Game - switch (a_PacketType) + switch (a_Metadata) { - 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; - } + case EntityMetadata::EntityFlags: return 0; + case EntityMetadata::EntityAir: return 1; + case EntityMetadata::EntityCustomName: return 2; + case EntityMetadata::EntityCustomNameVisible: return 3; + case EntityMetadata::EntitySilent: return 4; + case EntityMetadata::EntityNoGravity: return 5; + case EntityMetadata::PotionThrown: return Entity; + case EntityMetadata::FallingBlockPosition: return Entity; + case EntityMetadata::AreaEffectCloudRadius: return Entity; + case EntityMetadata::AreaEffectCloudColor: return Entity + 1; + case EntityMetadata::AreaEffectCloudSinglePointEffect: return Entity + 2; + case EntityMetadata::AreaEffectCloudParticleId: return Entity + 3; + case EntityMetadata::ArrowFlags: return Entity; + case EntityMetadata::TippedArrowColor: return Entity + 1; + case EntityMetadata::BoatLastHitTime: return Entity; + case EntityMetadata::BoatForwardDirection: return Entity + 1; + case EntityMetadata::BoatDamageTaken: return Entity + 2; + case EntityMetadata::BoatType: return Entity + 3; + case EntityMetadata::BoatLeftPaddleTurning: return Entity + 4; + case EntityMetadata::BoatRightPaddleTurning: return Entity + 5; + case EntityMetadata::BoatSplashTimer: return Entity + 6; + case EntityMetadata::EnderCrystalBeamTarget: return Entity; + case EntityMetadata::EnderCrystalShowBottom: return Entity + 1; + case EntityMetadata::WitherSkullInvulnerable: return Entity; + case EntityMetadata::FireworkInfo: return Entity; + case EntityMetadata::FireworkBoostedEntityId: return Entity + 1; + case EntityMetadata::ItemFrameItem: return Entity; + case EntityMetadata::ItemFrameRotation: return Entity + 1; + case EntityMetadata::ItemItem: return Entity; + case EntityMetadata::LivingActiveHand: return Entity; + case EntityMetadata::LivingHealth: return Entity + 1; + case EntityMetadata::LivingPotionEffectColor: return Entity + 2; + case EntityMetadata::LivingPotionEffectAmbient: return Entity + 3; + case EntityMetadata::LivingNumberOfArrows: return Entity + 4; + case EntityMetadata::PlayerAdditionalHearts: return Living; + case EntityMetadata::PlayerScore: return Living + 1; + case EntityMetadata::PlayerDisplayedSkinParts: return Living + 2; + case EntityMetadata::PlayerMainHand: return Living + 3; + case EntityMetadata::ArmorStandStatus: return Living; + case EntityMetadata::ArmorStandHeadRotation: return Living + 1; + case EntityMetadata::ArmorStandBodyRotation: return Living + 2; + case EntityMetadata::ArmorStandLeftArmRotation: return Living + 3; + case EntityMetadata::ArmorStandRightArmRotation: return Living + 4; + case EntityMetadata::ArmorStandLeftLegRotation: return Living + 5; + case EntityMetadata::ArmorStandRightLegRotation: return Living + 6; + case EntityMetadata::InsentientFlags: return Living; + case EntityMetadata::BatHanging: return Insentient; + case EntityMetadata::AgeableIsBaby: return Insentient; + case EntityMetadata::AbstractHorseFlags: return Ageable; + case EntityMetadata::AbstractHorseOwner: return Ageable + 1; + case EntityMetadata::HorseVariant: return AbstractHorse; + case EntityMetadata::HorseArmour: return AbstractHorse + 1; + case EntityMetadata::ChestedHorseChested: return AbstractHorse; + case EntityMetadata::LlamaStrength: return ChestedHorse; + case EntityMetadata::LlamaCarpetColor: return ChestedHorse + 1; + case EntityMetadata::LlamaVariant: return ChestedHorse + 2; + case EntityMetadata::PigHasSaddle: return Ageable; + case EntityMetadata::PigTotalCarrotOnAStickBoost: return Ageable + 1; + case EntityMetadata::RabbitType: return Ageable; + case EntityMetadata::PolarBearStanding: return Ageable; + case EntityMetadata::SheepFlags: return Ageable; + case EntityMetadata::TameableAnimalFlags: return Ageable; + case EntityMetadata::TameableAnimalOwner: return Ageable + 1; + case EntityMetadata::OcelotType: return TameableAnimal; + case EntityMetadata::WolfDamageTaken: return TameableAnimal; + case EntityMetadata::WolfBegging: return TameableAnimal + 1; + case EntityMetadata::WolfCollarColour: return TameableAnimal + 2; + case EntityMetadata::VillagerProfession: return Ageable; + case EntityMetadata::IronGolemPlayerCreated: return Insentient; + case EntityMetadata::ShulkerFacingDirection: return Insentient; + case EntityMetadata::ShulkerAttachmentFallingBlockPosition: return Insentient + 1; + case EntityMetadata::ShulkerShieldHeight: return Insentient + 2; + case EntityMetadata::BlazeOnFire: return Insentient; + case EntityMetadata::CreeperState: return Insentient; + case EntityMetadata::CreeperPowered: return Insentient + 1; + case EntityMetadata::CreeperIgnited: return Insentient + 2; + case EntityMetadata::GuardianStatus: return Insentient; + case EntityMetadata::GuardianTarget: return Insentient + 1; + case EntityMetadata::IllagerFlags: return Insentient; + case EntityMetadata::SpeIlagerSpell: return Insentient + 1; + case EntityMetadata::VexFlags: return Insentient; + case EntityMetadata::SpiderClimbing: return Insentient; + case EntityMetadata::WitchAggresive: return Insentient; + case EntityMetadata::WitherFirstHeadTarget: return Insentient; + case EntityMetadata::WitherSecondHeadTarget: return Insentient + 1; + case EntityMetadata::WitherThirdHeadTarget: return Insentient + 2; + case EntityMetadata::WitherInvulnerableTimer: return Insentient + 3; + case EntityMetadata::ZombieIsBaby: return Insentient; + case EntityMetadata::ZombieHandsRisedUp: return Insentient + 2; + case EntityMetadata::ZombieVillagerConverting: return Insentient + 4; + case EntityMetadata::ZombieVillagerProfession: return Insentient + 5; + case EntityMetadata::EndermanCarriedBlock: return Insentient; + case EntityMetadata::EndermanScreaming: return Insentient + 1; + case EntityMetadata::EnderDragonDragonPhase: return Insentient; + case EntityMetadata::GhastAttacking: return Insentient; + case EntityMetadata::SlimeSize: return Insentient; + case EntityMetadata::MinecartShakingPower: return Entity; + case EntityMetadata::MinecartShakingDirection: return Entity + 1; + case EntityMetadata::MinecartShakingMultiplier: return Entity + 2; + case EntityMetadata::MinecartBlockIDMeta: return Entity + 3; + case EntityMetadata::MinecartBlockY: return Entity + 4; + case EntityMetadata::MinecartShowBlock: return Entity + 5; + case EntityMetadata::MinecartCommandBlockCommand: return Minecart; + case EntityMetadata::MinecartCommandBlockLastOutput: return Minecart + 1; + case EntityMetadata::MinecartFurnacePowered: return Minecart; + case EntityMetadata::TNTPrimedFuseTime: return Entity; - return Super::HandlePacket(a_ByteBuffer, a_PacketType); + case EntityMetadata::EntityPose: + case EntityMetadata::AreaEffectCloudParticleParameter1: + case EntityMetadata::AreaEffectCloudParticleParameter2: + case EntityMetadata::AbstractSkeletonArmsSwinging: + case EntityMetadata::ZombieUnusedWasType: break; + } + UNREACHABLE("Retrieved invalid metadata for protocol"); } -void cProtocol_1_13::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) +UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadataType a_FieldType) const { - HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Channel); - - // If the plugin channel is recognized vanilla, handle it directly: - if (Channel.substr(0, 15) == "minecraft:brand") + switch (a_FieldType) { - 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; + 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; } - - 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); + UNREACHABLE("Translated invalid metadata type for protocol"); } -cProtocol::Version cProtocol_1_13::GetProtocolVersion() +std::pair<short, short> cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolID) const { - return Version::v1_13; + return PaletteUpgrade::ToItem(Palette_1_13::ToItem(a_ProtocolID)); } -UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) +UInt32 cProtocol_1_13::GetPacketID(ePacketType a_PacketType) const { switch (a_PacketType) { @@ -403,6 +476,15 @@ UInt32 cProtocol_1_13::GetPacketID(ePacketType 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) @@ -416,7 +498,16 @@ signed char cProtocol_1_13::GetProtocolEntityStatus(const EntityAnimation a_Anim -UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType) +UInt32 cProtocol_1_13::GetProtocolItemType(short a_ItemID, short a_ItemDamage) const +{ + return Palette_1_13::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); +} + + + + + +UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType) const { switch (a_MobType) { @@ -488,207 +579,116 @@ UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType) -UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata) +UInt32 cProtocol_1_13::GetProtocolStatisticType(Statistic a_Statistic) const { - const UInt8 Entity = 6; - const UInt8 Living = Entity + 5; - const UInt8 Insentient = Living + 1; - const UInt8 Ageable = Insentient + 1; - const UInt8 AbstractHorse = Ageable + 2; - const UInt8 ChestedHorse = AbstractHorse + 1; - const UInt8 TameableAnimal = Ageable + 2; - const UInt8 Minecart = Entity + 6; - - switch (a_Metadata) - { - case EntityMetadata::EntityFlags: return 0; - case EntityMetadata::EntityAir: return 1; - case EntityMetadata::EntityCustomName: return 2; - case EntityMetadata::EntityCustomNameVisible: return 3; - case EntityMetadata::EntitySilent: return 4; - case EntityMetadata::EntityNoGravity: return 5; - case EntityMetadata::PotionThrown: return Entity; - case EntityMetadata::FallingBlockPosition: return Entity; - case EntityMetadata::AreaEffectCloudRadius: return Entity; - case EntityMetadata::AreaEffectCloudColor: return Entity + 1; - case EntityMetadata::AreaEffectCloudSinglePointEffect: return Entity + 2; - case EntityMetadata::AreaEffectCloudParticleId: return Entity + 3; - case EntityMetadata::ArrowFlags: return Entity; - case EntityMetadata::TippedArrowColor: return Entity + 1; - case EntityMetadata::BoatLastHitTime: return Entity; - case EntityMetadata::BoatForwardDirection: return Entity + 1; - case EntityMetadata::BoatDamageTaken: return Entity + 2; - case EntityMetadata::BoatType: return Entity + 3; - case EntityMetadata::BoatLeftPaddleTurning: return Entity + 4; - case EntityMetadata::BoatRightPaddleTurning: return Entity + 5; - case EntityMetadata::BoatSplashTimer: return Entity + 6; - case EntityMetadata::EnderCrystalBeamTarget: return Entity; - case EntityMetadata::EnderCrystalShowBottom: return Entity + 1; - case EntityMetadata::WitherSkullInvulnerable: return Entity; - case EntityMetadata::FireworkInfo: return Entity; - case EntityMetadata::FireworkBoostedEntityId: return Entity + 1; - case EntityMetadata::ItemFrameItem: return Entity; - case EntityMetadata::ItemFrameRotation: return Entity + 1; - case EntityMetadata::ItemItem: return Entity; - case EntityMetadata::LivingActiveHand: return Entity; - case EntityMetadata::LivingHealth: return Entity + 1; - case EntityMetadata::LivingPotionEffectColor: return Entity + 2; - case EntityMetadata::LivingPotionEffectAmbient: return Entity + 3; - case EntityMetadata::LivingNumberOfArrows: return Entity + 4; - case EntityMetadata::PlayerAdditionalHearts: return Living; - case EntityMetadata::PlayerScore: return Living + 1; - case EntityMetadata::PlayerDisplayedSkinParts: return Living + 2; - case EntityMetadata::PlayerMainHand: return Living + 3; - case EntityMetadata::ArmorStandStatus: return Living; - case EntityMetadata::ArmorStandHeadRotation: return Living + 1; - case EntityMetadata::ArmorStandBodyRotation: return Living + 2; - case EntityMetadata::ArmorStandLeftArmRotation: return Living + 3; - case EntityMetadata::ArmorStandRightArmRotation: return Living + 4; - case EntityMetadata::ArmorStandLeftLegRotation: return Living + 5; - case EntityMetadata::ArmorStandRightLegRotation: return Living + 6; - case EntityMetadata::InsentientFlags: return Living; - case EntityMetadata::BatHanging: return Insentient; - case EntityMetadata::AgeableIsBaby: return Insentient; - case EntityMetadata::AbstractHorseFlags: return Ageable; - case EntityMetadata::AbstractHorseOwner: return Ageable + 1; - case EntityMetadata::HorseVariant: return AbstractHorse; - case EntityMetadata::HorseArmour: return AbstractHorse + 1; - case EntityMetadata::ChestedHorseChested: return AbstractHorse; - case EntityMetadata::LlamaStrength: return ChestedHorse; - case EntityMetadata::LlamaCarpetColor: return ChestedHorse + 1; - case EntityMetadata::LlamaVariant: return ChestedHorse + 2; - case EntityMetadata::PigHasSaddle: return Ageable; - case EntityMetadata::PigTotalCarrotOnAStickBoost: return Ageable + 1; - case EntityMetadata::RabbitType: return Ageable; - case EntityMetadata::PolarBearStanding: return Ageable; - case EntityMetadata::SheepFlags: return Ageable; - case EntityMetadata::TameableAnimalFlags: return Ageable; - case EntityMetadata::TameableAnimalOwner: return Ageable + 1; - case EntityMetadata::OcelotType: return TameableAnimal; - case EntityMetadata::WolfDamageTaken: return TameableAnimal; - case EntityMetadata::WolfBegging: return TameableAnimal + 1; - case EntityMetadata::WolfCollarColour: return TameableAnimal + 2; - case EntityMetadata::VillagerProfession: return Ageable; - case EntityMetadata::IronGolemPlayerCreated: return Insentient; - case EntityMetadata::ShulkerFacingDirection: return Insentient; - case EntityMetadata::ShulkerAttachmentFallingBlockPosition: return Insentient + 1; - case EntityMetadata::ShulkerShieldHeight: return Insentient + 2; - case EntityMetadata::BlazeOnFire: return Insentient; - case EntityMetadata::CreeperState: return Insentient; - case EntityMetadata::CreeperPowered: return Insentient + 1; - case EntityMetadata::CreeperIgnited: return Insentient + 2; - case EntityMetadata::GuardianStatus: return Insentient; - case EntityMetadata::GuardianTarget: return Insentient + 1; - case EntityMetadata::IllagerFlags: return Insentient; - case EntityMetadata::SpeIlagerSpell: return Insentient + 1; - case EntityMetadata::VexFlags: return Insentient; - case EntityMetadata::SpiderClimbing: return Insentient; - case EntityMetadata::WitchAggresive: return Insentient; - case EntityMetadata::WitherFirstHeadTarget: return Insentient; - case EntityMetadata::WitherSecondHeadTarget: return Insentient + 1; - case EntityMetadata::WitherThirdHeadTarget: return Insentient + 2; - case EntityMetadata::WitherInvulnerableTimer: return Insentient + 3; - case EntityMetadata::ZombieIsBaby: return Insentient; - case EntityMetadata::ZombieHandsRisedUp: return Insentient + 2; - case EntityMetadata::ZombieVillagerConverting: return Insentient + 4; - case EntityMetadata::ZombieVillagerProfession: return Insentient + 5; - case EntityMetadata::EndermanCarriedBlock: return Insentient; - case EntityMetadata::EndermanScreaming: return Insentient + 1; - case EntityMetadata::EnderDragonDragonPhase: return Insentient; - case EntityMetadata::GhastAttacking: return Insentient; - case EntityMetadata::SlimeSize: return Insentient; - case EntityMetadata::MinecartShakingPower: return Entity; - case EntityMetadata::MinecartShakingDirection: return Entity + 1; - case EntityMetadata::MinecartShakingMultiplier: return Entity + 2; - case EntityMetadata::MinecartBlockIDMeta: return Entity + 3; - case EntityMetadata::MinecartBlockY: return Entity + 4; - case EntityMetadata::MinecartShowBlock: return Entity + 5; - case EntityMetadata::MinecartCommandBlockCommand: return Minecart; - case EntityMetadata::MinecartCommandBlockLastOutput: return Minecart + 1; - 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; - } - UNREACHABLE("Retrieved invalid metadata for protocol"); + return Palette_1_13::From(a_Statistic); } -UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadataType a_FieldType) +cProtocol::Version cProtocol_1_13::GetProtocolVersion() 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"); + return Version::v1_13; } -std::pair<short, short> cProtocol_1_13::GetItemFromProtocolID(UInt32 a_ProtocolID) +bool cProtocol_1_13::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { - return PaletteUpgrade::ToItem(Palette_1_13::ToItem(a_ProtocolID)); + 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::GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +void cProtocol_1_13::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) { - return Palette_1_13::From(PaletteUpgrade::FromBlock(a_BlockType, a_Meta)); -} - + 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; -UInt32 cProtocol_1_13::GetProtocolItemType(short a_ItemID, short a_ItemDamage) -{ - return Palette_1_13::From(PaletteUpgrade::FromItem(a_ItemID, a_ItemDamage)); + // Read the plugin message and relay to clienthandle: + VERIFY(a_ByteBuffer.ReadSome(Data, a_ByteBuffer.GetReadableSpace())); // Always succeeds + m_Client->HandlePluginMessage(Channel, Data); } -UInt32 cProtocol_1_13::GetProtocolStatisticType(Statistic a_Statistic) +void cProtocol_1_13::HandlePacketSetBeaconEffect(cByteBuffer & a_ByteBuffer) { - return Palette_1_13::From(a_Statistic); + 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<Int16>(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<UInt8>(Player.GetSkinParts())); WriteEntityMetadata(a_Pkt, EntityMetadata::PlayerMainHand, EntityMetadataType::Byte); - a_Pkt.WriteBEUInt8(static_cast<UInt8>(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<Int16>(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<short, short> 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<short, short> 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 |