summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2013-12-15 14:48:17 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2013-12-15 14:48:17 +0100
commitb10d0b95cbdce1d476f14415901c89bf324c0c18 (patch)
tree00aff412ae4fe7c691dc18f2fc3d6fd61dde8a60 /src
parentMerge pull request #432 from mc-server/Broadcast_Effects (diff)
downloadcuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.tar
cuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.tar.gz
cuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.tar.bz2
cuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.tar.lz
cuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.tar.xz
cuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.tar.zst
cuberite-b10d0b95cbdce1d476f14415901c89bf324c0c18.zip
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp33
-rw-r--r--src/ClientHandle.h2
-rw-r--r--src/Entities/Player.cpp32
-rw-r--r--src/Entities/Player.h14
-rw-r--r--src/Protocol/Protocol17x.cpp12
5 files changed, 90 insertions, 3 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 8a92e1344..68c511d7c 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -490,6 +490,30 @@ void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_Hel
+void cClientHandle::HandlePlayerAbilities(int Flags, float FlyingSpeed, float WalkingSpeed)
+{
+ if ((Flags & 2) != 0)
+ {
+ m_Player->SetFlying(true);
+ }
+ else
+ {
+ m_Player->SetFlying(false);
+ }
+ if ((Flags & 4) != 0)
+ {
+ m_Player->SetCanFly(true);
+ }
+ else
+ {
+ m_Player->SetCanFly(false);
+ }
+}
+
+
+
+
+
void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround)
{
if ((m_Player == NULL) || (m_State != csPlaying))
@@ -1831,6 +1855,15 @@ void cClientHandle::SendEntityAnimation(const cEntity & a_Entity, char a_Animati
+void cClientHandle::SendPlayerAbilities()
+{
+ m_Protocol->SendPlayerAbilities();
+}
+
+
+
+
+
void cClientHandle::SendPlayerListItem(const cPlayer & a_Player, bool a_IsOnline)
{
m_Protocol->SendPlayerListItem(a_Player, a_IsOnline);
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 19ebc023d..51068a319 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -116,6 +116,7 @@ public:
void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item);
void SendPickupSpawn (const cPickup & a_Pickup);
void SendEntityAnimation (const cEntity & a_Entity, char a_Animation);
+ void SendPlayerAbilities (void);
void SendPlayerListItem (const cPlayer & a_Player, bool a_IsOnline);
void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+)
void SendPlayerMoveLook (void);
@@ -175,6 +176,7 @@ public:
void HandleKeepAlive (int a_KeepAliveID);
void HandleLeftClick (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
void HandlePing (void);
+ void HandlePlayerAbilities (int Flags, float FlyingSpeed, float WalkingSpeed);
void HandlePlayerLook (float a_Rotation, float a_Pitch, bool a_IsOnGround);
void HandlePlayerMoveLook (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, float a_Rotation, float a_Pitch, bool a_IsOnGround); // While m_bPositionConfirmed (normal gameplay)
void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround);
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index e057c25fe..c2a76342d 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -63,6 +63,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_IsSprinting(false)
, m_IsSwimming(false)
, m_IsSubmerged(false)
+ , m_IsFlying(false)
+ , m_CanFly(false)
, m_EatingFinishTick(-1)
, m_IsChargingBow(false)
, m_BowCharge(0)
@@ -751,6 +753,36 @@ void cPlayer::SetSprint(bool a_IsSprinting)
+void cPlayer::SetCanFly(bool a_CanFly)
+{
+ if (a_CanFly == m_CanFly)
+ {
+ return;
+ }
+
+ m_CanFly = a_CanFly;
+ m_ClientHandle->SendPlayerAbilities();
+}
+
+
+
+
+
+void cPlayer::SetFlying(bool a_IsFlying)
+{
+ if (a_IsFlying == m_IsFlying)
+ {
+ return;
+ }
+
+ m_IsFlying = a_IsFlying;
+ m_ClientHandle->SendPlayerAbilities();
+}
+
+
+
+
+
void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (a_TDI.DamageType != dtInVoid)
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 44cab7d74..f3ee841e7 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -250,6 +250,8 @@ public:
/// Returns true if the player is currently in the process of eating the currently equipped item
bool IsEating(void) const { return (m_EatingFinishTick >= 0); }
+ /// Returns true if the player is currently flying.
+ bool IsFlying(void) const { return m_IsFlying; }
// tolua_end
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
@@ -319,12 +321,20 @@ public:
/// Starts or stops sprinting, sends the max speed update to the client, if needed
void SetSprint(bool a_IsSprinting);
+ /// Flags the player as flying
+ void SetFlying(bool a_IsFlying);
+
+ /// If true the player can fly even when he's not in creative.
+ void SetCanFly(bool a_CanFly);
+
/// Returns whether the player is swimming or not
virtual bool IsSwimming(void) const{ return m_IsSwimming; }
/// Return whether the player is under water or not
virtual bool IsSubmerged(void) const{ return m_IsSubmerged; }
+ /// Returns wheter the player can fly or not.
+ virtual bool CanFly(void) const { return m_CanFly; }
// tolua_end
// cEntity overrides:
@@ -415,10 +425,12 @@ protected:
bool m_IsCrouched;
bool m_IsSprinting;
-
+ bool m_IsFlying;
bool m_IsSwimming;
bool m_IsSubmerged;
+ bool m_CanFly; // If this is true the player can fly. Even if he is not in creative.
+
/// The world tick in which eating will be finished. -1 if not eating
Int64 m_EatingFinishTick;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 0daf1c932..9b2b19026 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -491,7 +491,15 @@ void cProtocol172::SendPlayerAbilities(void)
{
Flags |= 0x01;
}
- // TODO: Other flags (god mode, flying, can fly
+ if (m_Client->GetPlayer()->IsFlying())
+ {
+ Flags |= 0x02;
+ }
+ if (m_Client->GetPlayer()->CanFly())
+ {
+ Flags |= 0x04;
+ }
+ // TODO: Other flags (god mode)
Pkt.WriteByte(Flags);
// TODO: Pkt.WriteFloat(m_Client->GetPlayer()->GetMaxFlyingSpeed());
Pkt.WriteFloat(0.05f);
@@ -1278,7 +1286,7 @@ void cProtocol172::HandlePacketPlayerAbilities(cByteBuffer & a_ByteBuffer)
HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Flags);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, FlyingSpeed);
HANDLE_READ(a_ByteBuffer, ReadBEFloat, float, WalkingSpeed);
- // TODO: m_Client->HandlePlayerAbilities();
+ m_Client->HandlePlayerAbilities(Flags, FlyingSpeed, WalkingSpeed);
}