1
0

Prefer static_cast to reinterpret_cast (#4223)

* Change reinterpret_cast -> static_cast wherever possible
* Remove more unnecessary `const_cast`s.

reinterpret_casts should be avoided for the same reason as c-style casts - they don't do any type-checking. reinterpret_cast was mainly being used for down-casting in inheritance hierarchies but static_cast works just as well while also making sure that there is actually an inheritance relationship there.
This commit is contained in:
peterbell10
2018-05-02 08:50:36 +01:00
committed by GitHub
parent 86a8fdf3fe
commit a4dbb5c582
48 changed files with 351 additions and 351 deletions

View File

@@ -410,7 +410,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer()))
{
cPlayer * Player = reinterpret_cast<cPlayer *>(a_TDI.Attacker);
cPlayer * Player = static_cast<cPlayer *>(a_TDI.Attacker);
Player->GetEquippedItem().GetHandler()->OnEntityAttack(Player, this);
@@ -441,7 +441,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (IsMob())
{
cMonster * Monster = reinterpret_cast<cMonster *>(this);
cMonster * Monster = static_cast<cMonster *>(this);
switch (Monster->GetMobType())
{
case mtSkeleton:
@@ -460,7 +460,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (IsMob())
{
cMonster * Monster = reinterpret_cast<cMonster *>(this);
cMonster * Monster = static_cast<cMonster *>(this);
switch (Monster->GetMobType())
{
case mtSpider:
@@ -496,7 +496,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
}
else if (IsMob() && !IsInWater())
{
cMonster * Monster = reinterpret_cast<cMonster *>(this);
cMonster * Monster = static_cast<cMonster *>(this);
switch (Monster->GetMobType())
{
case mtGhast:
@@ -871,7 +871,7 @@ void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Handle cactus damage or destruction:
if (
IsMob() || IsPickup() ||
(IsPlayer() && !((reinterpret_cast<cPlayer *>(this))->IsGameModeCreative() || (reinterpret_cast<cPlayer *>(this))->IsGameModeSpectator()))
(IsPlayer() && !((static_cast<cPlayer *>(this))->IsGameModeCreative() || (static_cast<cPlayer *>(this))->IsGameModeSpectator()))
)
{
DetectCacti();
@@ -1362,7 +1362,7 @@ bool cEntity::DetectPortal()
return false;
}
if (IsPlayer() && !(reinterpret_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++;
@@ -1385,7 +1385,7 @@ bool cEntity::DetectPortal()
if (IsPlayer())
{
// Send a respawn packet before world is loaded / generated so the client isn't left in limbo
(reinterpret_cast<cPlayer *>(this))->GetClientHandle()->SendRespawn(DestionationDim);
(static_cast<cPlayer *>(this))->GetClientHandle()->SendRespawn(DestionationDim);
}
Vector3d TargetPos = GetPosition();
@@ -1414,10 +1414,10 @@ bool cEntity::DetectPortal()
{
if (DestionationDim == dimNether)
{
reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterPortal);
static_cast<cPlayer *>(this)->AwardAchievement(achEnterPortal);
}
reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(DestionationDim);
static_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(DestionationDim);
}
Vector3d TargetPos = GetPosition();
@@ -1454,7 +1454,7 @@ bool cEntity::DetectPortal()
if (IsPlayer())
{
cPlayer * Player = reinterpret_cast<cPlayer *>(this);
cPlayer * Player = static_cast<cPlayer *>(this);
if (Player->GetBedWorld() == DestinationWorld)
{
Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
@@ -1487,9 +1487,9 @@ bool cEntity::DetectPortal()
{
if (DestionationDim == dimEnd)
{
reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterTheEnd);
static_cast<cPlayer *>(this)->AwardAchievement(achEnterTheEnd);
}
reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(DestionationDim);
static_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(DestionationDim);
}
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName());
@@ -1717,7 +1717,7 @@ void cEntity::HandleAir(void)
if (RespirationLevel > 0)
{
reinterpret_cast<cPawn *>(this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0);
static_cast<cPawn *>(this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0);
}
if (m_AirLevel <= 0)