diff options
author | Pablo Beltrán <spekdrum@gmail.com> | 2017-06-03 21:10:48 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-06-03 21:10:48 +0200 |
commit | 8f1e55611e52954316994706a29ba7953683361d (patch) | |
tree | 1996f7fcb649b0ee11024eb0ccb282fb9b206406 /src/Entities | |
parent | New icon colors (#3675) (diff) | |
download | cuberite-8f1e55611e52954316994706a29ba7953683361d.tar cuberite-8f1e55611e52954316994706a29ba7953683361d.tar.gz cuberite-8f1e55611e52954316994706a29ba7953683361d.tar.bz2 cuberite-8f1e55611e52954316994706a29ba7953683361d.tar.lz cuberite-8f1e55611e52954316994706a29ba7953683361d.tar.xz cuberite-8f1e55611e52954316994706a29ba7953683361d.tar.zst cuberite-8f1e55611e52954316994706a29ba7953683361d.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Entities/ExpOrb.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp index 1b4845c09..2d59206c2 100644 --- a/src/Entities/ExpOrb.cpp +++ b/src/Entities/ExpOrb.cpp @@ -12,6 +12,7 @@ cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) { SetMaxHealth(5); SetHealth(5); + SetGravity(0); } @@ -25,6 +26,7 @@ cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) { SetMaxHealth(5); SetHealth(5); + SetGravity(0); } @@ -44,28 +46,30 @@ void cExpOrb::SpawnOn(cClientHandle & a_Client) void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { - cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5)); - if ((a_ClosestPlayer != nullptr) && (!a_ClosestPlayer->IsGameModeSpectator())) + // Check player proximity no more than twice per second + if ((m_TicksAlive % 10) == 0) { - Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition()); - a_PlayerPos.y++; - Vector3f a_Distance(a_PlayerPos - GetPosition()); - double Distance(a_Distance.Length()); - if (Distance < 0.1f) + cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5, false)); + if ((a_ClosestPlayer != nullptr) && (!a_ClosestPlayer->IsGameModeSpectator())) { - LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); - a_ClosestPlayer->DeltaExperience(m_Reward); - - m_World->BroadcastSoundEffect("entity.experience_orb.pickup", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)); - - Destroy(); + Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition()); + a_PlayerPos.y++; + Vector3f a_Distance(a_PlayerPos - GetPosition()); + double Distance(a_Distance.Length()); + if (Distance < 0.5f) + { + LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward); + a_ClosestPlayer->DeltaExperience(m_Reward); + + m_World->BroadcastSoundEffect("entity.experience_orb.pickup", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)); + + Destroy(true); + return; + } + SetSpeedX((a_PlayerPos.x - GetPosition().x) * 2.0); + SetSpeedY((a_PlayerPos.y - GetPosition().y) * 2.0); + SetSpeedZ((a_PlayerPos.z - GetPosition().z) * 2.0); } - a_Distance.Normalize(); - a_Distance *= (static_cast<float>(5.5 - Distance)); - SetSpeedX( a_Distance.x); - SetSpeedY( a_Distance.y); - SetSpeedZ( a_Distance.z); - BroadcastMovementUpdate(); } HandlePhysics(a_Dt, a_Chunk); |