summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp12
-rw-r--r--source/Bindings.h2
-rw-r--r--source/ClientHandle.cpp12
-rw-r--r--source/ClientHandle.h1
-rw-r--r--source/Entities/Player.cpp49
-rw-r--r--source/Entities/Player.h16
-rw-r--r--source/Protocol/Protocol.h3
-rw-r--r--source/Protocol/Protocol125.cpp15
-rw-r--r--source/Protocol/Protocol125.h1
-rw-r--r--source/Protocol/Protocol17x.cpp12
-rw-r--r--source/Protocol/Protocol17x.h1
-rw-r--r--source/Protocol/ProtocolRecognizer.cpp10
-rw-r--r--source/Protocol/ProtocolRecognizer.h1
13 files changed, 106 insertions, 29 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 93c66d233..be0bbd8af 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/15/13 10:14:19.
+** Generated automatically by tolua++-1.0.92 on 11/16/13 02:20:34.
*/
#ifndef __cplusplus
@@ -7666,7 +7666,7 @@ static int tolua_AllToLua_cPlayer_SetExperience00(lua_State* tolua_S)
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
- int a_XpTotal = ((int) tolua_tonumber(tolua_S,2,0));
+ short a_XpTotal = ((short) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetExperience'", NULL);
#endif
@@ -7700,12 +7700,12 @@ static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S)
#endif
{
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
- int a_Xp_delta = ((int) tolua_tonumber(tolua_S,2,0));
+ short a_Xp_delta = ((short) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddExperience'", NULL);
#endif
{
- int tolua_ret = (int) self->AddExperience(a_Xp_delta);
+ short tolua_ret = (short) self->AddExperience(a_Xp_delta);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@@ -7737,7 +7737,7 @@ static int tolua_AllToLua_cPlayer_XpGetTotal00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetTotal'", NULL);
#endif
{
- int tolua_ret = (int) self->XpGetTotal();
+ short tolua_ret = (short) self->XpGetTotal();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@@ -7769,7 +7769,7 @@ static int tolua_AllToLua_cPlayer_XpGetLevel00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'XpGetLevel'", NULL);
#endif
{
- int tolua_ret = (int) self->XpGetLevel();
+ short tolua_ret = (short) self->XpGetLevel();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
diff --git a/source/Bindings.h b/source/Bindings.h
index 13f398a4d..42c158096 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/15/13 10:14:20.
+** Generated automatically by tolua++-1.0.92 on 11/16/13 02:20:35.
*/
/* Exported function */
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index f8fd4a8b7..daf09d4ea 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -260,6 +260,9 @@ void cClientHandle::Authenticate(void)
// Send health
m_Player->SendHealth();
+
+ // Send experience
+ m_Player->SendExperience();
// Send gamemode (1.6.1 movementSpeed):
SendGameMode(m_Player->GetGameMode());
@@ -1873,6 +1876,15 @@ void cClientHandle::SendRespawn(void)
+void cClientHandle::SendExperience(void)
+{
+ m_Protocol->SendExperience();
+}
+
+
+
+
+
void cClientHandle::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch)
{
m_Protocol->SendSoundEffect(a_SoundName, a_SrcX, a_SrcY, a_SrcZ, a_Volume, a_Pitch);
diff --git a/source/ClientHandle.h b/source/ClientHandle.h
index 3844937ad..b887bb11a 100644
--- a/source/ClientHandle.h
+++ b/source/ClientHandle.h
@@ -120,6 +120,7 @@ public:
void SendPlayerPosition (void);
void SendPlayerSpawn (const cPlayer & a_Player);
void SendRespawn (void);
+ void SendExperience (void);
void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch); // a_Src coords are Block * 8
void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data);
void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock);
diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp
index 098417dc5..f25483375 100644
--- a/source/Entities/Player.cpp
+++ b/source/Entities/Player.cpp
@@ -262,7 +262,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
-int cPlayer::CalcLevelFromXp(int a_XpTotal)
+short cPlayer::CalcLevelFromXp(short a_XpTotal)
{
//level 0 to 15
if(a_XpTotal <= XP_TO_LEVEL15)
@@ -273,18 +273,18 @@ int cPlayer::CalcLevelFromXp(int a_XpTotal)
//level 30+
if(a_XpTotal > XP_TO_LEVEL30)
{
- return (int) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7;
+ return (short) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7;
}
//level 16 to 30
- return (int) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal )))) / 3;
+ return (short) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal )))) / 3;
}
-int cPlayer::XpForLevel(int a_Level)
+short cPlayer::XpForLevel(short a_Level)
{
//level 0 to 15
if(a_Level <= 15)
@@ -295,18 +295,18 @@ int cPlayer::XpForLevel(int a_Level)
//level 30+
if(a_Level >= 31)
{
- return (int) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220 );
+ return (short) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220 );
}
//level 16 to 30
- return (int) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360 );
+ return (short) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360 );
}
-int cPlayer::XpGetLevel()
+short cPlayer::XpGetLevel()
{
return CalcLevelFromXp(m_XpTotal);
}
@@ -317,18 +317,20 @@ int cPlayer::XpGetLevel()
float cPlayer::XpGetPercentage()
{
- int currentLevel = CalcLevelFromXp(m_XpTotal);
+ short int currentLevel = CalcLevelFromXp(m_XpTotal);
+ short int currentLevel_XpBase = XpForLevel(currentLevel);
- return (float)m_XpTotal / (float)XpForLevel(1+currentLevel);
+ return (float)(m_XpTotal - currentLevel_XpBase) /
+ (float)(XpForLevel(1+currentLevel) - currentLevel_XpBase);
}
-bool cPlayer::SetExperience(int a_XpTotal)
+bool cPlayer::SetExperience(short int a_XpTotal)
{
- if(!(a_XpTotal >= 0) || (a_XpTotal > (INT_MAX - m_XpTotal)))
+ if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_XpTotal)))
{
LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_XpTotal);
return false; //oops, they gave us a dodgey number
@@ -336,6 +338,9 @@ bool cPlayer::SetExperience(int a_XpTotal)
m_XpTotal = a_XpTotal;
+ //send details to client
+ SendExperience();
+
return true;
}
@@ -343,7 +348,7 @@ bool cPlayer::SetExperience(int a_XpTotal)
-int cPlayer::AddExperience(int a_Xp_delta)
+short cPlayer::AddExperience(short a_Xp_delta)
{
if(a_Xp_delta < 0)
{
@@ -357,6 +362,9 @@ int cPlayer::AddExperience(int a_Xp_delta)
m_XpTotal += a_Xp_delta;
+ //send details to client
+ SendExperience();
+
return m_XpTotal;
}
@@ -607,6 +615,18 @@ void cPlayer::SendHealth(void)
+void cPlayer::SendExperience(void)
+{
+ if (m_ClientHandle != NULL)
+ {
+ m_ClientHandle->SendExperience();
+ }
+}
+
+
+
+
+
void cPlayer::ClearInventoryPaintSlots(void)
{
// Clear the list of slots that are being inventory-painted. Used by cWindow only
@@ -1411,14 +1431,15 @@ bool cPlayer::LoadFromDisk()
SetRoll ((float)JSON_PlayerRotation[(unsigned int)2].asDouble());
}
- m_Health = root.get("health", 0).asInt();
+ m_Health = root.get("health", 0).asInt();
m_AirLevel = root.get("air", MAX_AIR_LEVEL).asInt();
m_FoodLevel = root.get("food", MAX_FOOD_LEVEL).asInt();
m_FoodSaturationLevel = root.get("foodSaturation", MAX_FOOD_LEVEL).asDouble();
m_FoodTickTimer = root.get("foodTickTimer", 0).asInt();
m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble();
+ m_XpTotal = (short) root.get("experience", 0).asInt();
- SetExperience(root.get("experience", 0).asInt());
+ //SetExperience(root.get("experience", 0).asInt());
m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt();
diff --git a/source/Entities/Player.h b/source/Entities/Player.h
index ab2f94d4c..aeec9f361 100644
--- a/source/Entities/Player.h
+++ b/source/Entities/Player.h
@@ -71,18 +71,18 @@ public:
Returns true on success
"should" really only be called at init or player death, plugins excepted
*/
- bool SetExperience(int a_XpTotal);
+ bool SetExperience(short a_XpTotal);
/* Adds Xp, "should" not inc more than MAX_EXPERIENCE_ORB_SIZE unless you're a plugin being funny, *cough* cheating
Returns the new total experience, -1 on error
*/
- int AddExperience(int a_Xp_delta);
+ short AddExperience(short a_Xp_delta);
/// Gets the experience total - XpTotal
- inline int XpGetTotal(void) { return m_XpTotal; }
+ inline short XpGetTotal(void) { return m_XpTotal; }
/// Gets the current level - XpLevel
- int XpGetLevel(void);
+ short XpGetLevel(void);
/// Gets the experience bar percentage - XpP
float XpGetPercentage(void);
@@ -269,6 +269,8 @@ public:
void UseEquippedItem(void);
void SendHealth(void);
+
+ void SendExperience(void);
// In UI windows, the item that the player is dragging:
bool IsDraggingItem(void) const { return !m_DraggingItem.IsEmpty(); }
@@ -413,13 +415,13 @@ protected:
Int64 m_EatingFinishTick;
/// Player Xp level
- int m_XpTotal;
+ short int m_XpTotal;
/// Caculates the Xp needed for a given level, ref: http://minecraft.gamepedia.com/XP
- static int XpForLevel(int a_Level);
+ static short XpForLevel(short int a_Level);
/// inverse of XpAtLevel, ref: http://minecraft.gamepedia.com/XP values are as per this with pre-calculations
- static int CalcLevelFromXp(int a_XpTotal);
+ static short CalcLevelFromXp(short int a_XpTotal);
bool m_IsChargingBow;
int m_BowCharge;
diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h
index 5023ea227..542060ece 100644
--- a/source/Protocol/Protocol.h
+++ b/source/Protocol/Protocol.h
@@ -22,9 +22,9 @@ class cWindow;
class cInventory;
class cPawn;
class cPickup;
+class cWorld;
class cMonster;
class cChunkDataSerializer;
-class cWorld;
class cFallingBlock;
@@ -85,6 +85,7 @@ public:
virtual void SendPlayerPosition (void) = 0;
virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
virtual void SendRespawn (void) = 0;
+ virtual void SendExperience (void) = 0;
virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) = 0; // a_Src coords are Block * 8
virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) = 0;
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0;
diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp
index 9f2770815..c2dc1c9ce 100644
--- a/source/Protocol/Protocol125.cpp
+++ b/source/Protocol/Protocol125.cpp
@@ -72,6 +72,7 @@ enum
PACKET_ENT_STATUS = 0x26,
PACKET_ATTACH_ENTITY = 0x27,
PACKET_METADATA = 0x28,
+ PACKET_EXPERIENCE = 0x2b,
PACKET_PRE_CHUNK = 0x32,
PACKET_MAP_CHUNK = 0x33,
PACKET_MULTI_BLOCK = 0x34,
@@ -690,6 +691,20 @@ void cProtocol125::SendRespawn(void)
+void cProtocol125::SendExperience(void)
+{
+ cCSLock Lock(m_CSPacket);
+ WriteByte (PACKET_EXPERIENCE);
+ WriteFloat (m_Client->GetPlayer()->XpGetPercentage());
+ WriteShort (m_Client->GetPlayer()->XpGetLevel());
+ WriteShort (m_Client->GetPlayer()->XpGetTotal());
+ Flush();
+}
+
+
+
+
+
void cProtocol125::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch)
{
// Not needed in this protocol version
diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h
index db913bb57..c5f44c818 100644
--- a/source/Protocol/Protocol125.h
+++ b/source/Protocol/Protocol125.h
@@ -62,6 +62,7 @@ public:
virtual void SendPlayerPosition (void) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendRespawn (void) override;
+ virtual void SendExperience (void) override;
virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8
virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
diff --git a/source/Protocol/Protocol17x.cpp b/source/Protocol/Protocol17x.cpp
index 628b8e071..7ff2b54b1 100644
--- a/source/Protocol/Protocol17x.cpp
+++ b/source/Protocol/Protocol17x.cpp
@@ -597,6 +597,18 @@ void cProtocol172::SendRespawn(void)
+void cProtocol172::SendExperience (void)
+{
+ cPacketizer Pkt(*this, 0x1F); //Experience Packet
+ Pkt.WriteFloat(m_Client->GetPlayer()->XpGetPercentage());
+ Pkt.WriteShort(m_Client->GetPlayer()->XpGetLevel());
+ Pkt.WriteShort(m_Client->GetPlayer()->XpGetTotal());
+}
+
+
+
+
+
void cProtocol172::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) // a_Src coords are Block * 8
{
cPacketizer Pkt(*this, 0x29); // Sound Effect packet
diff --git a/source/Protocol/Protocol17x.h b/source/Protocol/Protocol17x.h
index 844069403..e3f2ad922 100644
--- a/source/Protocol/Protocol17x.h
+++ b/source/Protocol/Protocol17x.h
@@ -72,6 +72,7 @@ public:
virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendRespawn (void) override;
virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override; // a_Src coords are Block * 8
+ virtual void SendExperience (void) override;
virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;
virtual void SendSpawnMob (const cMonster & a_Mob) override;
diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp
index 9234785b5..64bd83075 100644
--- a/source/Protocol/ProtocolRecognizer.cpp
+++ b/source/Protocol/ProtocolRecognizer.cpp
@@ -466,6 +466,16 @@ void cProtocolRecognizer::SendRespawn(void)
+void cProtocolRecognizer::SendExperience(void)
+{
+ ASSERT(m_Protocol != NULL);
+ m_Protocol->SendExperience();
+}
+
+
+
+
+
void cProtocolRecognizer::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch)
{
ASSERT(m_Protocol != NULL);
diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h
index c085e2cd8..03f48fb35 100644
--- a/source/Protocol/ProtocolRecognizer.h
+++ b/source/Protocol/ProtocolRecognizer.h
@@ -97,6 +97,7 @@ public:
virtual void SendPlayerPosition (void) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendRespawn (void) override;
+ virtual void SendExperience (void) override;
virtual void SendSoundEffect (const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) override;
virtual void SendSoundParticleEffect (int a_EffectID, int a_SrcX, int a_SrcY, int a_SrcZ, int a_Data) override;
virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override;