summaryrefslogtreecommitdiffstats
path: root/src/Entities/ExpOrb.cpp
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2024-11-02 22:27:47 +0100
committerAlexander Harkness <me@bearbin.net>2024-11-02 22:27:47 +0100
commitcb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a (patch)
treef647b20e1823f1846af88e832cf82a4a02e96e69 /src/Entities/ExpOrb.cpp
parentImprove clang-format config file, remove automatically enforced code style from contrib guide. (diff)
downloadcuberite-clang-format-codebase.tar
cuberite-clang-format-codebase.tar.gz
cuberite-clang-format-codebase.tar.bz2
cuberite-clang-format-codebase.tar.lz
cuberite-clang-format-codebase.tar.xz
cuberite-clang-format-codebase.tar.zst
cuberite-clang-format-codebase.zip
Diffstat (limited to 'src/Entities/ExpOrb.cpp')
-rw-r--r--src/Entities/ExpOrb.cpp84
1 files changed, 46 insertions, 38 deletions
diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp
index 125ea394a..852f60efb 100644
--- a/src/Entities/ExpOrb.cpp
+++ b/src/Entities/ExpOrb.cpp
@@ -5,10 +5,8 @@
#include "../ClientHandle.h"
-cExpOrb::cExpOrb(Vector3d a_Pos, int a_Reward):
- Super(etExpOrb, a_Pos, 0.5f, 0.5f),
- m_Reward(a_Reward),
- m_Timer(0)
+cExpOrb::cExpOrb(Vector3d a_Pos, int a_Reward) :
+ Super(etExpOrb, a_Pos, 0.5f, 0.5f), m_Reward(a_Reward), m_Timer(0)
{
SetMaxHealth(5);
SetHealth(5);
@@ -37,41 +35,53 @@ void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_TicksAlive++;
// Find closest player within 6.5 meter (slightly increase detect range to have same effect in client)
- bool FoundPlayer = m_World->DoWithNearestPlayer(GetPosition(), 6.5, [&](cPlayer & a_Player) -> bool
- {
- Vector3f a_PlayerPos(a_Player.GetPosition());
- a_PlayerPos.y += 0.8f;
- Vector3f a_Distance = a_PlayerPos - GetPosition();
- double Distance = a_Distance.Length();
-
- if (Distance < 0.7f)
+ bool FoundPlayer = m_World->DoWithNearestPlayer(
+ GetPosition(),
+ 6.5,
+ [&](cPlayer & a_Player) -> bool
{
- a_Player.DeltaExperience(m_Reward);
+ Vector3f a_PlayerPos(a_Player.GetPosition());
+ a_PlayerPos.y += 0.8f;
+ Vector3f a_Distance = a_PlayerPos - GetPosition();
+ double Distance = a_Distance.Length();
+
+ if (Distance < 0.7f)
+ {
+ a_Player.DeltaExperience(m_Reward);
+
+ m_World->BroadcastSoundEffect(
+ "entity.experience_orb.pickup",
+ GetPosition(),
+ 0.5f,
+ (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)
+ );
+ Destroy();
+ return true;
+ }
+
+ // Experience orb will "float" or glide toward the player up to a distance of 6 blocks.
+ // speeding up as they get nearer to the player, Speed range 6 - 12 m per second, accelerate 60 m per
+ // second^2
+ Vector3d SpeedDelta(a_Distance);
+ SpeedDelta.Normalize();
+ SpeedDelta *= 3;
+
+ Vector3d CurrentSpeed = GetSpeed();
+ CurrentSpeed += SpeedDelta;
+ if (CurrentSpeed.Length() > 12)
+ {
+ CurrentSpeed.Normalize();
+ CurrentSpeed *= 12;
+ }
+
+ SetSpeed(CurrentSpeed);
+ m_Gravity = 0;
- m_World->BroadcastSoundEffect("entity.experience_orb.pickup", GetPosition(), 0.5f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
- Destroy();
return true;
- }
-
- // Experience orb will "float" or glide toward the player up to a distance of 6 blocks.
- // speeding up as they get nearer to the player, Speed range 6 - 12 m per second, accelerate 60 m per second^2
- Vector3d SpeedDelta(a_Distance);
- SpeedDelta.Normalize();
- SpeedDelta *= 3;
-
- Vector3d CurrentSpeed = GetSpeed();
- CurrentSpeed += SpeedDelta;
- if (CurrentSpeed.Length() > 12)
- {
- CurrentSpeed.Normalize();
- CurrentSpeed *= 12;
- }
-
- SetSpeed(CurrentSpeed);
- m_Gravity = 0;
-
- return true;
- }, false, true); // Don't check line of sight, ignore spectator mode player
+ },
+ false,
+ true
+ ); // Don't check line of sight, ignore spectator mode player
if (!FoundPlayer)
{
@@ -127,5 +137,3 @@ std::vector<int> cExpOrb::Split(int a_Reward)
return Rewards;
}
-
-