summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-11 20:06:28 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-11 20:06:28 +0200
commitc45bf7cf55cac42fd168df6d008cb814dd94eae1 (patch)
treedcd019680077936254c211ee27f45ec5a09c1785
parent1.8: Added ParticleEffect packet. (diff)
downloadcuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.tar
cuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.tar.gz
cuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.tar.bz2
cuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.tar.lz
cuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.tar.xz
cuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.tar.zst
cuberite-c45bf7cf55cac42fd168df6d008cb814dd94eae1.zip
-rw-r--r--src/Entities/ItemFrame.cpp2
-rw-r--r--src/Protocol/Protocol17x.cpp2
-rw-r--r--src/Protocol/Protocol18x.cpp114
-rw-r--r--src/Protocol/Protocol18x.h3
4 files changed, 89 insertions, 32 deletions
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
index 0bc10ec60..7f923ef61 100644
--- a/src/Entities/ItemFrame.cpp
+++ b/src/Entities/ItemFrame.cpp
@@ -26,7 +26,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
{
// Item not empty, rotate, clipping values to zero to three inclusive
m_Rotation++;
- if (m_Rotation >= 4)
+ if (m_Rotation >= 8)
{
m_Rotation = 0;
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index d83e86ece..2b0c8baf8 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -2834,7 +2834,7 @@ void cProtocol172::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
WriteByte(0xA2);
WriteItem(Frame.GetItem());
WriteByte(0x3);
- WriteByte(Frame.GetRotation());
+ WriteByte(Frame.GetRotation() / 2);
break;
}
default: break;
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 2ea83351e..28fffd851 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -406,9 +406,7 @@ void cProtocol180::SendEditSign(int a_BlockX, int a_BlockY, int a_BlockZ)
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x36); // Sign Editor Open packet
- Pkt.WriteInt(a_BlockX);
- Pkt.WriteInt(a_BlockY);
- Pkt.WriteInt(a_BlockZ);
+ Pkt.WritePosition(a_BlockX, a_BlockX, a_BlockZ);
}
@@ -702,12 +700,23 @@ void cProtocol180::SendLoginSuccess(void)
void cProtocol180::SendPaintingSpawn(const cPainting & a_Painting)
{
ASSERT(m_State == 3); // In game mode?
-
- /*cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
+ double PosX = a_Painting.GetPosX();
+ double PosY = a_Painting.GetPosY();
+ double PosZ = a_Painting.GetPosZ();
+
+ switch (a_Painting.GetDirection())
+ {
+ case 0: PosZ += 1; break;
+ case 1: PosX -= 1; break;
+ case 2: PosZ -= 1; break;
+ case 3: PosX += 1; break;
+ }
+
+ cPacketizer Pkt(*this, 0x10); // Spawn Painting packet
Pkt.WriteVarInt(a_Painting.GetUniqueID());
Pkt.WriteString(a_Painting.GetName().c_str());
- Pkt.WritePosition(Vector3i(a_Painting.GetPosX(), a_Painting.GetPosY(), a_Painting.GetPosZ()));
- Pkt.WriteChar(a_Painting.GetDirection());*/
+ Pkt.WritePosition(PosX, PosY, PosZ);
+ Pkt.WriteChar(a_Painting.GetDirection());
}
@@ -1194,7 +1203,7 @@ void cProtocol180::SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock)
Pkt.WriteFPInt(a_FallingBlock.GetPosZ());
Pkt.WriteByteAngle(a_FallingBlock.GetYaw());
Pkt.WriteByteAngle(a_FallingBlock.GetPitch());
- Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 16)); // Or 0x10
+ Pkt.WriteInt(((int)a_FallingBlock.GetBlockType()) | (((int)a_FallingBlock.GetBlockMeta()) << 12));
Pkt.WriteShort((short)(a_FallingBlock.GetSpeedX() * 400));
Pkt.WriteShort((short)(a_FallingBlock.GetSpeedY() * 400));
Pkt.WriteShort((short)(a_FallingBlock.GetSpeedZ() * 400));
@@ -1231,15 +1240,22 @@ void cProtocol180::SendSpawnMob(const cMonster & a_Mob)
void cProtocol180::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch)
{
ASSERT(m_State == 3); // In game mode?
-
+ double PosX = a_Entity.GetPosX();
+ double PosZ = a_Entity.GetPosZ();
+ double Yaw = a_Entity.GetYaw();
+ if (a_ObjectType == 71)
+ {
+ FixItemFramePositions(a_ObjectData, PosX, PosZ, Yaw);
+ }
+
cPacketizer Pkt(*this, 0xe); // Spawn Object packet
Pkt.WriteVarInt(a_Entity.GetUniqueID());
Pkt.WriteByte(a_ObjectType);
- Pkt.WriteFPInt(a_Entity.GetPosX());
+ Pkt.WriteFPInt(PosX);
Pkt.WriteFPInt(a_Entity.GetPosY());
- Pkt.WriteFPInt(a_Entity.GetPosZ());
+ Pkt.WriteFPInt(PosZ);
Pkt.WriteByteAngle(a_Entity.GetPitch());
- Pkt.WriteByteAngle(a_Entity.GetYaw());
+ Pkt.WriteByteAngle(Yaw);
Pkt.WriteInt(a_ObjectData);
if (a_ObjectData != 0)
{
@@ -1416,14 +1432,11 @@ void cProtocol180::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, cons
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x33);
- Pkt.WriteInt(a_BlockX);
- Pkt.WriteShort((short)a_BlockY);
- Pkt.WriteInt(a_BlockZ);
- // Need to send only up to 15 chars, otherwise the client crashes (#598)
- Pkt.WriteString(a_Line1.substr(0, 15));
- Pkt.WriteString(a_Line2.substr(0, 15));
- Pkt.WriteString(a_Line3.substr(0, 15));
- Pkt.WriteString(a_Line4.substr(0, 15));
+ Pkt.WritePosition(a_BlockX, a_BlockY, a_BlockZ);
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line1.c_str()));
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line2.c_str()));
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line3.c_str()));
+ Pkt.WriteString(Printf("{\"text\": \"%s\"}", a_Line4.c_str()));
}
@@ -1637,6 +1650,41 @@ int cProtocol180::GetParticleID(const AString & a_ParticleName)
+void cProtocol180::FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw)
+{
+ switch (a_ObjectData)
+ {
+ case 0:
+ {
+ a_PosZ += 1;
+ a_Yaw = 0;
+ break;
+ }
+ case 1:
+ {
+ a_PosX -= 1;
+ a_Yaw = 90;
+ break;
+ }
+ case 2:
+ {
+ a_PosZ -= 1;
+ a_Yaw = 180;
+ break;
+ }
+ case 3:
+ {
+ a_PosX += 1;
+ a_Yaw = 270;
+ break;
+ }
+ }
+}
+
+
+
+
+
void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
{
// Write the incoming data into the comm log file:
@@ -2328,14 +2376,20 @@ void cProtocol180::HandlePacketTabComplete(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockX);
- HANDLE_READ(a_ByteBuffer, ReadBEShort, short, BlockY);
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, BlockZ);
- HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line1);
- HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line2);
- HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line3);
- HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line4);
- m_Client->HandleUpdateSign(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4);
+ int BlockX, BlockY, BlockZ;
+ if (!a_ByteBuffer.ReadPosition(BlockX, BlockY, BlockZ))
+ {
+ return;
+ }
+
+ AString Lines[4];
+ for (int i = 0; i < 4; i++)
+ {
+ HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line);
+ Lines[i] = Line.substr(1, Line.length() - 2); // Remove ""
+ }
+
+ m_Client->HandleUpdateSign(BlockX, BlockY, BlockZ, Lines[0], Lines[1], Lines[2], Lines[3]);
}
@@ -3062,9 +3116,9 @@ void cProtocol180::cPacketizer::WriteEntityMetadata(const cEntity & a_Entity)
case cEntity::etItemFrame:
{
cItemFrame & Frame = (cItemFrame &)a_Entity;
- WriteByte(0xA2);
+ WriteByte(0xA8);
WriteItem(Frame.GetItem());
- WriteByte(0x3);
+ WriteByte(0x09);
WriteByte(Frame.GetRotation());
break;
}
diff --git a/src/Protocol/Protocol18x.h b/src/Protocol/Protocol18x.h
index 2b3063556..97ab3e93c 100644
--- a/src/Protocol/Protocol18x.h
+++ b/src/Protocol/Protocol18x.h
@@ -141,6 +141,9 @@ public:
/** The 1.8 protocol use a particle id instead of a string. This function converts the name to the id. If the name is incorrect, it returns 0. */
static int GetParticleID(const AString & a_ParticleName);
+ /** Minecraft 1.8 use other locations to spawn the item frame. This function converts the 1.7 positions to 1.8 positions. */
+ static void FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw);
+
protected:
/** Composes individual packets in the protocol's m_OutPacketBuffer; sends them upon being destructed */