14 #include "../Entities/Boat.h"
15 #include "../Entities/EnderCrystal.h"
16 #include "../Entities/Minecart.h"
17 #include "../Entities/Pickup.h"
18 #include "../Entities/Player.h"
19 #include "../Entities/ItemFrame.h"
20 #include "../Entities/ArrowEntity.h"
21 #include "../Entities/FireworkEntity.h"
22 #include "../Entities/SplashPotionEntity.h"
24 #include "../Mobs/IncludeAllMonsters.h"
26 #include "../CompositeChat.h"
27 #include "../ClientHandle.h"
29 #include "../Server.h"
31 #include "../JsonUtils.h"
32 #include "../WorldStorage/FastNBT.h"
35 #include "../Bindings/PluginManager.h"
67 for (
const auto & Change : a_Changes)
69 Int16 Coords =
static_cast<Int16>(Change.m_RelY | (Change.m_RelZ << 8) | (Change.m_RelX << 12));
123 for (
const auto & [Statistic, Value] : a_Manager.
Custom)
140 for (
const auto & [Statistic, Value] : a_Manager.
Custom)
143 if (ID ==
static_cast<UInt32>(-1))
218 const UInt8 Entity = 6;
219 const UInt8 Living = Entity + 5;
220 const UInt8 Insentient = Living + 1;
221 const UInt8 Ageable = Insentient + 1;
222 const UInt8 AbstractHorse = Ageable + 2;
223 const UInt8 ChestedHorse = AbstractHorse + 1;
224 const UInt8 TameableAnimal = Ageable + 2;
345 UNREACHABLE(
"Retrieved invalid metadata for protocol");
376 UNREACHABLE(
"Translated invalid metadata type for protocol");
394 switch (a_PacketType)
495 case mtBat:
return 3;
496 case mtCat:
return 48;
500 case mtCod:
return 8;
501 case mtCow:
return 9;
525 case mtPig:
return 51;
542 case mtVex:
return 78;
587 switch (a_PacketType)
638 LOGD(
"New item name : %s", NewItemName);
682 if (a_Channel ==
"brand")
773 auto & Player =
static_cast<const cPlayer &
>(a_Entity);
782 a_Pkt.
WriteBEFloat(
static_cast<float>(Player.GetHealth()));
816 const cItem & MinecartContent = RideableMinecart.GetContent();
817 if (!MinecartContent.
IsEmpty())
842 switch (Projectile.GetProjectileKind())
875 auto & Boat =
static_cast<const cBoat &
>(a_Entity);
890 a_Pkt.
WriteBool(Boat.IsRightPaddleUsed());
893 a_Pkt.
WriteBool(
static_cast<bool>(Boat.IsLeftPaddleUsed()));
903 const auto & Frame =
static_cast<const cItemFrame &
>(a_Entity);
913 const auto & EnderCrystal =
static_cast<const cEnderCrystal &
>(a_Entity);
914 if (EnderCrystal.DisplaysBeam())
921 a_Pkt.
WriteBool(EnderCrystal.ShowsBottom());
985 auto & Bat =
static_cast<const cBat &
>(a_Mob);
1003 auto & Cow =
static_cast<const cCow &
>(a_Mob);
1027 auto & Enderman =
static_cast<const cEnderman &
>(a_Mob);
1030 Carried |=
static_cast<UInt32>(Enderman.GetCarriedBlock() << 4);
1031 Carried |= Enderman.GetCarriedMeta();
1035 a_Pkt.
WriteBool(Enderman.IsScreaming());
1041 auto & Ghast =
static_cast<const cGhast &
>(a_Mob);
1053 auto & Horse =
static_cast<const cHorse &
>(a_Mob);
1060 if (Horse.IsSaddled())
1064 if (Horse.IsInLoveCooldown())
1068 if (Horse.IsEating())
1072 if (Horse.IsRearing())
1076 if (Horse.IsMthOpen())
1085 Appearance = Horse.GetHorseColor();
1086 Appearance |= Horse.GetHorseStyle() << 8;
1100 auto & MagmaCube =
static_cast<const cMagmaCube &
>(a_Mob);
1109 auto & Ocelot =
static_cast<const cOcelot &
>(a_Mob);
1114 Int8 OcelotStatus = 0;
1115 if (Ocelot.IsSitting())
1117 OcelotStatus |= 0x1;
1119 if (Ocelot.IsTame())
1121 OcelotStatus |= 0x4;
1134 auto & Pig =
static_cast<const cPig &
>(a_Mob);
1160 auto & Sheep =
static_cast<const cSheep &
>(a_Mob);
1165 Int8 SheepMetadata = 0;
1166 SheepMetadata =
static_cast<Int8>(Sheep.GetFurColor());
1167 if (Sheep.IsSheared())
1169 SheepMetadata |= 0x10;
1178 auto & Skeleton =
static_cast<const cSkeleton &
>(a_Mob);
1180 a_Pkt.
WriteBEUInt8(Skeleton.IsChargingBow() ? 0x01 : 0x00);
1183 a_Pkt.
WriteBool(Skeleton.IsChargingBow());
1189 auto & Slime =
static_cast<const cSlime &
>(a_Mob);
1198 auto & Villager =
static_cast<const cVillager &
>(a_Mob);
1210 auto & Witch =
static_cast<const cWitch &
>(a_Mob);
1219 auto & Wither =
static_cast<const cWither &
>(a_Mob);
1230 auto & Wolf =
static_cast<const cWolf &
>(a_Mob);
1235 Int8 WolfStatus = 0;
1236 if (Wolf.IsSitting())
1266 auto & Zombie =
static_cast<const cZombie &
>(a_Mob);
1275 auto & ZombiePigman =
static_cast<const cZombiePigman &
>(a_Mob);
1342 ASSERT(!
"cProtocol_1_13::WriteMobMetadata: received unimplemented type");
1363 default:
UNREACHABLE(
"cProtocol_1_13::WriteMobMetadata: received mob of invalid type");
1401 switch (a_DivisionType)
@ E_BLOCK_STANDING_BANNER
@ E_BLOCK_ENCHANTMENT_TABLE
std::vector< sSetBlock > sSetBlockVector
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
std::basic_string< std::byte > ContiguousByteBuffer
eMonsterType
Identifies individual monster type.
#define HANDLE_PACKET_READ(ByteBuf, Proc, Type, Var)
#define HANDLE_READ(ByteBuf, Proc, Type, Var)
Macros used to read packets more easily.
std::vector< AString > AStringVector
UInt32 From(const BlockState Block)
Item ToItem(const UInt32 ID)
Item ToItem(const UInt32 ID)
UInt32 From(const BlockState Block)
Item FromItem(const short Item, const short Damage)
std::pair< short, short > ToItem(const Item ID)
BlockState FromBlock(const BLOCKTYPE Block, const NIBBLETYPE Meta)
std::pair< Namespace, std::string_view > SplitNamespacedID(std::string_view ID)
BLOCKTYPE GetBlockType() const
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes ar...
size_t GetReadableSpace(void) const
Returns the number of bytes that are currently available for reading (may be less than UsedSpace due ...
bool ReadSome(ContiguousByteBuffer &a_String, size_t a_Count)
Reads a_Count bytes into a_String; returns true if successful.
void SetClientBrand(const AString &a_ClientBrand)
Called by the protocol when it receives the MC|Brand plugin message.
void SendPluginMessage(const AString &a_Channel, std::string_view a_Message)
void HandlePluginMessage(const AString &a_Channel, ContiguousByteBufferView a_Message)
void HandleBeaconSelection(unsigned a_PrimaryEffect, unsigned a_SecondaryEffect)
Called when the protocol receives a MC|Beacon plugin message, indicating that the player set an effec...
Container for a single chat message composed of multiple functional parts.
AString CreateJsonString(bool a_ShouldUseChatPrefixes=true) const
virtual bool IsRclking(void) const
virtual bool IsCrouched(void) const
float GetMaxHealth(void) const
eEntityType GetEntityType(void) const
virtual bool IsOnFire(void) const
virtual bool IsInvisible(void) const
float GetHealth(void) const
Returns the health of this entity.
virtual bool IsSprinting(void) const
bool IsEmpty(void) const
Returns true if the item represents an empty stack - either the type is invalid, or count is zero.
void Empty(void)
Empties the item and frees up any dynamic storage used by the internals.
Encapsulates an in-game world map.
bool HasCustomName(void) const
Returns true if the monster has a custom name.
const AString & GetCustomName(void) const
Gets the custom name of the monster.
bool IsCustomNameAlwaysVisible(void) const
Is the custom name of this monster always visible? If not, you only see the name when you sight the m...
eMonsterType GetMobType(void) const
Composes an individual packet in the protocol's m_OutPacketBuffer; sends it just before being destruc...
void WriteVarInt32(UInt32 a_Value)
void WriteBEInt32(Int32 a_Value)
void WriteBool(bool a_Value)
void WriteXYZPosition64(int a_BlockX, int a_BlockY, int a_BlockZ)
Writes the specified block position as a single encoded 64-bit BigEndian integer.
void WriteBEUInt64(UInt64 a_Value)
void WriteBEFloat(float a_Value)
void WriteBEInt16(Int16 a_Value)
void WriteString(const AString &a_Value)
void WriteBEUInt8(UInt8 a_Value)
void WriteBuf(const ContiguousByteBufferView a_Data)
void WriteBEInt8(Int8 a_Value)
ePacketType
Logical types of outgoing packets.
@ pktTabCompletionResults
@ pktPlayerListHeaderFooter
@ pktDisconnectDuringGame
Version
The protocol version number, received from the client in the Handshake packet.
@ ShulkerAttachmentFallingBlockPosition
@ ZombieVillagerProfession
@ MinecartCommandBlockCommand
@ FireworkBoostedEntityId
@ PlayerDisplayedSkinParts
@ MinecartShakingDirection
@ MinecartCommandBlockLastOutput
@ LivingPotionEffectColor
@ ArmorStandLeftLegRotation
@ PigTotalCarrotOnAStickBoost
@ ZombieVillagerConverting
@ WitherSkullInvulnerable
@ AreaEffectCloudSinglePointEffect
@ LivingPotionEffectAmbient
@ AbstractSkeletonArmsSwinging
@ AreaEffectCloudParticleParameter1
@ ArmorStandRightArmRotation
@ AreaEffectCloudParticleParameter2
@ AreaEffectCloudParticleId
@ ArmorStandRightLegRotation
@ WitherInvulnerableTimer
@ MinecartShakingMultiplier
@ EntityCustomNameVisible
@ ArmorStandLeftArmRotation
virtual void WriteBlockEntity(cFastNBTWriter &a_Writer, const cBlockEntity &a_BlockEntity) const override
Writes the block entity data for the specified block entity into the packet.
virtual void HandlePacketBlockPlace(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketAdvancementTab(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketCraftingBookData(cByteBuffer &a_ByteBuffer)
virtual signed char GetProtocolEntityStatus(EntityAnimation a_Animation) const override
Converts an animation into an ID suitable for use with the Entity Status packet.
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual UInt32 GetPacketID(ePacketType a_Packet) const override
Get the packet ID for a given packet.
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer) override
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item) const override
Writes the item data into a packet.
virtual std::pair< short, short > GetItemFromProtocolID(UInt32 a_ProtocolID) const
virtual void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity) override
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual void HandlePacketNameItem(cByteBuffer &a_ByteBuffer)
virtual void SendStatistics(const StatisticsManager &a_Manager) override
virtual UInt32 GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const
virtual void SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockVector &a_Changes) override
virtual void HandlePacketSetBeaconEffect(cByteBuffer &a_ByteBuffer)
virtual void WriteMobMetadata(cPacketizer &a_Pkt, const cMonster &a_Mob) const override
Writes the mob-specific metadata for the specified mob.
virtual void SendTabCompletionResults(const AStringVector &a_Results) override
virtual void SendPaintingSpawn(const cPainting &a_Painting) override
virtual void WriteEntityMetadata(cPacketizer &a_Pkt, EntityMetadata a_Metadata, EntityMetadataType a_FieldType) const
virtual bool ReadItem(cByteBuffer &a_ByteBuffer, cItem &a_Item, size_t a_KeepRemainingBytes) const override
Reads an item out of the received data, sets a_Item to the values read.
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual UInt8 GetEntityMetadataID(EntityMetadata a_Metadata) const
virtual void HandlePacketPluginMessage(cByteBuffer &a_ByteBuffer) override
virtual UInt32 GetProtocolItemType(short a_ItemID, short a_ItemDamage) const
virtual void SendParticleEffect(const AString &a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, std::array< int, 2 > a_Data) override
virtual UInt32 GetProtocolStatisticType(CustomStatistic a_Statistic) const
virtual void SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY) override
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) const override
Converts eMonsterType to protocol-specific mob types.
virtual signed char GetProtocolEntityStatus(EntityAnimation a_Animation) const override
Converts an animation into an ID suitable for use with the Entity Status packet.
virtual void SendScoreboardObjective(const AString &a_Name, const AString &a_DisplayName, Byte a_Mode) override
virtual UInt32 GetPacketID(ePacketType a_PacketType) const override
Get the packet ID for a given packet.
virtual void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual void HandleVanillaPluginMessage(cByteBuffer &a_ByteBuffer, std::string_view a_Channel) override
Parses Vanilla plugin messages into specific ClientHandle calls.
virtual UInt32 GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const override
virtual UInt32 GetProtocolItemType(short a_ItemID, short a_ItemDamage) const override
virtual void SendBossBarUpdateFlags(UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog) override
virtual void SendBossBarAdd(UInt32 a_UniqueID, const cCompositeChat &a_Title, float a_FractionFilled, BossBarColor a_Color, BossBarDivisionType a_DivisionType, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog) override
virtual std::pair< short, short > GetItemFromProtocolID(UInt32 a_ProtocolID) const override
virtual UInt32 GetProtocolStatisticType(CustomStatistic a_Statistic) const override
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual bool ReadItem(cByteBuffer &a_ByteBuffer, cItem &a_Item, size_t a_KeepRemainingBytes) const override
Reads an item out of the received data, sets a_Item to the values read.
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item) const override
Writes the item data into a packet.
virtual void HandlePacketPlayer(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketEnchantItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketCreativeInventoryAction(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClose(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketPlayerAbilities(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketChatMessage(cByteBuffer &a_ByteBuffer)
State m_State
State of the protocol.
virtual void HandlePacketPlayerLook(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketClientStatus(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSlotSelect(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSpectate(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSteerVehicle(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketUseEntity(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketPlayerPos(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketUseItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClick(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketClientSettings(cByteBuffer &a_ByteBuffer) override
virtual void ParseItemMetadata(cItem &a_Item, ContiguousByteBufferView a_Metadata) const override
Parses item metadata as read by ReadItem(), into the item enchantments.
virtual void HandlePacketEntityAction(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketPlayerPosLook(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketBoatSteer(cByteBuffer &a_ByteBuffer)
virtual void HandleConfirmTeleport(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketUpdateSign(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketBlockDig(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketAnimation(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketVehicleMove(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketTabComplete(cByteBuffer &a_ByteBuffer) override
Class that manages the statistics and achievements of a single player.
std::unordered_map< CustomStatistic, StatValue > Custom
ContiguousByteBufferView GetResult(void) const