From 28614b922fb77149a54da1a87bebfbc98736f296 Mon Sep 17 00:00:00 2001 From: ModMaker101 <119018978+ModMaker101@users.noreply.github.com> Date: Sun, 8 Mar 2026 19:08:36 -0400 Subject: 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 --- Minecraft.World/Ghast.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'Minecraft.World/Ghast.cpp') diff --git a/Minecraft.World/Ghast.cpp b/Minecraft.World/Ghast.cpp index f0817791..738a42da 100644 --- a/Minecraft.World/Ghast.cpp +++ b/Minecraft.World/Ghast.cpp @@ -56,7 +56,7 @@ bool Ghast::hurt(DamageSource *source, float dmg) if (isInvulnerable()) return false; if (source->getMsgId() == ChatPacket::e_ChatDeathFireball) { - if ( (source->getEntity() != NULL) && source->getEntity()->instanceof(eTYPE_PLAYER) ) + if ( (source->getEntity() != nullptr) && source->getEntity()->instanceof(eTYPE_PLAYER) ) { // reflected fireball, kill the ghast FlyingMob::hurt(source, 1000); @@ -72,7 +72,7 @@ void Ghast::defineSynchedData() { FlyingMob::defineSynchedData(); - entityData->define(DATA_IS_CHARGING, (byte) 0); + entityData->define(DATA_IS_CHARGING, static_cast(0)); } void Ghast::registerAttributes() @@ -121,37 +121,37 @@ void Ghast::serverAiStep() } } - if (target != NULL && target->removed) target = nullptr; - if (target == NULL || retargetTime-- <= 0) + if (target != nullptr && target->removed) target = nullptr; + if (target == nullptr || retargetTime-- <= 0) { target = level->getNearestAttackablePlayer(shared_from_this(), 100); - if (target != NULL) + if (target != nullptr) { retargetTime = 20; } } double maxDist = 64.0f; - if (target != NULL && target->distanceToSqr(shared_from_this()) < maxDist * maxDist) + if (target != nullptr && target->distanceToSqr(shared_from_this()) < maxDist * maxDist) { double xdd = target->x - x; double ydd = (target->bb->y0 + target->bbHeight / 2) - (y + bbHeight / 2); double zdd = target->z - z; - yBodyRot = yRot = -(float) atan2(xdd, zdd) * 180 / PI; + yBodyRot = yRot = -static_cast(atan2(xdd, zdd)) * 180 / PI; if (canSee(target)) { if (charge == 10) { // 4J - change brought forward from 1.2.3 - level->levelEvent(nullptr, LevelEvent::SOUND_GHAST_WARNING, (int) x, (int) y, (int) z, 0); + level->levelEvent(nullptr, LevelEvent::SOUND_GHAST_WARNING, static_cast(x), static_cast(y), static_cast(z), 0); } charge++; if (charge == 20) { // 4J - change brought forward from 1.2.3 - level->levelEvent(nullptr, LevelEvent::SOUND_GHAST_FIREBALL, (int) x, (int) y, (int) z, 0); - shared_ptr ie = shared_ptr( new LargeFireball(level, dynamic_pointer_cast( shared_from_this() ), xdd, ydd, zdd) ); + level->levelEvent(nullptr, LevelEvent::SOUND_GHAST_FIREBALL, static_cast(x), static_cast(y), static_cast(z), 0); + shared_ptr ie = std::make_shared(level, dynamic_pointer_cast(shared_from_this()), xdd, ydd, zdd); ie->explosionPower = explosionPower; double d = 4; Vec3 *v = getViewVector(1); @@ -169,14 +169,14 @@ void Ghast::serverAiStep() } else { - yBodyRot = yRot = -(float) atan2(this->xd, this->zd) * 180 / PI; + yBodyRot = yRot = -static_cast(atan2(this->xd, this->zd)) * 180 / PI; if (charge > 0) charge--; } if (!level->isClientSide) { byte old = entityData->getByte(DATA_IS_CHARGING); - byte current = (byte) (charge > 10 ? 1 : 0); + byte current = static_cast(charge > 10 ? 1 : 0); if (old != current) { entityData->set(DATA_IS_CHARGING, current); -- cgit v1.2.3