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/Village.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Minecraft.World/Village.cpp') diff --git a/Minecraft.World/Village.cpp b/Minecraft.World/Village.cpp index a72319fe..b7c82fa4 100644 --- a/Minecraft.World/Village.cpp +++ b/Minecraft.World/Village.cpp @@ -25,7 +25,7 @@ Village::Village() golemCount = 0; noBreedTimer = 0; - level = NULL; + level = nullptr; } Village::Village(Level *level) @@ -69,9 +69,9 @@ void Village::tick(int tick) if (golemCount < idealGolemCount && doorInfos.size() > 20 && level->random->nextInt(7000) == 0) { Vec3 *spawnPos = findRandomSpawnPos(center->x, center->y, center->z, 2, 4, 2); - if (spawnPos != NULL) + if (spawnPos != nullptr) { - shared_ptr vg = shared_ptr( new VillagerGolem(level) ); + shared_ptr vg = std::make_shared(level); vg->setPos(spawnPos->x, spawnPos->y, spawnPos->z); level->addEntity(vg); ++golemCount; @@ -103,7 +103,7 @@ Vec3 *Village::findRandomSpawnPos(int x, int y, int z, int sx, int sy, int sz) if (!isInside(xx, yy, zz)) continue; if (canSpawnAt(xx, yy, zz, sx, sy, sz)) return Vec3::newTemp(xx, yy, zz); } - return NULL; + return nullptr; } bool Village::canSpawnAt(int x, int y, int z, int sx, int sy, int sz) @@ -215,7 +215,7 @@ shared_ptrVillage::getBestDoorInfo(int x, int y, int z) bool Village::hasDoorInfo(int x, int y, int z) { - return getDoorInfo(x, y, z) != NULL; + return getDoorInfo(x, y, z) != nullptr; } shared_ptr Village::getDoorInfo(int x, int y, int z) @@ -260,7 +260,7 @@ void Village::addAggressor(shared_ptr mob) shared_ptr Village::getClosestAggressor(shared_ptr from) { double closestSqr = Double::MAX_VALUE; - Aggressor *closest = NULL; + Aggressor *closest = nullptr; for(auto& a : aggressors) { double distSqr = a->mob->distanceToSqr(from); @@ -268,7 +268,7 @@ shared_ptr Village::getClosestAggressor(shared_ptr f closest = a; closestSqr = distSqr; } - return closest != NULL ? closest->mob : nullptr; + return closest != nullptr ? closest->mob : nullptr; } shared_ptr Village::getClosestBadStandingPlayer(shared_ptr from) @@ -282,7 +282,7 @@ shared_ptr Village::getClosestBadStandingPlayer(shared_ptr if (isVeryBadStanding(player)) { shared_ptr mob = level->getPlayerByName(player); - if (mob != NULL) + if (mob != nullptr) { double distSqr = mob->distanceToSqr(from); if (distSqr > closestSqr) continue; @@ -422,7 +422,7 @@ void Village::readAdditionalSaveData(CompoundTag *tag) { CompoundTag *dTag = doorTags->get(i); - shared_ptr door = shared_ptr(new DoorInfo(dTag->getInt(L"X"), dTag->getInt(L"Y"), dTag->getInt(L"Z"), dTag->getInt(L"IDX"), dTag->getInt(L"IDZ"), dTag->getInt(L"TS"))); + shared_ptr door = std::make_shared(dTag->getInt(L"X"), dTag->getInt(L"Y"), dTag->getInt(L"Z"), dTag->getInt(L"IDX"), dTag->getInt(L"IDZ"), dTag->getInt(L"TS")); doorInfos.push_back(door); } -- cgit v1.2.3