14 #include "../Server.h"
16 #include "../UI/HorseWindow.h"
17 #include "../ClientHandle.h"
18 #include "../WorldStorage/FastNBT.h"
19 #include "../BlockEntities/BlockEntity.h"
21 #include "../Entities/ArrowEntity.h"
22 #include "../Entities/ItemFrame.h"
23 #include "../Mobs/Bat.h"
24 #include "../Entities/Boat.h"
25 #include "../Mobs/Chicken.h"
26 #include "../Mobs/Cow.h"
27 #include "../Mobs/Creeper.h"
28 #include "../Entities/EnderCrystal.h"
29 #include "../Mobs/Enderman.h"
30 #include "../Mobs/Ghast.h"
31 #include "../Mobs/Horse.h"
32 #include "../Mobs/MagmaCube.h"
33 #include "../Entities/Minecart.h"
34 #include "../Mobs/Ocelot.h"
35 #include "../Entities/Pickup.h"
36 #include "../Mobs/Pig.h"
37 #include "../Entities/Player.h"
38 #include "../Mobs/Rabbit.h"
39 #include "../Mobs/Sheep.h"
40 #include "../Mobs/Skeleton.h"
41 #include "../Mobs/Slime.h"
42 #include "../Mobs/Villager.h"
43 #include "../Mobs/Wolf.h"
44 #include "../Mobs/Wither.h"
45 #include "../Mobs/Zombie.h"
46 #include "../Mobs/ZombiePigman.h"
455 switch (a_PacketType)
510 const UInt8 Entity = 7;
511 const UInt8 Living = Entity + 6;
512 const UInt8 Insentient = Living + 1;
513 const UInt8 Ageable = Insentient + 1;
514 const UInt8 AbstractHorse = Ageable + 2;
515 const UInt8 ChestedHorse = AbstractHorse + 1;
516 const UInt8 TameableAnimal = Ageable + 2;
518 const UInt8 RaidParticipent = Insentient + 1;
643 UNREACHABLE(
"Retrieved invalid metadata for protocol");
701 case Type::etEnderCrystal:
return 17;
702 case Type::etPickup:
return 34;
703 case Type::etFallingBlock:
return 25;
704 case Type::etMinecart:
return 41;
705 case Type::etBoat:
return 5;
706 case Type::etTNT:
return 58;
707 case Type::etProjectile:
712 switch (Projectile.GetProjectileKind())
714 case PType::pkArrow:
return 2;
715 case PType::pkSnowball:
return 70;
716 case PType::pkEgg:
return 78;
717 case PType::pkGhastFireball:
return 36;
718 case PType::pkFireCharge:
return 68;
719 case PType::pkEnderPearl:
return 79;
720 case PType::pkExpBottle:
return 80;
721 case PType::pkSplashPotion:
return 81;
722 case PType::pkFirework:
return 26;
723 case PType::pkWitherSkull:
return 92;
727 case Type::etFloater:
return 101;
728 case Type::etItemFrame:
return 35;
729 case Type::etLeashKnot:
return 37;
734 case Type::etMonster:
736 case Type::etPainting:
break;
760 case mtBat:
return 3;
762 case mtCat:
return 6;
765 case mtCod:
return 9;
766 case mtCow:
return 10;
776 case mtFox:
return 27;
791 case mtPig:
return 54;
809 case mtVex:
return 83;
835 static const std::unordered_map<AString, int> ParticleMap
838 {
"ambiantentity", 0 },
839 {
"angryvillager", 1 },
845 {
"damageindicator", 7 },
846 {
"dragonbreath", 8 },
848 {
"fallinglava", 10 },
849 {
"landinglava", 11 },
851 {
"fallingwater", 13 },
854 {
"elderguardian", 16 },
855 {
"enchantedhit", 17 },
858 {
"entityeffect", 20 },
859 {
"explosionemitter", 21 },
861 {
"fallingdust", 23 },
866 {
"happyvillager", 28 },
869 {
"instanteffect", 31 },
873 {
"largesmoke", 35 },
884 {
"sweepattack", 46 },
886 {
"underwater", 48 },
890 {
"currentdown", 52 },
891 {
"bubblecolumnup", 53 },
894 {
"campfirecosysmoke", 56 },
895 {
"campfiresignalsmoke", 57 },
899 const auto ParticleName =
StrToLower(a_ParticleName);
900 const auto FindResult = ParticleMap.find(ParticleName);
901 if (FindResult == ParticleMap.end())
903 LOGWARNING(
"Unknown particle: %s", a_ParticleName.c_str());
904 ASSERT(!
"Unknown particle");
908 return FindResult->second;
941 switch (a_PacketType)
988 int BlockX, BlockY, BlockZ;
1006 int BlockX, BlockY, BlockZ;
1013 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, CursorX);
1014 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, CursorY);
1015 HANDLE_READ(a_ByteBuffer, ReadBEFloat,
float, CursorZ);
1016 HANDLE_READ(a_ByteBuffer, ReadBool,
bool, InsideBlock);
1085 auto & Player =
static_cast<const cPlayer &
>(a_Entity);
1094 a_Pkt.
WriteBEFloat(
static_cast<float>(Player.GetHealth()));
1128 const cItem & MinecartContent = RideableMinecart.GetContent();
1129 if (!MinecartContent.
IsEmpty())
1154 switch (Projectile.GetProjectileKind())
1189 auto & Boat =
static_cast<const cBoat &
>(a_Entity);
1204 a_Pkt.
WriteBool(Boat.IsRightPaddleUsed());
1207 a_Pkt.
WriteBool(
static_cast<bool>(Boat.IsLeftPaddleUsed()));
1217 const auto & Frame =
static_cast<const cItemFrame &
>(a_Entity);
1227 const auto & EnderCrystal =
static_cast<const cEnderCrystal &
>(a_Entity);
1228 if (EnderCrystal.DisplaysBeam())
1235 a_Pkt.
WriteBool(EnderCrystal.ShowsBottom());
1273 auto & Bat =
static_cast<const cBat &
>(a_Mob);
1291 auto & Cow =
static_cast<const cCow &
>(a_Mob);
1315 auto & Enderman =
static_cast<const cEnderman &
>(a_Mob);
1318 Carried |=
static_cast<UInt32>(Enderman.GetCarriedBlock() << 4);
1319 Carried |= Enderman.GetCarriedMeta();
1323 a_Pkt.
WriteBool(Enderman.IsScreaming());
1329 auto & Ghast =
static_cast<const cGhast &
>(a_Mob);
1341 auto & Horse =
static_cast<const cHorse &
>(a_Mob);
1348 if (Horse.IsSaddled())
1352 if (Horse.IsInLoveCooldown())
1356 if (Horse.IsEating())
1360 if (Horse.IsRearing())
1364 if (Horse.IsMthOpen())
1373 Appearance = Horse.GetHorseColor();
1374 Appearance |= Horse.GetHorseStyle() << 8;
1385 auto & MagmaCube =
static_cast<const cMagmaCube &
>(a_Mob);
1394 auto & Ocelot =
static_cast<const cOcelot &
>(a_Mob);
1406 auto & Pig =
static_cast<const cPig &
>(a_Mob);
1432 auto & Sheep =
static_cast<const cSheep &
>(a_Mob);
1437 Int8 SheepMetadata = 0;
1438 SheepMetadata =
static_cast<Int8>(Sheep.GetFurColor());
1439 if (Sheep.IsSheared())
1441 SheepMetadata |= 0x10;
1450 auto & Skeleton =
static_cast<const cSkeleton &
>(a_Mob);
1452 a_Pkt.
WriteBEUInt8(Skeleton.IsChargingBow() ? 0x01 : 0x00);
1460 auto & Slime =
static_cast<const cSlime &
>(a_Mob);
1469 auto & Villager =
static_cast<const cVillager &
>(a_Mob);
1476 switch (Villager.GetVilType())
1523 auto & Wither =
static_cast<const cWither &
>(a_Mob);
1534 auto & Wolf =
static_cast<const cWolf &
>(a_Mob);
1539 Int8 WolfStatus = 0;
1540 if (Wolf.IsSitting())
1570 auto & Zombie =
static_cast<const cZombie &
>(a_Mob);
1579 auto & ZombiePigman =
static_cast<const cZombiePigman &
>(a_Mob);
1646 ASSERT(!
"cProtocol_1_14::WriteMobMetadata: received unimplemented type");
1667 default:
UNREACHABLE(
"cProtocol_1_14::WriteMobMetadata: received mob of invalid type");
@ E_BLOCK_STANDING_BANNER
@ E_BLOCK_ENCHANTMENT_TABLE
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
@ PawnOffHandEquipmentBreaks
@ PawnFeetEquipmentBreaks
@ PawnMainHandEquipmentBreaks
@ PawnLegsEquipmentBreaks
@ PawnHeadEquipmentBreaks
@ PawnChestEquipmentBreaks
eDimension
Dimension of a world.
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
void LOGWARNING(std::string_view a_Format, const Args &... args)
eMonsterType
Identifies individual monster type.
#define HANDLE_READ(ByteBuf, Proc, Type, Var)
Macros used to read packets more easily.
AString StrToLower(const AString &s)
Returns a lower-cased copy of the string.
AString SerializeSingleValueJsonObject(const AString &a_Key, const AString &a_Value)
Creates a Json string representing an object with the specified single value.
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)
BLOCKTYPE GetBlockType() const
An object that can store incoming bytes and lets its clients read the bytes sequentially The bytes ar...
bool ReadXZYPosition64(int &a_BlockX, int &a_BlockY, int &a_BlockZ)
void HandleLeftClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, UInt8 a_Status)
void HandleRightClick(Vector3i a_BlockPos, eBlockFace a_BlockFace, Vector3i a_Cursor, bool a_UsedMainHand)
cPlayer * GetPlayer(void)
virtual bool IsElytraFlying(void) const
virtual bool IsRclking(void) const
double GetSpeedZ(void) const
virtual bool IsCrouched(void) const
float GetMaxHealth(void) const
double GetSpeedY(void) const
double GetPosX(void) const
double GetPosZ(void) const
UInt32 GetUniqueID(void) const
eEntityType GetEntityType(void) const
double GetPitch(void) const
virtual bool IsOnFire(void) const
double GetPosY(void) const
virtual bool IsInvisible(void) const
double GetYaw(void) const
float GetHealth(void) const
Returns the health of this entity.
virtual bool IsSprinting(void) const
double GetSpeedX(void) const
eGameMode GetEffectiveGameMode(void) const
Returns the current effective gamemode (inherited gamemode is resolved before returning)
eKind
The kind of the projectile.
bool IsEmpty(void) const
Returns true if the item represents an empty stack - either the type is invalid, or count is zero.
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 WriteBEUInt32(UInt32 a_Value)
void WriteBEInt32(Int32 a_Value)
void WriteXZYPosition64(int a_BlockX, int a_BlockY, int a_BlockZ)
Writes the specified block position as a single encoded 64-bit BigEndian integer.
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 WriteBEDouble(double a_Value)
void WriteBuf(const ContiguousByteBufferView a_Data)
void WriteByteAngle(double a_Angle)
Writes the specified angle using a single byte.
void WriteBEInt8(Int8 a_Value)
ePacketType
Logical types of outgoing packets.
@ 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 HandlePacketResourcePackStatus(cByteBuffer &a_ByteBuffer) override
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 SendEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation) override
virtual void HandleCraftRecipe(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketAdvancementTab(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketCraftingBookData(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketKeepAlive(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketNameItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSetBeaconEffect(cByteBuffer &a_ByteBuffer)
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 signed char GetProtocolEntityStatus(EntityAnimation a_Animation) const override
Converts an animation into an ID suitable for use with the Entity Status packet.
virtual UInt32 GetPacketID(ePacketType a_PacketType) const override
Get the packet ID for a given packet.
virtual void WriteItem(cPacketizer &a_Pkt, const cItem &a_Item) const override
Writes the item data into a packet.
virtual void SendWindowOpen(const cWindow &a_Window) override
virtual void WriteEntityMetadata(cPacketizer &a_Pkt, EntityMetadata a_Metadata, EntityMetadataType a_FieldType) const override
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual void HandlePacketBlockPlace(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketUpdateSign(cByteBuffer &a_ByteBuffer) override
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) const override
Converts eMonsterType to protocol-specific mob types.
virtual void SendBlockBreakAnim(UInt32 a_EntityID, Vector3i a_BlockPos, char a_Stage) override
virtual void SendRespawn(eDimension a_Dimension) override
virtual UInt32 GetProtocolStatisticType(CustomStatistic a_Statistic) const override
virtual UInt8 GetEntityMetadataID(EntityMetadata a_Metadata) const override
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 void SendUpdateSign(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4) override
virtual bool HandlePacket(cByteBuffer &a_ByteBuffer, UInt32 a_PacketType) override
Reads and handles the packet.
virtual void SendSoundParticleEffect(const EffectID a_EffectID, Vector3i a_Origin, int a_Data) override
virtual void SendPaintingSpawn(const cPainting &a_Painting) override
virtual void SendUpdateBlockEntity(cBlockEntity &a_BlockEntity) override
virtual void SendMapData(const cMap &a_Map, int a_DataStartX, int a_DataStartY) override
virtual void SendLogin(const cPlayer &a_Player, const cWorld &a_World) override
virtual UInt8 GetProtocolEntityType(const cEntity &a_Entity) const override
Converts an entity to a protocol-specific entity type.
virtual std::pair< short, short > GetItemFromProtocolID(UInt32 a_ProtocolID) const override
virtual int GetProtocolParticleID(const AString &a_ParticleName) const override
The 1.8 protocol use a particle id instead of a string.
virtual void SendEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation) override
virtual signed char GetProtocolEntityStatus(EntityAnimation a_Animation) const override
Converts an animation into an ID suitable for use with the Entity Status packet.
virtual UInt32 GetProtocolItemType(short a_ItemID, short a_ItemDamage) const override
virtual void SendBlockAction(Vector3i a_BlockPos, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) override
virtual void HandlePacketBlockDig(cByteBuffer &a_ByteBuffer) override
virtual void WriteMobMetadata(cPacketizer &a_Pkt, const cMonster &a_Mob) const override
Writes the mob-specific metadata for the specified mob.
virtual void SendEditSign(Vector3i a_BlockPos) override
Request the client to open up the sign editor for the sign (1.6+)
virtual void SendBlockChange(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual void SendEntitySpawn(const cEntity &a_Entity, const UInt8 a_ObjectType, const Int32 a_ObjectData) override
Sends the entity type and entity-dependent data required for the entity to initially spawn.
virtual UInt32 GetProtocolBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) const override
virtual UInt32 GetPacketID(ePacketType a_PacketType) const override
Get the packet ID for a given packet.
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual Version GetProtocolVersion() const override
Returns the protocol version.
virtual Version GetProtocolVersion() const override
Returns the protocol version.
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.
static eBlockFace FaceIntToBlockFace(Int32 a_FaceInt)
Converts the BlockFace received by the protocol into eBlockFace constants.
virtual void HandlePacketPlayerLook(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketClientStatus(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketSlotSelect(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 SendEntityMetadata(const cEntity &a_Entity) override
virtual void HandlePacketUseItem(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketWindowClick(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketClientSettings(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketPlayerPosLook(cByteBuffer &a_ByteBuffer) override
virtual void HandlePacketBoatSteer(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketVehicleMove(cByteBuffer &a_ByteBuffer)
virtual void HandlePacketTabComplete(cByteBuffer &a_ByteBuffer) override
cServer * GetServer(void)
size_t GetMaxPlayers(void) const
bool IsHardcore(void) const
int GetNumNonInventorySlots(void) const
Returns the number of slots, excluding the player's inventory (used for network protocols)
int GetNumSlots(void) const
Returns the total number of slots.
char GetWindowID(void) const
const AString & GetWindowTitle() const
int GetWindowType(void) const
int GetSpawnX(void) const
int GetSpawnZ(void) const
int GetMaxViewDistance(void) const
virtual eDimension GetDimension(void) const override
int GetSpawnY(void) const
ContiguousByteBufferView GetResult(void) const