summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-11-18 14:56:32 +0100
committerHowaner <franzi.moos@googlemail.com>2014-11-18 14:56:32 +0100
commit42120e2ea5db0cdb9920ff1c5efef33e0f496d48 (patch)
tree20ba1ae0a53f757cb8814b6cd6a466fe5acf1308 /src/Entities
parentFixed compile errors. (diff)
parentMerge pull request #1598 from mc-server/SignEditor (diff)
downloadcuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.gz
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.bz2
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.lz
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.xz
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.zst
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/ArrowEntity.cpp16
-rw-r--r--src/Entities/ArrowEntity.h47
-rw-r--r--src/Entities/Boat.cpp4
-rw-r--r--src/Entities/Entity.cpp56
-rw-r--r--src/Entities/Entity.h30
-rw-r--r--src/Entities/EntityEffect.cpp10
-rw-r--r--src/Entities/ExpBottleEntity.h17
-rw-r--r--src/Entities/ExpOrb.cpp2
-rw-r--r--src/Entities/FireChargeEntity.h15
-rw-r--r--src/Entities/FireworkEntity.cpp13
-rw-r--r--src/Entities/FireworkEntity.h32
-rw-r--r--src/Entities/Floater.cpp2
-rw-r--r--src/Entities/GhastFireballEntity.h15
-rw-r--r--src/Entities/HangingEntity.cpp30
-rw-r--r--src/Entities/HangingEntity.h29
-rw-r--r--src/Entities/ItemFrame.cpp20
-rw-r--r--src/Entities/ItemFrame.h17
-rw-r--r--src/Entities/Minecart.cpp52
-rw-r--r--src/Entities/Minecart.h41
-rw-r--r--src/Entities/Painting.cpp2
-rw-r--r--src/Entities/Painting.h13
-rw-r--r--src/Entities/Pickup.cpp16
-rw-r--r--src/Entities/Pickup.h12
-rw-r--r--src/Entities/Player.cpp83
-rw-r--r--src/Entities/Player.h12
-rw-r--r--src/Entities/ProjectileEntity.cpp22
-rw-r--r--src/Entities/ProjectileEntity.h26
-rw-r--r--src/Entities/SplashPotionEntity.h18
-rw-r--r--src/Entities/ThrownEggEntity.cpp21
-rw-r--r--src/Entities/ThrownEggEntity.h34
-rw-r--r--src/Entities/ThrownEnderPearlEntity.cpp22
-rw-r--r--src/Entities/ThrownEnderPearlEntity.h34
-rw-r--r--src/Entities/ThrownSnowballEntity.cpp25
-rw-r--r--src/Entities/ThrownSnowballEntity.h34
-rw-r--r--src/Entities/WitherSkullEntity.h12
35 files changed, 524 insertions, 310 deletions
diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp
index c265c5043..30f18f677 100644
--- a/src/Entities/ArrowEntity.cpp
+++ b/src/Entities/ArrowEntity.cpp
@@ -149,14 +149,14 @@ void cArrowEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
-void cArrowEntity::CollectedBy(cPlayer * a_Dest)
+void cArrowEntity::CollectedBy(cPlayer & a_Dest)
{
- if (m_IsInGround && !m_bIsCollected && CanPickup(*a_Dest))
+ if (m_IsInGround && !m_bIsCollected && CanPickup(a_Dest))
{
// Do not add the arrow to the inventory when the player is in creative:
- if (!a_Dest->IsGameModeCreative())
+ if (!a_Dest.IsGameModeCreative())
{
- int NumAdded = a_Dest->GetInventory().AddItem(E_ITEM_ARROW);
+ int NumAdded = a_Dest.GetInventory().AddItem(E_ITEM_ARROW);
if (NumAdded == 0)
{
// No space in the inventory
@@ -164,7 +164,7 @@ void cArrowEntity::CollectedBy(cPlayer * a_Dest)
}
}
- GetWorld()->BroadcastCollectEntity(*this, *a_Dest);
+ GetWorld()->BroadcastCollectEntity(*this, a_Dest);
GetWorld()->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
m_bIsCollected = true;
}
@@ -217,7 +217,7 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk)
int RelPosZ = m_HitBlockPos.z - a_Chunk.GetPosZ() * cChunkDef::Width;
cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ);
- if (Chunk == NULL)
+ if (Chunk == nullptr)
{
// Inside an unloaded chunk, abort
return;
@@ -229,3 +229,7 @@ void cArrowEntity::Tick(float a_Dt, cChunk & a_Chunk)
}
}
}
+
+
+
+
diff --git a/src/Entities/ArrowEntity.h b/src/Entities/ArrowEntity.h
index a1e7a17e7..436ec0293 100644
--- a/src/Entities/ArrowEntity.h
+++ b/src/Entities/ArrowEntity.h
@@ -1,6 +1,11 @@
-//
-// ArrowEntity.h
-//
+
+// ArrowEntity.h
+
+// Declares the cArrowEntity representing the arrow that has been shot by the player or by a skeleton
+
+
+
+
#pragma once
@@ -19,7 +24,7 @@ class cArrowEntity :
typedef cProjectileEntity super;
public:
- /// Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field
+ /** Determines when the arrow can be picked up (depending on player gamemode). Corresponds to the MCA file "pickup" field */
enum ePickupState
{
psNoPickup = 0,
@@ -31,33 +36,33 @@ public:
CLASS_PROTODEF(cArrowEntity)
- /// Creates a new arrow with psNoPickup state and default damage modifier coeff
+ /** Creates a new arrow with psNoPickup state and default damage modifier coeff */
cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed);
- /// Creates a new arrow as shot by a player, initializes it from the player object
+ /** Creates a new arrow as shot by a player, initializes it from the player object */
cArrowEntity(cPlayer & a_Player, double a_Force);
// tolua_begin
- /// Returns whether the arrow can be picked up by players
+ /** Returns whether the arrow can be picked up by players */
ePickupState GetPickupState(void) const { return m_PickupState; }
- /// Sets a new pickup state
+ /** Sets a new pickup state */
void SetPickupState(ePickupState a_PickupState) { m_PickupState = a_PickupState; }
- /// Returns the damage modifier coeff.
+ /** Returns the damage modifier coeff. */
double GetDamageCoeff(void) const { return m_DamageCoeff; }
- /// Sets the damage modifier coeff
+ /** Sets the damage modifier coeff */
void SetDamageCoeff(double a_DamageCoeff) { m_DamageCoeff = a_DamageCoeff; }
- /// Returns true if the specified player can pick the arrow up
+ /** Returns true if the specified player can pick the arrow up */
bool CanPickup(const cPlayer & a_Player) const;
- /// Returns true if the arrow is set as critical
+ /** Returns true if the arrow is set as critical */
bool IsCritical(void) const { return m_IsCritical; }
- /// Sets the IsCritical flag
+ /** Sets the IsCritical flag */
void SetIsCritical(bool a_IsCritical) { m_IsCritical = a_IsCritical; }
/** Gets the block arrow is in */
@@ -70,34 +75,34 @@ public:
protected:
- /// Determines when the arrow can be picked up by players
+ /** 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
+ /** If true, the arrow deals more damage */
bool m_IsCritical;
- /// Timer for pickup collection animation or five minute timeout
+ /** Timer for pickup collection animation or five minute timeout */
float m_Timer;
- /// Timer for client arrow position confirmation via TeleportEntity
+ /** Timer for client arrow position confirmation via TeleportEntity */
float m_HitGroundTimer;
// Whether the arrow has already been teleported into the proper position in the ground.
bool m_HasTeleported;
- /// If true, the arrow is in the process of being collected - don't go to anyone else
+ /** If true, the arrow is in the process of being collected - don't go to anyone else */
bool m_bIsCollected;
- /// Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air
+ /** Stores the block position that arrow is lodged into, sets m_IsInGround to false if it becomes air */
Vector3i m_HitBlockPos;
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
- virtual void CollectedBy(cPlayer * a_Player) override;
+ virtual void CollectedBy(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
}; // tolua_export
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index 328a70846..953213bca 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -42,7 +42,7 @@ bool cBoat::DoTakeDamage(TakeDamageInfo & TDI)
if (GetHealth() == 0)
{
- if (TDI.Attacker != NULL)
+ if (TDI.Attacker != nullptr)
{
if (TDI.Attacker->IsPlayer())
{
@@ -64,7 +64,7 @@ void cBoat::OnRightClicked(cPlayer & a_Player)
{
super::OnRightClicked(a_Player);
- if (m_Attachee != NULL)
+ if (m_Attachee != nullptr)
{
if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
{
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index da85dec50..afc61c73f 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -29,8 +29,8 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d
: m_UniqueID(0)
, m_Health(1)
, m_MaxHealth(1)
- , m_AttachedTo(NULL)
- , m_Attachee(NULL)
+ , m_AttachedTo(nullptr)
+ , m_Attachee(nullptr)
, m_bDirtyHead(true)
, m_bDirtyOrientation(true)
, m_bHasSentNoSpeed(true)
@@ -38,9 +38,9 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d
, m_Gravity(-9.81f)
, m_LastPos(a_X, a_Y, a_Z)
, m_IsInitialized(false)
- , m_WorldTravellingFrom(NULL)
+ , m_WorldTravellingFrom(nullptr)
, m_EntityType(a_EntityType)
- , m_World(NULL)
+ , m_World(nullptr)
, m_IsFireproof(false)
, m_TicksSinceLastBurnDamage(0)
, m_TicksSinceLastLavaDamage(0)
@@ -73,7 +73,7 @@ cEntity::cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, d
cEntity::~cEntity()
{
// Before deleting, the entity needs to have been removed from the world, if ever added
- ASSERT((m_World == NULL) || !m_World->HasEntity(m_UniqueID));
+ ASSERT((m_World == nullptr) || !m_World->HasEntity(m_UniqueID));
/*
// DEBUG:
@@ -85,11 +85,11 @@ cEntity::~cEntity()
);
*/
- if (m_AttachedTo != NULL)
+ if (m_AttachedTo != nullptr)
{
Detach();
}
- if (m_Attachee != NULL)
+ if (m_Attachee != nullptr)
{
m_Attachee->Detach();
}
@@ -242,7 +242,7 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R
TDI.FinalDamage = a_FinalDamage;
Vector3d Heading(0, 0, 0);
- if (a_Attacker != NULL)
+ if (a_Attacker != nullptr)
{
Heading = a_Attacker->GetLookVector() * (a_Attacker->IsSprinting() ? 16 : 11);
Heading.y = 1.6;
@@ -265,7 +265,7 @@ void cEntity::SetYawFromSpeed(void)
SetYaw(0);
return;
}
- SetYaw(atan2(m_Speed.x, m_Speed.z) * 180 / PI);
+ SetYaw(atan2(m_Speed.x, m_Speed.z) * 180 / M_PI);
}
@@ -282,7 +282,7 @@ void cEntity::SetPitchFromSpeed(void)
SetPitch(0);
return;
}
- SetPitch(atan2(m_Speed.y, xz) * 180 / PI);
+ SetPitch(atan2(m_Speed.y, xz) * 180 / M_PI);
}
@@ -308,7 +308,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
return false;
}
- if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer()))
+ if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer()))
{
cPlayer * Player = (cPlayer *)a_TDI.Attacker;
@@ -544,7 +544,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
m_Health = std::max(m_Health, 0);
// Add knockback:
- if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != NULL))
+ if ((IsMob() || IsPlayer()) && (a_TDI.Attacker != nullptr))
{
int KnockbackLevel = a_TDI.Attacker->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchKnockback); // More common enchantment
if (KnockbackLevel < 1)
@@ -571,7 +571,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
{
KilledBy(a_TDI);
- if (a_TDI.Attacker != NULL)
+ if (a_TDI.Attacker != nullptr)
{
a_TDI.Attacker->Killed(this);
}
@@ -778,7 +778,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
m_InvulnerableTicks--;
}
- if (m_AttachedTo != NULL)
+ if (m_AttachedTo != nullptr)
{
Vector3d DeltaPos = m_Pos - m_AttachedTo->GetPosition();
if (DeltaPos.Length() > 0.5)
@@ -1092,7 +1092,7 @@ void cEntity::TickBurning(cChunk & a_Chunk)
{
if (!m_IsFireproof)
{
- TakeDamage(dtOnFire, NULL, BURN_DAMAGE, 0);
+ TakeDamage(dtOnFire, nullptr, BURN_DAMAGE, 0);
}
m_TicksSinceLastBurnDamage = 0;
}
@@ -1163,7 +1163,7 @@ void cEntity::TickBurning(cChunk & a_Chunk)
{
if (!m_IsFireproof)
{
- TakeDamage(dtLavaContact, NULL, LAVA_DAMAGE, 0);
+ TakeDamage(dtLavaContact, nullptr, LAVA_DAMAGE, 0);
}
m_TicksSinceLastLavaDamage = 0;
}
@@ -1184,7 +1184,7 @@ void cEntity::TickBurning(cChunk & a_Chunk)
{
if (!m_IsFireproof)
{
- TakeDamage(dtFireContact, NULL, FIRE_DAMAGE, 0);
+ TakeDamage(dtFireContact, nullptr, FIRE_DAMAGE, 0);
}
m_TicksSinceLastFireDamage = 0;
}
@@ -1213,7 +1213,7 @@ void cEntity::TickInVoid(cChunk & a_Chunk)
{
if (m_TicksSinceLastVoidDamage == 20)
{
- TakeDamage(dtInVoid, NULL, 2, 0);
+ TakeDamage(dtInVoid, nullptr, 2, 0);
m_TicksSinceLastVoidDamage = 0;
}
else
@@ -1239,7 +1239,7 @@ void cEntity::DetectCacti(void)
(((GetPosY() - Y < 1) && (GetWorld()->GetBlock(X, Y, Z) == E_BLOCK_CACTUS))))
)
{
- TakeDamage(dtCactusContact, NULL, 1, 0);
+ TakeDamage(dtCactusContact, nullptr, 1, 0);
}
}
@@ -1380,7 +1380,7 @@ bool cEntity::DetectPortal()
bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
{
UNUSED(a_ShouldSendRespawn);
- ASSERT(a_World != NULL);
+ ASSERT(a_World != nullptr);
if (GetWorld() == a_World)
{
@@ -1406,7 +1406,7 @@ bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
{
cWorld * World = cRoot::Get()->GetWorld(a_WorldName);
- if (World == NULL)
+ if (World == nullptr)
{
LOG("%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName.c_str());
return false;
@@ -1493,7 +1493,7 @@ void cEntity::HandleAir(void)
if (m_AirTickTimer <= 0)
{
// Damage player
- TakeDamage(dtDrowning, NULL, 1, 1, 0);
+ TakeDamage(dtDrowning, nullptr, 1, 1, 0);
// Reset timer
m_AirTickTimer = DROWNING_TICKS;
}
@@ -1708,7 +1708,7 @@ void cEntity::AttachTo(cEntity * a_AttachTo)
// Already attached to that entity, nothing to do here
return;
}
- if (m_AttachedTo != NULL)
+ if (m_AttachedTo != nullptr)
{
// Detach from any previous entity:
Detach();
@@ -1726,14 +1726,14 @@ void cEntity::AttachTo(cEntity * a_AttachTo)
void cEntity::Detach(void)
{
- if (m_AttachedTo == NULL)
+ if (m_AttachedTo == nullptr)
{
// Attached to no entity, our work is done
return;
}
- m_AttachedTo->m_Attachee = NULL;
- m_AttachedTo = NULL;
- m_World->BroadcastAttachEntity(*this, NULL);
+ m_AttachedTo->m_Attachee = nullptr;
+ m_AttachedTo = nullptr;
+ m_World->BroadcastAttachEntity(*this, nullptr);
}
@@ -1956,7 +1956,7 @@ void cEntity::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
void cEntity::SteerVehicle(float a_Forward, float a_Sideways)
{
- if (m_AttachedTo == NULL)
+ if (m_AttachedTo == nullptr)
{
return;
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 3fa7e80c1..af545fe4a 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -27,12 +27,12 @@
return super::GetClass(); \
}
-#define POSX_TOINT (int)floor(GetPosX())
-#define POSY_TOINT (int)floor(GetPosY())
-#define POSZ_TOINT (int)floor(GetPosZ())
+#define POSX_TOINT FloorC(GetPosX())
+#define POSY_TOINT FloorC(GetPosY())
+#define POSZ_TOINT FloorC(GetPosZ())
#define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT)
-#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; }
+#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) { return; }
@@ -172,13 +172,13 @@ public:
/// 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;
- /// Returns the topmost class name for the object
- virtual const char * GetClass(void) const;
-
- // Returns the class name of this class
+ /** Returns the class name of this class */
static const char * GetClassStatic(void);
- /// Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent).
+ /** Returns the topmost class name for the object */
+ virtual const char * GetClass(void) const;
+
+ /** Returns the topmost class's parent class name for the object. cEntity returns an empty string (no parent). */
virtual const char * GetParentClass(void) const;
cWorld * GetWorld(void) const { return m_World; }
@@ -309,7 +309,7 @@ public:
/// Returns the currently equipped boots; empty item if none
virtual cItem GetEquippedBoots(void) const { return cItem(); }
- /// Called when the health drops below zero. a_Killer may be NULL (environmental damage)
+ /// Called when the health drops below zero. a_Killer may be nullptr (environmental damage)
virtual void KilledBy(TakeDamageInfo & a_TDI);
/// Called when the entity kills another entity
@@ -401,7 +401,7 @@ public:
void SetWorldTravellingFrom(cWorld * a_World) { m_WorldTravellingFrom = a_World; }
/// Updates clients of changes in the entity.
- virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = NULL);
+ virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr);
/// Attaches to the specified entity; detaches from any previous one first
void AttachTo(cEntity * a_AttachTo);
@@ -450,7 +450,7 @@ public:
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().
- virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL)
+ virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr)
{
UNUSED(a_Drops);
UNUSED(a_Killer);
@@ -471,10 +471,10 @@ protected:
int m_Health;
int m_MaxHealth;
- /// The entity to which this entity is attached (vehicle), NULL if none
+ /// The entity to which this entity is attached (vehicle), nullptr if none
cEntity * m_AttachedTo;
- /// The entity which is attached to this entity (rider), NULL if none
+ /// The entity which is attached to this entity (rider), nullptr if none
cEntity * m_Attachee;
/** Stores whether head yaw has been set manually */
@@ -502,7 +502,7 @@ protected:
bool m_IsInitialized;
/** World entity is travelling from
- Set to a valid world pointer by MoveToWorld; reset to NULL when the entity is removed from the old world
+ Set to a valid world pointer by MoveToWorld; reset to nullptr when the entity is removed from the old world
Can't be a simple boolean as context switches between worlds may leave the new chunk processing (and therefore immediately removing) the entity before the old chunk could remove it
*/
cWorld * m_WorldTravellingFrom;
diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp
index b1ddaa30e..bae686b77 100644
--- a/src/Entities/EntityEffect.cpp
+++ b/src/Entities/EntityEffect.cpp
@@ -216,7 +216,7 @@ cEntityEffect * cEntityEffect::CreateEntityEffect(cEntityEffect::eType a_EffectT
}
ASSERT(!"Unhandled entity effect type!");
- return NULL;
+ return nullptr;
}
@@ -329,7 +329,7 @@ void cEntityEffectInstantHealth::OnActivate(cPawn & a_Target)
if (a_Target.IsMob() && ((cMonster &) a_Target).IsUndead())
{
- a_Target.TakeDamage(dtPotionOfHarming, NULL, 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);
@@ -352,7 +352,7 @@ void cEntityEffectInstantDamage::OnActivate(cPawn & a_Target)
a_Target.Heal(amount);
return;
}
- a_Target.TakeDamage(dtPotionOfHarming, NULL, 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
}
@@ -452,7 +452,7 @@ void cEntityEffectPoison::OnTick(cPawn & a_Target)
// Cannot take poison damage when health is at 1
if (a_Target.GetHealth() > 1)
{
- a_Target.TakeDamage(dtPoisoning, NULL, 1, 0);
+ a_Target.TakeDamage(dtPoisoning, nullptr, 1, 0);
}
}
}
@@ -473,7 +473,7 @@ void cEntityEffectWither::OnTick(cPawn & a_Target)
if ((m_Ticks % frequency) == 0)
{
- a_Target.TakeDamage(dtWither, NULL, 1, 0);
+ a_Target.TakeDamage(dtWither, nullptr, 1, 0);
}
}
diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h
index d36110f97..715b9947e 100644
--- a/src/Entities/ExpBottleEntity.h
+++ b/src/Entities/ExpBottleEntity.h
@@ -1,6 +1,11 @@
-//
-// ExpBottleEntity.h
-//
+
+// ExpBottleEntity.h
+
+// Declares the cExpBottleEntity class representing the thrown exp bottle
+
+
+
+
#pragma once
@@ -33,6 +38,10 @@ protected:
/** Breaks the bottle, fires its particle effects and sounds
@param a_HitPos The position where the bottle will break */
- void Break(const Vector3d &a_HitPos);
+ void Break(const Vector3d & a_HitPos);
}; // tolua_export
+
+
+
+
diff --git a/src/Entities/ExpOrb.cpp b/src/Entities/ExpOrb.cpp
index 73d5cbfed..751308661 100644
--- a/src/Entities/ExpOrb.cpp
+++ b/src/Entities/ExpOrb.cpp
@@ -45,7 +45,7 @@ void cExpOrb::SpawnOn(cClientHandle & a_Client)
void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
{
cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5));
- if (a_ClosestPlayer != NULL)
+ if (a_ClosestPlayer != nullptr)
{
Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
a_PlayerPos.y++;
diff --git a/src/Entities/FireChargeEntity.h b/src/Entities/FireChargeEntity.h
index 5df55bec4..eb08f5324 100644
--- a/src/Entities/FireChargeEntity.h
+++ b/src/Entities/FireChargeEntity.h
@@ -1,6 +1,11 @@
-//
-// FireChargeEntity.h
-//
+
+// FireChargeEntity.h
+
+// Declares the cFireChargeEntity representing the fire charge shot by the blaze
+
+
+
+
#pragma once
@@ -34,3 +39,7 @@ protected:
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
} ; // tolua_export
+
+
+
+
diff --git a/src/Entities/FireworkEntity.cpp b/src/Entities/FireworkEntity.cpp
index 403a53c84..68d02640a 100644
--- a/src/Entities/FireworkEntity.cpp
+++ b/src/Entities/FireworkEntity.cpp
@@ -10,7 +10,7 @@
cFireworkEntity::cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item) :
super(pkFirework, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25),
- m_ExplodeTimer(0),
+ m_TicksToExplosion(a_Item.m_FireworkItem.m_FlightTimeInTicks),
m_FireworkItem(a_Item)
{
}
@@ -27,7 +27,9 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
if ((PosY < 0) || (PosY >= cChunkDef::Height))
{
- goto setspeed;
+ AddSpeedY(1);
+ AddPosition(GetSpeed() * (a_Dt / 1000));
+ return;
}
if (m_IsInGround)
@@ -50,7 +52,6 @@ void cFireworkEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
}
}
-setspeed:
AddSpeedY(1);
AddPosition(GetSpeed() * (a_Dt / 1000));
}
@@ -63,11 +64,13 @@ void cFireworkEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
- if (m_ExplodeTimer == m_FireworkItem.m_FireworkItem.m_FlightTimeInTicks)
+ if (m_TicksToExplosion <= 0)
{
+ // TODO: Notify the plugins
m_World->BroadcastEntityStatus(*this, esFireworkExploding);
Destroy();
+ return;
}
- m_ExplodeTimer++;
+ m_TicksToExplosion -= 1;
}
diff --git a/src/Entities/FireworkEntity.h b/src/Entities/FireworkEntity.h
index 20f18b6dc..300ec571e 100644
--- a/src/Entities/FireworkEntity.h
+++ b/src/Entities/FireworkEntity.h
@@ -1,6 +1,11 @@
-//
-// FireworkEntity.h
-//
+
+// FireworkEntity.h
+
+// Declares the cFireworkEntity class representing the flying firework rocket
+
+
+
+
#pragma once
@@ -24,7 +29,22 @@ public:
CLASS_PROTODEF(cFireworkEntity)
cFireworkEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem & a_Item);
+
+ // tolua_begin
+
+ /** Returns the item used to create the rocket (has all the firework effects on it) */
const cItem & GetItem(void) const { return m_FireworkItem; }
+
+ /** Sets the item that is used to create the rocket (has all the firework effects on it) */
+ void SetItem(const cItem & a_Item) { m_FireworkItem = a_Item; }
+
+ /** Returns the number of ticks left until the firework explosion. */
+ int GetTicksToExplosion(void) const { return m_TicksToExplosion; }
+
+ /** Sets the number of ticks left until the firework explosion. */
+ void SetTicksToExplosion(int a_TicksToExplosion) { m_TicksToExplosion = a_TicksToExplosion; }
+
+ // tolua_end
protected:
@@ -34,7 +54,11 @@ protected:
private:
- int m_ExplodeTimer;
+ int m_TicksToExplosion;
cItem m_FireworkItem;
}; // tolua_export
+
+
+
+
diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp
index 159429147..5fe6a1238 100644
--- a/src/Entities/Floater.cpp
+++ b/src/Entities/Floater.cpp
@@ -22,7 +22,7 @@ public:
m_Pos(a_Pos),
m_NextPos(a_NextPos),
m_MinCoeff(1),
- m_HitEntity(NULL)
+ m_HitEntity(nullptr)
{
}
virtual bool Item(cEntity * a_Entity) override
diff --git a/src/Entities/GhastFireballEntity.h b/src/Entities/GhastFireballEntity.h
index 3ed72d9ef..bbce89d31 100644
--- a/src/Entities/GhastFireballEntity.h
+++ b/src/Entities/GhastFireballEntity.h
@@ -1,6 +1,11 @@
-//
-// GhastFireballEntity.h
-//
+
+// GhastFireballEntity.h
+
+// Declares the cGhastFireballEntity class representing the ghast fireball in flight.
+
+
+
+
#pragma once
@@ -36,3 +41,7 @@ protected:
// TODO: Deflecting the fireballs by arrow- or sword- hits
} ; // tolua_export
+
+
+
+
diff --git a/src/Entities/HangingEntity.cpp b/src/Entities/HangingEntity.cpp
index 3276bc4a0..a6b9c40c8 100644
--- a/src/Entities/HangingEntity.cpp
+++ b/src/Entities/HangingEntity.cpp
@@ -9,9 +9,9 @@
-cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
- : cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8)
- , m_BlockFace(a_BlockFace)
+cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_Facing, double a_X, double a_Y, double a_Z) :
+ cEntity(a_EntityType, a_X, a_Y, a_Z, 0.8, 0.8),
+ m_Facing(a_Facing)
{
SetMaxHealth(1);
SetHealth(1);
@@ -21,15 +21,23 @@ cHangingEntity::cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace,
-void cHangingEntity::SetDirection(eBlockFace a_BlockFace)
+void cHangingEntity::SetFacing(eBlockFace a_Facing)
{
- if ((a_BlockFace < 2) || (a_BlockFace > 5))
+ // Y-based faces are not allowed:
+ switch (a_Facing)
{
- ASSERT(!"Tried to set a bad direction!");
- return;
+ case BLOCK_FACE_NONE:
+ case BLOCK_FACE_YM:
+ case BLOCK_FACE_YP:
+ {
+ LOGWARNING("%s: Invalid facing: %d. Ignoring.", __FUNCTION__, a_Facing);
+ ASSERT(!"Tried to set a bad facing!");
+ return;
+ }
+ default: break;
}
- m_BlockFace = a_BlockFace;
+ m_Facing = a_Facing;
}
@@ -41,7 +49,7 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
int Dir = 0;
// 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 (m_BlockFace)
+ switch (m_Facing)
{
case BLOCK_FACE_ZP: Dir = 0; break;
case BLOCK_FACE_ZM: Dir = 2; break;
@@ -49,8 +57,8 @@ void cHangingEntity::SpawnOn(cClientHandle & a_ClientHandle)
case BLOCK_FACE_XP: Dir = 3; break;
default:
{
- LOGINFO("Invalid face (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.",
- m_BlockFace, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ()
+ LOGINFO("Invalid facing (%d) in a cHangingEntity at {%d, %d, %d}, adjusting to BLOCK_FACE_XP.",
+ m_Facing, (int)GetPosX(), (int)GetPosY(), (int)GetPosZ()
);
Dir = 3;
}
diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h
index 1cc0034e1..67146a20b 100644
--- a/src/Entities/HangingEntity.h
+++ b/src/Entities/HangingEntity.h
@@ -11,36 +11,41 @@
class cHangingEntity :
public cEntity
{
- // tolua_end
typedef cEntity super;
public:
+ // tolua_end
+
CLASS_PROTODEF(cHangingEntity)
cHangingEntity(eEntityType a_EntityType, eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
- /** Returns the orientation from the hanging entity */
- eBlockFace GetDirection() const { return m_BlockFace; } // tolua_export
+ // tolua_begin
+
+ /** Returns the direction in which the entity is facing. */
+ eBlockFace GetFacing() const { return m_Facing; }
- /** Set the orientation from the hanging entity */
- void SetDirection(eBlockFace a_BlockFace); // tolua_export
+ /** Set the direction in which the entity is facing. */
+ void SetFacing(eBlockFace a_Facing);
- /** Returns the X coord. */
- int GetTileX() const { return POSX_TOINT; } // tolua_export
+ /** Returns the X coord of the block in which the entity resides. */
+ int GetBlockX() const { return POSX_TOINT; }
- /** Returns the Y coord. */
- int GetTileY() const { return POSY_TOINT; } // tolua_export
+ /** Returns the Y coord of the block in which the entity resides. */
+ int GetBlockY() const { return POSY_TOINT; }
- /** Returns the Z coord. */
- int GetTileZ() const { return POSZ_TOINT; } // tolua_export
+ /** Returns the Z coord of the block in which the entity resides. */
+ int GetBlockZ() const { return POSZ_TOINT; }
+
+ // tolua_end
private:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override {}
- eBlockFace m_BlockFace;
+ eBlockFace m_Facing;
}; // tolua_export
diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp
index f512324eb..dfffcd3ed 100644
--- a/src/Entities/ItemFrame.cpp
+++ b/src/Entities/ItemFrame.cpp
@@ -9,10 +9,10 @@
-cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z)
- : cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z)
- , m_Item(E_BLOCK_AIR)
- , m_Rotation(0)
+cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z) :
+ cHangingEntity(etItemFrame, a_BlockFace, a_X, a_Y, a_Z),
+ m_Item(E_BLOCK_AIR),
+ m_ItemRotation(0)
{
}
@@ -27,10 +27,10 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
if (!m_Item.IsEmpty())
{
// Item not empty, rotate, clipping values to zero to three inclusive
- m_Rotation++;
- if (m_Rotation >= 8)
+ m_ItemRotation++;
+ if (m_ItemRotation >= 8)
{
- m_Rotation = 0;
+ m_ItemRotation = 0;
}
}
else if (!a_Player.GetEquippedItem().IsEmpty())
@@ -62,7 +62,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI)
return;
}
- if ((a_TDI.Attacker != NULL) && a_TDI.Attacker->IsPlayer() && !((cPlayer *)a_TDI.Attacker)->IsGameModeCreative())
+ if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPlayer() && !((cPlayer *)a_TDI.Attacker)->IsGameModeCreative())
{
cItems Item;
Item.push_back(m_Item);
@@ -72,7 +72,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI)
SetHealth(GetMaxHealth());
m_Item.Empty();
- m_Rotation = 0;
+ m_ItemRotation = 0;
SetInvulnerableTicks(0);
GetWorld()->BroadcastEntityMetadata(*this);
}
@@ -83,7 +83,7 @@ void cItemFrame::KilledBy(TakeDamageInfo & a_TDI)
void cItemFrame::GetDrops(cItems & a_Items, cEntity * a_Killer)
{
- if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
+ if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
{
a_Items.push_back(cItem(E_ITEM_ITEM_FRAME));
}
diff --git a/src/Entities/ItemFrame.h b/src/Entities/ItemFrame.h
index a63b78b70..ced8c37af 100644
--- a/src/Entities/ItemFrame.h
+++ b/src/Entities/ItemFrame.h
@@ -11,26 +11,31 @@
class cItemFrame :
public cHangingEntity
{
- // tolua_end
typedef cHangingEntity super;
public:
+ // tolua_end
+
CLASS_PROTODEF(cItemFrame)
cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_Z);
+ // tolua_begin
+
/** Returns the item in the frame */
- const cItem & GetItem(void) { return m_Item; } // tolua_export
+ const cItem & GetItem(void) { return m_Item; }
/** Set the item in the frame */
- void SetItem(cItem & a_Item) { m_Item = a_Item; } // tolua_export
+ void SetItem(cItem & a_Item) { m_Item = a_Item; }
/** Returns the rotation from the item in the frame */
- Byte GetRotation(void) const { return m_Rotation; } // tolua_export
+ Byte GetItemRotation(void) const { return m_ItemRotation; }
/** Set the rotation from the item in the frame */
- void SetRotation(Byte a_Rotation) { m_Rotation = a_Rotation; } // tolua_export
+ void SetItemRotation(Byte a_ItemRotation) { m_ItemRotation = a_ItemRotation; }
+
+ // tolua_end
private:
@@ -39,7 +44,7 @@ private:
virtual void GetDrops(cItems & a_Items, cEntity * a_Killer) override;
cItem m_Item;
- Byte m_Rotation;
+ Byte m_ItemRotation;
}; // tolua_export
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 2df64d5c1..22e046800 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -7,7 +7,6 @@
#include "Globals.h"
#include "Minecart.h"
-#include "../World.h"
#include "../ClientHandle.h"
#include "../Chunk.h"
#include "Player.h"
@@ -37,7 +36,7 @@ public:
virtual bool Item(cEntity * a_Entity) override
{
- ASSERT(a_Entity != NULL);
+ ASSERT(a_Entity != nullptr);
if (!a_Entity->IsPlayer() && !a_Entity->IsMob() && !a_Entity->IsMinecart() && !a_Entity->IsBoat())
{
@@ -131,7 +130,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk)
int RelPosX = POSX_TOINT - a_Chunk.GetPosX() * cChunkDef::Width;
int RelPosZ = POSZ_TOINT - a_Chunk.GetPosZ() * cChunkDef::Width;
cChunk * Chunk = a_Chunk.GetRelNeighborChunkAdjustCoords(RelPosX, RelPosZ);
- if (Chunk == NULL)
+ if (Chunk == nullptr)
{
// Inside an unloaded chunk, bail out all processing
return;
@@ -807,7 +806,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
- cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID()));
+ cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == nullptr) ? -1 : m_Attachee->GetUniqueID()));
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback);
@@ -981,7 +980,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI)
{
- if ((TDI.Attacker != NULL) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative())
+ if ((TDI.Attacker != nullptr) && TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative())
{
Destroy();
TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative
@@ -1075,7 +1074,7 @@ void cRideableMinecart::OnRightClicked(cPlayer & a_Player)
{
super::OnRightClicked(a_Player);
- if (m_Attachee != NULL)
+ if (m_Attachee != nullptr)
{
if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
{
@@ -1106,28 +1105,55 @@ void cRideableMinecart::OnRightClicked(cPlayer & a_Player)
// cMinecartWithChest:
cMinecartWithChest::cMinecartWithChest(double a_X, double a_Y, double a_Z) :
- super(mpChest, a_X, a_Y, a_Z)
+ super(mpChest, a_X, a_Y, a_Z),
+ cEntityWindowOwner(this),
+ m_Contents(ContentsWidth, ContentsHeight)
{
+ m_Contents.AddListener(*this);
}
-void cMinecartWithChest::SetSlot(size_t a_Idx, const cItem & a_Item)
+void cMinecartWithChest::OnRightClicked(cPlayer & a_Player)
{
- ASSERT(a_Idx < ARRAYCOUNT(m_Items));
-
- m_Items[a_Idx] = a_Item;
+ // If the window is not created, open it anew:
+ cWindow * Window = GetWindow();
+ if (Window == nullptr)
+ {
+ OpenNewWindow();
+ Window = GetWindow();
+ }
+
+ // Open the window for the player:
+ if (Window != nullptr)
+ {
+ if (a_Player.GetWindow() != Window)
+ {
+ a_Player.OpenWindow(Window);
+ }
+ }
}
-void cMinecartWithChest::OnRightClicked(cPlayer & a_Player)
+void cMinecartWithChest::OpenNewWindow()
+{
+ OpenWindow(new cMinecartWithChestWindow(this));
+}
+
+
+
+
+
+void cMinecartWithChest::Destroyed()
{
- // TODO: Show the chest UI window to the player
+ cItems Pickups;
+ m_Contents.CopyToItems(Pickups);
+ GetWorld()->SpawnItemPickups(Pickups, GetPosX(), GetPosY() + 1, GetPosZ(), 4);
}
diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h
index 410d3c77d..40e22c641 100644
--- a/src/Entities/Minecart.h
+++ b/src/Entities/Minecart.h
@@ -10,6 +10,8 @@
#pragma once
#include "Entity.h"
+#include "World.h"
+#include "../UI/WindowOwner.h"
@@ -108,27 +110,46 @@ protected:
class cMinecartWithChest :
- public cMinecart
+ public cMinecart,
+ public cItemGrid::cListener,
+ public cEntityWindowOwner
{
typedef cMinecart super;
public:
CLASS_PROTODEF(cMinecartWithChest)
- /// Number of item slots in the chest
- static const int NumSlots = 9 * 3;
-
cMinecartWithChest(double a_X, double a_Y, double a_Z);
+
+ enum
+ {
+ ContentsHeight = 3,
+ ContentsWidth = 9,
+ };
- const cItem & GetSlot(int a_Idx) const { return m_Items[a_Idx]; }
- cItem & GetSlot(int a_Idx) { return m_Items[a_Idx]; }
-
- void SetSlot(size_t a_Idx, const cItem & a_Item);
+ const cItem & GetSlot(int a_Idx) const { return m_Contents.GetSlot(a_Idx); }
+ void SetSlot(size_t a_Idx, const cItem & a_Item) { m_Contents.SetSlot(a_Idx, a_Item); }
protected:
+ cItemGrid m_Contents;
+ void OpenNewWindow(void);
+ virtual void Destroyed() override;
- /// The chest contents:
- cItem m_Items[NumSlots];
+ // cItemGrid::cListener overrides:
+ virtual void OnSlotChanged(cItemGrid * a_Grid, int a_SlotNum)
+ {
+ UNUSED(a_SlotNum);
+ ASSERT(a_Grid == &m_Contents);
+ if (m_World != nullptr)
+ {
+ if (GetWindow() != nullptr)
+ {
+ GetWindow()->BroadcastWholeWindow();
+ }
+
+ m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
+ }
+ }
// cEntity overrides:
virtual void OnRightClicked(cPlayer & a_Player) override;
diff --git a/src/Entities/Painting.cpp b/src/Entities/Painting.cpp
index e217556c7..1aa6da0a1 100644
--- a/src/Entities/Painting.cpp
+++ b/src/Entities/Painting.cpp
@@ -43,7 +43,7 @@ void cPainting::Tick(float a_Dt, cChunk & a_Chunk)
void cPainting::GetDrops(cItems & a_Items, cEntity * a_Killer)
{
- if ((a_Killer != NULL) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
+ if ((a_Killer != nullptr) && a_Killer->IsPlayer() && !((cPlayer *)a_Killer)->IsGameModeCreative())
{
a_Items.push_back(cItem(E_ITEM_PAINTING));
}
diff --git a/src/Entities/Painting.h b/src/Entities/Painting.h
index 9877c95c5..078270b42 100644
--- a/src/Entities/Painting.h
+++ b/src/Entities/Painting.h
@@ -11,15 +11,22 @@
class cPainting :
public cEntity
{
- // tolua_end
typedef cEntity super;
public:
+
+ // tolua_end
+
CLASS_PROTODEF(cPainting)
cPainting(const AString & a_Name, int a_Direction, double a_X, double a_Y, double a_Z);
- const AString & GetName(void) const { return m_Name; } // tolua_export
- int GetDirection(void) const { return m_Direction; } // tolua_export
+
+ // tolua_begin
+
+ const AString & GetName(void) const { return m_Name; }
+ int GetDirection(void) const { return m_Direction; }
+
+ // tolua_end
private:
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp
index 87b5bed07..e5e28446d 100644
--- a/src/Entities/Pickup.cpp
+++ b/src/Entities/Pickup.cpp
@@ -191,10 +191,8 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk)
-bool cPickup::CollectedBy(cPlayer * a_Dest)
+bool cPickup::CollectedBy(cPlayer & a_Dest)
{
- ASSERT(a_Dest != NULL);
-
if (m_bCollected)
{
// LOG("Pickup %d cannot be collected by \"%s\", because it has already been collected.", m_UniqueID, a_Dest->GetName().c_str());
@@ -214,21 +212,21 @@ bool cPickup::CollectedBy(cPlayer * a_Dest)
return false;
}
- int NumAdded = a_Dest->GetInventory().AddItem(m_Item);
+ int NumAdded = a_Dest.GetInventory().AddItem(m_Item);
if (NumAdded > 0)
{
// Check achievements
switch (m_Item.m_ItemType)
{
- case E_BLOCK_LOG: a_Dest->AwardAchievement(achMineWood); break;
- case E_ITEM_LEATHER: a_Dest->AwardAchievement(achKillCow); break;
- case E_ITEM_DIAMOND: a_Dest->AwardAchievement(achDiamonds); break;
- case E_ITEM_BLAZE_ROD: a_Dest->AwardAchievement(achBlazeRod); break;
+ case E_BLOCK_LOG: a_Dest.AwardAchievement(achMineWood); break;
+ case E_ITEM_LEATHER: a_Dest.AwardAchievement(achKillCow); break;
+ case E_ITEM_DIAMOND: a_Dest.AwardAchievement(achDiamonds); break;
+ case E_ITEM_BLAZE_ROD: a_Dest.AwardAchievement(achBlazeRod); break;
default: break;
}
m_Item.m_ItemCount -= NumAdded;
- m_World->BroadcastCollectEntity(*this, *a_Dest);
+ m_World->BroadcastCollectEntity(*this, a_Dest);
// Also send the "pop" sound effect with a somewhat random pitch (fast-random using EntityID ;)
m_World->BroadcastSoundEffect("random.pop", GetPosX(), GetPosY(), GetPosZ(), 0.5, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
if (m_Item.m_ItemCount <= 0)
diff --git a/src/Entities/Pickup.h b/src/Entities/Pickup.h
index 4d5250819..d1176a7cf 100644
--- a/src/Entities/Pickup.h
+++ b/src/Entities/Pickup.h
@@ -19,7 +19,7 @@ class cPickup :
public cEntity
{
typedef cEntity super;
-
+
public:
// tolua_end
@@ -32,15 +32,15 @@ public:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
- bool CollectedBy(cPlayer * a_Dest); // tolua_export
+ bool CollectedBy(cPlayer & a_Dest); // tolua_export
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
/** Returns the number of ticks that this entity has existed */
- int GetAge(void) const { return (int)(m_Timer / 50); } // tolua_export
+ int GetAge(void) const { return static_cast<int>(m_Timer / 50); } // tolua_export
/** Set the number of ticks that this entity has existed */
- void SetAge(int a_Age) { m_Timer = (float)(a_Age * 50); } // tolua_export
+ void SetAge(int a_Age) { m_Timer = static_cast<float>(a_Age * 50); } // tolua_export
/** Returns true if the pickup has already been collected */
bool IsCollected(void) const { return m_bCollected; } // tolua_export
@@ -59,7 +59,3 @@ private:
bool m_bIsPlayerCreated;
}; // tolua_export
-
-
-
-
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 66da14c0c..edcdb4799 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -20,7 +20,7 @@
#include "../WorldStorage/StatSerializer.h"
#include "../CompositeChat.h"
-#include "inifile/iniFile.h"
+#include "../IniFile.h"
#include "json/json.h"
// 6000 ticks or 5 minutes
@@ -56,8 +56,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
m_Stance(0.0),
m_Inventory(*this),
m_EnderChestContents(9, 3),
- m_CurrentWindow(NULL),
- m_InventoryWindow(NULL),
+ m_CurrentWindow(nullptr),
+ m_InventoryWindow(nullptr),
m_GameMode(eGameMode_NotSet),
m_IP(""),
m_ClientHandle(a_Client),
@@ -78,10 +78,10 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
m_IsChargingBow(false),
m_BowCharge(0),
m_FloaterID(-1),
- m_Team(NULL),
+ m_Team(nullptr),
m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL),
m_bIsTeleporting(false),
- m_UUID((a_Client != NULL) ? a_Client->GetUUID() : ""),
+ m_UUID((a_Client != nullptr) ? a_Client->GetUUID() : ""),
m_CustomName("")
{
m_InventoryWindow = new cInventoryWindow(*this);
@@ -96,7 +96,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
m_PlayerName = a_PlayerName;
- cWorld * World = NULL;
+ cWorld * World = nullptr;
if (!LoadFromDisk(World))
{
m_Inventory.Clear();
@@ -144,10 +144,10 @@ cPlayer::~cPlayer(void)
SaveToDisk();
- m_ClientHandle = NULL;
+ m_ClientHandle = nullptr;
delete m_InventoryWindow;
- m_InventoryWindow = NULL;
+ m_InventoryWindow = nullptr;
LOGD("Player %p deleted", this);
}
@@ -186,12 +186,12 @@ void cPlayer::SpawnOn(cClientHandle & a_Client)
void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
{
- if (m_ClientHandle != NULL)
+ if (m_ClientHandle != nullptr)
{
if (m_ClientHandle->IsDestroyed())
{
// This should not happen, because destroying a client will remove it from the world, but just in case
- m_ClientHandle = NULL;
+ m_ClientHandle = nullptr;
return;
}
@@ -235,7 +235,6 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
CanMove = false;
TeleportToCoords(m_LastPos.x, m_LastPos.y, m_LastPos.z);
}
- m_ClientHandle->StreamChunks();
}
if (CanMove)
@@ -245,7 +244,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
if (m_Health > 0) // make sure player is alive
{
- m_World->CollectPickupsByPlayer(this);
+ m_World->CollectPickupsByPlayer(*this);
if ((m_EatingFinishTick >= 0) && (m_EatingFinishTick <= m_World->GetWorldAge()))
{
@@ -504,7 +503,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
if (Damage > 0)
{
// cPlayer makes sure damage isn't applied in creative, no need to check here
- TakeDamage(dtFalling, NULL, Damage, Damage, 0);
+ TakeDamage(dtFalling, nullptr, Damage, Damage, 0);
// Fall particles
GetWorld()->BroadcastSoundParticleEffect(2006, POSX_TOINT, (int)GetPosY() - 1, POSZ_TOINT, Damage /* Used as particle effect speed modifier */);
@@ -651,7 +650,7 @@ void cPlayer::AbortEating(void)
void cPlayer::SendHealth(void)
{
- if (m_ClientHandle != NULL)
+ if (m_ClientHandle != nullptr)
{
m_ClientHandle->SendHealth();
}
@@ -663,7 +662,7 @@ void cPlayer::SendHealth(void)
void cPlayer::SendExperience(void)
{
- if (m_ClientHandle != NULL)
+ if (m_ClientHandle != nullptr)
{
m_ClientHandle->SendExperience();
m_bDirtyExperience = false;
@@ -859,11 +858,11 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
}
}
- if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer()))
+ if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer()))
{
cPlayer * Attacker = (cPlayer *)a_TDI.Attacker;
- if ((m_Team != NULL) && (m_Team == Attacker->m_Team))
+ if ((m_Team != nullptr) && (m_Team == Attacker->m_Team))
{
if (!m_Team->AllowsFriendlyFire())
{
@@ -915,7 +914,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
SaveToDisk(); // Save it, yeah the world is a tough place !
- if ((a_TDI.Attacker == NULL) && m_World->ShouldBroadcastDeathMessages())
+ if ((a_TDI.Attacker == nullptr) && m_World->ShouldBroadcastDeathMessages())
{
AString DamageText;
switch (a_TDI.DamageType)
@@ -941,7 +940,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
}
GetWorld()->BroadcastChatDeath(Printf("%s %s", GetName().c_str(), DamageText.c_str()));
}
- else if (a_TDI.Attacker == NULL) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough
+ else if (a_TDI.Attacker == nullptr) // && !m_World->ShouldBroadcastDeathMessages() by fallthrough
{
// no-op
}
@@ -997,7 +996,7 @@ void cPlayer::Killed(cEntity * a_Victim)
void cPlayer::Respawn(void)
{
- ASSERT(m_World != NULL);
+ ASSERT(m_World != nullptr);
m_Health = GetMaxHealth();
SetInvulnerableTicks(20);
@@ -1107,9 +1106,9 @@ void cPlayer::SetTeam(cTeam * a_Team)
cTeam * cPlayer::UpdateTeam(void)
{
- if (m_World == NULL)
+ if (m_World == nullptr)
{
- SetTeam(NULL);
+ SetTeam(nullptr);
}
else
{
@@ -1142,7 +1141,7 @@ void cPlayer::OpenWindow(cWindow * a_Window)
void cPlayer::CloseWindow(bool a_CanRefuse)
{
- if (m_CurrentWindow == NULL)
+ if (m_CurrentWindow == nullptr)
{
m_CurrentWindow = m_InventoryWindow;
return;
@@ -1167,7 +1166,7 @@ void cPlayer::CloseWindow(bool a_CanRefuse)
void cPlayer::CloseWindowIfID(char a_WindowID, bool a_CanRefuse)
{
- if ((m_CurrentWindow == NULL) || (m_CurrentWindow->GetWindowID() != a_WindowID))
+ if ((m_CurrentWindow == nullptr) || (m_CurrentWindow->GetWindowID() != a_WindowID))
{
return;
}
@@ -1354,7 +1353,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos)
// Y = -999 and X, Z = attempting to create speed, usually up to 0.03
// We cannot test m_AttachedTo, because when deattaching, the server thinks the client is already deattached while
// the client may still send more of these nonsensical packets.
- if (m_AttachedTo != NULL)
+ if (m_AttachedTo != nullptr)
{
Vector3d AddSpeed(a_NewPos);
AddSpeed.y = 0;
@@ -1581,7 +1580,7 @@ void cPlayer::TossItems(const cItems & a_Items)
bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
{
- ASSERT(a_World != NULL);
+ ASSERT(a_World != nullptr);
if (GetWorld() == a_World)
{
@@ -1590,7 +1589,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
}
// Send the respawn packet:
- if (a_ShouldSendRespawn && (m_ClientHandle != NULL))
+ if (a_ShouldSendRespawn && (m_ClientHandle != nullptr))
{
m_ClientHandle->SendRespawn(a_World->GetDimension());
}
@@ -1603,6 +1602,9 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
a_World->AddPlayer(this);
SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value
+ // Update the view distance.
+ m_ClientHandle->SetViewDistance(m_ClientHandle->GetRequestedViewDistance());
+
return true;
}
@@ -1652,7 +1654,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World)
GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str(), OfflineUsage
);
- if (a_World == NULL)
+ if (a_World == nullptr)
{
a_World = cRoot::Get()->GetDefaultWorld();
}
@@ -1729,7 +1731,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
m_LoadedWorldName = root.get("world", "world").asString();
a_World = cRoot::Get()->GetWorld(GetLoadedWorldName(), false);
- if (a_World == NULL)
+ if (a_World == nullptr)
{
a_World = cRoot::Get()->GetDefaultWorld();
}
@@ -1795,7 +1797,7 @@ bool cPlayer::SaveToDisk()
root["SpawnY"] = GetLastBedPos().y;
root["SpawnZ"] = GetLastBedPos().z;
- if (m_World != NULL)
+ if (m_World != nullptr)
{
root["world"] = m_World->GetName();
if (m_GameMode == m_World->GetGameMode())
@@ -1949,7 +1951,7 @@ void cPlayer::HandleFood(void)
else if ((m_FoodLevel <= 0) && (m_Health > 1))
{
// Damage from starving
- TakeDamage(dtStarving, NULL, 1, 1, 0);
+ TakeDamage(dtStarving, nullptr, 1, 1, 0);
}
}
}
@@ -2018,7 +2020,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos)
{
StatValue Value = (StatValue)floor(a_DeltaPos.Length() * 100 + 0.5);
- if (m_AttachedTo == NULL)
+ if (m_AttachedTo == nullptr)
{
if (IsClimbing())
{
@@ -2091,7 +2093,7 @@ void cPlayer::ApplyFoodExhaustionFromMovement()
}
// If riding anything, apply no food exhaustion
- if (m_AttachedTo != NULL)
+ if (m_AttachedTo != nullptr)
{
return;
}
@@ -2134,14 +2136,19 @@ void cPlayer::ApplyFoodExhaustionFromMovement()
void cPlayer::LoadRank(void)
{
// Load the values from cRankManager:
- cRankManager & RankMgr = cRoot::Get()->GetRankManager();
- m_Rank = RankMgr.GetPlayerRankName(m_UUID);
+ cRankManager * RankMgr = cRoot::Get()->GetRankManager();
+ m_Rank = RankMgr->GetPlayerRankName(m_UUID);
if (m_Rank.empty())
{
- m_Rank = RankMgr.GetDefaultRank();
+ m_Rank = RankMgr->GetDefaultRank();
+ }
+ else
+ {
+ // Update the name:
+ RankMgr->UpdatePlayerName(m_UUID, m_PlayerName);
}
- m_Permissions = RankMgr.GetPlayerPermissions(m_UUID);
- RankMgr.GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
+ m_Permissions = RankMgr->GetPlayerPermissions(m_UUID);
+ RankMgr->GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
// Break up the individual permissions on each dot, into m_SplitPermissions:
m_SplitPermissions.clear();
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index ffd0b7e03..4bb51b556 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -176,17 +176,17 @@ public:
AString GetIP(void) const { return m_IP; } // tolua_export
- /** Returns the associated team, NULL if none */
+ /** Returns the associated team, nullptr if none */
cTeam * GetTeam(void) { return m_Team; } // tolua_export
- /** Sets the player team, NULL if none */
+ /** Sets the player team, nullptr if none */
void SetTeam(cTeam * a_Team);
+ // tolua_end
+
/** Forces the player to query the scoreboard for his team */
cTeam * UpdateTeam(void);
- // tolua_end
-
/** Return the associated statistic and achievement manager. */
cStatManager & GetStatManager() { return m_Stats; }
@@ -421,9 +421,13 @@ public:
/** Sets the player's bed (home) position */
void SetBedPos(const Vector3i & a_Pos) { m_LastBedPos = a_Pos; }
+
+ // tolua_end
/** Update movement-related statistics. */
void UpdateMovementStats(const Vector3d & a_DeltaPos);
+
+ // tolua_begin
/** Returns wheter the player can fly or not. */
virtual bool CanFly(void) const { return m_CanFly; }
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index acc9bd674..1768714f8 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -135,7 +135,7 @@ public:
m_Pos(a_Pos),
m_NextPos(a_NextPos),
m_MinCoeff(1),
- m_HitEntity(NULL)
+ m_HitEntity(nullptr)
{
}
@@ -221,9 +221,9 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a
super(etProjectile, a_X, a_Y, a_Z, a_Width, a_Height),
m_ProjectileKind(a_Kind),
m_CreatorData(
- ((a_Creator != NULL) ? a_Creator->GetUniqueID() : -1),
- ((a_Creator != NULL) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""),
- ((a_Creator != NULL) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments())
+ ((a_Creator != nullptr) ? a_Creator->GetUniqueID() : -1),
+ ((a_Creator != nullptr) ? (a_Creator->IsPlayer() ? ((cPlayer *)a_Creator)->GetName() : "") : ""),
+ ((a_Creator != nullptr) ? a_Creator->GetEquippedWeapon().m_Enchantments : cEnchantments())
),
m_IsInGround(false)
{
@@ -251,7 +251,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Ve
cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem * a_Item, const Vector3d * a_Speed)
{
Vector3d Speed;
- if (a_Speed != NULL)
+ if (a_Speed != nullptr)
{
Speed = *a_Speed;
}
@@ -269,10 +269,10 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator,
case pkWitherSkull: return new cWitherSkullEntity (a_Creator, a_X, a_Y, a_Z, Speed);
case pkFirework:
{
- ASSERT(a_Item != NULL);
+ ASSERT(a_Item != nullptr);
if (a_Item->m_FireworkItem.m_Colours.empty())
{
- return NULL;
+ return nullptr;
}
return new cFireworkEntity(a_Creator, a_X, a_Y, a_Z, *a_Item);
@@ -280,7 +280,7 @@ cProjectileEntity * cProjectileEntity::Create(eKind a_Kind, cEntity * a_Creator,
}
LOGWARNING("%s: Unknown projectile kind: %d", __FUNCTION__, a_Kind);
- return NULL;
+ return nullptr;
}
@@ -424,8 +424,12 @@ void cProjectileEntity::SpawnOn(cClientHandle & a_Client)
-void cProjectileEntity::CollectedBy(cPlayer * a_Dest)
+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 990136a32..2a98e31c7 100644
--- a/src/Entities/ProjectileEntity.h
+++ b/src/Entities/ProjectileEntity.h
@@ -1,7 +1,7 @@
// ProjectileEntity.h
-// Declares the cProjectileEntity class representing the common base class for projectiles, as well as individual projectile types
+// Declares the cProjectileEntity class representing the common base class for projectiles
@@ -23,7 +23,7 @@ class cProjectileEntity :
typedef cEntity super;
public:
- /// The kind of the projectile. The numbers correspond to the network type ID used for spawning via the 0x17 packet.
+ /** The kind of the projectile. The numbers correspond to the network type ID used for spawning them in the protocol. */
enum eKind
{
pkArrow = 60,
@@ -46,24 +46,24 @@ public:
cProjectileEntity(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Vector3d & a_Pos, const Vector3d & a_Speed, double a_Width, double a_Height);
- static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem * a_Item, const Vector3d * a_Speed = NULL);
+ static cProjectileEntity * Create(eKind a_Kind, cEntity * a_Creator, double a_X, double a_Y, double a_Z, const cItem * a_Item, const Vector3d * a_Speed = nullptr);
- /// 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(const Vector3d & a_HitPos, eBlockFace a_HitFace);
- /// Called by the physics blocktracer when the entity hits another entity
+ /** Called by the physics blocktracer when the entity hits another entity */
virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos)
{
UNUSED(a_EntityHit);
UNUSED(a_HitPos);
}
- /// Called by Chunk when the projectile is eligible for player collection
- virtual void CollectedBy(cPlayer * a_Dest);
+ /** Called by Chunk when the projectile is eligible for player collection */
+ virtual void CollectedBy(cPlayer & a_Dest);
// tolua_begin
- /// Returns the kind of the projectile (fast class identification)
+ /** Returns the kind of the projectile (fast class identification) */
eKind GetProjectileKind(void) const { return m_ProjectileKind; }
/** Returns the unique ID of the entity who created this projectile
@@ -76,15 +76,15 @@ public:
*/
AString GetCreatorName(void) const { return m_CreatorData.m_Name; }
- /// Returns the string that is used as the entity type (class name) in MCA files
+ /** Returns the string that is used as the entity type (class name) in MCA files */
AString GetMCAClassName(void) const;
- /// Returns true if the projectile has hit the ground and is stuck there
+ /** Returns true if the projectile has hit the ground and is stuck there */
bool IsInGround(void) const { return m_IsInGround; }
// tolua_end
- /// Sets the internal InGround flag. To be used by MCA loader only!
+ /** Sets the internal InGround flag. To be used by MCA loader only! */
void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; }
protected:
@@ -110,11 +110,11 @@ protected:
eKind m_ProjectileKind;
/** The structure for containing the entity ID and name who has created this projectile
- The ID and/or name may be NULL (e.g. for dispensers/mobs)
+ The ID and/or name may be nullptr (e.g. for dispensers/mobs)
*/
CreatorData m_CreatorData;
- /// True if the projectile has hit the ground and is stuck there
+ /** True if the projectile has hit the ground and is stuck there */
bool m_IsInGround;
// cEntity overrides:
diff --git a/src/Entities/SplashPotionEntity.h b/src/Entities/SplashPotionEntity.h
index 4afc5f204..9302d8292 100644
--- a/src/Entities/SplashPotionEntity.h
+++ b/src/Entities/SplashPotionEntity.h
@@ -1,6 +1,11 @@
-//
-// SplashPotionEntity.h
-//
+
+// SplashPotionEntity.h
+
+// Declares the cSplashPotionEntity class representing a splash potion that has been thrown
+
+
+
+
#pragma once
@@ -32,6 +37,7 @@ public:
const cItem & a_Item
);
+ // tolua_begin
cEntityEffect::eType GetEntityEffectType(void) const { return m_EntityEffectType; }
cEntityEffect GetEntityEffect(void) const { return m_EntityEffect; }
int GetPotionColor(void) const { return m_PotionColor; }
@@ -39,6 +45,8 @@ public:
void SetEntityEffectType(cEntityEffect::eType a_EntityEffectType) { m_EntityEffectType = a_EntityEffectType; }
void SetEntityEffect(cEntityEffect a_EntityEffect) { m_EntityEffect = a_EntityEffect; }
void SetPotionColor(int a_PotionColor) { m_PotionColor = a_PotionColor; }
+
+ // tolua_end
protected:
@@ -77,3 +85,7 @@ private:
/** Time in ticks to wait for the hit animation to begin before destroying */
int m_DestroyTimer;
} ; // tolua_export
+
+
+
+
diff --git a/src/Entities/ThrownEggEntity.cpp b/src/Entities/ThrownEggEntity.cpp
index 5ae85bee8..24c946a9c 100644
--- a/src/Entities/ThrownEggEntity.cpp
+++ b/src/Entities/ThrownEggEntity.cpp
@@ -44,6 +44,27 @@ void cThrownEggEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_Hit
+void cThrownEggEntity::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ if (m_DestroyTimer > 0)
+ {
+ m_DestroyTimer--;
+ if (m_DestroyTimer == 0)
+ {
+ Destroy();
+ return;
+ }
+ }
+ else
+ {
+ super::Tick(a_Dt, a_Chunk);
+ }
+}
+
+
+
+
+
void cThrownEggEntity::TrySpawnChicken(const Vector3d & a_HitPos)
{
if (m_World->GetTickRandomNumber(7) == 1)
diff --git a/src/Entities/ThrownEggEntity.h b/src/Entities/ThrownEggEntity.h
index a0b7d5340..6ffedf5b5 100644
--- a/src/Entities/ThrownEggEntity.h
+++ b/src/Entities/ThrownEggEntity.h
@@ -1,6 +1,11 @@
-//
-// ThrownEggEntity.h
-//
+
+// ThrownEggEntity.h
+
+// Declares the cThrownEggEntity class representing a regular thrown egg
+
+
+
+
#pragma once
@@ -29,23 +34,8 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
- virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
- virtual void Tick (float a_Dt, cChunk & a_Chunk) override
- {
- if (m_DestroyTimer > 0)
- {
- m_DestroyTimer--;
- if (m_DestroyTimer == 0)
- {
- Destroy();
- return;
- }
- }
- else
- {
- super::Tick(a_Dt, a_Chunk);
- }
- }
+ virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
// Randomly decides whether to spawn a chicken where the egg lands.
void TrySpawnChicken(const Vector3d & a_HitPos);
@@ -56,3 +46,7 @@ private:
int m_DestroyTimer;
} ; // tolua_export
+
+
+
+
diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp
index c7407e6ae..8f1b62934 100644
--- a/src/Entities/ThrownEnderPearlEntity.cpp
+++ b/src/Entities/ThrownEnderPearlEntity.cpp
@@ -1,3 +1,4 @@
+
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "ThrownEnderPearlEntity.h"
@@ -45,6 +46,27 @@ void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d
+void cThrownEnderPearlEntity::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ if (m_DestroyTimer > 0)
+ {
+ m_DestroyTimer--;
+ if (m_DestroyTimer == 0)
+ {
+ Destroy();
+ return;
+ }
+ }
+ else
+ {
+ super::Tick(a_Dt, a_Chunk);
+ }
+}
+
+
+
+
+
void cThrownEnderPearlEntity::TeleportCreator(const Vector3d & a_HitPos)
{
if (m_CreatorData.m_Name.empty())
diff --git a/src/Entities/ThrownEnderPearlEntity.h b/src/Entities/ThrownEnderPearlEntity.h
index 436450013..475ebde87 100644
--- a/src/Entities/ThrownEnderPearlEntity.h
+++ b/src/Entities/ThrownEnderPearlEntity.h
@@ -1,6 +1,11 @@
-//
-// ThrownEnderPearlEntity.h
-//
+
+// ThrownEnderPearlEntity.h
+
+// Declares the cThrownEnderPeralEntity class representing an ender pearl being thrown
+
+
+
+
#pragma once
@@ -29,23 +34,8 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
- virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
- virtual void Tick (float a_Dt, cChunk & a_Chunk) override
- {
- if (m_DestroyTimer > 0)
- {
- m_DestroyTimer--;
- if (m_DestroyTimer == 0)
- {
- Destroy();
- return;
- }
- }
- else
- {
- super::Tick(a_Dt, a_Chunk);
- }
- }
+ virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
/** Teleports the creator where the ender pearl lands */
void TeleportCreator(const Vector3d & a_HitPos);
@@ -56,3 +46,7 @@ private:
int m_DestroyTimer;
} ; // tolua_export
+
+
+
+
diff --git a/src/Entities/ThrownSnowballEntity.cpp b/src/Entities/ThrownSnowballEntity.cpp
index 496397100..88e39d22e 100644
--- a/src/Entities/ThrownSnowballEntity.cpp
+++ b/src/Entities/ThrownSnowballEntity.cpp
@@ -43,3 +43,28 @@ void cThrownSnowballEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d &
m_DestroyTimer = 5;
}
+
+
+
+
+
+void cThrownSnowballEntity::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ if (m_DestroyTimer > 0)
+ {
+ m_DestroyTimer--;
+ if (m_DestroyTimer == 0)
+ {
+ Destroy();
+ return;
+ }
+ }
+ else
+ {
+ super::Tick(a_Dt, a_Chunk);
+ }
+}
+
+
+
+
diff --git a/src/Entities/ThrownSnowballEntity.h b/src/Entities/ThrownSnowballEntity.h
index 8d195ced1..f806996cc 100644
--- a/src/Entities/ThrownSnowballEntity.h
+++ b/src/Entities/ThrownSnowballEntity.h
@@ -1,6 +1,11 @@
-//
-// ThrownSnowballEntity.h
-//
+
+// ThrownSnowballEntity.h
+
+// Declares the cThrownSnowballEntity representing a snowball that has been thrown
+
+
+
+
#pragma once
@@ -29,23 +34,8 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
- virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
- virtual void Tick (float a_Dt, cChunk & a_Chunk) override
- {
- if (m_DestroyTimer > 0)
- {
- m_DestroyTimer--;
- if (m_DestroyTimer == 0)
- {
- Destroy();
- return;
- }
- }
- else
- {
- super::Tick(a_Dt, a_Chunk);
- }
- }
+ virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
private:
@@ -53,3 +43,7 @@ private:
int m_DestroyTimer;
} ; // tolua_export
+
+
+
+
diff --git a/src/Entities/WitherSkullEntity.h b/src/Entities/WitherSkullEntity.h
index c59acd807..43a520388 100644
--- a/src/Entities/WitherSkullEntity.h
+++ b/src/Entities/WitherSkullEntity.h
@@ -1,8 +1,12 @@
-// WitherSkullEntity.h
+// WitherSkullEntity.h
// Declares the cWitherSkullEntity class representing the entity used by both blue and black wither skulls
+
+
+
+
#pragma once
#include "ProjectileEntity.h"
@@ -30,6 +34,10 @@ protected:
// cProjectileEntity overrides:
virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override;
- virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
+ virtual void OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) override;
} ; // tolua_export
+
+
+
+