aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/PathNavigation.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-08 19:08:36 -0400
committerGitHub <noreply@github.com>2026-03-08 18:08:36 -0500
commit28614b922fb77149a54da1a87bebfbc98736f296 (patch)
tree7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.World/PathNavigation.cpp
parent88798b501d0cf6287b6f87acb2592676e3cec58d (diff)
Modernize project codebase (#906)
* Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides * Add safety checks and fix a issue with vector going OOR
Diffstat (limited to 'Minecraft.World/PathNavigation.cpp')
-rw-r--r--Minecraft.World/PathNavigation.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/Minecraft.World/PathNavigation.cpp b/Minecraft.World/PathNavigation.cpp
index 7cac052e..51d08d1e 100644
--- a/Minecraft.World/PathNavigation.cpp
+++ b/Minecraft.World/PathNavigation.cpp
@@ -16,7 +16,7 @@ PathNavigation::PathNavigation(Mob *mob, Level *level)
this->level = level;
dist = mob->getAttribute(SharedMonsterAttributes::FOLLOW_RANGE);
- path = NULL;
+ path = nullptr;
speedModifier = 0.0;
avoidSun = false;
_tick = 0;
@@ -30,7 +30,7 @@ PathNavigation::PathNavigation(Mob *mob, Level *level)
PathNavigation::~PathNavigation()
{
- if(path != NULL) delete path;
+ if(path != nullptr) delete path;
delete lastStuckCheckPos;
}
@@ -81,19 +81,19 @@ void PathNavigation::setCanFloat(bool canFloat)
float PathNavigation::getMaxDist()
{
- return (float) dist->getValue();
+ return static_cast<float>(dist->getValue());
}
Path *PathNavigation::createPath(double x, double y, double z)
{
- if (!canUpdatePath()) return NULL;
- return level->findPath(mob->shared_from_this(), Mth::floor(x), (int) y, Mth::floor(z), getMaxDist(), _canPassDoors, _canOpenDoors, avoidWater, canFloat);
+ if (!canUpdatePath()) return nullptr;
+ return level->findPath(mob->shared_from_this(), Mth::floor(x), static_cast<int>(y), Mth::floor(z), getMaxDist(), _canPassDoors, _canOpenDoors, avoidWater, canFloat);
}
bool PathNavigation::moveTo(double x, double y, double z, double speedModifier)
{
MemSect(52);
- Path *newPath = createPath(Mth::floor(x), (int) y, Mth::floor(z));
+ Path *newPath = createPath(Mth::floor(x), static_cast<int>(y), Mth::floor(z));
MemSect(0);
// No need to delete newPath here as this will be copied into the member variable path and the class can assume responsibility for it
return moveTo(newPath, speedModifier);
@@ -101,7 +101,7 @@ bool PathNavigation::moveTo(double x, double y, double z, double speedModifier)
Path *PathNavigation::createPath(shared_ptr<Entity> target)
{
- if (!canUpdatePath()) return NULL;
+ if (!canUpdatePath()) return nullptr;
return level->findPath(mob->shared_from_this(), target, getMaxDist(), _canPassDoors, _canOpenDoors, avoidWater, canFloat);
}
@@ -111,21 +111,21 @@ bool PathNavigation::moveTo(shared_ptr<Entity> target, double speedModifier)
Path *newPath = createPath(target);
MemSect(0);
// No need to delete newPath here as this will be copied into the member variable path and the class can assume responsibility for it
- if (newPath != NULL) return moveTo(newPath, speedModifier);
+ if (newPath != nullptr) return moveTo(newPath, speedModifier);
else return false;
}
bool PathNavigation::moveTo(Path *newPath, double speedModifier)
{
- if(newPath == NULL)
+ if(newPath == nullptr)
{
- if(path != NULL) delete path;
- path = NULL;
+ if(path != nullptr) delete path;
+ path = nullptr;
return false;
}
if(!newPath->sameAs(path))
{
- if(path != NULL) delete path;
+ if(path != nullptr) delete path;
path = newPath;
}
else
@@ -158,7 +158,7 @@ void PathNavigation::tick()
if (isDone()) return;
Vec3 *target = path->currentPos(mob->shared_from_this());
- if (target == NULL) return;
+ if (target == nullptr) return;
mob->getMoveControl()->setWantedPosition(target->x, target->y, target->z, speedModifier);
}
@@ -169,9 +169,9 @@ void PathNavigation::updatePath()
// find first elevations in path
int firstElevation = path->getSize();
- for (int i = path->getIndex(); path != NULL && i < path->getSize(); ++i)
+ for (int i = path->getIndex(); path != nullptr && i < path->getSize(); ++i)
{
- if ((int) path->get(i)->y != (int) mobPos->y)
+ if (static_cast<int>(path->get(i)->y) != static_cast<int>(mobPos->y))
{
firstElevation = i;
break;
@@ -191,8 +191,8 @@ void PathNavigation::updatePath()
}
// smooth remaining on same elevation
- int sx = (int) ceil(mob->bbWidth);
- int sy = (int) mob->bbHeight + 1;
+ int sx = static_cast<int>(ceil(mob->bbWidth));
+ int sy = static_cast<int>(mob->bbHeight) + 1;
int sz = sx;
for (int i = firstElevation - 1; i >= path->getIndex(); --i)
{
@@ -216,13 +216,13 @@ void PathNavigation::updatePath()
bool PathNavigation::isDone()
{
- return path == NULL || path->isDone();
+ return path == nullptr || path->isDone();
}
void PathNavigation::stop()
{
- if(path != NULL) delete path;
- path = NULL;
+ if(path != nullptr) delete path;
+ path = nullptr;
}
Vec3 *PathNavigation::getTempMobPos()
@@ -232,16 +232,16 @@ Vec3 *PathNavigation::getTempMobPos()
int PathNavigation::getSurfaceY()
{
- if (!mob->isInWater() || !canFloat) return (int) (mob->bb->y0 + 0.5);
+ if (!mob->isInWater() || !canFloat) return static_cast<int>(mob->bb->y0 + 0.5);
- int surface = (int) (mob->bb->y0);
+ int surface = static_cast<int>(mob->bb->y0);
int tileId = level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z));
int steps = 0;
while (tileId == Tile::water_Id || tileId == Tile::calmWater_Id)
{
++surface;
tileId = level->getTile(Mth::floor(mob->x), surface, Mth::floor(mob->z));
- if (++steps > 16) return (int) (mob->bb->y0);
+ if (++steps > 16) return static_cast<int>(mob->bb->y0);
}
return surface;
}
@@ -258,7 +258,7 @@ bool PathNavigation::isInLiquid()
void PathNavigation::trimPathFromSun()
{
- if (level->canSeeSky(Mth::floor(mob->x), (int) (mob->bb->y0 + 0.5), Mth::floor(mob->z))) return;
+ if (level->canSeeSky(Mth::floor(mob->x), static_cast<int>(mob->bb->y0 + 0.5), Mth::floor(mob->z))) return;
for (int i = 0; i < path->getSize(); ++i)
{
@@ -288,7 +288,7 @@ bool PathNavigation::canMoveDirectly(Vec3 *startPos, Vec3 *stopPos, int sx, int
sx += 2;
sz += 2;
- if (!canWalkOn(gridPosX, (int) startPos->y, gridPosZ, sx, sy, sz, startPos, dirX, dirZ)) return false;
+ if (!canWalkOn(gridPosX, static_cast<int>(startPos->y), gridPosZ, sx, sy, sz, startPos, dirX, dirZ)) return false;
sx -= 2;
sz -= 2;
@@ -323,7 +323,7 @@ bool PathNavigation::canMoveDirectly(Vec3 *startPos, Vec3 *stopPos, int sx, int
currentDirZ = gridGoalZ - gridPosZ;
}
- if (!canWalkOn(gridPosX, (int) startPos->y, gridPosZ, sx, sy, sz, startPos, dirX, dirZ)) return false;
+ if (!canWalkOn(gridPosX, static_cast<int>(startPos->y), gridPosZ, sx, sy, sz, startPos, dirX, dirZ)) return false;
}
return true;
}