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/ThrownPotion.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Minecraft.World/ThrownPotion.cpp') diff --git a/Minecraft.World/ThrownPotion.cpp b/Minecraft.World/ThrownPotion.cpp index 69c096a2..170f6474 100644 --- a/Minecraft.World/ThrownPotion.cpp +++ b/Minecraft.World/ThrownPotion.cpp @@ -31,7 +31,7 @@ ThrownPotion::ThrownPotion(Level *level, shared_ptr mob, int potio { _init(); - potionItem = shared_ptr( new ItemInstance(Item::potion, 1, potionValue)); + potionItem = std::make_shared(Item::potion, 1, potionValue); } ThrownPotion::ThrownPotion(Level *level, shared_ptr mob, shared_ptr potion) : Throwable(level, mob) @@ -45,7 +45,7 @@ ThrownPotion::ThrownPotion(Level *level, double x, double y, double z, int potio { _init(); - potionItem = shared_ptr( new ItemInstance(Item::potion, 1, potionValue)); + potionItem = std::make_shared(Item::potion, 1, potionValue); } ThrownPotion::ThrownPotion(Level *level, double x, double y, double z, shared_ptr potion) : Throwable(level, x, y, z) @@ -72,13 +72,13 @@ float ThrownPotion::getThrowUpAngleOffset() void ThrownPotion::setPotionValue(int potionValue) { - if (potionItem == NULL) potionItem = shared_ptr( new ItemInstance(Item::potion, 1, 0) ); + if (potionItem == nullptr) potionItem = std::make_shared(Item::potion, 1, 0); potionItem->setAuxValue(potionValue); } int ThrownPotion::getPotionValue() { - if (potionItem == NULL) potionItem = shared_ptr( new ItemInstance(Item::potion, 1, 0) ); + if (potionItem == nullptr) potionItem = std::make_shared(Item::potion, 1, 0); return potionItem->getAuxValue(); } @@ -88,12 +88,12 @@ void ThrownPotion::onHit(HitResult *res) { vector *mobEffects = Item::potion->getMobEffects(potionItem); - if (mobEffects != NULL && !mobEffects->empty()) + if (mobEffects != nullptr && !mobEffects->empty()) { AABB *aoe = bb->grow(SPLASH_RANGE, SPLASH_RANGE / 2, SPLASH_RANGE); vector > *entitiesOfClass = level->getEntitiesOfClass(typeid(LivingEntity), aoe); - if (entitiesOfClass != NULL && !entitiesOfClass->empty()) + if (entitiesOfClass != nullptr && !entitiesOfClass->empty()) { for(auto & it : *entitiesOfClass) { @@ -117,7 +117,7 @@ void ThrownPotion::onHit(HitResult *res) } else { - int duration = (int) (scale * (double) effect->getDuration() + .5); + int duration = static_cast(scale * (double)effect->getDuration() + .5); if (duration > SharedConstants::TICKS_PER_SECOND) { e->addEffect(new MobEffectInstance(id, duration, effect->getAmplifier())); @@ -129,7 +129,7 @@ void ThrownPotion::onHit(HitResult *res) } delete entitiesOfClass; } - level->levelEvent(LevelEvent::PARTICLES_POTION_SPLASH, (int) Math::round(x), (int) Math::round(y), (int) Math::round(z), getPotionValue() ); + level->levelEvent(LevelEvent::PARTICLES_POTION_SPLASH, static_cast(Math::round(x)), static_cast(Math::round(y)), static_cast(Math::round(z)), getPotionValue() ); remove(); } @@ -148,12 +148,12 @@ void ThrownPotion::readAdditionalSaveData(CompoundTag *tag) setPotionValue(tag->getInt(L"potionValue")); } - if (potionItem == NULL) remove(); + if (potionItem == nullptr) remove(); } void ThrownPotion::addAdditonalSaveData(CompoundTag *tag) { Throwable::addAdditonalSaveData(tag); - if (potionItem != NULL) tag->putCompound(L"Potion", potionItem->save(new CompoundTag())); + if (potionItem != nullptr) tag->putCompound(L"Potion", potionItem->save(new CompoundTag())); } \ No newline at end of file -- cgit v1.2.3