summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/ArrowEntity.cpp31
-rw-r--r--src/Entities/ArrowEntity.h23
-rw-r--r--src/Entities/Boat.cpp20
-rw-r--r--src/Entities/Boat.h13
-rw-r--r--src/Entities/EnderCrystal.h13
-rw-r--r--src/Entities/Entity.cpp378
-rw-r--r--src/Entities/Entity.h253
-rw-r--r--src/Entities/EntityEffect.cpp146
-rw-r--r--src/Entities/EntityEffect.h265
-rw-r--r--src/Entities/ExpBottleEntity.h15
-rw-r--r--src/Entities/ExpOrb.cpp84
-rw-r--r--src/Entities/ExpOrb.h10
-rw-r--r--src/Entities/FallingBlock.cpp25
-rw-r--r--src/Entities/FallingBlock.h18
-rw-r--r--src/Entities/FireChargeEntity.cpp2
-rw-r--r--src/Entities/FireChargeEntity.h15
-rw-r--r--src/Entities/FireworkEntity.h16
-rw-r--r--src/Entities/Floater.cpp39
-rw-r--r--src/Entities/Floater.h16
-rw-r--r--src/Entities/GhastFireballEntity.cpp2
-rw-r--r--src/Entities/GhastFireballEntity.h15
-rw-r--r--src/Entities/HangingEntity.cpp9
-rw-r--r--src/Entities/HangingEntity.h19
-rw-r--r--src/Entities/ItemFrame.cpp8
-rw-r--r--src/Entities/ItemFrame.h9
-rw-r--r--src/Entities/LeashKnot.cpp25
-rw-r--r--src/Entities/LeashKnot.h19
-rw-r--r--src/Entities/Minecart.cpp207
-rw-r--r--src/Entities/Minecart.h98
-rw-r--r--src/Entities/Painting.cpp5
-rw-r--r--src/Entities/Painting.h13
-rw-r--r--src/Entities/Pawn.cpp159
-rw-r--r--src/Entities/Pawn.h51
-rw-r--r--src/Entities/Pickup.cpp67
-rw-r--r--src/Entities/Pickup.h24
-rw-r--r--src/Entities/Player.cpp290
-rw-r--r--src/Entities/Player.h118
-rw-r--r--src/Entities/ProjectileEntity.cpp123
-rw-r--r--src/Entities/ProjectileEntity.h33
-rw-r--r--src/Entities/SplashPotionEntity.cpp49
-rw-r--r--src/Entities/SplashPotionEntity.h24
-rw-r--r--src/Entities/TNTEntity.cpp7
-rw-r--r--src/Entities/TNTEntity.h10
-rw-r--r--src/Entities/ThrownEggEntity.cpp2
-rw-r--r--src/Entities/ThrownEggEntity.h11
-rw-r--r--src/Entities/ThrownEnderPearlEntity.cpp34
-rw-r--r--src/Entities/ThrownEnderPearlEntity.h11
-rw-r--r--src/Entities/ThrownSnowballEntity.cpp2
-rw-r--r--src/Entities/ThrownSnowballEntity.h11
-rw-r--r--src/Entities/WitherSkullEntity.cpp8
-rw-r--r--src/Entities/WitherSkullEntity.h15
51 files changed, 1521 insertions, 1339 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index c21f2a7f3..5f8988b61 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -9,7 +9,7 @@
-cArrowEntity::cArrowEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cArrowEntity::cArrowEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkArrow, a_Creator, a_Pos, a_Speed, 0.5f, 0.5f),
m_PickupState(psNoPickup),
m_DamageCoeff(2),
@@ -20,8 +20,12 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed
SetMass(0.1);
SetGravity(-20.0f);
- FLOGD("Created arrow {0} with speed {1:.02f} and rot {{{2:.02f}, {3:.02f}}}",
- m_UniqueID, GetSpeed(), GetYaw(), GetPitch()
+ FLOGD(
+ "Created arrow {0} with speed {1:.02f} and rot {{{2:.02f}, {3:.02f}}}",
+ m_UniqueID,
+ GetSpeed(),
+ GetYaw(),
+ GetPitch()
);
}
@@ -81,7 +85,12 @@ void cArrowEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
m_HitBlockPos = (a_HitPos + (Speed / 100000)).Floor();
// Broadcast arrow hit sound
- m_World->BroadcastSoundEffect("entity.arrow.hit", m_HitBlockPos, 0.5f, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
+ m_World->BroadcastSoundEffect(
+ "entity.arrow.hit",
+ m_HitBlockPos,
+ 0.5f,
+ static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)
+ );
// Trigger any buttons that were hit
// Wooden buttons will be depressed by the arrow
@@ -129,7 +138,12 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
}
// Broadcast successful hit sound
- GetWorld()->BroadcastSoundEffect("entity.arrow.hit", GetPosition(), 0.5, static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
+ GetWorld()->BroadcastSoundEffect(
+ "entity.arrow.hit",
+ GetPosition(),
+ 0.5,
+ static_cast<float>(0.75 + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)
+ );
Destroy();
}
@@ -154,7 +168,12 @@ void cArrowEntity::CollectedBy(cPlayer & a_Dest)
}
GetWorld()->BroadcastCollectEntity(*this, a_Dest, 1);
- GetWorld()->BroadcastSoundEffect("entity.item.pickup", GetPosition(), 0.3f, (1.2f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
+ GetWorld()->BroadcastSoundEffect(
+ "entity.item.pickup",
+ GetPosition(),
+ 0.3f,
+ (1.2f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)
+ );
m_bIsCollected = true;
}
}
diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h
index 793e09401..5cf9fb1eb 100644
--- a/src/Entities/ArrowEntity.h
+++ b/src/Entities/ArrowEntity.h
@@ -17,8 +17,7 @@
// tolua_begin
-class cArrowEntity :
- public cProjectileEntity
+class cArrowEntity : public cProjectileEntity
{
// tolua_end
@@ -27,19 +26,19 @@ class cArrowEntity :
// tolua_begin
-public:
-
- /** Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field */
+ public:
+ /** Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup"
+ * field */
enum ePickupState
{
- psNoPickup = 0,
+ psNoPickup = 0,
psInSurvivalOrCreative = 1,
- psInCreative = 2,
- } ;
+ psInCreative = 2,
+ };
// tolua_end
- static constexpr float ARROW_WATER_FRICTION = 50.0f; ///< Value used to calculate arrow speed in water
+ static constexpr float ARROW_WATER_FRICTION = 50.0f; ///< Value used to calculate arrow speed in water
CLASS_PROTODEF(cArrowEntity)
@@ -80,12 +79,12 @@ public:
/** Sets the block arrow is in. To be used by the MCA loader only! */
void SetBlockHit(const Vector3i & a_BlockHit) { m_HitBlockPos = a_BlockHit; }
-protected:
-
+ protected:
/** Determines when the arrow can be picked up by players */
ePickupState m_PickupState;
- /** The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal arrow */
+ /** The coefficient applied to the damage that the arrow will deal, based on the bow enchantment. 2.0 for normal
+ * arrow */
double m_DamageCoeff;
/** If true, the arrow deals more damage */
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index 9ad0dd5f9..38a24ab65 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -16,8 +16,7 @@
class cBoatCollisionCallback
{
-public:
-
+ public:
cBoatCollisionCallback(cBoat & a_Boat, cEntity * a_Attachee) :
m_Boat(a_Boat), m_Attachee(a_Attachee)
{
@@ -36,8 +35,7 @@ public:
return false;
}
-protected:
-
+ protected:
cBoat & m_Boat;
cEntity * m_Attachee;
};
@@ -48,9 +46,12 @@ protected:
cBoat::cBoat(Vector3d a_Pos, eMaterial a_Material) :
Super(etBoat, a_Pos, 1.375f, 0.5625f),
- m_LastDamage(0), m_ForwardDirection(0),
- m_DamageTaken(0.0f), m_Material(a_Material),
- m_RightPaddleUsed(false), m_LeftPaddleUsed(false)
+ m_LastDamage(0),
+ m_ForwardDirection(0),
+ m_DamageTaken(0.0f),
+ m_Material(a_Material),
+ m_RightPaddleUsed(false),
+ m_LeftPaddleUsed(false)
{
SetMass(20.0f);
SetGravity(-16.0f);
@@ -210,7 +211,7 @@ void cBoat::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
return;
}
- Vector3d ToAddSpeed = m_Attachee->GetLookVector() * (a_Sideways * 0.4) ;
+ Vector3d ToAddSpeed = m_Attachee->GetLookVector() * (a_Sideways * 0.4);
ToAddSpeed.y = 0;
AddSpeed(ToAddSpeed);
@@ -353,8 +354,7 @@ void cBoat::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Calculate boat's bounding box, run collision callback on all entities in said box
cBoatCollisionCallback BoatCollisionCallback(*this, m_Attachee);
Vector3d BoatPosition = GetPosition();
- cBoundingBox bbBoat(
- Vector3d(BoatPosition.x, floor(BoatPosition.y), BoatPosition.z), GetWidth() / 2, GetHeight());
+ cBoundingBox bbBoat(Vector3d(BoatPosition.x, floor(BoatPosition.y), BoatPosition.z), GetWidth() / 2, GetHeight());
m_World->ForEachEntityInBox(bbBoat, BoatCollisionCallback);
// Return to calculating physics normally
diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h
index 455e740e2..ddb7af93d 100644
--- a/src/Entities/Boat.h
+++ b/src/Entities/Boat.h
@@ -15,8 +15,7 @@
// tolua_begin
-class cBoat:
- public cEntity
+class cBoat : public cEntity
{
// tolua_end
@@ -24,7 +23,7 @@ class cBoat:
// tolua_begin
-public:
+ public:
enum eMaterial
{
bmOak,
@@ -63,7 +62,8 @@ public:
/** Sets the eMaterial of the boat */
void SetMaterial(cBoat::eMaterial a_Material) { m_Material = a_Material; }
- /** Returns the eMaterial that should be used for a boat created from the specified item. Returns bmOak if not a boat item */
+ /** Returns the eMaterial that should be used for a boat created from the specified item. Returns bmOak if not a
+ * boat item */
static eMaterial ItemToMaterial(const cItem & a_Item);
/** Returns the boat item of the boat material */
@@ -83,7 +83,8 @@ public:
void SetLastDamage(int TimeSinceLastHit);
void UpdatePaddles(bool rightPaddleUsed, bool leftPaddleUsed);
-private:
+
+ private:
int m_LastDamage;
int m_ForwardDirection;
@@ -93,4 +94,4 @@ private:
bool m_RightPaddleUsed;
bool m_LeftPaddleUsed;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/EnderCrystal.h b/src/Entities/EnderCrystal.h
index 7e783ffd2..8fa6acdbe 100644
--- a/src/Entities/EnderCrystal.h
+++ b/src/Entities/EnderCrystal.h
@@ -8,14 +8,12 @@
// tolua_begin
-class cEnderCrystal :
- public cEntity
+class cEnderCrystal : public cEntity
{
// tolua_end
using Super = cEntity;
-public:
-
+ public:
CLASS_PROTODEF(cEnderCrystal)
cEnderCrystal(Vector3d a_Pos, bool a_ShowBottom);
@@ -35,8 +33,7 @@ public:
// tolua_end
-private:
-
+ private:
Vector3i m_BeamTarget;
bool m_DisplayBeam;
@@ -49,7 +46,3 @@ private:
virtual void KilledBy(TakeDamageInfo & a_TDI) override;
}; // tolua_export
-
-
-
-
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 26ee7ed6f..8b4110b94 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -34,7 +34,7 @@ static UInt32 GetNextUniqueID(void)
////////////////////////////////////////////////////////////////////////////////
// cEntity:
-cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height):
+cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height) :
m_UniqueID(GetNextUniqueID()),
m_Health(1),
m_MaxHealth(1),
@@ -69,7 +69,7 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float
m_Rot(0.0, 0.0, 0.0),
m_Position(a_Pos),
m_WaterSpeed(0, 0, 0),
- m_Mass (0.001), // Default 1g
+ m_Mass(0.001), // Default 1g
m_Width(a_Width),
m_Height(a_Height),
m_InvulnerableTicks(0)
@@ -251,18 +251,23 @@ void cEntity::Destroy()
}
auto ParentChunkCoords = cChunkDef::BlockToChunk(GetPosition());
- m_World->QueueTask([this, ParentChunkCoords](cWorld & a_World)
- {
- LOGD("Destroying entity #%i (%s) from chunk (%d, %d)",
- this->GetUniqueID(), this->GetClass(),
- ParentChunkCoords.m_ChunkX, ParentChunkCoords.m_ChunkZ
- );
- UNUSED(ParentChunkCoords); // Non Debug mode only
+ m_World->QueueTask(
+ [this, ParentChunkCoords](cWorld & a_World)
+ {
+ LOGD(
+ "Destroying entity #%i (%s) from chunk (%d, %d)",
+ this->GetUniqueID(),
+ this->GetClass(),
+ ParentChunkCoords.m_ChunkX,
+ ParentChunkCoords.m_ChunkZ
+ );
+ UNUSED(ParentChunkCoords); // Non Debug mode only
- // Make sure that RemoveEntity returned a valid smart pointer
- // Also, not storing the returned pointer means automatic destruction
- VERIFY(a_World.RemoveEntity(*this));
- });
+ // Make sure that RemoveEntity returned a valid smart pointer
+ // Also, not storing the returned pointer means automatic destruction
+ VERIFY(a_World.RemoveEntity(*this));
+ }
+ );
}
@@ -295,12 +300,14 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
void cEntity::TakeDamage(eDamageType a_DamageType, UInt32 a_AttackerID, int a_RawDamage, double a_KnockbackAmount)
{
- m_World->DoWithEntityByID(a_AttackerID, [=](cEntity & a_Attacker)
+ m_World->DoWithEntityByID(
+ a_AttackerID,
+ [=](cEntity & a_Attacker)
{
cPawn * Attacker;
if (a_Attacker.IsPawn())
{
- Attacker = static_cast<cPawn*>(&a_Attacker);
+ Attacker = static_cast<cPawn *>(&a_Attacker);
}
else
{
@@ -317,7 +324,13 @@ void cEntity::TakeDamage(eDamageType a_DamageType, UInt32 a_AttackerID, int a_Ra
-void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, float a_FinalDamage, double a_KnockbackAmount)
+void cEntity::TakeDamage(
+ eDamageType a_DamageType,
+ cEntity * a_Attacker,
+ int a_RawDamage,
+ float a_FinalDamage,
+ double a_KnockbackAmount
+)
{
TakeDamageInfo TDI;
TDI.DamageType = a_DamageType;
@@ -358,7 +371,8 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
}
// Apply slight height to knockback
- Vector3d FinalKnockback = Vector3d(Heading.x * a_KnockbackAmount, Heading.y + KnockbackHeight, Heading.z * a_KnockbackAmount);
+ Vector3d FinalKnockback =
+ Vector3d(Heading.x * a_KnockbackAmount, Heading.y + KnockbackHeight, Heading.z * a_KnockbackAmount);
TDI.Knockback = FinalKnockback;
DoTakeDamage(TDI);
@@ -502,7 +516,8 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
// The duration of the effect is a random value between 1 and 1.5 seconds at level I,
// increasing the max duration by 0.5 seconds each level.
// Ref: https://minecraft.wiki/w/Enchanting#Bane_of_Arthropods
- int Duration = 20 + GetRandomProvider().RandInt(BaneOfArthropodsLevel * 10); // Duration in ticks.
+ int Duration =
+ 20 + GetRandomProvider().RandInt(BaneOfArthropodsLevel * 10); // Duration in ticks.
Monster->AddEntityEffect(cEntityEffect::effSlowness, Duration, 4);
break;
@@ -552,7 +567,8 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
unsigned int ThornsLevel = 0;
- const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() };
+ const cItem ArmorItems[] =
+ {GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots()};
for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++)
{
const cItem & Item = ArmorItems[i];
@@ -571,7 +587,8 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
}
- Player->GetStatistics().Custom[CustomStatistic::DamageDealt] += FloorC<StatisticsManager::StatValue>(a_TDI.FinalDamage * 10 + 0.5);
+ Player->GetStatistics().Custom[CustomStatistic::DamageDealt] +=
+ FloorC<StatisticsManager::StatValue>(a_TDI.FinalDamage * 10 + 0.5);
}
m_Health -= a_TDI.FinalDamage;
@@ -583,15 +600,18 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
SetSpeed(a_TDI.Knockback);
}
- m_World->BroadcastEntityAnimation(*this, [&a_TDI]
- {
- switch (a_TDI.DamageType)
+ m_World->BroadcastEntityAnimation(
+ *this,
+ [&a_TDI]
{
- case eDamageType::dtBurning: return EntityAnimation::PawnBurns;
- case eDamageType::dtDrowning: return EntityAnimation::PawnDrowns;
- default: return EntityAnimation::PawnHurts;
- }
- }());
+ switch (a_TDI.DamageType)
+ {
+ case eDamageType::dtBurning: return EntityAnimation::PawnBurns;
+ case eDamageType::dtDrowning: return EntityAnimation::PawnDrowns;
+ default: return EntityAnimation::PawnHurts;
+ }
+ }()
+ );
m_InvulnerableTicks = 10;
@@ -665,7 +685,8 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType)
{
case dtOnFire:
case dtSuffocating:
- case dtDrowning: // TODO: This one could be a special case - in various MC versions (PC vs XBox) it is and isn't armor-protected
+ case dtDrowning: // TODO: This one could be a special case - in various MC versions (PC vs XBox) it is and
+ // isn't armor-protected
case dtEnderPearl:
case dtStarving:
case dtInVoid:
@@ -702,7 +723,8 @@ float cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageTyp
{
int TotalEPF = 0;
- const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() };
+ const cItem ArmorItems[] =
+ {GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots()};
for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++)
{
const cItem & Item = ArmorItems[i];
@@ -712,7 +734,8 @@ float cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageTyp
TotalEPF += static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchProtection)) * 1;
}
- if ((a_DamageType == dtBurning) || (a_DamageType == dtFireContact) || (a_DamageType == dtLavaContact) || (a_DamageType == dtMagmaContact))
+ if ((a_DamageType == dtBurning) || (a_DamageType == dtFireContact) || (a_DamageType == dtLavaContact) ||
+ (a_DamageType == dtMagmaContact))
{
TotalEPF += static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchFireProtection)) * 2;
}
@@ -745,7 +768,8 @@ float cEntity::GetEnchantmentBlastKnockbackReduction()
{
UInt32 MaxLevel = 0;
- const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() };
+ const cItem ArmorItems[] =
+ {GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots()};
for (auto & Item : ArmorItems)
{
@@ -782,27 +806,36 @@ float cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Da
int Toughness = 0;
switch (GetEquippedHelmet().m_ItemType)
{
- case E_ITEM_LEATHER_CAP: ArmorValue += 1; break;
- case E_ITEM_GOLD_HELMET: ArmorValue += 2; break;
- case E_ITEM_CHAIN_HELMET: ArmorValue += 2; break;
- case E_ITEM_IRON_HELMET: ArmorValue += 2; break;
- case E_ITEM_DIAMOND_HELMET: ArmorValue += 3; Toughness += 2; break;
+ case E_ITEM_LEATHER_CAP: ArmorValue += 1; break;
+ case E_ITEM_GOLD_HELMET: ArmorValue += 2; break;
+ case E_ITEM_CHAIN_HELMET: ArmorValue += 2; break;
+ case E_ITEM_IRON_HELMET: ArmorValue += 2; break;
+ case E_ITEM_DIAMOND_HELMET:
+ ArmorValue += 3;
+ Toughness += 2;
+ break;
}
switch (GetEquippedChestplate().m_ItemType)
{
- case E_ITEM_LEATHER_TUNIC: ArmorValue += 3; break;
- case E_ITEM_GOLD_CHESTPLATE: ArmorValue += 5; break;
- case E_ITEM_CHAIN_CHESTPLATE: ArmorValue += 5; break;
- case E_ITEM_IRON_CHESTPLATE: ArmorValue += 6; break;
- case E_ITEM_DIAMOND_CHESTPLATE: ArmorValue += 8; Toughness += 2; break;
+ case E_ITEM_LEATHER_TUNIC: ArmorValue += 3; break;
+ case E_ITEM_GOLD_CHESTPLATE: ArmorValue += 5; break;
+ case E_ITEM_CHAIN_CHESTPLATE: ArmorValue += 5; break;
+ case E_ITEM_IRON_CHESTPLATE: ArmorValue += 6; break;
+ case E_ITEM_DIAMOND_CHESTPLATE:
+ ArmorValue += 8;
+ Toughness += 2;
+ break;
}
switch (GetEquippedLeggings().m_ItemType)
{
- case E_ITEM_LEATHER_PANTS: ArmorValue += 2; break;
- case E_ITEM_GOLD_LEGGINGS: ArmorValue += 3; break;
- case E_ITEM_CHAIN_LEGGINGS: ArmorValue += 4; break;
- case E_ITEM_IRON_LEGGINGS: ArmorValue += 5; break;
- case E_ITEM_DIAMOND_LEGGINGS: ArmorValue += 6; Toughness += 2; break;
+ case E_ITEM_LEATHER_PANTS: ArmorValue += 2; break;
+ case E_ITEM_GOLD_LEGGINGS: ArmorValue += 3; break;
+ case E_ITEM_CHAIN_LEGGINGS: ArmorValue += 4; break;
+ case E_ITEM_IRON_LEGGINGS: ArmorValue += 5; break;
+ case E_ITEM_DIAMOND_LEGGINGS:
+ ArmorValue += 6;
+ Toughness += 2;
+ break;
}
switch (GetEquippedBoots().m_ItemType)
{
@@ -810,7 +843,10 @@ float cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Da
case E_ITEM_GOLD_BOOTS: ArmorValue += 1; break;
case E_ITEM_CHAIN_BOOTS: ArmorValue += 1; break;
case E_ITEM_IRON_BOOTS: ArmorValue += 2; break;
- case E_ITEM_DIAMOND_BOOTS: ArmorValue += 3; Toughness += 2; break;
+ case E_ITEM_DIAMOND_BOOTS:
+ ArmorValue += 3;
+ Toughness += 2;
+ break;
}
// TODO: Special armor cases, such as wool, saddles, dog's collar
@@ -868,11 +904,8 @@ void cEntity::KilledBy(TakeDamageInfo & a_TDI)
}
// Drop loot, unless the attacker was a creative mode player:
- if (
- (a_TDI.Attacker == nullptr) ||
- !a_TDI.Attacker->IsPlayer() ||
- !static_cast<cPlayer *>(a_TDI.Attacker)->IsGameModeCreative()
- )
+ if ((a_TDI.Attacker == nullptr) || !a_TDI.Attacker->IsPlayer() ||
+ !static_cast<cPlayer *>(a_TDI.Attacker)->IsGameModeCreative())
{
cItems Drops;
GetDrops(Drops, a_TDI.Attacker);
@@ -955,27 +988,22 @@ void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
// Handle cactus damage or destruction:
- if (
- IsMob() || IsPickup() ||
- (IsPlayer() && !((static_cast<cPlayer *>(this))->IsGameModeCreative() || (static_cast<cPlayer *>(this))->IsGameModeSpectator()))
- )
+ if (IsMob() || IsPickup() ||
+ (IsPlayer() &&
+ !((static_cast<cPlayer *>(this))->IsGameModeCreative() ||
+ (static_cast<cPlayer *>(this))->IsGameModeSpectator())))
{
DetectCacti();
}
// Handle magma block damage
- if
- (
- IsOnGround() &&
- (
- (IsMob() && !static_cast<cPawn *>(this)->IsFireproof()) ||
- (
- IsPlayer() && !((static_cast<cPlayer *>(this))->IsGameModeCreative() || (static_cast<cPlayer *>(this))->IsGameModeSpectator())
- && !static_cast<cPlayer *>(this)->IsFireproof()
- && !static_cast<cPlayer *>(this)->HasEntityEffect(cEntityEffect::effFireResistance)
- )
- )
- )
+ if (IsOnGround() &&
+ ((IsMob() && !static_cast<cPawn *>(this)->IsFireproof()) ||
+ (IsPlayer() &&
+ !((static_cast<cPlayer *>(this))->IsGameModeCreative() ||
+ (static_cast<cPlayer *>(this))->IsGameModeSpectator()) &&
+ !static_cast<cPlayer *>(this)->IsFireproof() &&
+ !static_cast<cPlayer *>(this)->HasEntityEffect(cEntityEffect::effFireResistance))))
{
DetectMagma();
}
@@ -1022,7 +1050,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
- BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ);
+ BLOCKTYPE BlockIn = NextChunk->GetBlock(RelBlockX, BlockY, RelBlockZ);
BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
{
@@ -1042,18 +1070,22 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
static const struct
{
int x, y, z;
- } gCrossCoords[] =
- {
- { 1, 0, 0},
- {-1, 0, 0},
- { 0, 0, 1},
- { 0, 0, -1},
- } ;
+ } gCrossCoords[] = {
+ {1, 0, 0},
+ {-1, 0, 0},
+ {0, 0, 1},
+ {0, 0, -1},
+ };
bool IsNoAirSurrounding = true;
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
{
- if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock))
+ if (!NextChunk->UnboundedRelGetBlockType(
+ RelBlockX + gCrossCoords[i].x,
+ BlockY,
+ RelBlockZ + gCrossCoords[i].z,
+ GotBlock
+ ))
{
// The pickup is too close to an unloaded chunk, bail out of any physics handling
return;
@@ -1123,8 +1155,8 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
ApplyFriction(NextSpeed, 0.7, static_cast<float>(DtSec.count()));
}
- // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
- // might have different speed modifiers according to terrain.
+ // Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since
+ // we might have different speed modifiers according to terrain.
if (BlockIn == E_BLOCK_COBWEB)
{
NextSpeed.x *= 0.25;
@@ -1137,16 +1169,16 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_WaterSpeed *= 0.9; // Reduce speed each tick
auto AdjustSpeed = [](double & a_WaterSpeed, float a_WaterDir)
+ {
+ if (std::abs(a_WaterDir) > (0.05f / 0.4f))
{
- if (std::abs(a_WaterDir) > (0.05f / 0.4f))
- {
- a_WaterSpeed = 0.4 * a_WaterDir;
- }
- else if (std::abs(a_WaterSpeed) < 0.05)
- {
- a_WaterSpeed = 0.0;
- }
- };
+ a_WaterSpeed = 0.4 * a_WaterDir;
+ }
+ else if (std::abs(a_WaterSpeed) < 0.05)
+ {
+ a_WaterSpeed = 0.0;
+ }
+ };
AdjustSpeed(m_WaterSpeed.x, WaterDir.x);
AdjustSpeed(m_WaterSpeed.z, WaterDir.z);
@@ -1158,7 +1190,14 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
Vector3i HitBlockCoords;
eBlockFace HitBlockFace;
Vector3d wantNextPos = NextPos + NextSpeed * DtSec.count();
- auto isHit = cLineBlockTracer::FirstSolidHitTrace(*GetWorld(), NextPos, wantNextPos, HitCoords, HitBlockCoords, HitBlockFace);
+ auto isHit = cLineBlockTracer::FirstSolidHitTrace(
+ *GetWorld(),
+ NextPos,
+ wantNextPos,
+ HitCoords,
+ HitBlockCoords,
+ HitBlockFace
+ );
if (isHit)
{
// Set our position to where the block was hit:
@@ -1375,7 +1414,7 @@ void cEntity::DetectCacti(void)
{
for (int y = MinY; y <= MaxY; y++)
{
- if (GetWorld()->GetBlock({ x, y, z }) == E_BLOCK_CACTUS)
+ if (GetWorld()->GetBlock({x, y, z}) == E_BLOCK_CACTUS)
{
TakeDamage(dtCactusContact, nullptr, 1, 0);
return;
@@ -1404,7 +1443,7 @@ void cEntity::DetectMagma(void)
{
for (int y = MinY; y <= MaxY; y++)
{
- if (GetWorld()->GetBlock({ x, y, z }) == E_BLOCK_MAGMA)
+ if (GetWorld()->GetBlock({x, y, z}) == E_BLOCK_MAGMA)
{
TakeDamage(dtMagmaContact, nullptr, 1, 0);
return;
@@ -1452,7 +1491,8 @@ bool cEntity::DetectPortal()
return false;
}
- if (IsPlayer() && !(static_cast<cPlayer *>(this))->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80))
+ if (IsPlayer() && !(static_cast<cPlayer *>(this))->IsGameModeCreative() &&
+ (m_PortalCooldownData.m_TicksDelayed != 80))
{
// Delay teleportation for four seconds if the entity is a non-creative player
m_PortalCooldownData.m_TicksDelayed++;
@@ -1475,8 +1515,14 @@ bool cEntity::DetectPortal()
TargetPos.z *= 8.0;
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
- ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
- LOGD("Jumping %s -> %s", DimensionToString(dimNether).c_str(), DimensionToString(TargetWorld->GetDimension()).c_str());
+ ASSERT(
+ TargetWorld != nullptr
+ ); // The linkage checker should have prevented this at startup. See cWorld::start()
+ LOGD(
+ "Jumping %s -> %s",
+ DimensionToString(dimNether).c_str(),
+ DimensionToString(TargetWorld->GetDimension()).c_str()
+ );
new cNetherPortalScanner(*this, *TargetWorld, TargetPos, cChunkDef::Height);
return true;
}
@@ -1495,8 +1541,14 @@ bool cEntity::DetectPortal()
TargetPos.z /= 8.0;
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName());
- ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
- LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(TargetWorld->GetDimension()).c_str());
+ ASSERT(
+ TargetWorld != nullptr
+ ); // The linkage checker should have prevented this at startup. See cWorld::start()
+ LOGD(
+ "Jumping %s -> %s",
+ DimensionToString(dimOverworld).c_str(),
+ DimensionToString(TargetWorld->GetDimension()).c_str()
+ );
new cNetherPortalScanner(*this, *TargetWorld, TargetPos, (cChunkDef::Height / 2));
return true;
}
@@ -1525,8 +1577,14 @@ bool cEntity::DetectPortal()
m_PortalCooldownData.m_ShouldPreventTeleportation = true;
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
- ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
- LOGD("Jumping %s -> %s", DimensionToString(dimEnd).c_str(), DimensionToString(TargetWorld->GetDimension()).c_str());
+ ASSERT(
+ TargetWorld != nullptr
+ ); // The linkage checker should have prevented this at startup. See cWorld::start()
+ LOGD(
+ "Jumping %s -> %s",
+ DimensionToString(dimEnd).c_str(),
+ DimensionToString(TargetWorld->GetDimension()).c_str()
+ );
if (IsPlayer())
{
@@ -1550,11 +1608,16 @@ bool cEntity::DetectPortal()
m_PortalCooldownData.m_ShouldPreventTeleportation = true;
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName());
- ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
- LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(TargetWorld->GetDimension()).c_str());
+ ASSERT(
+ TargetWorld != nullptr
+ ); // The linkage checker should have prevented this at startup. See cWorld::start()
+ LOGD(
+ "Jumping %s -> %s",
+ DimensionToString(dimOverworld).c_str(),
+ DimensionToString(TargetWorld->GetDimension()).c_str()
+ );
return MoveToWorld(*TargetWorld, false);
}
-
}
default: break;
}
@@ -1588,10 +1651,14 @@ void cEntity::DoMoveToWorld(const sWorldChangeInfo & a_WorldChangeInfo)
return;
}
- LOGD("Warping entity #%i (%s) from world \"%s\" to \"%s\". Source chunk: (%d, %d) ",
- GetUniqueID(), GetClass(),
- m_World->GetName(), a_WorldChangeInfo.m_NewWorld->GetName(),
- GetChunkX(), GetChunkZ()
+ LOGD(
+ "Warping entity #%i (%s) from world \"%s\" to \"%s\". Source chunk: (%d, %d) ",
+ GetUniqueID(),
+ GetClass(),
+ m_World->GetName(),
+ a_WorldChangeInfo.m_NewWorld->GetName(),
+ GetChunkX(),
+ GetChunkZ()
);
// Stop ticking, in preperation for detaching from this world.
@@ -1626,7 +1693,7 @@ bool cEntity::MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_SetPo
// Create new world change info
// (The last warp command always takes precedence)
- m_WorldChangeInfo = { &a_World, a_NewPosition, a_SetPortalCooldown };
+ m_WorldChangeInfo = {&a_World, a_NewPosition, a_SetPortalCooldown};
if (OldWorld != nullptr)
{
@@ -1644,8 +1711,8 @@ bool cEntity::MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_SetPo
The last invocation takes effect
As of writing, cWorld ticks entities, clients, and then processes tasks
- We may call MoveToWorld (any number of times - consider multiple /portal commands within a tick) in the first and second stages
- Queue a task onto the third stage to invoke DoMoveToWorld ONCE with the last given destination world
+ We may call MoveToWorld (any number of times - consider multiple /portal commands within a tick) in the first and
+ second stages Queue a task onto the third stage to invoke DoMoveToWorld ONCE with the last given destination world
Store entity IDs in case client tick found the player disconnected and immediately destroys the object
After the move begins, no further calls to MoveToWorld is possible since neither the client nor entity is ticked
@@ -1676,7 +1743,11 @@ bool cEntity::MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_SetPo
bool cEntity::MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn)
{
- return MoveToWorld(a_World, a_ShouldSendRespawn, Vector3i(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ()));
+ return MoveToWorld(
+ a_World,
+ a_ShouldSendRespawn,
+ Vector3i(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ())
+ );
}
@@ -1692,7 +1763,12 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
return false;
}
- return MoveToWorld(*World, Vector3i(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ()), false, a_ShouldSendRespawn);
+ return MoveToWorld(
+ *World,
+ Vector3i(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ()),
+ false,
+ a_ShouldSendRespawn
+ );
}
@@ -1801,7 +1877,8 @@ void cEntity::HandleAir(void)
// See if the entity is /submerged/ water (head is in water)
// Get the type of block the entity is standing in:
- int RespirationLevel = static_cast<int>(GetEquippedHelmet().m_Enchantments.GetLevel(cEnchantments::enchRespiration));
+ int RespirationLevel =
+ static_cast<int>(GetEquippedHelmet().m_Enchantments.GetLevel(cEnchantments::enchRespiration));
if (IsHeadInWater())
{
@@ -1846,7 +1923,6 @@ void cEntity::HandleAir(void)
{
m_AirTickTimer = DROWNING_TICKS + (RespirationLevel * 15 * 20);
}
-
}
}
@@ -1952,8 +2028,10 @@ void cEntity::TeleportToEntity(cEntity & a_Entity)
void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
- // ask the plugins to allow teleport to the new position.
- if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
+ // ask the plugins to allow teleport to the new position.
+ if (!cRoot::Get()
+ ->GetPluginManager()
+ ->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
{
SetPosition({a_PosX, a_PosY, a_PosZ});
}
@@ -2080,10 +2158,7 @@ bool cEntity::IsA(const char * a_ClassName) const
bool cEntity::IsAttachedTo(const cEntity * a_Entity) const
{
- return (
- (m_AttachedTo != nullptr) &&
- (a_Entity->GetUniqueID() == m_AttachedTo->GetUniqueID())
- );
+ return ((m_AttachedTo != nullptr) && (a_Entity->GetUniqueID() == m_AttachedTo->GetUniqueID()));
}
@@ -2338,9 +2413,7 @@ void cEntity::BroadcastLeashedMobs()
-void cEntity::OnDetach()
-{
-}
+void cEntity::OnDetach() {}
@@ -2365,7 +2438,10 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
}
else
{
- Name = NamespaceSerializer::PrettifyEntityName(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
+ Name = NamespaceSerializer::PrettifyEntityName(
+ AString(NamespaceSerializer::From(Monster->GetMobType())),
+ Monster->IsTame()
+ );
}
}
else
@@ -2377,32 +2453,33 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
if (a_TDI.Attacker == nullptr)
{
const AString DamageText = [&]
+ {
+ switch (a_TDI.DamageType)
{
- switch (a_TDI.DamageType)
- {
- case dtRangedAttack: return "was shot";
- case dtLightning: return "was plasmified by lightining";
- case dtFalling: return GetRandomProvider().RandBool() ? "fell to death" : "hit the ground too hard";
- case dtDrowning: return "drowned";
- case dtSuffocating: return GetRandomProvider().RandBool() ? "git merge'd into a block" : "fused with a block";
- case dtStarving: return "forgot the importance of food";
- case dtCactusContact: return "was impaled on a cactus";
- case dtMagmaContact: return "discovered the floor was lava";
- case dtLavaContact: return "was melted by lava";
- case dtPoisoning: return "died from septicaemia";
- case dtWithering: return "is a husk of their former selves";
- case dtOnFire: return "forgot to stop, drop, and roll";
- case dtFireContact: return "burnt themselves to death";
- case dtInVoid: return "somehow fell out of the world";
- case dtPotionOfHarming: return "was magicked to death";
- case dtEnderPearl: return "misused an ender pearl";
- case dtAdmin: return "was administrator'd";
- case dtExplosion: return "blew up";
- case dtAttack: return "was attacked by thin air";
- case dtEnvironment: return "played too much dress up"; // This is not vanilla - added a own pun
- }
- UNREACHABLE("Unsupported damage type");
- }();
+ case dtRangedAttack: return "was shot";
+ case dtLightning: return "was plasmified by lightining";
+ case dtFalling: return GetRandomProvider().RandBool() ? "fell to death" : "hit the ground too hard";
+ case dtDrowning: return "drowned";
+ case dtSuffocating:
+ return GetRandomProvider().RandBool() ? "git merge'd into a block" : "fused with a block";
+ case dtStarving: return "forgot the importance of food";
+ case dtCactusContact: return "was impaled on a cactus";
+ case dtMagmaContact: return "discovered the floor was lava";
+ case dtLavaContact: return "was melted by lava";
+ case dtPoisoning: return "died from septicaemia";
+ case dtWithering: return "is a husk of their former selves";
+ case dtOnFire: return "forgot to stop, drop, and roll";
+ case dtFireContact: return "burnt themselves to death";
+ case dtInVoid: return "somehow fell out of the world";
+ case dtPotionOfHarming: return "was magicked to death";
+ case dtEnderPearl: return "misused an ender pearl";
+ case dtAdmin: return "was administrator'd";
+ case dtExplosion: return "blew up";
+ case dtAttack: return "was attacked by thin air";
+ case dtEnvironment: return "played too much dress up"; // This is not vanilla - added a own pun
+ }
+ UNREACHABLE("Unsupported damage type");
+ }();
auto DeathMessage = fmt::format(FMT_STRING("{} {}"), Name, DamageText);
PluginManager->CallHookKilled(*this, a_TDI, DeathMessage);
if (!DeathMessage.empty())
@@ -2431,7 +2508,10 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
}
else
{
- AString KillerName = NamespaceSerializer::PrettifyEntityName(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
+ AString KillerName = NamespaceSerializer::PrettifyEntityName(
+ AString(NamespaceSerializer::From(Monster->GetMobType())),
+ Monster->IsTame()
+ );
DeathMessage = fmt::format(FMT_STRING("{0} was killed by a {1}"), Name, KillerName);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 1f0c6e107..dad4dc6d1 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -10,37 +10,39 @@
// Place this macro in the public section of each cEntity descendant class and you're done :)
-#define CLASS_PROTODEF(classname) \
- virtual bool IsA(const char * a_ClassName) const override\
- { \
+#define CLASS_PROTODEF(classname) \
+ virtual bool IsA(const char * a_ClassName) const override \
+ { \
return ((a_ClassName != nullptr) && ((strcmp(a_ClassName, #classname) == 0) || Super::IsA(a_ClassName))); \
- } \
- virtual const char * GetClass(void) const override \
- { \
- return #classname; \
- } \
- static const char * GetClassStatic(void) \
- { \
- return #classname; \
- } \
- virtual const char * GetParentClass(void) const override \
- { \
- return Super::GetClass(); \
+ } \
+ virtual const char * GetClass(void) const override \
+ { \
+ return #classname; \
+ } \
+ static const char * GetClassStatic(void) \
+ { \
+ return #classname; \
+ } \
+ virtual const char * GetParentClass(void) const override \
+ { \
+ return Super::GetClass(); \
}
#define POSX_TOINT FloorC(GetPosX())
#define POSY_TOINT FloorC(GetPosY())
#define POSZ_TOINT FloorC(GetPosZ())
-#define POS_TOINT GetPosition().Floor()
+#define POS_TOINT GetPosition().Floor()
-#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) \
- cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); \
- do { \
+#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) \
+ cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); \
+ do \
+ { \
if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) \
- { \
- return; \
- } \
- } while (false)
+ { \
+ return; \
+ } \
+ } \
+ while (false)
@@ -58,13 +60,13 @@ class cMonster;
// tolua_begin
struct TakeDamageInfo
{
- eDamageType DamageType; // Where does the damage come from? Being hit / on fire / contact with cactus / ...
- cEntity * Attacker; // The attacking entity; valid only for dtAttack
- int RawDamage; // What damage would the receiver get without any armor. Usually: attacker mob type + weapons
- float FinalDamage; // What actual damage will be received. Usually: m_RawDamage minus armor
- Vector3d Knockback; // The amount and direction of knockback received from the damage
+ eDamageType DamageType; // Where does the damage come from? Being hit / on fire / contact with cactus / ...
+ cEntity * Attacker; // The attacking entity; valid only for dtAttack
+ int RawDamage; // What damage would the receiver get without any armor. Usually: attacker mob type + weapons
+ float FinalDamage; // What actual damage will be received. Usually: m_RawDamage minus armor
+ Vector3d Knockback; // The amount and direction of knockback received from the damage
// TODO: Effects - list of effects that the hit is causing. Unknown representation yet
-} ;
+};
// tolua_end
@@ -74,7 +76,7 @@ struct TakeDamageInfo
// tolua_begin
class cEntity
{
-protected:
+ protected:
/** State variables for MoveToWorld. */
struct sWorldChangeInfo
{
@@ -83,8 +85,7 @@ protected:
bool m_SetPortalCooldown;
};
-public:
-
+ public:
enum eEntityType
{
etEntity, // For all other types
@@ -105,27 +106,28 @@ public:
// Common variations
etMob = etMonster, // DEPRECATED, use etMonster instead!
- } ;
+ };
// tolua_end
- static const int FIRE_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in fire
- static const int FIRE_DAMAGE = 1; ///< Damage to deal when standing in fire
- static const int LAVA_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in lava
- static const int LAVA_DAMAGE = 4; ///< Damage to deal when standing in lava
- static const int BURN_TICKS_PER_DAMAGE = 20; ///< Ticks to wait between damaging an entity when it is burning
- static const int BURN_DAMAGE = 1; ///< Damage to deal when the entity is burning
+ static const int FIRE_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in fire
+ static const int FIRE_DAMAGE = 1; ///< Damage to deal when standing in fire
+ static const int LAVA_TICKS_PER_DAMAGE = 10; ///< Ticks to wait between damaging an entity when it stands in lava
+ static const int LAVA_DAMAGE = 4; ///< Damage to deal when standing in lava
+ static const int BURN_TICKS_PER_DAMAGE = 20; ///< Ticks to wait between damaging an entity when it is burning
+ static const int BURN_DAMAGE = 1; ///< Damage to deal when the entity is burning
- static const int BURN_TICKS = 160; ///< Ticks to keep an entity burning after it has stood in lava / fire
+ static const int BURN_TICKS = 160; ///< Ticks to keep an entity burning after it has stood in lava / fire
- static const int MAX_AIR_LEVEL = 300; ///< Maximum air an entity can have
- static const int DROWNING_TICKS = 20; ///< Number of ticks per heart of damage
+ static const int MAX_AIR_LEVEL = 300; ///< Maximum air an entity can have
+ static const int DROWNING_TICKS = 20; ///< Number of ticks per heart of damage
- static const int VOID_BOUNDARY = -64; ///< Y position to begin applying void damage
- static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied
+ static const int VOID_BOUNDARY = -64; ///< Y position to begin applying void damage
+ static const int FALL_DAMAGE_HEIGHT = 4; ///< Y difference after which fall damage is applied
/** Special ID that is considered an "invalid value", signifying no entity. */
- static const UInt32 INVALID_ID = 0; // Exported to Lua in ManualBindings.cpp, ToLua doesn't parse initialized constants.
+ static const UInt32 INVALID_ID =
+ 0; // Exported to Lua in ManualBindings.cpp, ToLua doesn't parse initialized constants.
cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height);
@@ -155,22 +157,22 @@ public:
eEntityType GetEntityType(void) const { return m_EntityType; }
- bool IsArrow (void) const { return IsA("cArrowEntity"); }
+ bool IsArrow(void) const { return IsA("cArrowEntity"); }
bool IsEnderCrystal(void) const { return (m_EntityType == etEnderCrystal); }
- bool IsPlayer (void) const { return (m_EntityType == etPlayer); }
- bool IsPickup (void) const { return (m_EntityType == etPickup); }
- bool IsMob (void) const { return (m_EntityType == etMonster); }
- bool IsPawn (void) const { return (IsMob() || IsPlayer()); }
+ bool IsPlayer(void) const { return (m_EntityType == etPlayer); }
+ bool IsPickup(void) const { return (m_EntityType == etPickup); }
+ bool IsMob(void) const { return (m_EntityType == etMonster); }
+ bool IsPawn(void) const { return (IsMob() || IsPlayer()); }
bool IsFallingBlock(void) const { return (m_EntityType == etFallingBlock); }
- bool IsMinecart (void) const { return (m_EntityType == etMinecart); }
- bool IsBoat (void) const { return (m_EntityType == etBoat); }
- bool IsTNT (void) const { return (m_EntityType == etTNT); }
- bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
- bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
- bool IsFloater (void) const { return (m_EntityType == etFloater); }
- bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); }
- bool IsLeashKnot (void) const { return (m_EntityType == etLeashKnot); }
- bool IsPainting (void) const { return (m_EntityType == etPainting); }
+ bool IsMinecart(void) const { return (m_EntityType == etMinecart); }
+ bool IsBoat(void) const { return (m_EntityType == etBoat); }
+ bool IsTNT(void) const { return (m_EntityType == etTNT); }
+ bool IsProjectile(void) const { return (m_EntityType == etProjectile); }
+ bool IsExpOrb(void) const { return (m_EntityType == etExpOrb); }
+ bool IsFloater(void) const { return (m_EntityType == etFloater); }
+ bool IsItemFrame(void) const { return (m_EntityType == etItemFrame); }
+ bool IsLeashKnot(void) const { return (m_EntityType == etLeashKnot); }
+ bool IsPainting(void) const { return (m_EntityType == etPainting); }
/** Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true) */
virtual bool IsA(const char * a_ClassName) const;
@@ -189,20 +191,20 @@ public:
cWorld * GetWorld(void) const { return m_World; }
- double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees
- float GetHeight (void) const { return m_Height; }
- double GetMass (void) const { return m_Mass; }
- double GetPosX (void) const { return m_Position.x; }
- double GetPosY (void) const { return m_Position.y; }
- double GetPosZ (void) const { return m_Position.z; }
- double GetYaw (void) const { return m_Rot.x; } // In degrees, [-180, +180)
- double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90]
- double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client
- Vector3d GetLookVector(void) const;
- double GetSpeedX (void) const { return m_Speed.x; }
- double GetSpeedY (void) const { return m_Speed.y; }
- double GetSpeedZ (void) const { return m_Speed.z; }
- float GetWidth (void) const { return m_Width; }
+ double GetHeadYaw(void) const { return m_HeadYaw; } // In degrees
+ float GetHeight(void) const { return m_Height; }
+ double GetMass(void) const { return m_Mass; }
+ double GetPosX(void) const { return m_Position.x; }
+ double GetPosY(void) const { return m_Position.y; }
+ double GetPosZ(void) const { return m_Position.z; }
+ double GetYaw(void) const { return m_Rot.x; } // In degrees, [-180, +180)
+ double GetPitch(void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90]
+ double GetRoll(void) const { return m_Rot.z; } // In degrees, unused in current client
+ Vector3d GetLookVector(void) const;
+ double GetSpeedX(void) const { return m_Speed.x; }
+ double GetSpeedY(void) const { return m_Speed.y; }
+ double GetSpeedZ(void) const { return m_Speed.z; }
+ float GetWidth(void) const { return m_Width; }
int GetChunkX(void) const { return FloorC(m_Position.x / cChunkDef::Width); }
int GetChunkZ(void) const { return FloorC(m_Position.z / cChunkDef::Width); }
@@ -210,16 +212,16 @@ public:
// Get the Entity's axis aligned bounding box, with absolute (world-relative) coordinates.
cBoundingBox GetBoundingBox() const { return cBoundingBox(GetPosition(), GetWidth() / 2, GetHeight()); }
- void SetHeadYaw (double a_HeadYaw);
- void SetMass (double a_Mass);
- void SetPosX (double a_PosX) { SetPosition({a_PosX, m_Position.y, m_Position.z}); }
- void SetPosY (double a_PosY) { SetPosition({m_Position.x, a_PosY, m_Position.z}); }
- void SetPosZ (double a_PosZ) { SetPosition({m_Position.x, m_Position.y, a_PosZ}); }
+ void SetHeadYaw(double a_HeadYaw);
+ void SetMass(double a_Mass);
+ void SetPosX(double a_PosX) { SetPosition({a_PosX, m_Position.y, m_Position.z}); }
+ void SetPosY(double a_PosY) { SetPosition({m_Position.x, a_PosY, m_Position.z}); }
+ void SetPosZ(double a_PosZ) { SetPosition({m_Position.x, m_Position.y, a_PosZ}); }
void SetPosition(double a_PosX, double a_PosY, double a_PosZ) { SetPosition({a_PosX, a_PosY, a_PosZ}); }
void SetPosition(const Vector3d & a_Position);
- void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180)
- void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180)
- void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180)
+ void SetYaw(double a_Yaw); // In degrees, normalizes to [-180, +180)
+ void SetPitch(double a_Pitch); // In degrees, normalizes to [-180, +180)
+ void SetRoll(double a_Roll); // In degrees, normalizes to [-180, +180)
/** Sets the speed of the entity, measured in m / sec */
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
@@ -236,16 +238,19 @@ public:
/** Sets the speed in the Z axis, leaving the other speed components intact. Measured in m / sec. */
void SetSpeedZ(double a_SpeedZ);
- void AddPosX (double a_AddPosX) { AddPosition(a_AddPosX, 0, 0); }
- void AddPosY (double a_AddPosY) { AddPosition(0, a_AddPosY, 0); }
- void AddPosZ (double a_AddPosZ) { AddPosition(0, 0, a_AddPosZ); }
- void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ) { SetPosition(m_Position + Vector3d(a_AddPosX, a_AddPosY, a_AddPosZ)); }
+ void AddPosX(double a_AddPosX) { AddPosition(a_AddPosX, 0, 0); }
+ void AddPosY(double a_AddPosY) { AddPosition(0, a_AddPosY, 0); }
+ void AddPosZ(double a_AddPosZ) { AddPosition(0, 0, a_AddPosZ); }
+ void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
+ {
+ SetPosition(m_Position + Vector3d(a_AddPosX, a_AddPosY, a_AddPosZ));
+ }
void AddPosition(const Vector3d & a_AddPos) { AddPosition(a_AddPos.x, a_AddPos.y, a_AddPos.z); }
- void AddSpeed (double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ);
- void AddSpeed (const Vector3d & a_AddSpeed) { AddSpeed(a_AddSpeed.x, a_AddSpeed.y, a_AddSpeed.z); }
- void AddSpeedX (double a_AddSpeedX);
- void AddSpeedY (double a_AddSpeedY);
- void AddSpeedZ (double a_AddSpeedZ);
+ void AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ);
+ void AddSpeed(const Vector3d & a_AddSpeed) { AddSpeed(a_AddSpeed.x, a_AddSpeed.y, a_AddSpeed.z); }
+ void AddSpeedX(double a_AddSpeedX);
+ void AddSpeedY(double a_AddSpeedY);
+ void AddSpeedZ(double a_AddSpeedZ);
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways);
void SteerVehicle(float a_Forward, float a_Sideways);
@@ -253,11 +258,11 @@ public:
inline UInt32 GetUniqueID(void) const { return m_UniqueID; }
/** Deprecated. Use IsTicking instead. */
- inline bool IsDestroyed() const {return !IsTicking();}
+ inline bool IsDestroyed() const { return !IsTicking(); }
- /** Returns true if the entity is valid and ticking. Returns false if the entity is not ticking and is about to leave
- its current world either via teleportation or destruction.
- If this returns false, you must stop using the cEntity pointer you have. */
+ /** Returns true if the entity is valid and ticking. Returns false if the entity is not ticking and is about to
+ leave its current world either via teleportation or destruction. If this returns false, you must stop using the
+ cEntity pointer you have. */
bool IsTicking(void) const;
// tolua_end
@@ -265,17 +270,27 @@ public:
void Destroy();
// tolua_begin
- /** Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and DoTakeDamage() called */
+ /** Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and
+ * DoTakeDamage() called */
void TakeDamage(cEntity & a_Attacker);
- /** Makes this entity take the specified damage. The final damage is calculated using current armor, then DoTakeDamage() called */
+ /** Makes this entity take the specified damage. The final damage is calculated using current armor, then
+ * DoTakeDamage() called */
void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, double a_KnockbackAmount);
- /** Makes this entity take the specified damage. The final damage is calculated using current armor, then DoTakeDamage() called */
+ /** Makes this entity take the specified damage. The final damage is calculated using current armor, then
+ * DoTakeDamage() called */
void TakeDamage(eDamageType a_DamageType, UInt32 a_Attacker, int a_RawDamage, double a_KnockbackAmount);
- /** Makes this entity take the specified damage. The values are packed into a TDI, knockback calculated, then sent through DoTakeDamage() */
- void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, float a_FinalDamage, double a_KnockbackAmount);
+ /** Makes this entity take the specified damage. The values are packed into a TDI, knockback calculated, then sent
+ * through DoTakeDamage() */
+ void TakeDamage(
+ eDamageType a_DamageType,
+ cEntity * a_Attacker,
+ int a_RawDamage,
+ float a_FinalDamage,
+ double a_KnockbackAmount
+ );
float GetGravity(void) const { return m_Gravity; }
@@ -431,7 +446,12 @@ public:
/** Teleports to the coordinates specified */
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ);
- bool MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = true);
+ bool MoveToWorld(
+ cWorld & a_World,
+ Vector3d a_NewPosition,
+ bool a_ShouldSetPortalCooldown = false,
+ bool a_ShouldSendRespawn = true
+ );
bool MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition)
{
@@ -447,10 +467,7 @@ public:
// tolua_end
/** Returns true if a world change is scheduled to happen. */
- bool IsWorldChangeScheduled() const
- {
- return (m_WorldChangeInfo.m_NewWorld != nullptr);
- }
+ bool IsWorldChangeScheduled() const { return (m_WorldChangeInfo.m_NewWorld != nullptr); }
/** Updates clients of changes in the entity. */
virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr);
@@ -483,13 +500,13 @@ public:
// tolua_begin
// COMMON metadata flags; descendants may override the defaults:
- virtual bool IsCrouched (void) const { return false; }
+ virtual bool IsCrouched(void) const { return false; }
virtual bool IsElytraFlying(void) const { return false; }
- virtual bool IsInvisible (void) const { return false; }
- virtual bool IsOnFire (void) const { return m_TicksLeftBurning > 0; }
- virtual bool IsRclking (void) const { return false; }
- virtual bool IsRiding (void) const { return false; }
- virtual bool IsSprinting (void) const { return false; }
+ virtual bool IsInvisible(void) const { return false; }
+ virtual bool IsOnFire(void) const { return m_TicksLeftBurning > 0; }
+ virtual bool IsRclking(void) const { return false; }
+ virtual bool IsRiding(void) const { return false; }
+ virtual bool IsSprinting(void) const { return false; }
/** Returns true if any part of the entity is in a fire block */
virtual bool IsInFire(void) const { return m_IsInFire; }
@@ -523,7 +540,8 @@ public:
/** Called when the specified player right-clicks this entity */
virtual void OnRightClicked(cPlayer & a_Player) {}
- /** Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). */
+ /** Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of
+ * looting etc.). Called from KilledBy(). */
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr)
{
UNUSED(a_Drops);
@@ -559,8 +577,7 @@ public:
/** Announces a death message on chat about killing the entity. */
void BroadcastDeathMessage(TakeDamageInfo & a_TDI);
-protected:
-
+ protected:
/** Structure storing the portal delay timer and cooldown boolean */
struct sPortalCooldownData
{
@@ -692,8 +709,7 @@ protected:
/** Called when this entity dismounts from m_AttachedTo. */
virtual void OnDetach();
-private:
-
+ private:
/** Whether the entity is ticking or not. If not, it is scheduled for removal or world-teleportation. */
bool m_IsTicking;
@@ -701,7 +717,7 @@ private:
cChunk * m_ParentChunk;
/** Measured in degrees, [-180, +180) */
- double m_HeadYaw;
+ double m_HeadYaw;
/** Measured in degrees, [-180, +180) */
Vector3d m_Rot;
@@ -715,7 +731,8 @@ private:
/** Measured in Kilograms (Kg) */
double m_Mass;
- /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. */
+ /** Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter.
+ */
float m_Width;
/** Height of the entity (Y axis). */
@@ -732,4 +749,4 @@ private:
/** List of players who are spectating this entity. */
std::vector<cPlayer *> m_Spectators;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp
index ea3a90d9d..9121e916c 100644
--- a/src/Entities/EntityEffect.cpp
+++ b/src/Entities/EntityEffect.cpp
@@ -135,46 +135,37 @@ bool cEntityEffect::IsPotionDrinkable(short a_ItemDamage)
-cEntityEffect::cEntityEffect():
- m_Ticks(0),
- m_Duration(0),
- m_Intensity(0),
- m_DistanceModifier(1)
+cEntityEffect::cEntityEffect() :
+ m_Ticks(0), m_Duration(0), m_Intensity(0), m_DistanceModifier(1)
{
-
}
-cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, double a_DistanceModifier):
- m_Ticks(0),
- m_Duration(a_Duration),
- m_Intensity(a_Intensity),
- m_DistanceModifier(a_DistanceModifier)
+cEntityEffect::cEntityEffect(int a_Duration, short a_Intensity, double a_DistanceModifier) :
+ m_Ticks(0), m_Duration(a_Duration), m_Intensity(a_Intensity), m_DistanceModifier(a_DistanceModifier)
{
-
}
-cEntityEffect::cEntityEffect(const cEntityEffect & a_OtherEffect):
+cEntityEffect::cEntityEffect(const cEntityEffect & a_OtherEffect) :
m_Ticks(a_OtherEffect.m_Ticks),
m_Duration(a_OtherEffect.m_Duration),
m_Intensity(a_OtherEffect.m_Intensity),
m_DistanceModifier(a_OtherEffect.m_DistanceModifier)
{
-
}
-cEntityEffect & cEntityEffect::operator =(cEntityEffect a_OtherEffect)
+cEntityEffect & cEntityEffect::operator=(cEntityEffect a_OtherEffect)
{
std::swap(m_Ticks, a_OtherEffect.m_Ticks);
std::swap(m_Duration, a_OtherEffect.m_Duration);
@@ -187,35 +178,64 @@ cEntityEffect & cEntityEffect::operator =(cEntityEffect a_OtherEffect)
-std::unique_ptr<cEntityEffect> cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier)
+std::unique_ptr<cEntityEffect> cEntityEffect::CreateEntityEffect(
+ cEntityEffect::eType a_EffectType,
+ int a_Duration,
+ short a_Intensity,
+ double a_DistanceModifier
+)
{
switch (a_EffectType)
{
- case cEntityEffect::effNoEffect: return std::make_unique<cEntityEffect >(a_Duration, a_Intensity, a_DistanceModifier);
-
- case cEntityEffect::effAbsorption: return std::make_unique<cEntityEffectAbsorption >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effBlindness: return std::make_unique<cEntityEffectBlindness >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effFireResistance: return std::make_unique<cEntityEffectFireResistance>(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effHaste: return std::make_unique<cEntityEffectHaste >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effHealthBoost: return std::make_unique<cEntityEffectHealthBoost >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effHunger: return std::make_unique<cEntityEffectHunger >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effInstantDamage: return std::make_unique<cEntityEffectInstantDamage >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effInstantHealth: return std::make_unique<cEntityEffectInstantHealth >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effInvisibility: return std::make_unique<cEntityEffectInvisibility >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effJumpBoost: return std::make_unique<cEntityEffectJumpBoost >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effMiningFatigue: return std::make_unique<cEntityEffectMiningFatigue >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effNausea: return std::make_unique<cEntityEffectNausea >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effNightVision: return std::make_unique<cEntityEffectNightVision >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effPoison: return std::make_unique<cEntityEffectPoison >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effRegeneration: return std::make_unique<cEntityEffectRegeneration >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effResistance: return std::make_unique<cEntityEffectResistance >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effSaturation: return std::make_unique<cEntityEffectSaturation >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effSlowness: return std::make_unique<cEntityEffectSlowness >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effSpeed: return std::make_unique<cEntityEffectSpeed >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effStrength: return std::make_unique<cEntityEffectStrength >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effWaterBreathing: return std::make_unique<cEntityEffectWaterBreathing>(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effWeakness: return std::make_unique<cEntityEffectWeakness >(a_Duration, a_Intensity, a_DistanceModifier);
- case cEntityEffect::effWither: return std::make_unique<cEntityEffectWither >(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effNoEffect:
+ return std::make_unique<cEntityEffect>(a_Duration, a_Intensity, a_DistanceModifier);
+
+ case cEntityEffect::effAbsorption:
+ return std::make_unique<cEntityEffectAbsorption>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effBlindness:
+ return std::make_unique<cEntityEffectBlindness>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effFireResistance:
+ return std::make_unique<cEntityEffectFireResistance>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effHaste:
+ return std::make_unique<cEntityEffectHaste>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effHealthBoost:
+ return std::make_unique<cEntityEffectHealthBoost>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effHunger:
+ return std::make_unique<cEntityEffectHunger>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effInstantDamage:
+ return std::make_unique<cEntityEffectInstantDamage>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effInstantHealth:
+ return std::make_unique<cEntityEffectInstantHealth>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effInvisibility:
+ return std::make_unique<cEntityEffectInvisibility>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effJumpBoost:
+ return std::make_unique<cEntityEffectJumpBoost>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effMiningFatigue:
+ return std::make_unique<cEntityEffectMiningFatigue>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effNausea:
+ return std::make_unique<cEntityEffectNausea>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effNightVision:
+ return std::make_unique<cEntityEffectNightVision>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effPoison:
+ return std::make_unique<cEntityEffectPoison>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effRegeneration:
+ return std::make_unique<cEntityEffectRegeneration>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effResistance:
+ return std::make_unique<cEntityEffectResistance>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effSaturation:
+ return std::make_unique<cEntityEffectSaturation>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effSlowness:
+ return std::make_unique<cEntityEffectSlowness>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effSpeed:
+ return std::make_unique<cEntityEffectSpeed>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effStrength:
+ return std::make_unique<cEntityEffectStrength>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effWaterBreathing:
+ return std::make_unique<cEntityEffectWaterBreathing>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effWeakness:
+ return std::make_unique<cEntityEffectWeakness>(a_Duration, a_Intensity, a_DistanceModifier);
+ case cEntityEffect::effWither:
+ return std::make_unique<cEntityEffectWither>(a_Duration, a_Intensity, a_DistanceModifier);
}
UNREACHABLE("Unsupported entity effect");
}
@@ -241,12 +261,12 @@ void cEntityEffectSpeed::OnActivate(cPawn & a_Target)
{
if (a_Target.IsMob())
{
- cMonster * Mob = static_cast<cMonster*>(&a_Target);
+ cMonster * Mob = static_cast<cMonster *>(&a_Target);
Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() + 0.2 * m_Intensity);
}
else if (a_Target.IsPlayer())
{
- cPlayer * Player = static_cast<cPlayer*>(&a_Target);
+ cPlayer * Player = static_cast<cPlayer *>(&a_Target);
Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() + 0.2 * m_Intensity);
Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() + 0.26 * m_Intensity);
Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() + 0.2 * m_Intensity);
@@ -261,12 +281,12 @@ void cEntityEffectSpeed::OnDeactivate(cPawn & a_Target)
{
if (a_Target.IsMob())
{
- cMonster * Mob = static_cast<cMonster*>(&a_Target);
+ cMonster * Mob = static_cast<cMonster *>(&a_Target);
Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() - 0.2 * m_Intensity);
}
else if (a_Target.IsPlayer())
{
- cPlayer * Player = static_cast<cPlayer*>(&a_Target);
+ cPlayer * Player = static_cast<cPlayer *>(&a_Target);
Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() - 0.2 * m_Intensity);
Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() - 0.26 * m_Intensity);
Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() - 0.2 * m_Intensity);
@@ -284,12 +304,12 @@ void cEntityEffectSlowness::OnActivate(cPawn & a_Target)
{
if (a_Target.IsMob())
{
- cMonster * Mob = static_cast<cMonster*>(&a_Target);
+ cMonster * Mob = static_cast<cMonster *>(&a_Target);
Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() - 0.15 * m_Intensity);
}
else if (a_Target.IsPlayer())
{
- cPlayer * Player = static_cast<cPlayer*>(&a_Target);
+ cPlayer * Player = static_cast<cPlayer *>(&a_Target);
Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() - 0.15 * m_Intensity);
Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() - 0.195 * m_Intensity);
Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() - 0.15 * m_Intensity);
@@ -304,12 +324,12 @@ void cEntityEffectSlowness::OnDeactivate(cPawn & a_Target)
{
if (a_Target.IsMob())
{
- cMonster * Mob = static_cast<cMonster*>(&a_Target);
+ cMonster * Mob = static_cast<cMonster *>(&a_Target);
Mob->SetRelativeWalkSpeed(Mob->GetRelativeWalkSpeed() + 0.15 * m_Intensity);
}
else if (a_Target.IsPlayer())
{
- cPlayer * Player = static_cast<cPlayer*>(&a_Target);
+ cPlayer * Player = static_cast<cPlayer *>(&a_Target);
Player->SetNormalMaxSpeed(Player->GetNormalMaxSpeed() + 0.15 * m_Intensity);
Player->SetSprintingMaxSpeed(Player->GetSprintingMaxSpeed() + 0.195 * m_Intensity);
Player->SetFlyingMaxSpeed(Player->GetFlyingMaxSpeed() + 0.15 * m_Intensity);
@@ -330,7 +350,12 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target)
if (a_Target.IsMob() && static_cast<cMonster &>(a_Target).IsUndead())
{
- a_Target.TakeDamage(dtPotionOfHarming, nullptr, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
+ a_Target.TakeDamage(
+ dtPotionOfHarming,
+ nullptr,
+ amount,
+ 0
+ ); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
return;
}
a_Target.Heal(amount);
@@ -353,7 +378,12 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target)
a_Target.Heal(amount);
return;
}
- a_Target.TakeDamage(dtPotionOfHarming, nullptr, amount, 0); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
+ a_Target.TakeDamage(
+ dtPotionOfHarming,
+ nullptr,
+ amount,
+ 0
+ ); // TODO: Store attacker in a pointer-safe way, pass to TakeDamage
}
@@ -397,7 +427,9 @@ void cEntityEffectHunger::OnTick(cPawn & a_Target)
if (a_Target.IsPlayer())
{
cPlayer & Target = static_cast<cPlayer &>(a_Target);
- Target.AddFoodExhaustion(0.025 * (static_cast<double>(GetIntensity()) + 1.0)); // 0.5 per second = 0.025 per tick
+ Target.AddFoodExhaustion(
+ 0.025 * (static_cast<double>(GetIntensity()) + 1.0)
+ ); // 0.5 per second = 0.025 per tick
}
}
@@ -451,11 +483,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target)
cMonster & Target = static_cast<cMonster &>(a_Target);
// Doesn't effect undead mobs, spiders
- if (
- Target.IsUndead() ||
- (Target.GetMobType() == mtSpider) ||
- (Target.GetMobType() == mtCaveSpider)
- )
+ if (Target.IsUndead() || (Target.GetMobType() == mtSpider) || (Target.GetMobType() == mtCaveSpider))
{
return;
}
@@ -506,6 +534,8 @@ void cEntityEffectSaturation::OnTick(cPawn & a_Target)
if (a_Target.IsPlayer())
{
cPlayer & Target = static_cast<cPlayer &>(a_Target);
- Target.SetFoodSaturationLevel(Target.GetFoodSaturationLevel() + (1 + m_Intensity)); // Increase saturation 1 per tick, adds 1 for every increase in level
+ Target.SetFoodSaturationLevel(
+ Target.GetFoodSaturationLevel() + (1 + m_Intensity)
+ ); // Increase saturation 1 per tick, adds 1 for every increase in level
}
}
diff --git a/src/Entities/EntityEffect.h b/src/Entities/EntityEffect.h
index b4e01d8d9..d8fa1aed0 100644
--- a/src/Entities/EntityEffect.h
+++ b/src/Entities/EntityEffect.h
@@ -5,36 +5,35 @@ class cPawn;
// tolua_begin
class cEntityEffect
{
-public:
-
+ public:
/** All types of entity effects (numbers correspond to protocol / storage types) */
enum eType
{
- effNoEffect = 0,
- effSpeed = 1,
- effSlowness = 2,
- effHaste = 3,
- effMiningFatigue = 4,
- effStrength = 5,
- effInstantHealth = 6,
- effInstantDamage = 7,
- effJumpBoost = 8,
- effNausea = 9,
- effRegeneration = 10,
- effResistance = 11,
+ effNoEffect = 0,
+ effSpeed = 1,
+ effSlowness = 2,
+ effHaste = 3,
+ effMiningFatigue = 4,
+ effStrength = 5,
+ effInstantHealth = 6,
+ effInstantDamage = 7,
+ effJumpBoost = 8,
+ effNausea = 9,
+ effRegeneration = 10,
+ effResistance = 11,
effFireResistance = 12,
effWaterBreathing = 13,
- effInvisibility = 14,
- effBlindness = 15,
- effNightVision = 16,
- effHunger = 17,
- effWeakness = 18,
- effPoison = 19,
- effWither = 20,
- effHealthBoost = 21,
- effAbsorption = 22,
- effSaturation = 23,
- } ;
+ effInvisibility = 14,
+ effBlindness = 15,
+ effNightVision = 16,
+ effHunger = 17,
+ effWeakness = 18,
+ effPoison = 19,
+ effWither = 20,
+ effHealthBoost = 21,
+ effAbsorption = 22,
+ effSaturation = 23,
+ };
/** Returns the potion color (used by the client for visuals), based on the potion's damage value */
static int GetPotionColor(short a_ItemDamage);
@@ -44,7 +43,8 @@ public:
static cEntityEffect::eType GetPotionEffectType(short a_ItemDamage);
- /** Retrieves the intensity level from the potion's damage value. Returns 0 for level I potions, 1 for level II potions. */
+ /** Retrieves the intensity level from the potion's damage value. Returns 0 for level I potions, 1 for level II
+ * potions. */
static short GetPotionEffectIntensity(short a_ItemDamage);
@@ -71,7 +71,7 @@ public:
/** Creates an entity effect by copying another
@param a_OtherEffect The other effect to copy */
- cEntityEffect & operator =(cEntityEffect a_OtherEffect);
+ cEntityEffect & operator=(cEntityEffect a_OtherEffect);
virtual ~cEntityEffect(void) = default;
@@ -81,7 +81,12 @@ public:
@param a_Duration How long this effect will last, in ticks
@param a_Intensity How strong the effect will be applied
@param a_DistanceModifier The distance modifier for affecting potency, defaults to 1 */
- static std::unique_ptr<cEntityEffect> CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier);
+ static std::unique_ptr<cEntityEffect> CreateEntityEffect(
+ cEntityEffect::eType a_EffectType,
+ int a_Duration,
+ short a_Intensity,
+ double a_DistanceModifier
+ );
/** Returns how many ticks this effect has been active for */
int GetTicks(void) const { return m_Ticks; }
@@ -95,9 +100,9 @@ public:
/** Returns the distance modifier for affecting potency */
double GetDistanceModifier(void) const { return m_DistanceModifier; }
- void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; }
- void SetDuration(int a_Duration) { m_Duration = a_Duration; }
- void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; }
+ void SetTicks(int a_Ticks) { m_Ticks = a_Ticks; }
+ void SetDuration(int a_Duration) { m_Duration = a_Duration; }
+ void SetIntensity(short a_Intensity) { m_Intensity = a_Intensity; }
void SetDistanceModifier(double a_DistanceModifier) { m_DistanceModifier = a_DistanceModifier; }
/** Called on each tick.
@@ -105,12 +110,12 @@ public:
virtual void OnTick(cPawn & a_Target);
/** Called when the effect is first added to an entity */
- virtual void OnActivate(cPawn & a_Target) { }
+ virtual void OnActivate(cPawn & a_Target) {}
/** Called when the effect is removed from an entity */
- virtual void OnDeactivate(cPawn & a_Target) { }
+ virtual void OnDeactivate(cPawn & a_Target) {}
-protected:
+ protected:
/** How many ticks this effect has been active for */
int m_Ticks;
@@ -128,14 +133,12 @@ protected:
-class cEntityEffectSpeed:
- public cEntityEffect
+class cEntityEffectSpeed : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectSpeed(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectSpeed(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -149,14 +152,12 @@ public:
-class cEntityEffectSlowness:
- public cEntityEffect
+class cEntityEffectSlowness : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectSlowness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectSlowness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -170,14 +171,12 @@ public:
-class cEntityEffectHaste:
- public cEntityEffect
+class cEntityEffectHaste : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectHaste(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectHaste(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -187,14 +186,12 @@ public:
-class cEntityEffectMiningFatigue:
- public cEntityEffect
+class cEntityEffectMiningFatigue : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectMiningFatigue(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectMiningFatigue(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -204,14 +201,12 @@ public:
-class cEntityEffectStrength:
- public cEntityEffect
+class cEntityEffectStrength : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectStrength(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectStrength(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -221,14 +216,12 @@ public:
-class cEntityEffectInstantHealth:
- public cEntityEffect
+class cEntityEffectInstantHealth : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectInstantHealth(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectInstantHealth(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -240,14 +233,12 @@ public:
-class cEntityEffectInstantDamage:
- public cEntityEffect
+class cEntityEffectInstantDamage : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectInstantDamage(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectInstantDamage(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -259,14 +250,12 @@ public:
-class cEntityEffectJumpBoost:
- public cEntityEffect
+class cEntityEffectJumpBoost : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectJumpBoost(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectJumpBoost(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -276,14 +265,12 @@ public:
-class cEntityEffectNausea:
- public cEntityEffect
+class cEntityEffectNausea : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectNausea(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectNausea(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -293,14 +280,12 @@ public:
-class cEntityEffectRegeneration:
- public cEntityEffect
+class cEntityEffectRegeneration : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectRegeneration(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectRegeneration(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -312,14 +297,12 @@ public:
-class cEntityEffectResistance:
- public cEntityEffect
+class cEntityEffectResistance : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectResistance(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectResistance(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -329,14 +312,12 @@ public:
-class cEntityEffectFireResistance:
- public cEntityEffect
+class cEntityEffectFireResistance : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectFireResistance(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectFireResistance(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -346,14 +327,12 @@ public:
-class cEntityEffectWaterBreathing:
- public cEntityEffect
+class cEntityEffectWaterBreathing : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectWaterBreathing(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectWaterBreathing(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -363,22 +342,20 @@ public:
-class cEntityEffectInvisibility:
- public cEntityEffect
+class cEntityEffectInvisibility : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectInvisibility(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectInvisibility(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
- virtual void OnActivate (cPawn & a_Target) override { BroadcastMetadata(a_Target); }
+ virtual void OnActivate(cPawn & a_Target) override { BroadcastMetadata(a_Target); }
virtual void OnDeactivate(cPawn & a_Target) override { BroadcastMetadata(a_Target); }
-private:
+ private:
static void BroadcastMetadata(cPawn & a_Target);
};
@@ -386,14 +363,12 @@ private:
-class cEntityEffectBlindness:
- public cEntityEffect
+class cEntityEffectBlindness : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectBlindness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectBlindness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -403,14 +378,12 @@ public:
-class cEntityEffectNightVision:
- public cEntityEffect
+class cEntityEffectNightVision : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectNightVision(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectNightVision(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -420,14 +393,12 @@ public:
-class cEntityEffectHunger:
- public cEntityEffect
+class cEntityEffectHunger : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectHunger(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectHunger(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -440,14 +411,12 @@ public:
-class cEntityEffectWeakness:
- public cEntityEffect
+class cEntityEffectWeakness : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectWeakness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectWeakness(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -460,14 +429,12 @@ public:
-class cEntityEffectPoison:
- public cEntityEffect
+class cEntityEffectPoison : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectPoison(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectPoison(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -480,14 +447,12 @@ public:
-class cEntityEffectWither:
- public cEntityEffect
+class cEntityEffectWither : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectWither(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectWither(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -500,14 +465,12 @@ public:
-class cEntityEffectHealthBoost:
- public cEntityEffect
+class cEntityEffectHealthBoost : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectHealthBoost(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectHealthBoost(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -517,14 +480,12 @@ public:
-class cEntityEffectAbsorption:
- public cEntityEffect
+class cEntityEffectAbsorption : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectAbsorption(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectAbsorption(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
@@ -534,21 +495,15 @@ public:
-class cEntityEffectSaturation:
- public cEntityEffect
+class cEntityEffectSaturation : public cEntityEffect
{
using Super = cEntityEffect;
-public:
-
- cEntityEffectSaturation(int a_Duration, short a_Intensity, double a_DistanceModifier = 1):
+ public:
+ cEntityEffectSaturation(int a_Duration, short a_Intensity, double a_DistanceModifier = 1) :
Super(a_Duration, a_Intensity, a_DistanceModifier)
{
}
virtual void OnTick(cPawn & a_Target) override;
};
-
-
-
-
diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h
index b05f6da31..a26f18005 100644
--- a/src/Entities/ExpBottleEntity.h
+++ b/src/Entities/ExpBottleEntity.h
@@ -17,31 +17,24 @@
// tolua_begin
-class cExpBottleEntity :
- public cProjectileEntity
+class cExpBottleEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cExpBottleEntity)
cExpBottleEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-protected:
-
+ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
- virtual void OnHitEntity (cEntity & a_EntityHit, Vector3d a_HitPos) override;
+ virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
/** Breaks the bottle, fires its particle effects and sounds
@param a_HitPos The position where the bottle will break */
void Break(Vector3d a_HitPos);
}; // tolua_export
-
-
-
-
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;
}
-
-
diff --git a/src/Entities/ExpOrb.h b/src/Entities/ExpOrb.h
index 3a7f4ee69..cd1ee5ffb 100644
--- a/src/Entities/ExpOrb.h
+++ b/src/Entities/ExpOrb.h
@@ -8,15 +8,13 @@
// tolua_begin
-class cExpOrb:
- public cEntity
+class cExpOrb : public cEntity
{
// tolua_end
using Super = cEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cExpOrb)
cExpOrb(Vector3d a_Pos, int a_Reward);
@@ -47,9 +45,9 @@ public: // tolua_export
/** Split reward into small values according to regular Minecraft rules */
static std::vector<int> Split(int a_Reward);
-protected:
+ protected:
int m_Reward;
/** The number of ticks that the entity has existed / timer between collect and destroy; in msec */
std::chrono::milliseconds m_Timer;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/FallingBlock.cpp b/src/Entities/FallingBlock.cpp
index aa6baae82..9ceb215fb 100644
--- a/src/Entities/FallingBlock.cpp
+++ b/src/Entities/FallingBlock.cpp
@@ -11,10 +11,8 @@
-cFallingBlock::cFallingBlock(Vector3d a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta):
- Super(etFallingBlock, a_Position, 0.98f, 0.98f),
- m_BlockType(a_BlockType),
- m_BlockMeta(a_BlockMeta)
+cFallingBlock::cFallingBlock(Vector3d a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
+ Super(etFallingBlock, a_Position, 0.98f, 0.98f), m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta)
{
SetGravity(-16.0f);
SetAirDrag(0.02f);
@@ -57,8 +55,16 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
return;
}
- BLOCKTYPE BlockBelow = a_Chunk.GetBlock(BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width);
- NIBBLETYPE BelowMeta = a_Chunk.GetMeta(BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width);
+ BLOCKTYPE BlockBelow = a_Chunk.GetBlock(
+ BlockX - a_Chunk.GetPosX() * cChunkDef::Width,
+ BlockY,
+ BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width
+ );
+ NIBBLETYPE BelowMeta = a_Chunk.GetMeta(
+ BlockX - a_Chunk.GetPosX() * cChunkDef::Width,
+ BlockY,
+ BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width
+ );
if (cSandSimulator::DoesBreakFallingThrough(BlockBelow, BelowMeta))
{
// Fallen onto a block that breaks this into pickups (e. g. half-slab)
@@ -99,12 +105,9 @@ void cFallingBlock::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
AddPosition(GetSpeed() * MilliDt);
// If not static (one billionth precision) broadcast movement
- if ((fabs(GetSpeedX()) > std::numeric_limits<double>::epsilon()) || (fabs(GetSpeedZ()) > std::numeric_limits<double>::epsilon()))
+ if ((fabs(GetSpeedX()) > std::numeric_limits<double>::epsilon()) ||
+ (fabs(GetSpeedZ()) > std::numeric_limits<double>::epsilon()))
{
BroadcastMovementUpdate();
}
}
-
-
-
-
diff --git a/src/Entities/FallingBlock.h b/src/Entities/FallingBlock.h
index 5f083402b..a1f5dfd06 100644
--- a/src/Entities/FallingBlock.h
+++ b/src/Entities/FallingBlock.h
@@ -8,15 +8,13 @@
// tolua_begin
-class cFallingBlock :
- public cEntity
+class cFallingBlock : public cEntity
{
// tolua_end
using Super = cEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cFallingBlock)
/** Creates a new falling block.
@@ -25,7 +23,7 @@ public: // tolua_export
// tolua_begin
- BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
+ BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
NIBBLETYPE GetBlockMeta(void) const { return m_BlockMeta; }
// tolua_end
@@ -34,11 +32,7 @@ public: // tolua_export
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
-private:
- BLOCKTYPE m_BlockType;
+ private:
+ BLOCKTYPE m_BlockType;
NIBBLETYPE m_BlockMeta;
-} ; // tolua_export
-
-
-
-
+}; // tolua_export
diff --git a/src/Entities/FireChargeEntity.cpp b/src/Entities/FireChargeEntity.cpp
index edbc05e2c..81240293c 100644
--- a/src/Entities/FireChargeEntity.cpp
+++ b/src/Entities/FireChargeEntity.cpp
@@ -7,7 +7,7 @@
-cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cFireChargeEntity::cFireChargeEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkFireCharge, a_Creator, a_Pos, 0.3125f, 0.3125f)
{
SetSpeed(a_Speed);
diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h
index 93e273c2c..29e519c9d 100644
--- a/src/Entities/FireChargeEntity.h
+++ b/src/Entities/FireChargeEntity.h
@@ -17,29 +17,22 @@
// tolua_begin
-class cFireChargeEntity :
- public cProjectileEntity
+class cFireChargeEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cFireChargeEntity)
cFireChargeEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-protected:
-
+ protected:
void Explode(Vector3i a_Block);
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
-} ; // tolua_export
-
-
-
-
+}; // tolua_export
diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h
index ce30c392e..aa3331341 100644
--- a/src/Entities/FireworkEntity.h
+++ b/src/Entities/FireworkEntity.h
@@ -17,15 +17,13 @@
// tolua_begin
-class cFireworkEntity :
- public cProjectileEntity
+class cFireworkEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cFireworkEntity)
cFireworkEntity(cEntity * a_Creator, Vector3d a_Pos, const cItem & a_Item);
@@ -46,19 +44,13 @@ public: // tolua_export
// tolua_end
-protected:
-
+ protected:
// cProjectileEntity overrides:
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
-private:
-
+ private:
int m_TicksToExplosion;
cItem m_FireworkItem;
}; // tolua_export
-
-
-
-
diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp
index 1fd4673bd..3a5856776 100644
--- a/src/Entities/Floater.cpp
+++ b/src/Entities/Floater.cpp
@@ -15,16 +15,12 @@
// cFloaterEntityCollisionCallback
class cFloaterEntityCollisionCallback
{
-public:
+ public:
cFloaterEntityCollisionCallback(cFloater * a_Floater, const Vector3d & a_Pos, const Vector3d & a_NextPos) :
- m_Floater(a_Floater),
- m_Pos(a_Pos),
- m_NextPos(a_NextPos),
- m_MinCoeff(1),
- m_HitEntity(nullptr)
+ m_Floater(a_Floater), m_Pos(a_Pos), m_NextPos(a_NextPos), m_MinCoeff(1), m_HitEntity(nullptr)
{
}
- bool operator () (cEntity & a_Entity)
+ bool operator()(cEntity & a_Entity)
{
if (!a_Entity.IsMob()) // Floaters can only pull mobs not other entities.
{
@@ -59,16 +55,17 @@ public:
/** Returns true if the callback has encountered a true hit */
bool HasHit(void) const { return (m_MinCoeff < 1); }
-protected:
+ protected:
cFloater * m_Floater;
const Vector3d & m_Pos;
const Vector3d & m_NextPos;
double m_MinCoeff; // The coefficient of the nearest hit on the Pos line
// Although it's bad(tm) to store entity ptrs from a callback, we can afford it here, because the entire callback
- // is processed inside the tick thread, so the entities won't be removed in between the calls and the final processing
+ // is processed inside the tick thread, so the entities won't be removed in between the calls and the final
+ // processing
cEntity * m_HitEntity; // The nearest hit entity
-} ;
+};
@@ -112,7 +109,9 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
auto & Random = GetRandomProvider();
if (IsBlockWater(Chunk->GetBlock(Rel)) && (Chunk->GetMeta(Rel) == 0))
{
- if (!m_CanPickupItem && (m_AttachedMobID == cEntity::INVALID_ID)) // Check if you can't already pickup a fish and if the floater isn't attached to a mob.
+ if (!m_CanPickupItem &&
+ (m_AttachedMobID == cEntity::INVALID_ID
+ )) // Check if you can't already pickup a fish and if the floater isn't attached to a mob.
{
if (m_CountDownTime <= 0)
{
@@ -124,16 +123,17 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_CountDownTime = Random.RandInt(100, 900);
LOGD("Floater %i can be picked up", GetUniqueID());
}
- else if (m_CountDownTime == 20) // Calculate the position where the particles should spawn and start producing them.
+ else if (m_CountDownTime ==
+ 20) // Calculate the position where the particles should spawn and start producing them.
{
LOGD("Started producing particles for floater %i", GetUniqueID());
m_ParticlePos.Set(GetPosX() + Random.RandInt(-4, 4), GetPosY(), GetPosZ() + Random.RandInt(-4, 4));
- m_World->BroadcastParticleEffect("splash", static_cast<Vector3f>(m_ParticlePos), Vector3f{}, 0, 15);
+ m_World->BroadcastParticleEffect("splash", static_cast<Vector3f>(m_ParticlePos), Vector3f {}, 0, 15);
}
else if (m_CountDownTime < 20)
{
m_ParticlePos = (m_ParticlePos + (GetPosition() - m_ParticlePos) / 6);
- m_World->BroadcastParticleEffect("splash", static_cast<Vector3f>(m_ParticlePos), Vector3f{}, 0, 15);
+ m_World->BroadcastParticleEffect("splash", static_cast<Vector3f>(m_ParticlePos), Vector3f {}, 0, 15);
}
m_CountDownTime--;
@@ -155,10 +155,8 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
// Check water at the top of floater otherwise it floats into the air above the water
- if (
- const auto Above = Rel.addedY(FloorC(GetPosY() + GetHeight()));
- (Above.y < cChunkDef::Height) && IsBlockWater(m_World->GetBlock(Above))
- )
+ if (const auto Above = Rel.addedY(FloorC(GetPosY() + GetHeight()));
+ (Above.y < cChunkDef::Height) && IsBlockWater(m_World->GetBlock(Above)))
{
SetSpeedY(0.7);
}
@@ -186,7 +184,10 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
}
- if (!m_World->DoWithEntityByID(m_PlayerID, [](cEntity &) { return true; })) // The owner doesn't exist anymore. Destroy the floater entity.
+ if (!m_World->DoWithEntityByID(
+ m_PlayerID,
+ [](cEntity &) { return true; }
+ )) // The owner doesn't exist anymore. Destroy the floater entity.
{
Destroy();
}
diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h
index 0c20632db..9f0e67d70 100644
--- a/src/Entities/Floater.h
+++ b/src/Entities/Floater.h
@@ -8,15 +8,13 @@
// tolua_begin
-class cFloater :
- public cEntity
+class cFloater : public cEntity
{
// tolua_end
using Super = cEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cFloater)
cFloater(Vector3d a_Pos, Vector3d a_Speed, UInt32 a_PlayerID, int a_CountDownTime);
@@ -25,13 +23,13 @@ public: // tolua_export
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
// tolua_begin
- bool CanPickup(void) const { return m_CanPickupItem; }
- UInt32 GetOwnerID(void) const { return m_PlayerID; }
+ bool CanPickup(void) const { return m_CanPickupItem; }
+ UInt32 GetOwnerID(void) const { return m_PlayerID; }
UInt32 GetAttachedMobID(void) const { return m_AttachedMobID; }
- Vector3d GetBitePos(void) const { return m_BitePos; }
+ Vector3d GetBitePos(void) const { return m_BitePos; }
// tolua_end
-protected:
+ protected:
// Position
Vector3d m_ParticlePos;
@@ -48,4 +46,4 @@ protected:
// Entity IDs
UInt32 m_PlayerID;
UInt32 m_AttachedMobID;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/GhastFireballEntity.cpp b/src/Entities/GhastFireballEntity.cpp
index 31dd3dbc9..544d9f494 100644
--- a/src/Entities/GhastFireballEntity.cpp
+++ b/src/Entities/GhastFireballEntity.cpp
@@ -7,7 +7,7 @@
-cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cGhastFireballEntity::cGhastFireballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkGhastFireball, a_Creator, a_Pos, 1, 1)
{
SetSpeed(a_Speed);
diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h
index 41ac7f75b..0066a181c 100644
--- a/src/Entities/GhastFireballEntity.h
+++ b/src/Entities/GhastFireballEntity.h
@@ -17,21 +17,18 @@
// tolua_begin
-class cGhastFireballEntity :
- public cProjectileEntity
+class cGhastFireballEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cGhastFireballEntity)
cGhastFireballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-protected:
-
+ protected:
void Explode(Vector3i a_Block);
// cProjectileEntity overrides:
@@ -40,8 +37,4 @@ protected:
// TODO: Deflecting the fireballs by arrow- or sword- hits
-} ; // tolua_export
-
-
-
-
+}; // tolua_export
diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp
index 926c45fa1..4a8e0c006 100644
--- a/src/Entities/HangingEntity.cpp
+++ b/src/Entities/HangingEntity.cpp
@@ -12,8 +12,7 @@
cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, Vector3d a_Pos) :
- Super(a_EntityType, a_Pos, 0.5f, 0.5f),
- m_Facing(cHangingEntity::BlockFaceToProtocolFace(a_Facing))
+ Super(a_EntityType, a_Pos, 0.5f, 0.5f), m_Facing(cHangingEntity::BlockFaceToProtocolFace(a_Facing))
{
SetMaxHealth(1);
SetHealth(1);
@@ -25,7 +24,8 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, Ve
bool cHangingEntity::IsValidSupportBlock(const BLOCKTYPE a_BlockType)
{
- return cBlockInfo::IsSolid(a_BlockType) && (a_BlockType != E_BLOCK_REDSTONE_REPEATER_OFF) && (a_BlockType != E_BLOCK_REDSTONE_REPEATER_ON);
+ return cBlockInfo::IsSolid(a_BlockType) && (a_BlockType != E_BLOCK_REDSTONE_REPEATER_OFF) &&
+ (a_BlockType != E_BLOCK_REDSTONE_REPEATER_ON);
}
@@ -63,7 +63,8 @@ void cHangingEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
BLOCKTYPE Block;
- const auto SupportPosition = AddFaceDirection(cChunkDef::AbsoluteToRelative(GetPosition()), ProtocolFaceToBlockFace(m_Facing), true);
+ const auto SupportPosition =
+ AddFaceDirection(cChunkDef::AbsoluteToRelative(GetPosition()), ProtocolFaceToBlockFace(m_Facing), true);
if (!a_Chunk.UnboundedRelGetBlockType(SupportPosition, Block) || IsValidSupportBlock(Block))
{
return;
diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h
index a0e63d794..9cc7ee16b 100644
--- a/src/Entities/HangingEntity.h
+++ b/src/Entities/HangingEntity.h
@@ -8,15 +8,13 @@
// tolua_begin
-class cHangingEntity :
- public cEntity
+class cHangingEntity : public cEntity
{
// tolua_end
using Super = cEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cHangingEntity)
cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, Vector3d a_Pos);
@@ -30,8 +28,10 @@ public: // tolua_export
/** Returns if the given block can support hanging entity placements. */
static bool IsValidSupportBlock(BLOCKTYPE a_BlockType); // tolua_export
+ // tolua_begin
/** Set the direction in which the entity is facing. */
- void SetFacing(eBlockFace a_Facing) { m_Facing = cHangingEntity::BlockFaceToProtocolFace(a_Facing); } // tolua_export
+ void SetFacing(eBlockFace a_Facing) { m_Facing = cHangingEntity::BlockFaceToProtocolFace(a_Facing); }
+ // tolua_end
/** Set the direction in which the entity is facing. */
void SetProtocolFacing(Byte a_Facing)
@@ -40,8 +40,7 @@ public: // tolua_export
m_Facing = a_Facing;
}
-protected:
-
+ protected:
Byte m_Facing;
virtual void KilledBy(TakeDamageInfo & a_TDI) override;
@@ -51,7 +50,8 @@ protected:
/** Converts protocol hanging item facing to eBlockFace values */
inline static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace)
{
- // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
+ // The client uses different values for item frame directions and block faces. Our constants are for the block
+ // faces, so we convert them here to item frame faces
switch (a_ProtocolFace)
{
case 0: return BLOCK_FACE_ZP;
@@ -72,7 +72,8 @@ protected:
/** Converts eBlockFace values to protocol hanging item faces */
inline static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace)
{
- // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces
+ // The client uses different values for item frame directions and block faces. Our constants are for the block
+ // faces, so we convert them here to item frame faces
switch (a_BlockFace)
{
case BLOCK_FACE_ZP: return 0;
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
index 90d3bb049..18993e43b 100644
--- a/src/Entities/ItemFrame.cpp
+++ b/src/Entities/ItemFrame.cpp
@@ -10,10 +10,8 @@
-cItemFrame::cItemFrame(eBlockFace a_BlockFace, Vector3d a_Pos):
- Super(etItemFrame, a_BlockFace, a_Pos),
- m_Item(E_BLOCK_AIR),
- m_ItemRotation(0)
+cItemFrame::cItemFrame(eBlockFace a_BlockFace, Vector3d a_Pos) :
+ Super(etItemFrame, a_BlockFace, a_Pos), m_Item(E_BLOCK_AIR), m_ItemRotation(0)
{
}
@@ -95,7 +93,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
}
GetWorld()->BroadcastEntityMetadata(*this); // Update clients
- GetParentChunk()->MarkDirty(); // Mark chunk dirty to save rotation or item
+ GetParentChunk()->MarkDirty(); // Mark chunk dirty to save rotation or item
}
diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h
index 08363e5d8..cb1cb82aa 100644
--- a/src/Entities/ItemFrame.h
+++ b/src/Entities/ItemFrame.h
@@ -8,15 +8,13 @@
// tolua_begin
-class cItemFrame :
- public cHangingEntity
+class cItemFrame : public cHangingEntity
{
// tolua_end
using Super = cHangingEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cItemFrame)
cItemFrame(eBlockFace a_BlockFace, Vector3d a_Pos);
@@ -37,8 +35,7 @@ public: // tolua_export
// tolua_end
-private:
-
+ private:
virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
diff --git a/src/Entities/LeashKnot.cpp b/src/Entities/LeashKnot.cpp
index e98ca52ec..a9c99f43d 100644
--- a/src/Entities/LeashKnot.cpp
+++ b/src/Entities/LeashKnot.cpp
@@ -15,9 +15,7 @@
cLeashKnot::cLeashKnot(eBlockFace a_BlockFace, Vector3d a_Pos) :
- Super(etLeashKnot, a_BlockFace, a_Pos),
- m_ShouldSelfDestroy(false),
- m_TicksToSelfDestroy(20 * 1)
+ Super(etLeashKnot, a_BlockFace, a_Pos), m_ShouldSelfDestroy(false), m_TicksToSelfDestroy(20 * 1)
{
}
@@ -42,7 +40,9 @@ void cLeashKnot::TiePlayersLeashedMobs(cPlayer & a_Player, bool a_ShouldBroadcas
{
// Check leashed nearby mobs to tie them to this knot
// taking world from player (instead from this) because this can be called before entity was initialized
- a_Player.GetWorld()->ForEachEntityInBox(cBoundingBox(GetPosition(), 8, 8, -4), [&](cEntity & a_Entity)
+ a_Player.GetWorld()->ForEachEntityInBox(
+ cBoundingBox(GetPosition(), 8, 8, -4),
+ [&](cEntity & a_Entity)
{
// If the entity is not a monster skip it
if (a_Entity.GetEntityType() != cEntity::eEntityType::etMonster)
@@ -50,7 +50,7 @@ void cLeashKnot::TiePlayersLeashedMobs(cPlayer & a_Player, bool a_ShouldBroadcas
return false;
}
- auto & PotentialLeashed = static_cast<cMonster&>(a_Entity);
+ auto & PotentialLeashed = static_cast<cMonster &>(a_Entity);
// If can't be leashed skip it
if (!PotentialLeashed.CanBeLeashed())
@@ -59,11 +59,8 @@ void cLeashKnot::TiePlayersLeashedMobs(cPlayer & a_Player, bool a_ShouldBroadcas
}
// If it's not leashed to the player skip it
- if (
- !PotentialLeashed.IsLeashed() ||
- !PotentialLeashed.GetLeashedTo()->IsPlayer() ||
- (PotentialLeashed.GetLeashedTo()->GetUniqueID() != a_Player.GetUniqueID())
- )
+ if (!PotentialLeashed.IsLeashed() || !PotentialLeashed.GetLeashedTo()->IsPlayer() ||
+ (PotentialLeashed.GetLeashedTo()->GetUniqueID() != a_Player.GetUniqueID()))
{
return false;
}
@@ -142,7 +139,9 @@ void cLeashKnot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
cLeashKnot * cLeashKnot::FindKnotAtPos(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos)
{
cLeashKnot * LeashKnot = nullptr;
- a_WorldInterface.ForEachEntityInBox(cBoundingBox(a_BlockPos, 0.5, 1), [&](cEntity & a_Entity)
+ a_WorldInterface.ForEachEntityInBox(
+ cBoundingBox(a_BlockPos, 0.5, 1),
+ [&](cEntity & a_Entity)
{
if (a_Entity.IsLeashKnot())
{
@@ -155,7 +154,3 @@ cLeashKnot * cLeashKnot::FindKnotAtPos(cWorldInterface & a_WorldInterface, Vecto
return LeashKnot;
}
-
-
-
-
diff --git a/src/Entities/LeashKnot.h b/src/Entities/LeashKnot.h
index 8a8d0a45e..e62222b74 100644
--- a/src/Entities/LeashKnot.h
+++ b/src/Entities/LeashKnot.h
@@ -10,14 +10,12 @@ class cWorldInterface;
// tolua_begin
-class cLeashKnot :
- public cHangingEntity
+class cLeashKnot : public cHangingEntity
{
// tolua_end
using Super = cHangingEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cLeashKnot)
cLeashKnot(eBlockFace a_BlockFace, Vector3d a_Pos);
@@ -27,12 +25,13 @@ public: // tolua_export
void SetShouldSelfDestroy() { m_ShouldSelfDestroy = true; }
- /** Returns the leash knot entity representing the knot at the specified position. Returns nullptr if there's no knot. */
+ /** Returns the leash knot entity representing the knot at the specified position. Returns nullptr if there's no
+ * knot. */
static cLeashKnot * FindKnotAtPos(cWorldInterface & a_WorldInterface, Vector3i a_BlockPos);
-private:
-
- /** When a fence is destroyed, the knot on it gets destroyed after a while. This flag turns on the countdown to self destroy. */
+ private:
+ /** When a fence is destroyed, the knot on it gets destroyed after a while. This flag turns on the countdown to self
+ * destroy. */
bool m_ShouldSelfDestroy;
int m_TicksToSelfDestroy;
@@ -43,7 +42,3 @@ private:
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
}; // tolua_export
-
-
-
-
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 851161e4c..b985bd82c 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -28,7 +28,7 @@
class cMinecartAttachCallback
{
-public:
+ public:
cMinecartAttachCallback(cMinecart & a_Minecart, cEntity * a_Attachee) :
m_Minecart(a_Minecart), m_Attachee(a_Attachee)
{
@@ -46,8 +46,7 @@ public:
return false;
}
-protected:
-
+ protected:
cMinecart & m_Minecart;
cEntity * m_Attachee;
};
@@ -58,8 +57,14 @@ protected:
class cMinecartCollisionCallback
{
-public:
- cMinecartCollisionCallback(Vector3d a_Pos, double a_Height, double a_Width, UInt32 a_UniqueID, UInt32 a_AttacheeUniqueID) :
+ public:
+ cMinecartCollisionCallback(
+ Vector3d a_Pos,
+ double a_Height,
+ double a_Width,
+ UInt32 a_UniqueID,
+ UInt32 a_AttacheeUniqueID
+ ) :
m_DoesIntersect(false),
m_CollidedEntityPos(0, 0, 0),
m_Pos(a_Pos),
@@ -70,17 +75,12 @@ public:
{
}
- bool operator () (cEntity & a_Entity)
+ bool operator()(cEntity & a_Entity)
{
- if (
- (
- !a_Entity.IsPlayer() ||
- static_cast<cPlayer &>(a_Entity).IsGameModeSpectator() // Spectators doesn't collide with anything
+ if ((!a_Entity.IsPlayer() ||
+ static_cast<cPlayer &>(a_Entity).IsGameModeSpectator() // Spectators doesn't collide with anything
) &&
- !a_Entity.IsMob() &&
- !a_Entity.IsMinecart() &&
- !a_Entity.IsBoat()
- )
+ !a_Entity.IsMob() && !a_Entity.IsMinecart() && !a_Entity.IsBoat())
{
return false;
}
@@ -101,17 +101,11 @@ public:
return false;
}
- bool FoundIntersection(void) const
- {
- return m_DoesIntersect;
- }
+ bool FoundIntersection(void) const { return m_DoesIntersect; }
- Vector3d GetCollidedEntityPosition(void) const
- {
- return m_CollidedEntityPos;
- }
+ Vector3d GetCollidedEntityPosition(void) const { return m_CollidedEntityPos; }
-protected:
+ protected:
bool m_DoesIntersect;
Vector3d m_CollidedEntityPos;
@@ -129,7 +123,7 @@ protected:
////////////////////////////////////////////////////////////////////////////////
// cMinecart:
-cMinecart::cMinecart(ePayload a_Payload, Vector3d a_Pos):
+cMinecart::cMinecart(ePayload a_Payload, Vector3d a_Pos) :
Super(etMinecart, a_Pos, 0.98f, 0.7f),
m_Payload(a_Payload),
m_LastDamage(0),
@@ -186,7 +180,11 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Check if the rail is still there
if (m_World->GetBlock(m_DetectorRailPosition) == E_BLOCK_DETECTOR_RAIL)
{
- m_World->SetBlock(m_DetectorRailPosition, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07);
+ m_World->SetBlock(
+ m_DetectorRailPosition,
+ E_BLOCK_DETECTOR_RAIL,
+ m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07
+ );
}
m_bIsOnDetectorRail = false;
@@ -230,9 +228,9 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
switch (InsideType)
{
- case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt); break;
+ case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt); break;
case E_BLOCK_ACTIVATOR_RAIL: HandleActivatorRailPhysics(InsideMeta, a_Dt); break;
- case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break;
+ case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break;
case E_BLOCK_DETECTOR_RAIL:
{
m_DetectorRailPosition = Vector3i(POSX_TOINT, POSY_TOINT, POSZ_TOINT);
@@ -243,12 +241,16 @@ void cMinecart::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break;
}
- AddPosition(GetSpeed() * (static_cast<double>(a_Dt.count()) / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp
+ AddPosition(
+ GetSpeed() * (static_cast<double>(a_Dt.count()) / 1000)
+ ); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in
+ // Entity.cpp
}
else
{
// Not on rail, default physics
- SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail
+ SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop
+ // ground clipping minecart bottom when off-rail
Super::HandlePhysics(a_Dt, *chunk);
}
@@ -292,12 +294,12 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon
if (GetSpeedZ() > 0)
{
// Going SOUTH, slow down
- ApplyAcceleration({ 0.0, 0.0, 1.0 }, -0.1);
+ ApplyAcceleration({0.0, 0.0, 1.0}, -0.1);
}
else
{
// Going NORTH, slow down
- ApplyAcceleration({ 0.0, 0.0, -1.0 }, -0.1);
+ ApplyAcceleration({0.0, 0.0, -1.0}, -0.1);
}
}
@@ -321,11 +323,11 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon
{
if (GetSpeedX() > 0)
{
- ApplyAcceleration({ 1.0, 0.0, 0.0 }, -0.1);
+ ApplyAcceleration({1.0, 0.0, 0.0}, -0.1);
}
else
{
- ApplyAcceleration({ -1.0, 0.0, 0.0 }, -0.1);
+ ApplyAcceleration({-1.0, 0.0, 0.0}, -0.1);
}
}
@@ -531,11 +533,11 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
{
if (GetSpeedZ() > NO_SPEED)
{
- ApplyAcceleration({ 0.0, 0.0, 1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, 1.0}, Acceleration);
}
else
{
- ApplyAcceleration({ 0.0, 0.0, -1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, -1.0}, Acceleration);
}
}
// If rail is powered check for nearby blocks that could kick-start the minecart
@@ -546,11 +548,11 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
// Only kick-start the minecart if a block is on one side, but not both
if (IsBlockZM && !IsBlockZP)
{
- ApplyAcceleration({ 0.0, 0.0, 1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, 1.0}, Acceleration);
}
else if (!IsBlockZM && IsBlockZP)
{
- ApplyAcceleration({ 0.0, 0.0, -1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, -1.0}, Acceleration);
}
}
break;
@@ -572,11 +574,11 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
{
if (GetSpeedX() > NO_SPEED)
{
- ApplyAcceleration({ 1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({1.0, 0.0, 0.0}, Acceleration);
}
else
{
- ApplyAcceleration({ -1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({-1.0, 0.0, 0.0}, Acceleration);
}
}
// If rail is powered check for nearby blocks that could kick-start the minecart
@@ -587,11 +589,11 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
// Only kick-start the minecart if a block is on one side, but not both
if (IsBlockXM && !IsBlockXP)
{
- ApplyAcceleration({ 1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({1.0, 0.0, 0.0}, Acceleration);
}
else if (!IsBlockXM && IsBlockXP)
{
- ApplyAcceleration({ -1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({-1.0, 0.0, 0.0}, Acceleration);
}
}
break;
@@ -603,12 +605,12 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
if (GetSpeedX() >= NO_SPEED)
{
- ApplyAcceleration({ 1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({1.0, 0.0, 0.0}, Acceleration);
SetSpeedY(-GetSpeedX());
}
else
{
- ApplyAcceleration({ -1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({-1.0, 0.0, 0.0}, Acceleration);
SetSpeedY(-GetSpeedX());
}
break;
@@ -620,12 +622,12 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
if (GetSpeedX() > NO_SPEED)
{
- ApplyAcceleration({ 1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({1.0, 0.0, 0.0}, Acceleration);
SetSpeedY(GetSpeedX());
}
else
{
- ApplyAcceleration({ -1.0, 0.0, 0.0 }, Acceleration);
+ ApplyAcceleration({-1.0, 0.0, 0.0}, Acceleration);
SetSpeedY(GetSpeedX());
}
break;
@@ -637,12 +639,12 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
if (GetSpeedZ() >= NO_SPEED)
{
- ApplyAcceleration({ 0.0, 0.0, 1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, 1.0}, Acceleration);
SetSpeedY(-GetSpeedZ());
}
else
{
- ApplyAcceleration({ 0.0, 0.0, -1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, -1.0}, Acceleration);
SetSpeedY(-GetSpeedZ());
}
break;
@@ -654,12 +656,12 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
if (GetSpeedZ() > NO_SPEED)
{
- ApplyAcceleration({ 0.0, 0.0, 1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, 1.0}, Acceleration);
SetSpeedY(GetSpeedZ());
}
else
{
- ApplyAcceleration({ 0.0, 0.0, -1.0 }, Acceleration);
+ ApplyAcceleration({0.0, 0.0, -1.0}, Acceleration);
SetSpeedY(GetSpeedZ());
}
break;
@@ -714,7 +716,8 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetPosX(floor(GetPosX()) + 0.5);
break;
}
- // Curved rail physics: once minecart has reached more than half of the block in the direction that it is travelling in, jerk it in the direction of curvature
+ // Curved rail physics: once minecart has reached more than half of the block in the direction that it is
+ // travelling in, jerk it in the direction of curvature
case E_META_RAIL_CURVED_ZM_XM:
{
if (GetPosZ() > floor(GetPosZ()) + 0.5)
@@ -850,10 +853,8 @@ bool cMinecart::IsBlockCollisionAtOffset(Vector3i a_Offset)
return false;
}
- auto bbBlock = cBoundingBox(
- static_cast<Vector3d>(BlockPosition),
- static_cast<Vector3d>(BlockPosition + Vector3i(1, 1, 1))
- );
+ auto bbBlock =
+ cBoundingBox(static_cast<Vector3d>(BlockPosition), static_cast<Vector3d>(BlockPosition + Vector3i(1, 1, 1)));
return GetBoundingBox().DoesIntersect(bbBlock);
}
@@ -867,20 +868,20 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
auto SpeedX = GetSpeedX();
auto SpeedZ = GetSpeedZ();
- // Don't do anything if minecarts aren't moving.
- #ifdef __clang__
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wfloat-equal"
- #endif
+// Don't do anything if minecarts aren't moving.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wfloat-equal"
+#endif
if ((SpeedX == 0) && (SpeedZ == 0))
{
return false;
}
- #ifdef __clang__
- #pragma clang diagnostic pop
- #endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
auto StopTheCart = true;
auto StopOffset = Vector3d();
@@ -1051,10 +1052,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
{
SetSpeed(0, 0, 0);
- #ifdef __clang__
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wfloat-equal"
- #endif
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wfloat-equal"
+#endif
if (StopOffset.x != 0)
{
@@ -1065,9 +1066,9 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
SetPosZ(POSZ_TOINT + StopOffset.z);
}
- #ifdef __clang__
- #pragma clang diagnostic pop
- #endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
return true;
}
@@ -1082,7 +1083,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
cMinecartCollisionCallback MinecartCollisionCallback(
- GetPosition(), GetHeight(), GetWidth(), GetUniqueID(),
+ GetPosition(),
+ GetHeight(),
+ GetWidth(),
+ GetUniqueID(),
((m_Attachee == nullptr) ? cEntity::INVALID_ID : m_Attachee->GetUniqueID())
);
int ChunkX, ChunkZ;
@@ -1097,7 +1101,11 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
// Collision was true, create bounding box for minecart, call attach callback for all entities within that box
cMinecartAttachCallback MinecartAttachCallback(*this, m_Attachee);
Vector3d MinecartPosition = GetPosition();
- cBoundingBox bbMinecart(Vector3d(MinecartPosition.x, floor(MinecartPosition.y), MinecartPosition.z), GetWidth() / 2, GetHeight());
+ cBoundingBox bbMinecart(
+ Vector3d(MinecartPosition.x, floor(MinecartPosition.y), MinecartPosition.z),
+ GetWidth() / 2,
+ GetHeight()
+ );
m_World->ForEachEntityInBox(bbMinecart, MinecartAttachCallback);
switch (a_RailMeta)
@@ -1141,7 +1149,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
case E_META_RAIL_CURVED_ZM_XM:
case E_META_RAIL_CURVED_ZP_XP:
{
- Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
+ Vector3d Distance =
+ MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
if (std::abs(Distance.z) < 0.001)
@@ -1152,11 +1161,10 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0, 0).
The minecart moves along the line x = -z, the perpendicular line to this is x = z.
- In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
- if (
- ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
- ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
- )
+ In order to decide to which side the minecart is to be pushed, it must be checked on what side of the
+ perpendicular line the pushing entity is located. */
+ if (((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
+ ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1)))
{
// Moving -X +Z
if ((-GetSpeedX() * 0.4 / sqrt(2.0)) < 0.01)
@@ -1190,7 +1198,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
case E_META_RAIL_CURVED_ZM_XP:
case E_META_RAIL_CURVED_ZP_XM:
{
- Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
+ Vector3d Distance =
+ MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
// Prevent division by small numbers
if (std::abs(Distance.z) < 0.001)
@@ -1201,11 +1210,10 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
/* Check to which side the minecart is to be pushed.
Let's consider a z-x-coordinate system where the minecart is the center (0, 0).
The minecart moves along the line x = z, the perpendicular line to this is x = -z.
- In order to decide to which side the minecart is to be pushed, it must be checked on what side of the perpendicular line the pushing entity is located. */
- if (
- ((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
- ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
- )
+ In order to decide to which side the minecart is to be pushed, it must be checked on what side of the
+ perpendicular line the pushing entity is located. */
+ if (((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
+ ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1)))
{
// Moving +X +Z
if ((GetSpeedX() * 0.4) < 0.01)
@@ -1248,7 +1256,8 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI)
{
- if ((TDI.Attacker != nullptr) && TDI.Attacker->IsPlayer() && static_cast<cPlayer *>(TDI.Attacker)->IsGameModeCreative())
+ if ((TDI.Attacker != nullptr) && TDI.Attacker->IsPlayer() &&
+ static_cast<cPlayer *>(TDI.Attacker)->IsGameModeCreative())
{
TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative
SetInvulnerableTicks(0);
@@ -1285,7 +1294,11 @@ void cMinecart::OnRemoveFromWorld(cWorld & a_World)
{
if (m_bIsOnDetectorRail)
{
- m_World->SetBlock(m_DetectorRailPosition, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07);
+ m_World->SetBlock(
+ m_DetectorRailPosition,
+ E_BLOCK_DETECTOR_RAIL,
+ m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07
+ );
}
Super::OnRemoveFromWorld(a_World);
@@ -1304,7 +1317,7 @@ void cMinecart::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
return;
}
Vector3d LookVector = m_Attachee->GetLookVector();
- Vector3d ToAddSpeed = LookVector * (a_Forward * 0.4) ;
+ Vector3d ToAddSpeed = LookVector * (a_Forward * 0.4);
ToAddSpeed.y = 0;
AddSpeed(ToAddSpeed);
}
@@ -1336,10 +1349,8 @@ void cMinecart::ApplyAcceleration(Vector3d a_ForwardDirection, double a_Accelera
////////////////////////////////////////////////////////////////////////////////
// cRideableMinecart:
-cRideableMinecart::cRideableMinecart(Vector3d a_Pos, const cItem & a_Content, int a_ContentHeight):
- Super(mpNone, a_Pos),
- m_Content(a_Content),
- m_ContentHeight(a_ContentHeight)
+cRideableMinecart::cRideableMinecart(Vector3d a_Pos, const cItem & a_Content, int a_ContentHeight) :
+ Super(mpNone, a_Pos), m_Content(a_Content), m_ContentHeight(a_ContentHeight)
{
}
@@ -1390,10 +1401,8 @@ void cRideableMinecart::OnRightClicked(cPlayer & a_Player)
////////////////////////////////////////////////////////////////////////////////
// cMinecartWithChest:
-cMinecartWithChest::cMinecartWithChest(Vector3d a_Pos):
- Super(mpChest, a_Pos),
- cEntityWindowOwner(this),
- m_Contents(ContentsWidth, ContentsHeight)
+cMinecartWithChest::cMinecartWithChest(Vector3d a_Pos) :
+ Super(mpChest, a_Pos), cEntityWindowOwner(this), m_Contents(ContentsWidth, ContentsHeight)
{
m_Contents.AddListener(*this);
}
@@ -1463,10 +1472,8 @@ void cMinecartWithChest::OpenNewWindow()
////////////////////////////////////////////////////////////////////////////////
// cMinecartWithFurnace:
-cMinecartWithFurnace::cMinecartWithFurnace(Vector3d a_Pos):
- Super(mpFurnace, a_Pos),
- m_FueledTimeLeft(-1),
- m_IsFueled(false)
+cMinecartWithFurnace::cMinecartWithFurnace(Vector3d a_Pos) :
+ Super(mpFurnace, a_Pos), m_FueledTimeLeft(-1), m_IsFueled(false)
{
}
@@ -1539,7 +1546,7 @@ void cMinecartWithFurnace::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk
////////////////////////////////////////////////////////////////////////////////
// cMinecartWithTNT:
-cMinecartWithTNT::cMinecartWithTNT(Vector3d a_Pos):
+cMinecartWithTNT::cMinecartWithTNT(Vector3d a_Pos) :
Super(mpTNT, a_Pos)
{
}
@@ -1603,7 +1610,7 @@ void cMinecartWithTNT::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
////////////////////////////////////////////////////////////////////////////////
// cMinecartWithHopper:
-cMinecartWithHopper::cMinecartWithHopper(Vector3d a_Pos):
+cMinecartWithHopper::cMinecartWithHopper(Vector3d a_Pos) :
Super(mpHopper, a_Pos)
{
}
diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h
index 5656f04ce..bf3c74da5 100644
--- a/src/Entities/Minecart.h
+++ b/src/Entities/Minecart.h
@@ -17,24 +17,23 @@
-class cMinecart :
- public cEntity
+class cMinecart : public cEntity
{
using Super = cEntity;
-public:
+ public:
CLASS_PROTODEF(cMinecart)
/** Minecart payload, values correspond to packet subtype */
enum ePayload
{
- mpNone = 0, // Empty minecart, ridable by player or mobs
- mpChest = 1, // Minecart-with-chest, can store a grid of 3 * 8 items
+ mpNone = 0, // Empty minecart, ridable by player or mobs
+ mpChest = 1, // Minecart-with-chest, can store a grid of 3 * 8 items
mpFurnace = 2, // Minecart-with-furnace, can be powered
- mpTNT = 3, // Minecart-with-TNT, can be blown up with activator rail
- mpHopper = 5, // Minecart-with-hopper, can be hopper
+ mpTNT = 3, // Minecart-with-TNT, can be blown up with activator rail
+ mpHopper = 5, // Minecart-with-hopper, can be hopper
// TODO: Spawner minecarts, (and possibly any block in a minecart with NBT editing)
- } ;
+ };
// cEntity overrides:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
@@ -46,8 +45,7 @@ public:
int LastDamage(void) const { return m_LastDamage; }
ePayload GetPayload(void) const { return m_Payload; }
-protected:
-
+ protected:
ePayload m_Payload;
int m_LastDamage;
Vector3i m_DetectorRailPosition;
@@ -59,7 +57,8 @@ protected:
cMinecart(ePayload a_Payload, Vector3d a_Pos);
/** Handles physics on normal rails
- For each tick, slow down on flat rails, speed up or slow down on ascending / descending rails (depending on direction), and turn on curved rails. */
+ For each tick, slow down on flat rails, speed up or slow down on ascending / descending rails (depending on
+ direction), and turn on curved rails. */
void HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt);
/** Handles powered rail physics
@@ -78,7 +77,8 @@ protected:
/** Snaps a mincecart to a rail's axis, resetting its speed
For curved rails, it changes the cart's direction as well as snapping it to axis */
void SnapToRail(NIBBLETYPE a_RailMeta);
- /** Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no obstruction */
+ /** Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no
+ * obstruction */
bool TestBlockCollision(NIBBLETYPE a_RailMeta);
/** Tests if there is a block at the specified position which is impassable to minecarts */
bool IsSolidBlockAtPosition(Vector3i a_Offset);
@@ -87,21 +87,20 @@ protected:
bool IsBlockCollisionAtOffset(Vector3i a_Offset);
- /** Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and pushes mincecart away if necessary */
+ /** Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and pushes
+ * mincecart away if necessary */
bool TestEntityCollision(NIBBLETYPE a_RailMeta);
-} ;
+};
-class cRideableMinecart final :
- public cMinecart
+class cRideableMinecart final : public cMinecart
{
using Super = cMinecart;
-public:
-
+ public:
CLASS_PROTODEF(cRideableMinecart)
cRideableMinecart(Vector3d a_Pos, const cItem & a_Content, int a_ContentHeight);
@@ -113,25 +112,22 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
-protected:
-
+ protected:
cItem m_Content;
int m_ContentHeight;
-} ;
+};
-class cMinecartWithChest final :
- public cMinecart,
- public cItemGrid::cListener,
- public cEntityWindowOwner
+class cMinecartWithChest final : public cMinecart,
+ public cItemGrid::cListener,
+ public cEntityWindowOwner
{
using Super = cMinecart;
-public:
-
+ public:
CLASS_PROTODEF(cMinecartWithChest)
cMinecartWithChest(Vector3d a_Pos);
@@ -146,8 +142,7 @@ public:
void SetSlot(int a_Idx, const cItem & a_Item) { m_Contents.SetSlot(a_Idx, a_Item); }
-protected:
-
+ protected:
cItemGrid m_Contents;
void OpenNewWindow(void);
@@ -171,19 +166,17 @@ protected:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void OnRemoveFromWorld(cWorld & a_World) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
-} ;
+};
-class cMinecartWithFurnace final :
- public cMinecart
+class cMinecartWithFurnace final : public cMinecart
{
using Super = cMinecart;
-public:
-
+ public:
CLASS_PROTODEF(cMinecartWithFurnace)
cMinecartWithFurnace(Vector3d a_Pos);
@@ -194,59 +187,56 @@ public:
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
// Set functions.
- void SetIsFueled(bool a_IsFueled, int a_FueledTimeLeft = -1) {m_IsFueled = a_IsFueled; m_FueledTimeLeft = a_FueledTimeLeft;}
+ void SetIsFueled(bool a_IsFueled, int a_FueledTimeLeft = -1)
+ {
+ m_IsFueled = a_IsFueled;
+ m_FueledTimeLeft = a_FueledTimeLeft;
+ }
// Get functions.
- int GetFueledTimeLeft(void) const {return m_FueledTimeLeft; }
- bool IsFueled (void) const {return m_IsFueled;}
-
-private:
+ int GetFueledTimeLeft(void) const { return m_FueledTimeLeft; }
+ bool IsFueled(void) const { return m_IsFueled; }
+ private:
int m_FueledTimeLeft;
bool m_IsFueled;
-
-} ;
+};
-class cMinecartWithTNT final :
- public cMinecart
+class cMinecartWithTNT final : public cMinecart
{
using Super = cMinecart;
-public:
-
+ public:
CLASS_PROTODEF(cMinecartWithTNT)
cMinecartWithTNT(Vector3d a_Pos);
void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
-private:
+ private:
int m_TNTFuseTicksLeft;
bool m_isTNTFused = false;
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
void HandleActivatorRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::milliseconds a_Dt) override;
-} ;
+};
-class cMinecartWithHopper final :
- public cMinecart
+class cMinecartWithHopper final : public cMinecart
{
using Super = cMinecart;
-public:
-
+ public:
CLASS_PROTODEF(cMinecartWithHopper)
cMinecartWithHopper(Vector3d a_Pos);
-private:
-
+ private:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
-} ;
+};
diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp
index dc1781fde..1f4ce9003 100644
--- a/src/Entities/Painting.cpp
+++ b/src/Entities/Painting.cpp
@@ -10,9 +10,8 @@
-cPainting::cPainting(const AString & a_Name, eBlockFace a_Direction, Vector3d a_Pos):
- Super(etPainting, a_Direction, a_Pos),
- m_Name(a_Name)
+cPainting::cPainting(const AString & a_Name, eBlockFace a_Direction, Vector3d a_Pos) :
+ Super(etPainting, a_Direction, a_Pos), m_Name(a_Name)
{
}
diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h
index f6ca5f000..8ad597b8d 100644
--- a/src/Entities/Painting.h
+++ b/src/Entities/Painting.h
@@ -8,15 +8,13 @@
// tolua_begin
-class cPainting :
- public cHangingEntity
+class cPainting : public cHangingEntity
{
// tolua_end
using Super = cHangingEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cPainting)
cPainting(const AString & a_Name, eBlockFace a_Direction, Vector3d a_Pos);
@@ -24,8 +22,7 @@ public: // tolua_export
/** Returns the protocol name of the painting */
const AString & GetName(void) const { return m_Name; } // tolua_export
-private:
-
+ private:
virtual void SpawnOn(cClientHandle & a_Client) override;
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
virtual void KilledBy(TakeDamageInfo & a_TDI) override;
@@ -33,7 +30,3 @@ private:
AString m_Name;
}; // tolua_export
-
-
-
-
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index 61653acd2..13190ddcb 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -66,7 +66,9 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Spectators cannot push entities around
if ((!IsPlayer()) || (!static_cast<cPlayer *>(this)->IsGameModeSpectator()))
{
- m_World->ForEachEntityInBox(GetBoundingBox(), [=](cEntity & a_Entity)
+ m_World->ForEachEntityInBox(
+ GetBoundingBox(),
+ [=](cEntity & a_Entity)
{
if (a_Entity.GetUniqueID() == GetUniqueID())
{
@@ -74,7 +76,8 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
// we only push other mobs, boats and minecarts
- if ((a_Entity.GetEntityType() != etMonster) && (a_Entity.GetEntityType() != etMinecart) && (a_Entity.GetEntityType() != etBoat))
+ if ((a_Entity.GetEntityType() != etMonster) && (a_Entity.GetEntityType() != etMinecart) &&
+ (a_Entity.GetEntityType() != etBoat))
{
return false;
}
@@ -183,10 +186,16 @@ void cPawn::HandleAir(void)
-void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier)
+void cPawn::AddEntityEffect(
+ cEntityEffect::eType a_EffectType,
+ int a_Duration,
+ short a_Intensity,
+ double a_DistanceModifier
+)
{
// Check if the plugins allow the addition:
- if (cPluginManager::Get()->CallHookEntityAddEffect(*this, a_EffectType, a_Duration, a_Intensity, a_DistanceModifier))
+ if (cPluginManager::Get()
+ ->CallHookEntityAddEffect(*this, a_EffectType, a_Duration, a_Intensity, a_DistanceModifier))
{
// A plugin disallows the addition, bail out.
return;
@@ -206,7 +215,10 @@ void cPawn::AddEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, s
ExistingEffect->second->OnDeactivate(*this);
}
- auto Res = m_EntityEffects.emplace(a_EffectType, cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier));
+ auto Res = m_EntityEffects.emplace(
+ a_EffectType,
+ cEntityEffect::CreateEntityEffect(a_EffectType, a_Duration, a_Intensity, a_DistanceModifier)
+ );
m_World->BroadcastEntityEffect(*this, a_EffectType, a_Intensity, a_Duration);
cEntityEffect * Effect = Res.first->second.get();
Effect->OnActivate(*this);
@@ -270,12 +282,15 @@ void cPawn::NoLongerTargetingMe(cMonster * a_Monster)
cMonster * Monster = *i;
if (Monster == a_Monster)
{
- ASSERT(Monster->GetTarget() != this); // The monster is notifying us it is no longer targeting us, assert if that's a lie
+ ASSERT(
+ Monster->GetTarget() != this
+ ); // The monster is notifying us it is no longer targeting us, assert if that's a lie
m_TargetingMe.erase(i);
return;
}
}
- ASSERT(false); // If this happens, something is wrong. Perhaps the monster never called TargetingMe() or called NoLongerTargetingMe() twice.
+ ASSERT(false); // If this happens, something is wrong. Perhaps the monster never called TargetingMe() or called
+ // NoLongerTargetingMe() twice.
}
@@ -316,14 +331,17 @@ void cPawn::HandleFalling(void)
will slow players down enough to have multiple updates that keep them alive)
- Slime blocks reverse falling velocity, unless it's a crouching player, in which case they act as standard blocks.
They also reset the topmost point of the damage calculation with each bounce,
- so if the block is removed while the player is bouncing or crouches after a bounce, the last bounce's zenith is considered as fall damage.
+ so if the block is removed while the player is bouncing or crouches after a bounce, the last bounce's zenith is
+ considered as fall damage.
With this in mind, we first check the block at the player's feet, then the one below that (because fences),
and decide which behaviour we want to go with.
*/
- const auto BlockAtFoot = (cChunkDef::IsValidHeight(POS_TOINT)) ? GetWorld()->GetBlock(POS_TOINT) : static_cast<BLOCKTYPE>(E_BLOCK_AIR);
+ const auto BlockAtFoot =
+ (cChunkDef::IsValidHeight(POS_TOINT)) ? GetWorld()->GetBlock(POS_TOINT) : static_cast<BLOCKTYPE>(E_BLOCK_AIR);
- /* We initialize these with what the foot is really IN, because for sampling we will move down with the epsilon above */
+ /* We initialize these with what the foot is really IN, because for sampling we will move down with the epsilon
+ * above */
bool IsFootInWater = IsBlockWater(BlockAtFoot);
bool IsFootOnSlimeBlock = false;
@@ -331,22 +349,21 @@ void cPawn::HandleFalling(void)
static const struct
{
int x, z;
- } CrossSampleCoords[] =
- {
- { 0, 0 },
- { 1, 0 },
- { -1, 0 },
- { 0, 1 },
- { 0, -1 },
+ } CrossSampleCoords[] = {
+ {0, 0},
+ {1, 0},
+ {-1, 0},
+ {0, 1},
+ {0, -1},
};
/* The blocks we're interested in relative to the player to account for larger than 1 blocks.
This can be extended to do additional checks in case there are blocks that are represented as one block
in memory but have a hitbox larger than 1 (like fences) */
- static const Vector3i BlockSampleOffsets[] =
- {
- { 0, 0, 0 }, // TODO: something went wrong here (offset 0?)
- { 0, -1, 0 }, // Potentially causes mis-detection (IsFootInWater) when player stands on block diagonal to water (i.e. on side of pool)
+ static const Vector3i BlockSampleOffsets[] = {
+ {0, 0, 0}, // TODO: something went wrong here (offset 0?)
+ {0, -1, 0}, // Potentially causes mis-detection (IsFootInWater) when player stands on block diagonal to water
+ // (i.e. on side of pool)
};
/* Here's the rough outline of how this mechanism works:
@@ -355,10 +372,11 @@ void cPawn::HandleFalling(void)
bool OnGround = false;
for (size_t i = 0; i < ARRAYCOUNT(CrossSampleCoords); i++)
{
- /* We calculate from the player's position, one of the cross-offsets above, and we move it down slightly so it's beyond inaccuracy.
- The added advantage of this method is that if the player is simply standing on the floor,
- the point will move into the next block, and the floor() will retrieve that instead of air. */
- Vector3d CrossTestPosition = GetPosition() + Vector3d(CrossSampleCoords[i].x * HalfWidth, -EPS, CrossSampleCoords[i].z * HalfWidth);
+ /* We calculate from the player's position, one of the cross-offsets above, and we move it down slightly so it's
+ beyond inaccuracy. The added advantage of this method is that if the player is simply standing on the floor, the
+ point will move into the next block, and the floor() will retrieve that instead of air. */
+ Vector3d CrossTestPosition =
+ GetPosition() + Vector3d(CrossSampleCoords[i].x * HalfWidth, -EPS, CrossSampleCoords[i].z * HalfWidth);
/* We go through the blocks that we consider "relevant" */
for (size_t j = 0; j < ARRAYCOUNT(BlockSampleOffsets); j++)
@@ -373,15 +391,18 @@ void cPawn::HandleFalling(void)
BLOCKTYPE BlockType = GetWorld()->GetBlock(BlockTestPosition);
NIBBLETYPE BlockMeta = GetWorld()->GetBlockMeta(BlockTestPosition);
- /* we do the cross-shaped sampling to check for water / liquids, but only on our level because water blocks are never bigger than unit voxels */
+ /* we do the cross-shaped sampling to check for water / liquids, but only on our level because water blocks
+ * are never bigger than unit voxels */
if (j == 0)
{
IsFootInWater |= IsBlockWater(BlockType);
IsFootOnSlimeBlock |= (BlockType == E_BLOCK_SLIME_BLOCK);
}
- /* If the block is solid, and the blockhandler confirms the block to be inside, we're officially on the ground. */
- if ((cBlockInfo::IsSolid(BlockType)) && (cBlockHandler::For(BlockType).IsInsideBlock(CrossTestPosition - BlockTestPosition, BlockMeta)))
+ /* If the block is solid, and the blockhandler confirms the block to be inside, we're officially on the
+ * ground. */
+ if ((cBlockInfo::IsSolid(BlockType)) &&
+ (cBlockHandler::For(BlockType).IsInsideBlock(CrossTestPosition - BlockTestPosition, BlockMeta)))
{
OnGround = true;
}
@@ -418,14 +439,16 @@ void cPawn::HandleFalling(void)
NOTE: this will only work in some cases; should be done in HandlePhysics() */
if (IsFootOnSlimeBlock && ShouldBounceOnSlime)
{
- // TODO: doesn't work too well, causes dissatisfactory experience for players on slime blocks - SetSpeedY(-GetSpeedY());
+ // TODO: doesn't work too well, causes dissatisfactory experience for players on slime blocks -
+ // SetSpeedY(-GetSpeedY());
}
// TODO: put player speed into GetSpeedY, and use that.
// If flying, climbing, swimming, or going up...
if (FallDamageAbsorbed || ((GetPosition() - m_LastPosition).y > 0))
{
- // ...update the ground height to have the highest position of the player (i.e. jumping up adds to the eventual fall damage)
+ // ...update the ground height to have the highest position of the player (i.e. jumping up adds to the eventual
+ // fall damage)
m_LastGroundHeight = GetPosY();
}
@@ -435,7 +458,8 @@ void cPawn::HandleFalling(void)
auto Damage = static_cast<int>(FallHeight - 3.0);
const auto Below = POS_TOINT.addedY(-1);
- const auto BlockBelow = (cChunkDef::IsValidHeight(Below)) ? GetWorld()->GetBlock(Below) : static_cast<BLOCKTYPE>(E_BLOCK_AIR);
+ const auto BlockBelow =
+ (cChunkDef::IsValidHeight(Below)) ? GetWorld()->GetBlock(Below) : static_cast<BLOCKTYPE>(E_BLOCK_AIR);
if ((Damage > 0) && !FallDamageAbsorbed)
{
@@ -454,10 +478,13 @@ void cPawn::HandleFalling(void)
GetWorld()->BroadcastParticleEffect(
"blockdust",
GetPosition(),
- { 0, 0, 0 },
- (Damage - 1.f) * ((0.3f - 0.1f) / (15.f - 1.f)) + 0.1f, // Map damage (1 - 15) to particle speed (0.1 - 0.3)
- static_cast<int>((Damage - 1.f) * ((50.f - 20.f) / (15.f - 1.f)) + 20.f), // Map damage (1 - 15) to particle quantity (20 - 50)
- { { BlockBelow, 0 } }
+ {0, 0, 0},
+ (Damage - 1.f) * ((0.3f - 0.1f) / (15.f - 1.f)) +
+ 0.1f, // Map damage (1 - 15) to particle speed (0.1 - 0.3)
+ static_cast<int>(
+ (Damage - 1.f) * ((50.f - 20.f) / (15.f - 1.f)) + 20.f
+ ), // Map damage (1 - 15) to particle quantity (20 - 50)
+ {{BlockBelow, 0}}
);
TakeDamage(dtFalling, nullptr, Damage, static_cast<float>(Damage), 0);
@@ -487,7 +514,11 @@ void cPawn::HandleFalling(void)
-void cPawn::HandleFarmlandTrampling(const double a_FallHeight, const BLOCKTYPE a_BlockAtFoot, const BLOCKTYPE a_BlockBelow)
+void cPawn::HandleFarmlandTrampling(
+ const double a_FallHeight,
+ const BLOCKTYPE a_BlockAtFoot,
+ const BLOCKTYPE a_BlockBelow
+)
{
// No trampling if FallHeight <= 0.6875
if (a_FallHeight <= 0.6875)
@@ -541,11 +572,14 @@ void cPawn::HandleFarmlandTrampling(const double a_FallHeight, const BLOCKTYPE a
if (ShouldTrample)
{
- GetWorld()->DoWithChunkAt(AbsPos, [&](cChunk & Chunk)
- {
- cBlockFarmlandHandler::TurnToDirt(Chunk, AbsPos);
- return true;
- });
+ GetWorld()->DoWithChunkAt(
+ AbsPos,
+ [&](cChunk & Chunk)
+ {
+ cBlockFarmlandHandler::TurnToDirt(Chunk, AbsPos);
+ return true;
+ }
+ );
}
}
@@ -565,7 +599,7 @@ void cPawn::OnRemoveFromWorld(cWorld & a_World)
void cPawn::StopEveryoneFromTargetingMe()
{
- std::vector<cMonster*>::iterator i = m_TargetingMe.begin();
+ std::vector<cMonster *>::iterator i = m_TargetingMe.begin();
while (i != m_TargetingMe.end())
{
cMonster * Monster = *i;
@@ -585,7 +619,7 @@ std::map<cEntityEffect::eType, cEntityEffect *> cPawn::GetEntityEffects() const
std::map<cEntityEffect::eType, cEntityEffect *> Effects;
for (auto & Effect : m_EntityEffects)
{
- Effects.insert({ Effect.first, Effect.second.get() });
+ Effects.insert({Effect.first, Effect.second.get()});
}
return Effects;
}
@@ -649,13 +683,20 @@ bool cPawn::DeductTotem(const eDamageType a_DamageType)
-bool cPawn::FindTeleportDestination(cWorld & a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d & a_Destination, const Vector3i a_MinBoxCorner, const Vector3i a_MaxBoxCorner)
+bool cPawn::FindTeleportDestination(
+ cWorld & a_World,
+ const int a_HeightRequired,
+ const unsigned int a_NumTries,
+ Vector3d & a_Destination,
+ const Vector3i a_MinBoxCorner,
+ const Vector3i a_MaxBoxCorner
+)
{
/*
Algorithm:
Choose random destination.
- Seek downwards, regardless of distance until the block is made of movement-blocking material: https://minecraft.wiki/w/Materials
- Succeeds if no liquid or solid blocks prevents from standing at destination.
+ Seek downwards, regardless of distance until the block is made of movement-blocking material:
+ https://minecraft.wiki/w/Materials Succeeds if no liquid or solid blocks prevents from standing at destination.
*/
auto & Random = GetRandomProvider();
@@ -707,16 +748,36 @@ bool cPawn::FindTeleportDestination(cWorld & a_World, const int a_HeightRequired
-bool cPawn::FindTeleportDestination(cWorld & a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d & a_Destination, const cBoundingBox a_BoundingBox)
+bool cPawn::FindTeleportDestination(
+ cWorld & a_World,
+ const int a_HeightRequired,
+ const unsigned int a_NumTries,
+ Vector3d & a_Destination,
+ const cBoundingBox a_BoundingBox
+)
{
- return FindTeleportDestination(a_World, a_HeightRequired, a_NumTries, a_Destination, a_BoundingBox.GetMin(), a_BoundingBox.GetMax());
+ return FindTeleportDestination(
+ a_World,
+ a_HeightRequired,
+ a_NumTries,
+ a_Destination,
+ a_BoundingBox.GetMin(),
+ a_BoundingBox.GetMax()
+ );
}
-bool cPawn::FindTeleportDestination(cWorld & a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d & a_Destination, Vector3i a_Centre, const int a_HalfCubeWidth)
+bool cPawn::FindTeleportDestination(
+ cWorld & a_World,
+ const int a_HeightRequired,
+ const unsigned int a_NumTries,
+ Vector3d & a_Destination,
+ Vector3i a_Centre,
+ const int a_HalfCubeWidth
+)
{
Vector3i MinCorner(a_Centre.x - a_HalfCubeWidth, a_Centre.y - a_HalfCubeWidth, a_Centre.z - a_HalfCubeWidth);
Vector3i MaxCorner(a_Centre.x + a_HalfCubeWidth, a_Centre.y + a_HalfCubeWidth, a_Centre.z + a_HalfCubeWidth);
diff --git a/src/Entities/Pawn.h b/src/Entities/Pawn.h
index 721f9deb2..322118351 100644
--- a/src/Entities/Pawn.h
+++ b/src/Entities/Pawn.h
@@ -12,14 +12,12 @@ class cMonster;
// tolua_begin
-class cPawn:
- public cEntity
+class cPawn : public cEntity
{
// tolua_end
using Super = cEntity;
-public:
-
+ public:
CLASS_PROTODEF(cPawn)
cPawn(eEntityType a_EntityType, float a_Width, float a_Height);
@@ -56,7 +54,12 @@ public:
a_EffectIntensity is the level of the effect (0 = Potion I, 1 = Potion II, etc).
a_DistanceModifier is the scalar multiplied to the potion duration (only applies to splash potions).
*/
- void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier = 1);
+ void AddEntityEffect(
+ cEntityEffect::eType a_EffectType,
+ int a_EffectDurationTicks,
+ short a_EffectIntensity,
+ double a_DistanceModifier = 1
+ );
/** Removes a currently applied entity effect. */
void RemoveEntityEffect(cEntityEffect::eType a_EffectType);
@@ -83,21 +86,40 @@ public:
// tolua_begin
- static bool FindTeleportDestination(cWorld & a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d & a_Destination, const Vector3i a_MinBoxCorner, const Vector3i a_MaxBoxCorner);
-
- static bool FindTeleportDestination(cWorld & a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d & a_Destination, const cBoundingBox a_BoundingBox);
+ static bool FindTeleportDestination(
+ cWorld & a_World,
+ const int a_HeightRequired,
+ const unsigned int a_NumTries,
+ Vector3d & a_Destination,
+ const Vector3i a_MinBoxCorner,
+ const Vector3i a_MaxBoxCorner
+ );
+
+ static bool FindTeleportDestination(
+ cWorld & a_World,
+ const int a_HeightRequired,
+ const unsigned int a_NumTries,
+ Vector3d & a_Destination,
+ const cBoundingBox a_BoundingBox
+ );
/** Used by enderman and chorus fruit.
Checks for valid destinations in a cube of length 2 * a_HalfCubeWidth centred at a_Centre.
Returns true and places destination in a_Destination if successful.
Returns false if destination could be found after a_NumTries attempts.
Details at: https://minecraft.wiki/w/Enderman#Teleportation. */
- static bool FindTeleportDestination(cWorld & a_World, const int a_HeightRequired, const unsigned int a_NumTries, Vector3d & a_Destination, Vector3i a_Centre, const int a_HalfCubeWidth);
+ static bool FindTeleportDestination(
+ cWorld & a_World,
+ const int a_HeightRequired,
+ const unsigned int a_NumTries,
+ Vector3d & a_Destination,
+ Vector3i a_Centre,
+ const int a_HalfCubeWidth
+ );
// tolua_end
-protected:
-
+ protected:
typedef std::map<cEntityEffect::eType, std::unique_ptr<cEntityEffect>> tEffectMap;
tEffectMap m_EntityEffects;
@@ -106,12 +128,11 @@ protected:
virtual void ResetPosition(Vector3d a_NewPosition) override;
-private:
-
+ private:
/** A list of all monsters that are targeting this pawn. */
- std::vector<cMonster*> m_TargetingMe;
+ std::vector<cMonster *> m_TargetingMe;
/** Attempt to activate a Totem of Undying.
If activation for the given type of damage was successful, consumes the totem and returns true. */
bool DeductTotem(eDamageType a_DamageType);
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp
index 05d1cd185..1568c2bb6 100644
--- a/src/Entities/Pickup.cpp
+++ b/src/Entities/Pickup.cpp
@@ -21,15 +21,13 @@
class cPickupCombiningCallback
{
-public:
+ public:
cPickupCombiningCallback(Vector3d a_Position, cPickup * a_Pickup) :
- m_FoundMatchingPickup(false),
- m_Position(a_Position),
- m_Pickup(a_Pickup)
+ m_FoundMatchingPickup(false), m_Position(a_Position), m_Pickup(a_Pickup)
{
}
- bool operator () (cEntity & a_Entity)
+ bool operator()(cEntity & a_Entity)
{
ASSERT(a_Entity.IsTicking());
if (!a_Entity.IsPickup() || (a_Entity.GetUniqueID() <= m_Pickup->GetUniqueID()) || !a_Entity.IsOnGround())
@@ -46,7 +44,8 @@ public:
if ((Distance < 1.2) && Item.IsEqual(m_Pickup->GetItem()) && OtherPickup.CanCombine())
{
short CombineCount = static_cast<short>(Item.m_ItemCount);
- if ((CombineCount + static_cast<short>(m_Pickup->GetItem().m_ItemCount)) > static_cast<short>(Item.GetMaxStackSize()))
+ if ((CombineCount + static_cast<short>(m_Pickup->GetItem().m_ItemCount)) >
+ static_cast<short>(Item.GetMaxStackSize()))
{
CombineCount = Item.GetMaxStackSize() - m_Pickup->GetItem().m_ItemCount;
}
@@ -76,12 +75,9 @@ public:
return false;
}
- inline bool FoundMatchingPickup()
- {
- return m_FoundMatchingPickup;
- }
+ inline bool FoundMatchingPickup() { return m_FoundMatchingPickup; }
-protected:
+ protected:
bool m_FoundMatchingPickup;
Vector3d m_Position;
@@ -95,7 +91,14 @@ protected:
////////////////////////////////////////////////////////////////////////////////
// cPickup:
-cPickup::cPickup(Vector3d a_Pos, const cItem & a_Item, bool IsPlayerCreated, Vector3f a_Speed, int a_LifetimeTicks, bool a_CanCombine):
+cPickup::cPickup(
+ Vector3d a_Pos,
+ const cItem & a_Item,
+ bool IsPlayerCreated,
+ Vector3f a_Speed,
+ int a_LifetimeTicks,
+ bool a_CanCombine
+) :
Super(etPickup, a_Pos, 0.25f, 0.25f),
m_Timer(0),
m_Item(a_Item),
@@ -143,7 +146,8 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
int BlockX = POSX_TOINT;
int BlockZ = POSZ_TOINT;
- if ((BlockY >= 0) && (BlockY < cChunkDef::Height)) // Don't do anything except for falling when outside the world
+ if ((BlockY >= 0) &&
+ (BlockY < cChunkDef::Height)) // Don't do anything except for falling when outside the world
{
// Position might have changed due to physics. So we have to make sure we have the correct chunk.
GET_AND_VERIFY_CURRENT_CHUNK(CurrentChunk, BlockX, BlockZ);
@@ -162,10 +166,11 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
// Try to combine the pickup with adjacent same-item pickups:
- if ((m_Item.m_ItemCount < m_Item.GetMaxStackSize()) && IsOnGround() && CanCombine()) // Don't combine if already full or not on ground
+ if ((m_Item.m_ItemCount < m_Item.GetMaxStackSize()) && IsOnGround() &&
+ CanCombine()) // Don't combine if already full or not on ground
{
- // By using a_Chunk's ForEachEntity() instead of cWorld's, pickups don't combine across chunk boundaries.
- // That is a small price to pay for not having to traverse the entire world for each entity.
+ // By using a_Chunk's ForEachEntity() instead of cWorld's, pickups don't combine across chunk
+ // boundaries. That is a small price to pay for not having to traverse the entire world for each entity.
// The speedup in the tick thread is quite considerable.
cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this);
a_Chunk.ForEachEntity(PickupCombiningCallback);
@@ -215,7 +220,8 @@ bool cPickup::CollectedBy(cEntity & a_Dest)
{
if (m_bCollected)
{
- // LOG("Pickup %d cannot be collected by \"%s\", because it has already been collected.", m_UniqueID, a_Dest->GetName().c_str());
+ // LOG("Pickup %d cannot be collected by \"%s\", because it has already been collected.", m_UniqueID,
+ // a_Dest->GetName().c_str());
return false; // It's already collected!
}
@@ -228,7 +234,8 @@ bool cPickup::CollectedBy(cEntity & a_Dest)
// Two seconds if player created the pickup (vomiting), half a second if anything else
if (m_Timer < (m_bIsPlayerCreated ? std::chrono::seconds(2) : std::chrono::milliseconds(500)))
{
- // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID, a_Dest->GetName().c_str());
+ // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID,
+ // a_Dest->GetName().c_str());
return false; // Not old enough
}
@@ -253,7 +260,12 @@ bool cPickup::CollectedBy(cEntity & a_Dest)
m_World->BroadcastCollectEntity(*this, a_Dest, static_cast<unsigned>(NumAdded));
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;)
- m_World->BroadcastSoundEffect("entity.item.pickup", GetPosition(), 0.3f, (1.2f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
+ m_World->BroadcastSoundEffect(
+ "entity.item.pickup",
+ GetPosition(),
+ 0.3f,
+ (1.2f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)
+ );
if (m_Item.m_ItemCount <= 0)
{
// All of the pickup has been collected, schedule the pickup for destroying
@@ -278,7 +290,8 @@ bool cPickup::CollectedBy(cEntity & a_Dest)
if (cRoot::Get()->GetPluginManager()->CallHookCollectingPickup(Player, *this))
{
- // LOG("Pickup %d cannot be collected by \"%s\", because a plugin has said no.", m_UniqueID, a_Dest->GetName().c_str());
+ // LOG("Pickup %d cannot be collected by \"%s\", because a plugin has said no.", m_UniqueID,
+ // a_Dest->GetName().c_str());
return false;
}
@@ -289,17 +302,22 @@ bool cPickup::CollectedBy(cEntity & a_Dest)
switch (m_Item.m_ItemType)
{
case E_BLOCK_LOG: Player.AwardAchievement(CustomStatistic::AchMineWood); break;
- case E_ITEM_LEATHER: Player.AwardAchievement(CustomStatistic::AchKillCow); break;
+ case E_ITEM_LEATHER: Player.AwardAchievement(CustomStatistic::AchKillCow); break;
case E_ITEM_DIAMOND: Player.AwardAchievement(CustomStatistic::AchDiamonds); break;
case E_ITEM_BLAZE_ROD: Player.AwardAchievement(CustomStatistic::AchBlazeRod); break;
- default: break;
+ default: break;
}
m_Item.m_ItemCount -= NumAdded;
m_World->BroadcastCollectEntity(*this, a_Dest, static_cast<unsigned>(NumAdded));
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;)
- m_World->BroadcastSoundEffect("entity.item.pickup", GetPosition(), 0.3f, (1.2f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
+ m_World->BroadcastSoundEffect(
+ "entity.item.pickup",
+ GetPosition(),
+ 0.3f,
+ (1.2f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64)
+ );
if (m_Item.m_ItemCount <= 0)
{
// All of the pickup has been collected, schedule the pickup for destroying
@@ -310,6 +328,7 @@ bool cPickup::CollectedBy(cEntity & a_Dest)
}
}
- // LOG("Pickup %d cannot be collected by \"%s\", because there's no space in the inventory.", a_Dest->GetName().c_str(), m_UniqueID);
+ // LOG("Pickup %d cannot be collected by \"%s\", because there's no space in the inventory.",
+ // a_Dest->GetName().c_str(), m_UniqueID);
return false;
}
diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h
index c995055ff..636428deb 100644
--- a/src/Entities/Pickup.h
+++ b/src/Entities/Pickup.h
@@ -15,21 +15,26 @@ class cPlayer;
// tolua_begin
-class cPickup :
- public cEntity
+class cPickup : public cEntity
{
// tolua_end
using Super = cEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cPickup)
- cPickup(Vector3d a_Pos, const cItem & a_Item, bool IsPlayerCreated, Vector3f a_Speed = Vector3f(), int a_LifetimeTicks = 6000, bool a_CanCombine = true);
+ cPickup(
+ Vector3d a_Pos,
+ const cItem & a_Item,
+ bool IsPlayerCreated,
+ Vector3f a_Speed = Vector3f(),
+ int a_LifetimeTicks = 6000,
+ bool a_CanCombine = true
+ );
- cItem & GetItem(void) {return m_Item; } // tolua_export
- const cItem & GetItem(void) const {return m_Item; }
+ cItem & GetItem(void) { return m_Item; } // tolua_export
+ const cItem & GetItem(void) const { return m_Item; }
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
@@ -48,7 +53,7 @@ public: // tolua_export
void SetCanCombine(bool a_CanCombine) { m_bCanCombine = a_CanCombine; } // tolua_export
/** Returns the number of ticks that this entity has existed */
- int GetAge(void) const { return std::chrono::duration_cast<cTickTime>(m_Timer).count(); } // tolua_export
+ int GetAge(void) const { return std::chrono::duration_cast<cTickTime>(m_Timer).count(); } // tolua_export
/** Set the number of ticks that this entity has existed */
void SetAge(int a_Age) { m_Timer = cTickTime(a_Age); } // tolua_export
@@ -65,8 +70,7 @@ public: // tolua_export
/** Returns true if created by player (i.e. vomiting), used for determining picking-up delay time */
bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export
-private:
-
+ private:
/** The number of ticks that the entity has existed / timer between collect and destroy; in msec */
std::chrono::milliseconds m_Timer;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index de99a299d..05d7d6b5c 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -50,7 +50,7 @@ AString GetUUIDFolderName(const cUUID & a_Uuid)
return res;
}
-} // namespace (anonymous)
+} // namespace
@@ -145,7 +145,8 @@ cPlayer::cPlayer(const std::shared_ptr<cClientHandle> & a_Client) :
LoadFromDisk();
SetMaxHealth(MAX_HEALTH);
- UpdateCapabilities(); // Only required for plugins listening to HOOK_SPAWNING_ENTITY to not read uninitialised variables.
+ UpdateCapabilities(
+ ); // Only required for plugins listening to HOOK_SPAWNING_ENTITY to not read uninitialised variables.
}
@@ -192,11 +193,11 @@ int cPlayer::CalcLevelFromXp(int a_XpTotal)
// level 30+
if (a_XpTotal > XP_TO_LEVEL30)
{
- return static_cast<int>((151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7);
+ return static_cast<int>((151.5 + sqrt(22952.25 - (14 * (2220 - a_XpTotal)))) / 7);
}
// level 16 to 30
- return static_cast<int>((29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal)))) / 3);
+ return static_cast<int>((29.5 + sqrt(870.25 - (6 * (360 - a_XpTotal)))) / 3);
}
@@ -356,7 +357,8 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
}
UNUSED(a_bTouchGround);
- /* Unfortunately whatever the reason, there are still desyncs in on-ground status between the client and server. For example:
+ /* Unfortunately whatever the reason, there are still desyncs in on-ground status between the client and server. For
+ example:
1. Walking off a ledge (whatever height)
2. Initial login
Thus, it is too risky to compare their value against ours and kick them for hacking */
@@ -681,7 +683,8 @@ void cPlayer::SetCrouch(const bool a_ShouldCrouch)
void cPlayer::SetElytraFlight(const bool a_ShouldElytraFly)
{
- if (a_ShouldElytraFly && IsStanding() && !IsOnGround() && !IsInWater() && !IsRiding() && (GetEquippedChestplate().m_ItemType == E_ITEM_ELYTRA))
+ if (a_ShouldElytraFly && IsStanding() && !IsOnGround() && !IsInWater() && !IsRiding() &&
+ (GetEquippedChestplate().m_ItemType == E_ITEM_ELYTRA))
{
m_BodyStance = BodyStanceGliding(*this);
}
@@ -832,14 +835,16 @@ void cPlayer::NotifyNearbyWolves(cPawn * a_Opponent, bool a_IsPlayerInvolved)
{
ASSERT(a_Opponent != nullptr);
- m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 16), [&] (cEntity & a_Entity)
+ m_World->ForEachEntityInBox(
+ cBoundingBox(GetPosition(), 16),
+ [&](cEntity & a_Entity)
{
if (a_Entity.IsMob())
{
- auto & Mob = static_cast<cMonster&>(a_Entity);
+ auto & Mob = static_cast<cMonster &>(a_Entity);
if (Mob.GetMobType() == mtWolf)
{
- auto & Wolf = static_cast<cWolf&>(Mob);
+ auto & Wolf = static_cast<cWolf &>(Mob);
Wolf.ReceiveNearbyFightInfo(GetUUID(), a_Opponent, a_IsPlayerInvolved);
}
}
@@ -858,7 +863,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
if (m_Health > 0)
{
- return; // not dead yet =]
+ return; // not dead yet =]
}
m_IsVisible = false; // So new clients don't see the player
@@ -876,7 +881,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
{
Pickups.Add(cItem(E_ITEM_RED_APPLE));
}
- m_Stats.Custom[CustomStatistic::Drop] += static_cast<StatisticsManager::StatValue>(Pickups.Size());
+ m_Stats.Custom[CustomStatistic::Drop] += static_cast<StatisticsManager::StatValue>(Pickups.Size());
m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
SaveToDisk(); // Save it, yeah the world is a tough place !
@@ -964,7 +969,10 @@ void cPlayer::Respawn(void)
const auto & DefaultWorld = *cRoot::Get()->GetDefaultWorld();
// If not, reset spawn to default and inform:
- SetRespawnPosition(Vector3i(DefaultWorld.GetSpawnX(), DefaultWorld.GetSpawnY(), DefaultWorld.GetSpawnZ()), DefaultWorld);
+ SetRespawnPosition(
+ Vector3i(DefaultWorld.GetSpawnX(), DefaultWorld.GetSpawnY(), DefaultWorld.GetSpawnZ()),
+ DefaultWorld
+ );
SendAboveActionBarMessage("Your home bed was missing or obstructed");
}
@@ -1410,8 +1418,10 @@ void cPlayer::AwardAchievement(const CustomStatistic a_Ach)
void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
- // ask plugins to allow teleport to the new position.
- if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
+ // ask plugins to allow teleport to the new position.
+ if (!cRoot::Get()
+ ->GetPluginManager()
+ ->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
{
m_IsTeleporting = true;
@@ -1601,7 +1611,7 @@ bool cPlayer::HasPermission(const AString & a_Permission) const
AStringVector Split = StringSplit(a_Permission, ".");
// Iterate over all restrictions; if any matches, then return failure:
- for (auto & Restriction: m_SplitRestrictions)
+ for (auto & Restriction : m_SplitRestrictions)
{
if (PermissionMatches(Split, Restriction))
{
@@ -1610,7 +1620,7 @@ bool cPlayer::HasPermission(const AString & a_Permission) const
} // for Restriction - m_SplitRestrictions[]
// Iterate over all granted permissions; if any matches, then return success:
- for (auto & Permission: m_SplitPermissions)
+ for (auto & Permission : m_SplitPermissions)
{
if (PermissionMatches(Split, Permission))
{
@@ -1736,7 +1746,10 @@ void cPlayer::TossEquippedItem(char a_Amount)
NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there
}
- GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount);
+ GetInventory().GetHotbarGrid().ChangeSlotCount(
+ GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */,
+ -a_Amount
+ );
DroppedItem.m_ItemCount = NewAmount;
Drops.push_back(DroppedItem);
@@ -1833,7 +1846,9 @@ void cPlayer::LoadFromDisk()
}
// This is a new player whom we haven't seen yet with no save file, let them have the defaults:
- LOG("Player \"%s\" (%s) save or statistics file not found, resetting to defaults", GetName().c_str(), UUID.ToShortString().c_str());
+ LOG("Player \"%s\" (%s) save or statistics file not found, resetting to defaults",
+ GetName().c_str(),
+ UUID.ToShortString().c_str());
}
m_CurrentWorldName = Root.get("world", cRoot::Get()->GetDefaultWorld()->GetName()).asString();
@@ -1845,26 +1860,28 @@ void cPlayer::LoadFromDisk()
}
else
{
- SetPosition(Vector3d(0.5, 0.5, 0.5) + Vector3i(m_World->GetSpawnX(), m_World->GetSpawnY(), m_World->GetSpawnZ()));
+ SetPosition(
+ Vector3d(0.5, 0.5, 0.5) + Vector3i(m_World->GetSpawnX(), m_World->GetSpawnY(), m_World->GetSpawnZ())
+ );
}
if (const auto & PlayerRotation = Root["rotation"]; PlayerRotation.size() == 3)
{
- SetYaw (PlayerRotation[0].asDouble());
+ SetYaw(PlayerRotation[0].asDouble());
SetPitch(PlayerRotation[1].asDouble());
- SetRoll (PlayerRotation[2].asDouble());
+ SetRoll(PlayerRotation[2].asDouble());
}
- m_Health = Root.get("health", MAX_HEALTH).asFloat();
- m_AirLevel = Root.get("air", MAX_AIR_LEVEL).asInt();
- m_FoodLevel = Root.get("food", MAX_FOOD_LEVEL).asInt();
+ m_Health = Root.get("health", MAX_HEALTH).asFloat();
+ m_AirLevel = Root.get("air", MAX_AIR_LEVEL).asInt();
+ m_FoodLevel = Root.get("food", MAX_FOOD_LEVEL).asInt();
m_FoodSaturationLevel = Root.get("foodSaturation", RESPAWN_FOOD_SATURATION).asDouble();
- m_FoodTickTimer = Root.get("foodTickTimer", 0).asInt();
+ m_FoodTickTimer = Root.get("foodTickTimer", 0).asInt();
m_FoodExhaustionLevel = Root.get("foodExhaustion", 0).asDouble();
- m_LifetimeTotalXp = Root.get("xpTotal", 0).asInt();
- m_CurrentXp = Root.get("xpCurrent", 0).asInt();
- m_IsFlying = Root.get("isflying", 0).asBool();
- m_EnchantmentSeed = Root.get("enchantmentSeed", GetRandomProvider().RandInt<unsigned int>()).asUInt();
+ m_LifetimeTotalXp = Root.get("xpTotal", 0).asInt();
+ m_CurrentXp = Root.get("xpCurrent", 0).asInt();
+ m_IsFlying = Root.get("isflying", 0).asBool();
+ m_EnchantmentSeed = Root.get("enchantmentSeed", GetRandomProvider().RandInt<unsigned int>()).asUInt();
Json::Value & JSON_KnownItems = Root["knownItems"];
for (UInt32 i = 0; i < JSON_KnownItems.size(); i++)
@@ -1899,8 +1916,12 @@ void cPlayer::LoadFromDisk()
m_IsRespawnPointForced = Root.get("SpawnForced", true).asBool();
m_SpawnWorldName = Root.get("SpawnWorld", m_World->GetName()).asString();
- FLOGD("Player \"{0}\" with save file \"{1}\" is spawning at {2:.2f} in world \"{3}\"",
- GetName(), FileName, GetPosition(), m_World->GetName()
+ FLOGD(
+ "Player \"{0}\" with save file \"{1}\" is spawning at {2:.2f} in world \"{3}\"",
+ GetName(),
+ FileName,
+ GetPosition(),
+ m_World->GetName()
);
}
@@ -1910,10 +1931,7 @@ void cPlayer::LoadFromDisk()
void cPlayer::OpenHorseInventory()
{
- if (
- (m_AttachedTo == nullptr) ||
- !m_AttachedTo->IsMob()
- )
+ if ((m_AttachedTo == nullptr) || !m_AttachedTo->IsMob())
{
return;
}
@@ -1975,31 +1993,31 @@ void cPlayer::SaveToDisk()
}
Json::Value root;
- root["position"] = JSON_PlayerPosition;
- root["rotation"] = JSON_PlayerRotation;
- root["inventory"] = JSON_Inventory;
- root["knownItems"] = JSON_KnownItems;
- root["knownRecipes"] = JSON_KnownRecipes;
- root["equippedItemSlot"] = m_Inventory.GetEquippedSlotNum();
+ root["position"] = JSON_PlayerPosition;
+ root["rotation"] = JSON_PlayerRotation;
+ root["inventory"] = JSON_Inventory;
+ root["knownItems"] = JSON_KnownItems;
+ root["knownRecipes"] = JSON_KnownRecipes;
+ root["equippedItemSlot"] = m_Inventory.GetEquippedSlotNum();
root["enderchestinventory"] = JSON_EnderChestInventory;
- root["health"] = m_Health;
- root["xpTotal"] = m_LifetimeTotalXp;
- root["xpCurrent"] = m_CurrentXp;
- root["air"] = m_AirLevel;
- root["food"] = m_FoodLevel;
- root["foodSaturation"] = m_FoodSaturationLevel;
- root["foodTickTimer"] = m_FoodTickTimer;
- root["foodExhaustion"] = m_FoodExhaustionLevel;
- root["isflying"] = IsFlying();
- root["lastknownname"] = GetName();
- root["SpawnX"] = GetLastBedPos().x;
- root["SpawnY"] = GetLastBedPos().y;
- root["SpawnZ"] = GetLastBedPos().z;
- root["SpawnForced"] = m_IsRespawnPointForced;
- root["SpawnWorld"] = m_SpawnWorldName;
- root["enchantmentSeed"] = m_EnchantmentSeed;
- root["world"] = m_CurrentWorldName;
- root["gamemode"] = static_cast<int>(m_GameMode);
+ root["health"] = m_Health;
+ root["xpTotal"] = m_LifetimeTotalXp;
+ root["xpCurrent"] = m_CurrentXp;
+ root["air"] = m_AirLevel;
+ root["food"] = m_FoodLevel;
+ root["foodSaturation"] = m_FoodSaturationLevel;
+ root["foodTickTimer"] = m_FoodTickTimer;
+ root["foodExhaustion"] = m_FoodExhaustionLevel;
+ root["isflying"] = IsFlying();
+ root["lastknownname"] = GetName();
+ root["SpawnX"] = GetLastBedPos().x;
+ root["SpawnY"] = GetLastBedPos().y;
+ root["SpawnZ"] = GetLastBedPos().z;
+ root["SpawnForced"] = m_IsRespawnPointForced;
+ root["SpawnWorld"] = m_SpawnWorldName;
+ root["enchantmentSeed"] = m_EnchantmentSeed;
+ root["world"] = m_CurrentWorldName;
+ root["gamemode"] = static_cast<int>(m_GameMode);
auto JsonData = JsonUtils::WriteStyledString(root);
AString SourceFile = GetUUIDFileName(UUID);
@@ -2007,15 +2025,19 @@ void cPlayer::SaveToDisk()
cFile f;
if (!f.Open(SourceFile, cFile::fmWrite))
{
- LOGWARNING("Error writing player \"%s\" to file \"%s\": cannot open file. Player will lose their progress",
- GetName().c_str(), SourceFile.c_str()
+ LOGWARNING(
+ "Error writing player \"%s\" to file \"%s\": cannot open file. Player will lose their progress",
+ GetName().c_str(),
+ SourceFile.c_str()
);
return;
}
if (f.Write(JsonData.c_str(), JsonData.size()) != static_cast<int>(JsonData.size()))
{
- LOGWARNING("Error writing player \"%s\" to file \"%s\": cannot save data. Player will lose their progress",
- GetName().c_str(), SourceFile.c_str()
+ LOGWARNING(
+ "Error writing player \"%s\" to file \"%s\": cannot save data. Player will lose their progress",
+ GetName().c_str(),
+ SourceFile.c_str()
);
return;
}
@@ -2078,8 +2100,8 @@ void cPlayer::UseItem(int a_SlotNumber, short a_Damage)
// Ref: https://minecraft.wiki/w/Enchanting#Unbreaking
unsigned int UnbreakingLevel = Item.m_Enchantments.GetLevel(cEnchantments::enchUnbreaking);
- double chance = ItemCategory::IsArmor(Item.m_ItemType)
- ? (0.6 + (0.4 / (UnbreakingLevel + 1))) : (1.0 / (UnbreakingLevel + 1));
+ double chance =
+ ItemCategory::IsArmor(Item.m_ItemType) ? (0.6 + (0.4 / (UnbreakingLevel + 1))) : (1.0 / (UnbreakingLevel + 1));
// When durability is reduced by multiple points
// Unbreaking is applied for each point of reduction.
@@ -2101,11 +2123,16 @@ void cPlayer::UseItem(int a_SlotNumber, short a_Damage)
{
switch (a_SlotNumber)
{
- case cInventory::invArmorOffset: return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnHeadEquipmentBreaks);
- case cInventory::invArmorOffset + 1: return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnChestEquipmentBreaks);
- case cInventory::invArmorOffset + 2: return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnLegsEquipmentBreaks);
- case cInventory::invArmorOffset + 3: return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnFeetEquipmentBreaks);
- case cInventory::invShieldOffset: return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnOffHandEquipmentBreaks);
+ case cInventory::invArmorOffset:
+ return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnHeadEquipmentBreaks);
+ case cInventory::invArmorOffset + 1:
+ return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnChestEquipmentBreaks);
+ case cInventory::invArmorOffset + 2:
+ return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnLegsEquipmentBreaks);
+ case cInventory::invArmorOffset + 3:
+ return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnFeetEquipmentBreaks);
+ case cInventory::invShieldOffset:
+ return m_World->BroadcastEntityAnimation(*this, EntityAnimation::PawnOffHandEquipmentBreaks);
}
}
}
@@ -2182,7 +2209,9 @@ void cPlayer::HandleFloater()
{
return;
}
- m_World->DoWithEntityByID(m_FloaterID, [](cEntity & a_Entity)
+ m_World->DoWithEntityByID(
+ m_FloaterID,
+ [](cEntity & a_Entity)
{
a_Entity.Destroy();
return true;
@@ -2241,7 +2270,8 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIs
{
if (a_DeltaPos.y > 0.0) // Going up
{
- m_Stats.Custom[CustomStatistic::ClimbOneCm] += FloorC<StatisticsManager::StatValue>(a_DeltaPos.y * 100 + 0.5);
+ m_Stats.Custom[CustomStatistic::ClimbOneCm] +=
+ FloorC<StatisticsManager::StatValue>(a_DeltaPos.y * 100 + 0.5);
}
}
else if (IsInWater())
@@ -2285,7 +2315,8 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIs
else if (a_DeltaPos.y < 0.0)
{
// Increment statistic
- m_Stats.Custom[CustomStatistic::FallOneCm] += static_cast<StatisticsManager::StatValue>(-a_DeltaPos.y * 100 + 0.5);
+ m_Stats.Custom[CustomStatistic::FallOneCm] +=
+ static_cast<StatisticsManager::StatValue>(-a_DeltaPos.y * 100 + 0.5);
}
// TODO: good opportunity to detect illegal flight (check for falling tho)
}
@@ -2295,15 +2326,15 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIs
switch (m_AttachedTo->GetEntityType())
{
case cEntity::etMinecart: m_Stats.Custom[CustomStatistic::MinecartOneCm] += Value; break;
- case cEntity::etBoat: m_Stats.Custom[CustomStatistic::BoatOneCm] += Value; break;
+ case cEntity::etBoat: m_Stats.Custom[CustomStatistic::BoatOneCm] += Value; break;
case cEntity::etMonster:
{
cMonster * Monster = static_cast<cMonster *>(m_AttachedTo);
switch (Monster->GetMobType())
{
- case mtPig: m_Stats.Custom[CustomStatistic::PigOneCm] += Value; break;
+ case mtPig: m_Stats.Custom[CustomStatistic::PigOneCm] += Value; break;
case mtHorse: m_Stats.Custom[CustomStatistic::HorseOneCm] += Value; break;
- default: break;
+ default: break;
}
break;
}
@@ -2339,7 +2370,13 @@ void cPlayer::SendBlocksAround(Vector3i a_BlockPos, int a_Range)
{
for (int x = a_BlockPos.x - a_Range + 1; x < a_BlockPos.x + a_Range; x++)
{
- blks.emplace_back(x, y, z, E_BLOCK_AIR, static_cast<NIBBLETYPE>(0)); // Use fake blocktype, it will get set later on.
+ blks.emplace_back(
+ x,
+ y,
+ z,
+ E_BLOCK_AIR,
+ static_cast<NIBBLETYPE>(0)
+ ); // Use fake blocktype, it will get set later on.
}
}
} // for y
@@ -2353,7 +2390,7 @@ void cPlayer::SendBlocksAround(Vector3i a_BlockPos, int a_Range)
// Divide the block changes by their respective chunks:
std::unordered_map<cChunkCoords, sSetBlockVector, cChunkCoordsHash> Changes;
- for (const auto & blk: blks)
+ for (const auto & blk : blks)
{
Changes[cChunkCoords(blk.m_ChunkX, blk.m_ChunkZ)].push_back(blk);
} // for blk - blks[]
@@ -2376,19 +2413,22 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const std::initializer_list<sSetB
std::vector<cBoundingBox> PlacementBoxes;
cBoundingBox PlacingBounds(0, 0, 0, 0, 0, 0);
bool HasInitializedBounds = false;
- for (auto blk: a_Blocks)
+ for (auto blk : a_Blocks)
{
int x = blk.GetX();
int y = blk.GetY();
int z = blk.GetZ();
- cBoundingBox BlockBox = cBlockHandler::For(blk.m_BlockType).GetPlacementCollisionBox(
- m_World->GetBlock({ x - 1, y, z }),
- m_World->GetBlock({ x + 1, y, z }),
- (y == 0) ? static_cast<BLOCKTYPE>(E_BLOCK_AIR) : m_World->GetBlock({ x, y - 1, z }),
- (y == cChunkDef::Height - 1) ? static_cast<BLOCKTYPE>(E_BLOCK_AIR) : m_World->GetBlock({ x, y + 1, z }),
- m_World->GetBlock({ x, y, z - 1 }),
- m_World->GetBlock({ x, y, z + 1 })
- );
+ cBoundingBox BlockBox =
+ cBlockHandler::For(blk.m_BlockType)
+ .GetPlacementCollisionBox(
+ m_World->GetBlock({x - 1, y, z}),
+ m_World->GetBlock({x + 1, y, z}),
+ (y == 0) ? static_cast<BLOCKTYPE>(E_BLOCK_AIR) : m_World->GetBlock({x, y - 1, z}),
+ (y == cChunkDef::Height - 1) ? static_cast<BLOCKTYPE>(E_BLOCK_AIR)
+ : m_World->GetBlock({x, y + 1, z}),
+ m_World->GetBlock({x, y, z - 1}),
+ m_World->GetBlock({x, y, z + 1})
+ );
BlockBox.Move(x, y, z);
PlacementBoxes.push_back(BlockBox);
@@ -2407,7 +2447,9 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const std::initializer_list<sSetB
cWorld * World = GetWorld();
// Check to see if any entity intersects any block being placed
- return !World->ForEachEntityInBox(PlacingBounds, [&](cEntity & a_Entity)
+ return !World->ForEachEntityInBox(
+ PlacingBounds,
+ [&](cEntity & a_Entity)
{
// The distance inside the block the entity can still be.
const double EPSILON = 0.0005;
@@ -2446,7 +2488,7 @@ const cUUID & cPlayer::GetUUID(void) const
bool cPlayer::PlaceBlock(const Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
- return PlaceBlocks({ { a_Position, a_BlockType, a_BlockMeta } });
+ return PlaceBlocks({{a_Position, a_BlockType, a_BlockMeta}});
}
@@ -2470,12 +2512,14 @@ bool cPlayer::PlaceBlocks(const std::initializer_list<sSetBlock> a_Blocks)
// Check the blocks CanBeAt, and call the "placing" hooks; if any fail, abort:
for (const auto & Block : a_Blocks)
{
- if (
- !m_World->DoWithChunkAt(Block.GetAbsolutePos(), [&Block](cChunk & a_Chunk)
- {
- return cBlockHandler::For(Block.m_BlockType).CanBeAt(a_Chunk, Block.GetRelativePos(), Block.m_BlockMeta);
- })
- )
+ if (!m_World->DoWithChunkAt(
+ Block.GetAbsolutePos(),
+ [&Block](cChunk & a_Chunk)
+ {
+ return cBlockHandler::For(Block.m_BlockType)
+ .CanBeAt(a_Chunk, Block.GetRelativePos(), Block.m_BlockMeta);
+ }
+ ))
{
return false;
}
@@ -2621,9 +2665,11 @@ float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
// If we can harvest the block then we can apply material and enchantment bonuses
if (GetEquippedItem().GetHandler().CanHarvestBlock(a_Block))
{
- if (MiningSpeed > 1.0f) // If the base multiplier for this block is greater than 1, now we can check enchantments
+ if (MiningSpeed >
+ 1.0f) // If the base multiplier for this block is greater than 1, now we can check enchantments
{
- unsigned int EfficiencyModifier = GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchEfficiency);
+ unsigned int EfficiencyModifier =
+ GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchEfficiency);
if (EfficiencyModifier > 0) // If an efficiency enchantment is present, apply formula as on wiki
{
MiningSpeed += (EfficiencyModifier * EfficiencyModifier) + 1;
@@ -2650,16 +2696,16 @@ float cPlayer::GetDigSpeed(BLOCKTYPE a_Block)
int intensity = MiningFatigue->GetIntensity();
switch (intensity)
{
- case 0: MiningSpeed *= 0.3f; break;
- case 1: MiningSpeed *= 0.09f; break;
- case 2: MiningSpeed *= 0.0027f; break;
+ case 0: MiningSpeed *= 0.3f; break;
+ case 1: MiningSpeed *= 0.09f; break;
+ case 2: MiningSpeed *= 0.0027f; break;
default: MiningSpeed *= 0.00081f; break;
-
}
}
// 5x speed loss for being in water
- if (IsInsideWater() && !(GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchAquaAffinity) > 0))
+ if (IsInsideWater() &&
+ !(GetEquippedItem().m_Enchantments.GetLevel(cEnchantments::eEnchantment::enchAquaAffinity) > 0))
{
MiningSpeed /= 5.0f;
}
@@ -2774,10 +2820,8 @@ void cPlayer::TickFreezeCode()
while (NewY < cChunkDef::Height - 2)
{
// If we find a position with enough space for the player
- if (
- !cBlockInfo::IsSolid(Chunk->GetBlock(Rel.x, NewY, Rel.z)) &&
- !cBlockInfo::IsSolid(Chunk->GetBlock(Rel.x, NewY + 1, Rel.z))
- )
+ if (!cBlockInfo::IsSolid(Chunk->GetBlock(Rel.x, NewY, Rel.z)) &&
+ !cBlockInfo::IsSolid(Chunk->GetBlock(Rel.x, NewY + 1, Rel.z)))
{
// If the found position is not the same as the original
if (NewY != Rel.y)
@@ -2923,10 +2967,11 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (a_TDI.Attacker->IsPawn())
{
- NotifyNearbyWolves(static_cast<cPawn*>(a_TDI.Attacker), true);
+ NotifyNearbyWolves(static_cast<cPawn *>(a_TDI.Attacker), true);
}
}
- m_Stats.Custom[CustomStatistic::DamageTaken] += FloorC<StatisticsManager::StatValue>(a_TDI.FinalDamage * 10 + 0.5);
+ m_Stats.Custom[CustomStatistic::DamageTaken] +=
+ FloorC<StatisticsManager::StatValue>(a_TDI.FinalDamage * 10 + 0.5);
return true;
}
return false;
@@ -2938,10 +2983,7 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
float cPlayer::GetEnchantmentBlastKnockbackReduction()
{
- if (
- IsGameModeSpectator() ||
- (IsGameModeCreative() && !IsOnGround())
- )
+ if (IsGameModeSpectator() || (IsGameModeCreative() && !IsOnGround()))
{
return 1; // No impact from explosion
}
@@ -3001,8 +3043,8 @@ void cPlayer::OnAddToWorld(cWorld & a_World)
FreezeInternal(GetPosition(), false);
// UpdateCapabilities was called in the constructor, and in OnRemoveFromWorld, possibly changing our visibility.
- // If world is in spectator mode, invisibility will need updating. If we just connected, we might be on fire from a previous game.
- // Hence, tell the client by sending metadata:
+ // If world is in spectator mode, invisibility will need updating. If we just connected, we might be on fire from a
+ // previous game. Hence, tell the client by sending metadata:
m_ClientHandle->SendEntityMetadata(*this);
// Send contents of the inventory window:
@@ -3061,11 +3103,9 @@ void cPlayer::OnDetach()
{
for (int z = PosZ - 1; z <= (PosZ + 1); ++z)
{
- if (
- (m_World->GetBlock({ x, y, z }) == E_BLOCK_AIR) &&
- (m_World->GetBlock({ x, y + 1, z }) == E_BLOCK_AIR) &&
- cBlockInfo::IsSolid(m_World->GetBlock({ x, y - 1, z }))
- )
+ if ((m_World->GetBlock({x, y, z}) == E_BLOCK_AIR) &&
+ (m_World->GetBlock({x, y + 1, z}) == E_BLOCK_AIR) &&
+ cBlockInfo::IsSolid(m_World->GetBlock({x, y - 1, z})))
{
TeleportToCoords(x + 0.5, y, z + 0.5);
return;
@@ -3092,7 +3132,8 @@ void cPlayer::OnRemoveFromWorld(cWorld & a_World)
// Remove the client handle from the world:
m_World->RemoveClientFromChunks(m_ClientHandle.get());
- if (m_ClientHandle->IsDestroyed()) // Note: checking IsWorldChangeScheduled not appropriate here since we can disconnecting while having a scheduled warp
+ if (m_ClientHandle->IsDestroyed()) // Note: checking IsWorldChangeScheduled not appropriate here since we can
+ // disconnecting while having a scheduled warp
{
// Disconnecting, do the necessary cleanup.
// This isn't in the destructor to avoid crashing accessing destroyed objects during shutdown.
@@ -3176,7 +3217,8 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
{
- const auto TicksElapsed = static_cast<StatisticsManager::StatValue>(std::chrono::duration_cast<cTickTime>(a_Dt).count());
+ const auto TicksElapsed =
+ static_cast<StatisticsManager::StatValue>(std::chrono::duration_cast<cTickTime>(a_Dt).count());
m_Stats.Custom[CustomStatistic::PlayOneMinute] += TicksElapsed;
m_Stats.Custom[CustomStatistic::TimeSinceDeath] += TicksElapsed;
@@ -3193,9 +3235,9 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Handle a frozen player:
TickFreezeCode();
- if (
- m_IsFrozen || // Don't do Tick updates if frozen
- IsWorldChangeScheduled() // If we're about to change worlds (e.g. respawn), abort processing all world interactions (GH #3939)
+ if (m_IsFrozen || // Don't do Tick updates if frozen
+ IsWorldChangeScheduled(
+ ) // If we're about to change worlds (e.g. respawn), abort processing all world interactions (GH #3939)
)
{
return;
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index cee8a1a9c..888bab90b 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -24,8 +24,7 @@ class cTeam;
// tolua_begin
-class cPlayer:
- public cPawn
+class cPlayer : public cPawn
{
// tolua_end
@@ -80,8 +79,7 @@ class cPlayer:
// tolua_begin
-public:
-
+ public:
static const int MAX_HEALTH;
static const int MAX_FOOD_LEVEL;
@@ -93,7 +91,8 @@ public:
cPlayer(const std::shared_ptr<cClientHandle> & a_Client);
virtual ~cPlayer() override;
- /** Called when spectation stops, because the player crouched or when the entity we're spectating gets removed from the world. */
+ /** Called when spectation stops, because the player crouched or when the entity we're spectating gets removed from
+ * the world. */
void OnLoseSpectated();
// tolua_begin
@@ -153,7 +152,7 @@ public:
void SetTouchGround(bool a_bTouchGround);
double GetEyeHeight(void) const; // tolua_export
Vector3d GetEyePosition(void) const; // tolua_export
- inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export
+ inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export
inline const cInventory & GetInventory(void) const { return m_Inventory; }
/** Gets the contents of the player's associated enderchest */
@@ -225,7 +224,6 @@ public:
virtual bool IsFireproof() const override
{
return (m_IsFireproof || IsGameModeCreative() || IsGameModeSpectator());
-
}
/** Returns true if the player can be targeted by Mobs */
@@ -267,7 +265,8 @@ public:
/** Opens the specified window; closes the current one first using CloseWindow() */
void OpenWindow(cWindow & a_Window);
- /** Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if a_CanRefuse is true */
+ /** Closes the current window, resets current window to m_InventoryWindow. A plugin may refuse the closing if
+ * a_CanRefuse is true */
void CloseWindow(bool a_CanRefuse = true);
/** Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow */
@@ -278,7 +277,8 @@ public:
// tolua_end
/** Get a copy of the PRNG for enchanting related generation, don't use this for other purposes.
- The PRNG's state is initialised with an internal seed, such that until PermuteEnchantmentSeed is called, this function returns the same PRNG. */
+ The PRNG's state is initialised with an internal seed, such that until PermuteEnchantmentSeed is called, this
+ function returns the same PRNG. */
MTRand GetEnchantmentRandomProvider();
/** Permute the seed for enchanting related PRNGs, don't use this for other purposes. */
@@ -286,18 +286,18 @@ public:
// tolua_begin
- void SendMessage (const AString & a_Message);
- void SendMessageInfo (const AString & a_Message);
- void SendMessageFailure (const AString & a_Message);
- void SendMessageSuccess (const AString & a_Message);
- void SendMessageWarning (const AString & a_Message);
- void SendMessageFatal (const AString & a_Message);
- void SendMessagePrivateMsg (const AString & a_Message, const AString & a_Sender);
- void SendMessage (const cCompositeChat & a_Message);
- void SendMessageRaw (const AString & a_MessageRaw, eChatType a_Type = eChatType::ctChatBox);
- void SendSystemMessage (const AString & a_Message);
+ void SendMessage(const AString & a_Message);
+ void SendMessageInfo(const AString & a_Message);
+ void SendMessageFailure(const AString & a_Message);
+ void SendMessageSuccess(const AString & a_Message);
+ void SendMessageWarning(const AString & a_Message);
+ void SendMessageFatal(const AString & a_Message);
+ void SendMessagePrivateMsg(const AString & a_Message, const AString & a_Sender);
+ void SendMessage(const cCompositeChat & a_Message);
+ void SendMessageRaw(const AString & a_MessageRaw, eChatType a_Type = eChatType::ctChatBox);
+ void SendSystemMessage(const AString & a_Message);
void SendAboveActionBarMessage(const AString & a_Message);
- void SendSystemMessage (const cCompositeChat & a_Message);
+ void SendSystemMessage(const cCompositeChat & a_Message);
void SendAboveActionBarMessage(const cCompositeChat & a_Message);
const AString & GetName(void) const;
@@ -307,9 +307,12 @@ public:
bool HasPermission(const AString & a_Permission) const; // tolua_export
/** Returns true iff a_Permission matches the a_Template.
- A match is defined by either being exactly the same, or each sub-item matches until there's a wildcard in a_Template.
- Ie. {"a", "b", "c"} matches {"a", "b", "*"} but doesn't match {"a", "b"} */
- static bool PermissionMatches(const AStringVector & a_Permission, const AStringVector & a_Template); // Exported in ManualBindings with AString params
+ A match is defined by either being exactly the same, or each sub-item matches until there's a wildcard in
+ a_Template. Ie. {"a", "b", "c"} matches {"a", "b", "*"} but doesn't match {"a", "b"} */
+ static bool PermissionMatches(
+ const AStringVector & a_Permission,
+ const AStringVector & a_Template
+ ); // Exported in ManualBindings with AString params
/** Returns all the permissions that the player has assigned to them. */
const AStringVector & GetPermissions(void) const { return m_Permissions; } // Exported in ManualBindings.cpp
@@ -351,18 +354,18 @@ public:
/** Heals the player by the specified amount of HPs (positive only); sends health update */
virtual void Heal(int a_Health) override;
- int GetFoodLevel (void) const { return m_FoodLevel; }
- double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; }
- int GetFoodTickTimer (void) const { return m_FoodTickTimer; }
- double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; }
+ int GetFoodLevel(void) const { return m_FoodLevel; }
+ double GetFoodSaturationLevel(void) const { return m_FoodSaturationLevel; }
+ int GetFoodTickTimer(void) const { return m_FoodTickTimer; }
+ double GetFoodExhaustionLevel(void) const { return m_FoodExhaustionLevel; }
/** Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore */
bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); }
- void SetFoodLevel (int a_FoodLevel);
- void SetFoodSaturationLevel (double a_FoodSaturationLevel);
- void SetFoodTickTimer (int a_FoodTickTimer);
- void SetFoodExhaustionLevel (double a_FoodExhaustionLevel);
+ void SetFoodLevel(int a_FoodLevel);
+ void SetFoodSaturationLevel(double a_FoodSaturationLevel);
+ void SetFoodTickTimer(int a_FoodTickTimer);
+ void SetFoodExhaustionLevel(double a_FoodExhaustionLevel);
/** Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed, false if player "full" */
bool Feed(int a_Food, double a_Saturation);
@@ -385,7 +388,11 @@ public:
/** Returns true if the player has thrown out a floater */
bool IsFishing(void) const { return m_IsFishing; }
- void SetIsFishing(bool a_IsFishing, UInt32 a_FloaterID = cEntity::INVALID_ID) { m_IsFishing = a_IsFishing; m_FloaterID = a_FloaterID; }
+ void SetIsFishing(bool a_IsFishing, UInt32 a_FloaterID = cEntity::INVALID_ID)
+ {
+ m_IsFishing = a_IsFishing;
+ m_FloaterID = a_FloaterID;
+ }
UInt32 GetFloaterID(void) const { return m_FloaterID; }
@@ -417,13 +424,14 @@ public:
void Respawn(void); // tolua_export
- void SetVisible( bool a_bVisible); // tolua_export
+ void SetVisible(bool a_bVisible); // tolua_export
/** Saves all player data, such as inventory, to JSON. */
void SaveToDisk(void);
/** Loads the player data from the save file.
- Sets m_World to the world where the player will spawn, based on the stored world name or the default world by calling LoadFromFile(). */
+ Sets m_World to the world where the player will spawn, based on the stored world name or the default world by
+ calling LoadFromFile(). */
void LoadFromDisk();
const AString & GetLoadedWorldName() const { return m_CurrentWorldName; }
@@ -445,7 +453,7 @@ public:
void UseItem(int a_SlotNumber, short a_Damage = 1);
/** In UI windows, get the item that the player is dragging */
- cItem & GetDraggingItem(void) {return m_DraggingItem; } // tolua_export
+ cItem & GetDraggingItem(void) { return m_DraggingItem; } // tolua_export
/** In UI windows, set the item that the player is dragging */
void SetDraggingItem(const cItem & a_Item); // tolua_export
@@ -566,14 +574,15 @@ public:
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
/** Calls the block placement hooks and places the blocks in the world.
- First the "placing" hooks for all the blocks are called, then the blocks are placed, and finally the "placed" hooks are called.
- If the any of the "placing" hooks aborts, none of the blocks are placed and the function returns false.
+ First the "placing" hooks for all the blocks are called, then the blocks are placed, and finally the "placed" hooks
+ are called. If the any of the "placing" hooks aborts, none of the blocks are placed and the function returns false.
Returns true if all the blocks are placed. */
bool PlaceBlocks(std::initializer_list<sSetBlock> a_Blocks);
/** Notify nearby wolves that the player or one of the player's wolves took damage or did damage to an entity
@param a_Opponent the opponent we're fighting.
- @param a_IsPlayerInvolved Should be true if the player took or did damage, and false if one of the player's wolves took or did damage.
+ @param a_IsPlayerInvolved Should be true if the player took or did damage, and false if one of the player's wolves
+ took or did damage.
*/
void NotifyNearbyWolves(cPawn * a_Opponent, bool a_IsPlayerInvolved);
@@ -604,12 +613,12 @@ public:
virtual bool IsOnGround(void) const override { return m_bTouchGround; }
virtual bool IsSprinting(void) const override;
-private:
-
- typedef std::vector<std::vector<AString> > AStringVectorVector;
+ private:
+ typedef std::vector<std::vector<AString>> AStringVectorVector;
/** The current body stance the player has adopted. */
- std::variant<BodyStanceCrouching, BodyStanceSleeping, BodyStanceSprinting, BodyStanceStanding, BodyStanceGliding> m_BodyStance;
+ std::variant<BodyStanceCrouching, BodyStanceSleeping, BodyStanceSprinting, BodyStanceStanding, BodyStanceGliding>
+ m_BodyStance;
/** The name of the rank assigned to this player. */
AString m_Rank;
@@ -642,7 +651,8 @@ private:
/** Count-up to the healing or damaging action, based on m_FoodLevel */
int m_FoodTickTimer;
- /** A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action adds a little */
+ /** A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel. Each action
+ * adds a little */
double m_FoodExhaustionLevel;
/** Stores the player's inventory, consisting of crafting grid, hotbar, and main slots */
@@ -655,11 +665,13 @@ private:
cWindow * m_InventoryWindow;
/** The player's potential respawn position, initialised to world spawn by default.
- During player respawn from death, if m_IsRespawnPointForced is false and no bed exists here, it will be reset to world spawn. */
+ During player respawn from death, if m_IsRespawnPointForced is false and no bed exists here, it will be reset to
+ world spawn. */
Vector3i m_RespawnPosition;
/** The name of the world which the player respawns in upon death.
- This is stored as a string to enable SaveToDisk to not touch cRoot, and thus can be safely called in the player's destructor. */
+ This is stored as a string to enable SaveToDisk to not touch cRoot, and thus can be safely called in the player's
+ destructor. */
std::string m_SpawnWorldName;
/** The name of the world which the player currently resides in.
@@ -710,7 +722,8 @@ private:
/** Was the player frozen manually by a plugin or automatically by the server? */
bool m_IsManuallyFrozen;
- /** Whether we unconditionally respawn to m_RespawnPosition, or check if a bed is unobstructed and available first. */
+ /** Whether we unconditionally respawn to m_RespawnPosition, or check if a bed is unobstructed and available first.
+ */
bool m_IsRespawnPointForced;
/** Flag used by food handling system to determine whether a teleport has just happened.
@@ -756,7 +769,8 @@ private:
/** Called in each tick to handle food-related processing */
void HandleFood(void);
- /** Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a fishing rod as equipped item. */
+ /** Called in each tick if the player is fishing to make sure the floater dissapears when the player doesn't have a
+ * fishing rod as equipped item. */
void HandleFloater(void);
/** Returns the filename for the player data based on the UUID given.
@@ -776,10 +790,10 @@ private:
/** Returns the dig speed using the current tool on the block a_Block.
Returns one if using hand.
If the player is using a tool that is good to break the block the value is higher.
- If he has an enchanted tool with efficiency or he has a haste or mining fatique effect it gets multiplied by a specific factor depending on the strength of the effect or enchantment.
- In he is in water it gets divided by 5 except if his tool is enchanted with aqua affinity.
- If he is not on ground it also gets divided by 5.
- Source: https://minecraft.wiki/w/Breaking#Calculation */
+ If he has an enchanted tool with efficiency or he has a haste or mining fatique effect it gets multiplied by a
+ specific factor depending on the strength of the effect or enchantment. In he is in water it gets divided by 5
+ except if his tool is enchanted with aqua affinity. If he is not on ground it also gets divided by 5. Source:
+ https://minecraft.wiki/w/Breaking#Calculation */
float GetDigSpeed(BLOCKTYPE a_Block);
/** Add the recipe Id to the known recipes.
@@ -807,4 +821,4 @@ private:
virtual void SpawnOn(cClientHandle & a_Client) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index ea59c9c46..cfe33c13f 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -1,7 +1,8 @@
// ProjectileEntity.cpp
-// Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
+// Implements the cProjectileEntity class representing the common base class for projectiles, as well as individual
+// projectile types
#include "Globals.h"
@@ -33,24 +34,23 @@
////////////////////////////////////////////////////////////////////////////////
// cProjectileTracerCallback:
-class cProjectileTracerCallback :
- public cBlockTracer::cCallbacks
+class cProjectileTracerCallback : public cBlockTracer::cCallbacks
{
-public:
+ public:
cProjectileTracerCallback(cProjectileEntity * a_Projectile) :
- m_Projectile(a_Projectile),
- m_SlowdownCoeff(0.99) // Default slowdown when not in water
+ m_Projectile(a_Projectile), m_SlowdownCoeff(0.99) // Default slowdown when not in water
{
}
double GetSlowdownCoeff(void) const { return m_SlowdownCoeff; }
-protected:
+ protected:
cProjectileEntity * m_Projectile;
double m_SlowdownCoeff;
// cCallbacks overrides:
- virtual bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace) override
+ virtual bool OnNextBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, eBlockFace a_EntryFace)
+ override
{
/*
// DEBUG:
@@ -66,14 +66,18 @@ protected:
{
// The projectile hit a solid block, calculate the exact hit coords:
cBoundingBox bb(a_BlockPos, a_BlockPos + Vector3i(1, 1, 1)); // Bounding box of the block hit
- const Vector3d LineStart = m_Projectile->GetPosition(); // Start point for the imaginary line that goes through the block hit
- const Vector3d LineEnd = LineStart + m_Projectile->GetSpeed(); // End point for the imaginary line that goes through the block hit
- double LineCoeff = 0; // Used to calculate where along the line an intersection with the bounding box occurs
+ const Vector3d LineStart =
+ m_Projectile->GetPosition(); // Start point for the imaginary line that goes through the block hit
+ const Vector3d LineEnd = LineStart +
+ m_Projectile->GetSpeed(); // End point for the imaginary line that goes through the block hit
+ double LineCoeff =
+ 0; // Used to calculate where along the line an intersection with the bounding box occurs
eBlockFace Face; // Face hit
if (bb.CalcLineIntersection(LineStart, LineEnd, LineCoeff, Face))
{
- Vector3d Intersection = LineStart + m_Projectile->GetSpeed() * LineCoeff; // Point where projectile goes into the hit block
+ Vector3d Intersection =
+ LineStart + m_Projectile->GetSpeed() * LineCoeff; // Point where projectile goes into the hit block
if (cPluginManager::Get()->CallHookProjectileHitBlock(*m_Projectile, a_BlockPos, Face, Intersection))
{
@@ -96,14 +100,16 @@ protected:
case E_BLOCK_STATIONARY_LAVA:
{
m_Projectile->StartBurning(30);
- m_SlowdownCoeff = std::min(m_SlowdownCoeff, 0.9); // Slow down to 0.9* the speed each tick when moving through lava
+ m_SlowdownCoeff =
+ std::min(m_SlowdownCoeff, 0.9); // Slow down to 0.9* the speed each tick when moving through lava
break;
}
case E_BLOCK_WATER:
case E_BLOCK_STATIONARY_WATER:
{
m_Projectile->StopBurning();
- m_SlowdownCoeff = std::min(m_SlowdownCoeff, 0.8); // Slow down to 0.8* the speed each tick when moving through water
+ m_SlowdownCoeff =
+ std::min(m_SlowdownCoeff, 0.8); // Slow down to 0.8* the speed each tick when moving through water
break;
}
} // switch (a_BlockType)
@@ -111,7 +117,7 @@ protected:
// Continue tracing
return false;
}
-} ;
+};
@@ -122,21 +128,20 @@ protected:
class cProjectileEntityCollisionCallback
{
-public:
- cProjectileEntityCollisionCallback(cProjectileEntity * a_Projectile, const Vector3d & a_Pos, const Vector3d & a_NextPos) :
- m_Projectile(a_Projectile),
- m_Pos(a_Pos),
- m_NextPos(a_NextPos),
- m_MinCoeff(1),
- m_HitEntity(nullptr)
+ public:
+ cProjectileEntityCollisionCallback(
+ cProjectileEntity * a_Projectile,
+ const Vector3d & a_Pos,
+ const Vector3d & a_NextPos
+ ) :
+ m_Projectile(a_Projectile), m_Pos(a_Pos), m_NextPos(a_NextPos), m_MinCoeff(1), m_HitEntity(nullptr)
{
}
- bool operator () (cEntity & a_Entity)
+ bool operator()(cEntity & a_Entity)
{
- if (
- (&a_Entity == m_Projectile) || // Do not check collisions with self
+ if ((&a_Entity == m_Projectile) || // Do not check collisions with self
(a_Entity.GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile
)
{
@@ -149,8 +154,8 @@ public:
auto EntBox = a_Entity.GetBoundingBox();
- // Instead of colliding the bounding box with another bounding box in motion, we collide an enlarged bounding box with a hairline.
- // The results should be good enough for our purposes
+ // Instead of colliding the bounding box with another bounding box in motion, we collide an enlarged bounding
+ // box with a hairline. The results should be good enough for our purposes
double LineCoeff;
eBlockFace Face;
EntBox.Expand(m_Projectile->GetWidth() / 2, m_Projectile->GetHeight() / 2, m_Projectile->GetWidth() / 2);
@@ -160,16 +165,9 @@ public:
return false;
}
- if (
- !a_Entity.IsMob() &&
- !a_Entity.IsMinecart() &&
- (
- !a_Entity.IsPlayer() ||
- static_cast<cPlayer &>(a_Entity).IsGameModeSpectator()
- ) &&
- !a_Entity.IsBoat() &&
- !a_Entity.IsEnderCrystal()
- )
+ if (!a_Entity.IsMob() && !a_Entity.IsMinecart() &&
+ (!a_Entity.IsPlayer() || static_cast<cPlayer &>(a_Entity).IsGameModeSpectator()) && !a_Entity.IsBoat() &&
+ !a_Entity.IsEnderCrystal())
{
// Not an entity that interacts with a projectile
return false;
@@ -201,16 +199,17 @@ public:
/** Returns true if the callback has encountered a true hit */
bool HasHit(void) const { return (m_MinCoeff < 1); }
-protected:
+ protected:
cProjectileEntity * m_Projectile;
const Vector3d & m_Pos;
const Vector3d & m_NextPos;
double m_MinCoeff; // The coefficient of the nearest hit on the Pos line
// Although it's bad(tm) to store entity ptrs from a callback, we can afford it here, because the entire callback
- // is processed inside the tick thread, so the entities won't be removed in between the calls and the final processing
+ // is processed inside the tick thread, so the entities won't be removed in between the calls and the final
+ // processing
cEntity * m_HitEntity; // The nearest hit entity
-} ;
+};
@@ -219,7 +218,7 @@ protected:
////////////////////////////////////////////////////////////////////////////////
// cProjectileEntity:
-cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, float a_Width, float a_Height):
+cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, float a_Width, float a_Height) :
Super(etProjectile, a_Pos, a_Width, a_Height),
m_ProjectileKind(a_Kind),
m_CreatorData(
@@ -237,7 +236,14 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d
-cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, float a_Width, float a_Height):
+cProjectileEntity::cProjectileEntity(
+ eKind a_Kind,
+ cEntity * a_Creator,
+ Vector3d a_Pos,
+ Vector3d a_Speed,
+ float a_Width,
+ float a_Height
+) :
cProjectileEntity(a_Kind, a_Creator, a_Pos, a_Width, a_Height)
{
SetSpeed(a_Speed);
@@ -265,15 +271,15 @@ std::unique_ptr<cProjectileEntity> cProjectileEntity::Create(
switch (a_Kind)
{
- case pkArrow: return std::make_unique<cArrowEntity> (a_Creator, a_Pos, Speed);
- case pkEgg: return std::make_unique<cThrownEggEntity> (a_Creator, a_Pos, Speed);
+ case pkArrow: return std::make_unique<cArrowEntity>(a_Creator, a_Pos, Speed);
+ case pkEgg: return std::make_unique<cThrownEggEntity>(a_Creator, a_Pos, Speed);
case pkEnderPearl: return std::make_unique<cThrownEnderPearlEntity>(a_Creator, a_Pos, Speed);
- case pkSnowball: return std::make_unique<cThrownSnowballEntity> (a_Creator, a_Pos, Speed);
- case pkGhastFireball: return std::make_unique<cGhastFireballEntity> (a_Creator, a_Pos, Speed);
- case pkFireCharge: return std::make_unique<cFireChargeEntity> (a_Creator, a_Pos, Speed);
- case pkExpBottle: return std::make_unique<cExpBottleEntity> (a_Creator, a_Pos, Speed);
- case pkSplashPotion: return std::make_unique<cSplashPotionEntity> (a_Creator, a_Pos, Speed, *a_Item);
- case pkWitherSkull: return std::make_unique<cWitherSkullEntity> (a_Creator, a_Pos, Speed);
+ case pkSnowball: return std::make_unique<cThrownSnowballEntity>(a_Creator, a_Pos, Speed);
+ case pkGhastFireball: return std::make_unique<cGhastFireballEntity>(a_Creator, a_Pos, Speed);
+ case pkFireCharge: return std::make_unique<cFireChargeEntity>(a_Creator, a_Pos, Speed);
+ case pkExpBottle: return std::make_unique<cExpBottleEntity>(a_Creator, a_Pos, Speed);
+ case pkSplashPotion: return std::make_unique<cSplashPotionEntity>(a_Creator, a_Pos, Speed, *a_Item);
+ case pkWitherSkull: return std::make_unique<cWitherSkullEntity>(a_Creator, a_Pos, Speed);
case pkFirework:
{
ASSERT(a_Item != nullptr);
@@ -301,9 +307,7 @@ void cProjectileEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace)
SetSpeed(0, 0, 0);
// DEBUG:
- FLOGD("Projectile {0}: pos {1:.02f}, hit solid block at face {2}",
- m_UniqueID, a_HitPos, a_HitFace
- );
+ FLOGD("Projectile {0}: pos {1:.02f}, hit solid block at face {2}", m_UniqueID, a_HitPos, a_HitFace);
m_IsInGround = true;
}
@@ -320,9 +324,11 @@ void cProjectileEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
if (a_EntityHit.IsPawn() && (GetCreatorName() != ""))
{
auto EntityHit = static_cast<cPawn *>(&a_EntityHit);
- m_World->DoWithEntityByID(GetCreatorUniqueID(), [=](cEntity & a_Hitter)
+ m_World->DoWithEntityByID(
+ GetCreatorUniqueID(),
+ [=](cEntity & a_Hitter)
{
- static_cast<cPlayer&>(a_Hitter).NotifyNearbyWolves(EntityHit, true);
+ static_cast<cPlayer &>(a_Hitter).NotifyNearbyWolves(EntityHit, true);
return true;
}
);
@@ -393,7 +399,8 @@ void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a
Vector3d HitPos = Pos + (NextPos - Pos) * EntityCollisionCallback.GetMinCoeff();
// DEBUG:
- FLOGD("Projectile {0} has hit an entity {1} ({2}) at {3:.02f} (coeff {4:.03f})",
+ FLOGD(
+ "Projectile {0} has hit an entity {1} ({2}) at {3:.02f} (coeff {4:.03f})",
m_UniqueID,
EntityCollisionCallback.GetHitEntity()->GetUniqueID(),
EntityCollisionCallback.GetHitEntity()->GetClass(),
@@ -416,7 +423,8 @@ void cProjectileEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a
// Something has been hit, abort all other processing
return;
}
- // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its SlowdownCoeff
+ // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its
+ // SlowdownCoeff
// Update the position:
SetPosition(NextPos);
@@ -455,4 +463,3 @@ void cProjectileEntity::CollectedBy(cPlayer & a_Dest)
// Overriden in arrow
UNUSED(a_Dest);
}
-
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h
index 1c8c00854..d86589490 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -17,8 +17,7 @@
// tolua_begin
-class cProjectileEntity :
- public cEntity
+class cProjectileEntity : public cEntity
{
// tolua_end
@@ -27,8 +26,7 @@ class cProjectileEntity :
// tolua_begin
-public:
-
+ public:
/** The kind of the projectile. */
enum eKind
{
@@ -42,14 +40,21 @@ public:
pkSplashPotion,
pkFirework,
pkWitherSkull,
- } ;
+ };
// tolua_end
CLASS_PROTODEF(cProjectileEntity)
cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, float a_Width, float a_Height);
- cProjectileEntity(eKind a_Kind, cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, float a_Width, float a_Height);
+ cProjectileEntity(
+ eKind a_Kind,
+ cEntity * a_Creator,
+ Vector3d a_Pos,
+ Vector3d a_Speed,
+ float a_Width,
+ float a_Height
+ );
/** Creates a new instance of the specified projectile entity.
a_Item is the item from which the projectile originated (such as firework or arrow). */
@@ -67,7 +72,9 @@ public:
static std::unique_ptr<cProjectileEntity> Create(
eKind a_Kind,
cEntity * a_Creator,
- double a_PosX, double a_PosY, double a_PosZ,
+ double a_PosX,
+ double a_PosY,
+ double a_PosZ,
const cItem * a_Item,
const Vector3d * a_Speed = nullptr
)
@@ -75,7 +82,8 @@ public:
return Create(a_Kind, a_Creator, {a_PosX, a_PosY, a_PosZ}, a_Item, a_Speed);
}
- /** Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit (BLOCK_FACE_) is given */
+ /** Called by the physics blocktracer when the entity hits a solid block, the hit position and the face hit
+ * (BLOCK_FACE_) is given */
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace);
/** Called by the physics blocktracer when the entity hits another entity */
@@ -110,16 +118,13 @@ public:
/** Sets the internal InGround flag. To be used by MCA loader only! */
void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
-protected:
-
+ protected:
/** A structure that stores the Entity ID and Playername of the projectile's creator
Used to migitate invalid pointers caused by the creator being destroyed. */
struct CreatorData
{
CreatorData(UInt32 a_UniqueID, const AString & a_Name, const cEnchantments & a_Enchantments) :
- m_UniqueID(a_UniqueID),
- m_Name(a_Name),
- m_Enchantments(a_Enchantments)
+ m_UniqueID(a_UniqueID), m_Name(a_Name), m_Enchantments(a_Enchantments)
{
}
@@ -143,4 +148,4 @@ protected:
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
virtual void SpawnOn(cClientHandle & a_Client) final override;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/SplashPotionEntity.cpp b/src/Entities/SplashPotionEntity.cpp
index dece6a1ea..935f93716 100644
--- a/src/Entities/SplashPotionEntity.cpp
+++ b/src/Entities/SplashPotionEntity.cpp
@@ -11,14 +11,8 @@
////////////////////////////////////////////////////////////////////////////////
// cSplashPotionEntity:
-cSplashPotionEntity::cSplashPotionEntity(
- cEntity * a_Creator,
- Vector3d a_Pos,
- Vector3d a_Speed,
- const cItem & a_Item
-):
- Super(pkSplashPotion, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f),
- m_Item(a_Item)
+cSplashPotionEntity::cSplashPotionEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, const cItem & a_Item) :
+ Super(pkSplashPotion, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f), m_Item(a_Item)
{
m_EntityEffectType = cEntityEffect::GetPotionEffectType(a_Item.m_ItemDamage);
m_EntityEffect = cEntityEffect(
@@ -35,27 +29,32 @@ cSplashPotionEntity::cSplashPotionEntity(
void cSplashPotionEntity::Splash(Vector3d a_HitPos)
{
// Look for entities in 8.25 (width) x 4.25 (height) cuboid _centred_ on hit position:
- m_World->ForEachEntityInBox({ a_HitPos.addedY(-4.25 / 2), 8.25 / 2, 4.25 }, [this, a_HitPos](cEntity & a_Entity)
- {
- if (!a_Entity.IsPawn())
+ m_World->ForEachEntityInBox(
+ {a_HitPos.addedY(-4.25 / 2), 8.25 / 2, 4.25},
+ [this, a_HitPos](cEntity & a_Entity)
{
- // Not an entity that can take effects
+ if (!a_Entity.IsPawn())
+ {
+ // Not an entity that can take effects
+ return false;
+ }
+
+ double SplashDistance = (a_Entity.GetPosition() - a_HitPos).Length();
+ double Reduction = -0.25 * SplashDistance +
+ 1.0; // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
+ Reduction = std::max(Reduction, 0.0);
+
+ static_cast<cPawn &>(a_Entity).AddEntityEffect(
+ m_EntityEffectType,
+ m_EntityEffect.GetDuration(),
+ m_EntityEffect.GetIntensity(),
+ Reduction
+ );
return false;
}
-
- double SplashDistance = (a_Entity.GetPosition() - a_HitPos).Length();
- double Reduction = -0.25 * SplashDistance + 1.0; // y = -0.25x + 1, where x is the distance from the player. Approximation for potion splash.
- Reduction = std::max(Reduction, 0.0);
-
- static_cast<cPawn &>(a_Entity).AddEntityEffect(m_EntityEffectType, m_EntityEffect.GetDuration(), m_EntityEffect.GetIntensity(), Reduction);
- return false;
- });
-
- m_World->BroadcastSoundParticleEffect(
- EffectID::PARTICLE_SPLASH_POTION,
- a_HitPos.Floor(),
- m_PotionColor
);
+
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SPLASH_POTION, a_HitPos.Floor(), m_PotionColor);
}
diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h
index 30ca8997d..02a570bc9 100644
--- a/src/Entities/SplashPotionEntity.h
+++ b/src/Entities/SplashPotionEntity.h
@@ -21,39 +21,31 @@ class cEntity;
// tolua_begin
-class cSplashPotionEntity :
- public cProjectileEntity
+class cSplashPotionEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cSplashPotionEntity)
- cSplashPotionEntity(
- cEntity * a_Creator,
- Vector3d a_Pos,
- Vector3d a_Speed,
- const cItem & a_Item
- );
+ cSplashPotionEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed, const cItem & a_Item);
// tolua_begin
cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; }
- int GetPotionColor(void) const { return m_PotionColor; }
- const cItem & GetItem(void) const { return m_Item; }
+ int GetPotionColor(void) const { return m_PotionColor; }
+ const cItem & GetItem(void) const { return m_Item; }
void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; }
void SetPotionColor(int a_PotionColor) { m_PotionColor = a_PotionColor; }
// tolua_end
- cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
+ cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
-private:
-
+ private:
cEntityEffect::eType m_EntityEffectType;
cEntityEffect m_EntityEffect;
int m_PotionColor;
@@ -66,4 +58,4 @@ private:
// cProjectileEntity overrides:
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/TNTEntity.cpp b/src/Entities/TNTEntity.cpp
index 0d7340513..a56729e06 100644
--- a/src/Entities/TNTEntity.cpp
+++ b/src/Entities/TNTEntity.cpp
@@ -9,8 +9,7 @@
cTNTEntity::cTNTEntity(Vector3d a_Pos, unsigned a_FuseTicks) :
- Super(etTNT, a_Pos, 0.98f, 0.98f),
- m_FuseTicks(a_FuseTicks)
+ Super(etTNT, a_Pos, 0.98f, 0.98f), m_FuseTicks(a_FuseTicks)
{
SetGravity(-16.0f);
SetAirDrag(0.02f);
@@ -68,7 +67,3 @@ void cTNTEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
Explode();
}
}
-
-
-
-
diff --git a/src/Entities/TNTEntity.h b/src/Entities/TNTEntity.h
index d181eee22..4ed20399e 100644
--- a/src/Entities/TNTEntity.h
+++ b/src/Entities/TNTEntity.h
@@ -7,16 +7,14 @@
// tolua_begin
-class cTNTEntity:
- public cEntity
+class cTNTEntity : public cEntity
{
// tolua_end
using Super = cEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cTNTEntity)
cTNTEntity(Vector3d a_Pos, unsigned a_FuseTicks = 80);
@@ -38,6 +36,6 @@ public: // tolua_export
// tolua_end
-protected:
- unsigned m_FuseTicks; ///< How much ticks is left, while the tnt will explode
+ protected:
+ unsigned m_FuseTicks; ///< How much ticks is left, while the tnt will explode
}; // tolua_export
diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp
index 44cfda937..5654a43e0 100644
--- a/src/Entities/ThrownEggEntity.cpp
+++ b/src/Entities/ThrownEggEntity.cpp
@@ -7,7 +7,7 @@
-cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cThrownEggEntity::cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkEgg, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
{
}
diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h
index f20705b81..5c5252f26 100644
--- a/src/Entities/ThrownEggEntity.h
+++ b/src/Entities/ThrownEggEntity.h
@@ -17,21 +17,18 @@
// tolua_begin
-class cThrownEggEntity :
- public cProjectileEntity
+class cThrownEggEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cThrownEggEntity)
cThrownEggEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-private:
-
+ private:
/** Randomly decides whether to spawn a chicken where the egg lands. */
void TrySpawnChicken(Vector3d a_HitPos);
@@ -39,4 +36,4 @@ private:
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp
index 6fc21e179..8b41a7e92 100644
--- a/src/Entities/ThrownEnderPearlEntity.cpp
+++ b/src/Entities/ThrownEnderPearlEntity.cpp
@@ -10,7 +10,7 @@
-cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cThrownEnderPearlEntity::cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkEnderPearl, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
{
}
@@ -60,23 +60,25 @@ void cThrownEnderPearlEntity::TeleportCreator(Vector3d a_HitPos)
- GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, [=](cPlayer & a_Entity)
- {
-
- auto & Random = GetRandomProvider();
-
- // 5% chance to spawn an endermite
- if (Random.RandBool(0.05))
+ GetWorld()->FindAndDoWithPlayer(
+ m_CreatorData.m_Name,
+ [=](cPlayer & a_Entity)
{
- Vector3d PlayerPosition = a_Entity.GetPosition();
- m_World->SpawnMob(PlayerPosition.x, PlayerPosition.y, PlayerPosition.z, mtEndermite);
- }
+ auto & Random = GetRandomProvider();
+
+ // 5% chance to spawn an endermite
+ if (Random.RandBool(0.05))
+ {
+ Vector3d PlayerPosition = a_Entity.GetPosition();
+ m_World->SpawnMob(PlayerPosition.x, PlayerPosition.y, PlayerPosition.z, mtEndermite);
+ }
- // Teleport the creator here, make them take 5 damage:
- a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
- a_Entity.TakeDamage(dtEnderPearl, this, 5, 0);
+ // Teleport the creator here, make them take 5 damage:
+ a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z);
+ a_Entity.TakeDamage(dtEnderPearl, this, 5, 0);
- return false;
- });
+ return false;
+ }
+ );
}
diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h
index f503c5398..9e75d7283 100644
--- a/src/Entities/ThrownEnderPearlEntity.h
+++ b/src/Entities/ThrownEnderPearlEntity.h
@@ -17,21 +17,18 @@
// tolua_begin
-class cThrownEnderPearlEntity :
- public cProjectileEntity
+class cThrownEnderPearlEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cThrownEnderPearlEntity)
cThrownEnderPearlEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-private:
-
+ private:
/** Teleports the creator where the ender pearl lands */
void TeleportCreator(Vector3d a_HitPos);
@@ -39,4 +36,4 @@ private:
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp
index ab8a5f012..84f6adf62 100644
--- a/src/Entities/ThrownSnowballEntity.cpp
+++ b/src/Entities/ThrownSnowballEntity.cpp
@@ -7,7 +7,7 @@
-cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkSnowball, a_Creator, a_Pos, a_Speed, 0.25f, 0.25f)
{
}
diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h
index 84dc394dd..0e62b7627 100644
--- a/src/Entities/ThrownSnowballEntity.h
+++ b/src/Entities/ThrownSnowballEntity.h
@@ -17,23 +17,20 @@
// tolua_begin
-class cThrownSnowballEntity :
- public cProjectileEntity
+class cThrownSnowballEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cThrownSnowballEntity)
cThrownSnowballEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-private:
-
+ private:
// cProjectileEntity overrides:
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
-} ; // tolua_export
+}; // tolua_export
diff --git a/src/Entities/WitherSkullEntity.cpp b/src/Entities/WitherSkullEntity.cpp
index 22e474395..5b9e35ac3 100644
--- a/src/Entities/WitherSkullEntity.cpp
+++ b/src/Entities/WitherSkullEntity.cpp
@@ -1,5 +1,5 @@
-// WitherSkullEntity.cpp
+// WitherSkullEntity.cpp
// Implements the cWitherSkullEntity class representing the entity used by both blue and black wither skulls
@@ -12,7 +12,7 @@
-cWitherSkullEntity::cWitherSkullEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed):
+cWitherSkullEntity::cWitherSkullEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed) :
Super(pkWitherSkull, a_Creator, a_Pos, 0.3125f, 0.3125f)
{
SetSpeed(a_Speed);
@@ -45,7 +45,3 @@ void cWitherSkullEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos)
Destroy();
}
-
-
-
-
diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h
index f335b1da7..a37e7b5a4 100644
--- a/src/Entities/WitherSkullEntity.h
+++ b/src/Entities/WitherSkullEntity.h
@@ -17,27 +17,20 @@
// tolua_begin
-class cWitherSkullEntity :
-public cProjectileEntity
+class cWitherSkullEntity : public cProjectileEntity
{
// tolua_end
using Super = cProjectileEntity;
-public: // tolua_export
-
+ public: // tolua_export
CLASS_PROTODEF(cWitherSkullEntity)
cWitherSkullEntity(cEntity * a_Creator, Vector3d a_Pos, Vector3d a_Speed);
-protected:
-
+ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) override;
-} ; // tolua_export
-
-
-
-
+}; // tolua_export