From b10d0b95cbdce1d476f14415901c89bf324c0c18 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 14:48:17 +0100 Subject: Added m_IsFlying and m_CanFly. Both have a Get and Set function. Added cClientHandle::SendPlayerAbilities() function --- src/ClientHandle.cpp | 33 +++++++++++++++++++++++++++++++++ src/ClientHandle.h | 2 ++ src/Entities/Player.cpp | 32 ++++++++++++++++++++++++++++++++ src/Entities/Player.h | 14 +++++++++++++- src/Protocol/Protocol17x.cpp | 12 ++++++++++-- 5 files changed, 90 insertions(+), 3 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3 From 9fe06af598b7e298c0df315f6bdcd65fd1c9b0c4 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 14:52:17 +0100 Subject: Exported Set and Get functions to Lua. --- src/Bindings/Bindings.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++- src/Bindings/Bindings.h | 2 +- 2 files changed, 136 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Bindings/Bindings.cpp b/src/Bindings/Bindings.cpp index f4fb3f791..46f8c8f40 100644 --- a/src/Bindings/Bindings.cpp +++ b/src/Bindings/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/14/13 22:33:52. +** Generated automatically by tolua++-1.0.92 on 12/15/13 14:19:12. */ #ifndef __cplusplus @@ -10460,6 +10460,38 @@ static int tolua_AllToLua_cPlayer_IsEating00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: IsFlying of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_IsFlying00 +static int tolua_AllToLua_cPlayer_IsFlying00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cPlayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cPlayer* self = (const cPlayer*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsFlying'", NULL); +#endif + { + bool tolua_ret = (bool) self->IsFlying(); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'IsFlying'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: Respawn of class cPlayer */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_Respawn00 static int tolua_AllToLua_cPlayer_Respawn00(lua_State* tolua_S) @@ -10849,6 +10881,72 @@ static int tolua_AllToLua_cPlayer_SetSprint00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: SetFlying of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetFlying00 +static int tolua_AllToLua_cPlayer_SetFlying00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) || + !tolua_isboolean(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + bool a_IsFlying = ((bool) tolua_toboolean(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetFlying'", NULL); +#endif + { + self->SetFlying(a_IsFlying); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetFlying'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetCanFly of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SetCanFly00 +static int tolua_AllToLua_cPlayer_SetCanFly00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) || + !tolua_isboolean(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0); + bool a_CanFly = ((bool) tolua_toboolean(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetCanFly'", NULL); +#endif + { + self->SetCanFly(a_CanFly); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetCanFly'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: IsSwimming of class cPlayer */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_IsSwimming00 static int tolua_AllToLua_cPlayer_IsSwimming00(lua_State* tolua_S) @@ -10913,6 +11011,38 @@ static int tolua_AllToLua_cPlayer_IsSubmerged00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: CanFly of class cPlayer */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_CanFly00 +static int tolua_AllToLua_cPlayer_CanFly00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cPlayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cPlayer* self = (const cPlayer*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CanFly'", NULL); +#endif + { + bool tolua_ret = (bool) self->CanFly(); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'CanFly'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: new of class cPickup */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cPickup_new00 static int tolua_AllToLua_cPickup_new00(lua_State* tolua_S) @@ -30978,6 +31108,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"AddFoodExhaustion",tolua_AllToLua_cPlayer_AddFoodExhaustion00); tolua_function(tolua_S,"FoodPoison",tolua_AllToLua_cPlayer_FoodPoison00); tolua_function(tolua_S,"IsEating",tolua_AllToLua_cPlayer_IsEating00); + tolua_function(tolua_S,"IsFlying",tolua_AllToLua_cPlayer_IsFlying00); tolua_function(tolua_S,"Respawn",tolua_AllToLua_cPlayer_Respawn00); tolua_function(tolua_S,"SetVisible",tolua_AllToLua_cPlayer_SetVisible00); tolua_function(tolua_S,"IsVisible",tolua_AllToLua_cPlayer_IsVisible00); @@ -30990,8 +31121,11 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"SetSprintingMaxSpeed",tolua_AllToLua_cPlayer_SetSprintingMaxSpeed00); tolua_function(tolua_S,"SetCrouch",tolua_AllToLua_cPlayer_SetCrouch00); tolua_function(tolua_S,"SetSprint",tolua_AllToLua_cPlayer_SetSprint00); + tolua_function(tolua_S,"SetFlying",tolua_AllToLua_cPlayer_SetFlying00); + tolua_function(tolua_S,"SetCanFly",tolua_AllToLua_cPlayer_SetCanFly00); tolua_function(tolua_S,"IsSwimming",tolua_AllToLua_cPlayer_IsSwimming00); tolua_function(tolua_S,"IsSubmerged",tolua_AllToLua_cPlayer_IsSubmerged00); + tolua_function(tolua_S,"CanFly",tolua_AllToLua_cPlayer_CanFly00); tolua_endmodule(tolua_S); #ifdef __cplusplus tolua_cclass(tolua_S,"cPickup","cPickup","cEntity",tolua_collect_cPickup); diff --git a/src/Bindings/Bindings.h b/src/Bindings/Bindings.h index e8f766b43..4805c260e 100644 --- a/src/Bindings/Bindings.h +++ b/src/Bindings/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 12/14/13 22:33:53. +** Generated automatically by tolua++-1.0.92 on 12/15/13 14:19:13. */ /* Exported function */ -- cgit v1.2.3 From ffb5a69a9e1e531cb8effc72d2a2ad0a459981e3 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 15 Dec 2013 15:11:59 +0100 Subject: Moved reading flags to the protocol. --- src/ClientHandle.cpp | 20 +++----------------- src/ClientHandle.h | 2 +- src/Protocol/Protocol17x.cpp | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 68c511d7c..d585eccf1 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -490,24 +490,10 @@ void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_Hel -void cClientHandle::HandlePlayerAbilities(int Flags, float FlyingSpeed, float WalkingSpeed) +void cClientHandle::HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, 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); - } + m_Player->SetCanFly(a_CanFly); + m_Player->SetFlying(a_IsFlying); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 51068a319..147a5b2b3 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -176,7 +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 HandlePlayerAbilities (bool a_CanFly, bool a_IsFlying, 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/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp index 9b2b19026..edf7d2529 100644 --- a/src/Protocol/Protocol17x.cpp +++ b/src/Protocol/Protocol17x.cpp @@ -1286,7 +1286,25 @@ 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); - m_Client->HandlePlayerAbilities(Flags, FlyingSpeed, WalkingSpeed); + + bool IsFlying, CanFly; + if ((Flags & 2) != 0) + { + IsFlying = true; + } + else + { + IsFlying = false; + } + if ((Flags & 4) != 0) + { + CanFly = true; + } + else + { + CanFly = false; + } + m_Client->HandlePlayerAbilities(CanFly, IsFlying, FlyingSpeed, WalkingSpeed); } -- cgit v1.2.3