From c088f7ff0a336703fb19038eef36f736a4e388f7 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Sat, 27 Aug 2016 09:37:54 +0300 Subject: Proper respawn packets on dimension travel --- src/Protocol/Protocol19x.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/Protocol/Protocol19x.cpp') diff --git a/src/Protocol/Protocol19x.cpp b/src/Protocol/Protocol19x.cpp index d8c86cf6b..456ca8a91 100644 --- a/src/Protocol/Protocol19x.cpp +++ b/src/Protocol/Protocol19x.cpp @@ -117,8 +117,7 @@ cProtocol190::cProtocol190(cClientHandle * a_Client, const AString & a_ServerAdd m_ServerPort(a_ServerPort), m_State(a_State), m_ReceivedData(32 KiB), - m_IsEncrypted(false), - m_LastSentDimension(dimNotSet) + m_IsEncrypted(false) { // BungeeCord handling: @@ -640,7 +639,6 @@ void cProtocol190::SendLogin(const cPlayer & a_Player, const cWorld & a_World) Pkt.WriteString("default"); // Level type - wtf? Pkt.WriteBool(false); // Reduced Debug Info - wtf? } - m_LastSentDimension = a_World.GetDimension(); // Send the spawn position: { @@ -1110,21 +1108,14 @@ void cProtocol190::SendResetTitle(void) -void cProtocol190::SendRespawn(eDimension a_Dimension, bool a_ShouldIgnoreDimensionChecks) +void cProtocol190::SendRespawn(eDimension a_Dimension) { - if ((m_LastSentDimension == a_Dimension) && !a_ShouldIgnoreDimensionChecks) - { - // Must not send a respawn for the world with the same dimension, the client goes cuckoo if we do (unless we are respawning from death) - return; - } - cPacketizer Pkt(*this, 0x33); // Respawn packet cPlayer * Player = m_Client->GetPlayer(); Pkt.WriteBEInt32(static_cast(a_Dimension)); Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) Pkt.WriteBEUInt8(static_cast(Player->GetEffectiveGameMode())); Pkt.WriteString("default"); - m_LastSentDimension = a_Dimension; } @@ -4058,7 +4049,6 @@ void cProtocol191::SendLogin(const cPlayer & a_Player, const cWorld & a_World) Pkt.WriteString("default"); // Level type - wtf? Pkt.WriteBool(false); // Reduced Debug Info - wtf? } - m_LastSentDimension = a_World.GetDimension(); // Send the spawn position: { -- cgit v1.2.3 From 61078e8402dc289cca0ace12933a688660d10b03 Mon Sep 17 00:00:00 2001 From: bibo38 Date: Fri, 2 Sep 2016 19:22:06 +0200 Subject: Added support for the Minecraft 1.10 protocol(#210) (#3348) * Added support for the Minecraft 1.10 protocol(#210) * Fixed the Clang compilation errors * Fixed wrong sound pitch value and fixed SendPlayerSpawn Metadata value. * Prefixed each enum item with the appropriate class name. --- src/Protocol/Protocol19x.cpp | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'src/Protocol/Protocol19x.cpp') diff --git a/src/Protocol/Protocol19x.cpp b/src/Protocol/Protocol19x.cpp index 456ca8a91..6791da8cd 100644 --- a/src/Protocol/Protocol19x.cpp +++ b/src/Protocol/Protocol19x.cpp @@ -739,7 +739,7 @@ void cProtocol190::SendPickupSpawn(const cPickup & a_Pickup) { ASSERT(m_State == 3); // In game mode? - { + { // TODO Use SendSpawnObject cPacketizer Pkt(*this, 0x00); // Spawn Object packet Pkt.WriteVarInt32(a_Pickup.GetUniqueID()); // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. @@ -757,14 +757,7 @@ void cProtocol190::SendPickupSpawn(const cPickup & a_Pickup) Pkt.WriteBEInt16(0); } - { - cPacketizer Pkt(*this, 0x39); // Entity Metadata packet - Pkt.WriteVarInt32(a_Pickup.GetUniqueID()); - Pkt.WriteBEUInt8(5); // Index 5: Item - Pkt.WriteBEUInt8(METADATA_TYPE_ITEM); - WriteItem(Pkt, a_Pickup.GetItem()); - Pkt.WriteBEUInt8(0xff); // End of metadata - } + SendEntityMetadata(a_Pickup); } @@ -1057,12 +1050,7 @@ void cProtocol190::SendPlayerSpawn(const cPlayer & a_Player) Pkt.WriteBEDouble(a_Player.GetPosZ()); Pkt.WriteByteAngle(a_Player.GetYaw()); Pkt.WriteByteAngle(a_Player.GetPitch()); - Pkt.WriteBEUInt8(6); // Start metadata - Index 6: Health - Pkt.WriteBEUInt8(METADATA_TYPE_FLOAT); - Pkt.WriteBEFloat(static_cast(a_Player.GetHealth())); - Pkt.WriteBEUInt8(2); // Index 2: Custom name - Pkt.WriteBEUInt8(METADATA_TYPE_STRING); - Pkt.WriteString(a_Player.GetName()); + WriteEntityMetadata(Pkt, a_Player); Pkt.WriteBEUInt8(0xff); // Metadata: end } @@ -3520,7 +3508,22 @@ void cProtocol190::WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_En switch (a_Entity.GetEntityType()) { - case cEntity::etPlayer: break; // TODO? + case cEntity::etPlayer: + { + auto & Player = reinterpret_cast(a_Entity); + + // TODO Set player custom name to their name. + // Then it's possible to move the custom name of mobs to the entities + // and to remove the "special" player custom name. + a_Pkt.WriteBEUInt8(2); // Index 2: Custom name + a_Pkt.WriteBEUInt8(METADATA_TYPE_STRING); + a_Pkt.WriteString(Player.GetName()); + + a_Pkt.WriteBEUInt8(6); // Start metadata - Index 6: Health + a_Pkt.WriteBEUInt8(METADATA_TYPE_FLOAT); + a_Pkt.WriteBEFloat(static_cast(Player.GetHealth())); + break; + } case cEntity::etPickup: { a_Pkt.WriteBEUInt8(5); // Index 5: Item @@ -4367,8 +4370,3 @@ void cProtocol194::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, cons Writer.Finish(); Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size()); } - - - - - -- cgit v1.2.3