aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Bat.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/Bat.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/Bat.cpp')
-rw-r--r--Minecraft.World/Bat.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/Minecraft.World/Bat.cpp b/Minecraft.World/Bat.cpp
index d3bd3521..462fef57 100644
--- a/Minecraft.World/Bat.cpp
+++ b/Minecraft.World/Bat.cpp
@@ -15,7 +15,7 @@ Bat::Bat(Level *level) : AmbientCreature(level)
registerAttributes();
setHealth(getMaxHealth());
- targetPosition = NULL;
+ targetPosition = nullptr;
setSize(.5f, .9f);
setResting(true);
@@ -90,11 +90,11 @@ void Bat::setResting(bool value)
char current = entityData->getByte(DATA_ID_FLAGS);
if (value)
{
- entityData->set(DATA_ID_FLAGS, (char) (current | FLAG_RESTING));
+ entityData->set(DATA_ID_FLAGS, static_cast<char>(current | FLAG_RESTING));
}
else
{
- entityData->set(DATA_ID_FLAGS, (char) (current & ~FLAG_RESTING));
+ entityData->set(DATA_ID_FLAGS, static_cast<char>(current & ~FLAG_RESTING));
}
}
@@ -128,10 +128,10 @@ void Bat::newServerAiStep()
if (isResting())
{
- if (!level->isSolidBlockingTile(Mth::floor(x), (int) y + 1, Mth::floor(z)))
+ if (!level->isSolidBlockingTile(Mth::floor(x), static_cast<int>(y) + 1, Mth::floor(z)))
{
setResting(false);
- level->levelEvent(nullptr, LevelEvent::SOUND_BAT_LIFTOFF, (int) x, (int) y, (int) z, 0);
+ level->levelEvent(nullptr, LevelEvent::SOUND_BAT_LIFTOFF, static_cast<int>(x), static_cast<int>(y), static_cast<int>(z), 0);
}
else
{
@@ -141,25 +141,25 @@ void Bat::newServerAiStep()
yHeadRot = random->nextInt(360);
}
- if (level->getNearestPlayer(shared_from_this(), 4.0f) != NULL)
+ if (level->getNearestPlayer(shared_from_this(), 4.0f) != nullptr)
{
setResting(false);
- level->levelEvent(nullptr, LevelEvent::SOUND_BAT_LIFTOFF, (int) x, (int) y, (int) z, 0);
+ level->levelEvent(nullptr, LevelEvent::SOUND_BAT_LIFTOFF, static_cast<int>(x), static_cast<int>(y), static_cast<int>(z), 0);
}
}
}
else
{
- if (targetPosition != NULL && (!level->isEmptyTile(targetPosition->x, targetPosition->y, targetPosition->z) || targetPosition->y < 1))
+ if (targetPosition != nullptr && (!level->isEmptyTile(targetPosition->x, targetPosition->y, targetPosition->z) || targetPosition->y < 1))
{
delete targetPosition;
- targetPosition = NULL;
+ targetPosition = nullptr;
}
- if (targetPosition == NULL || random->nextInt(30) == 0 || targetPosition->distSqr((int) x, (int) y, (int) z) < 4)
+ if (targetPosition == nullptr || random->nextInt(30) == 0 || targetPosition->distSqr(static_cast<int>(x), static_cast<int>(y), static_cast<int>(z)) < 4)
{
delete targetPosition;
- targetPosition = new Pos((int) x + random->nextInt(7) - random->nextInt(7), (int) y + random->nextInt(6) - 2, (int) z + random->nextInt(7) - random->nextInt(7));
+ targetPosition = new Pos(static_cast<int>(x) + random->nextInt(7) - random->nextInt(7), static_cast<int>(y) + random->nextInt(6) - 2, static_cast<int>(z) + random->nextInt(7) - random->nextInt(7));
}
double dx = (targetPosition->x + .5) - x;
@@ -170,12 +170,12 @@ void Bat::newServerAiStep()
yd = yd + (signum(dy) * .7f - yd) * .1f;
zd = zd + (signum(dz) * .5f - zd) * .1f;
- float yRotD = (float) (atan2(zd, xd) * 180 / PI) - 90;
+ float yRotD = static_cast<float>(atan2(zd, xd) * 180 / PI) - 90;
float rotDiff = Mth::wrapDegrees(yRotD - yRot);
yya = .5f;
yRot += rotDiff;
- if (random->nextInt(100) == 0 && level->isSolidBlockingTile(Mth::floor(x), (int) y + 1, Mth::floor(z)))
+ if (random->nextInt(100) == 0 && level->isSolidBlockingTile(Mth::floor(x), static_cast<int>(y) + 1, Mth::floor(z)))
{
setResting(true);
}