diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Bindings/Bindings.cpp | 136 | ||||
-rw-r--r-- | src/Bindings/Bindings.h | 2 | ||||
-rw-r--r-- | src/ClientHandle.cpp | 19 | ||||
-rw-r--r-- | src/ClientHandle.h | 2 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 32 | ||||
-rw-r--r-- | src/Entities/Player.h | 14 | ||||
-rw-r--r-- | src/Protocol/Protocol17x.cpp | 30 |
7 files changed, 230 insertions, 5 deletions
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 */ diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 8a92e1344..d585eccf1 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -490,6 +490,16 @@ void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_Hel +void cClientHandle::HandlePlayerAbilities(bool a_CanFly, bool a_IsFlying, float FlyingSpeed, float WalkingSpeed) +{ + m_Player->SetCanFly(a_CanFly); + m_Player->SetFlying(a_IsFlying); +} + + + + + 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 +1841,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..147a5b2b3 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 (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/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..edf7d2529 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,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); - // TODO: m_Client->HandlePlayerAbilities(); + + 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); } |