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/PotionItem.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'Minecraft.World/PotionItem.cpp') diff --git a/Minecraft.World/PotionItem.cpp b/Minecraft.World/PotionItem.cpp index fd8937bf..fd156883 100644 --- a/Minecraft.World/PotionItem.cpp +++ b/Minecraft.World/PotionItem.cpp @@ -26,26 +26,26 @@ PotionItem::PotionItem(int id) : Item(id) setStackedByData(true); setMaxDamage(0); - iconThrowable = NULL; - iconDrinkable = NULL; - iconOverlay = NULL; + iconThrowable = nullptr; + iconDrinkable = nullptr; + iconOverlay = nullptr; } vector *PotionItem::getMobEffects(shared_ptr potion) { if (!potion->hasTag() || !potion->getTag()->contains(L"CustomPotionEffects")) { - vector *effects = NULL; + vector *effects = nullptr; auto it = cachedMobEffects.find(potion->getAuxValue()); if(it != cachedMobEffects.end()) effects = it->second; - if (effects == NULL) + if (effects == nullptr) { effects = PotionBrewing::getEffects(potion->getAuxValue(), false); cachedMobEffects[potion->getAuxValue()] = effects; } // Result should be a new (unmanaged) vector, so create a new one - return effects == NULL ? NULL : new vector(*effects); + return effects == nullptr ? nullptr : new vector(*effects); } else { @@ -64,13 +64,13 @@ vector *PotionItem::getMobEffects(shared_ptr vector *PotionItem::getMobEffects(int auxValue) { - vector *effects = NULL; + vector *effects = nullptr; auto it = cachedMobEffects.find(auxValue); if(it != cachedMobEffects.end()) effects = it->second; - if (effects == NULL) + if (effects == nullptr) { effects = PotionBrewing::getEffects(auxValue, false); - if(effects != NULL) cachedMobEffects.insert( std::pair *>(auxValue, effects) ); + if(effects != nullptr) cachedMobEffects.insert( std::pair *>(auxValue, effects) ); } return effects; } @@ -82,7 +82,7 @@ shared_ptr PotionItem::useTimeDepleted(shared_ptr in if (!level->isClientSide) { vector *effects = getMobEffects(instance); - if (effects != NULL) + if (effects != nullptr) { for(auto& effect : *effects) { @@ -94,11 +94,11 @@ shared_ptr PotionItem::useTimeDepleted(shared_ptr in { if (instance->count <= 0) { - return shared_ptr( new ItemInstance(Item::glassBottle) ); + return std::make_shared(Item::glassBottle); } else { - player->inventory->add( shared_ptr( new ItemInstance(Item::glassBottle) ) ); + player->inventory->add(std::make_shared(Item::glassBottle)); } } @@ -126,7 +126,7 @@ shared_ptr PotionItem::use(shared_ptr instance, Leve { if (!player->abilities.instabuild) instance->count--; level->playEntitySound(player, eSoundType_RANDOM_BOW, 0.5f, 0.4f / (random->nextFloat() * 0.4f + 0.8f)); - if (!level->isClientSide) level->addEntity(shared_ptr( new ThrownPotion(level, player, instance->getAuxValue()) )); + if (!level->isClientSide) level->addEntity(std::make_shared(level, player, instance->getAuxValue())); return instance; } player->startUsingItem(instance, getUseDuration(instance)); @@ -183,7 +183,7 @@ bool PotionItem::hasMultipleSpriteLayers() bool PotionItem::hasInstantenousEffects(int itemAuxValue) { vector *mobEffects = getMobEffects(itemAuxValue); - if (mobEffects == NULL || mobEffects->empty()) + if (mobEffects == nullptr || mobEffects->empty()) { return false; } @@ -216,7 +216,7 @@ wstring PotionItem::getHoverName(shared_ptr itemInstance) } vector *effects = ((PotionItem *) Item::potion)->getMobEffects(itemInstance); - if (effects != NULL && !effects->empty()) + if (effects != nullptr && !effects->empty()) { //String postfixString = effects.get(0).getDescriptionId(); //postfixString += ".postfix"; @@ -244,7 +244,7 @@ void PotionItem::appendHoverText(shared_ptr itemInstance, shared_p } vector *effects = ((PotionItem *) Item::potion)->getMobEffects(itemInstance); attrAttrModMap modifiers; - if (effects != NULL && !effects->empty()) + if (effects != nullptr && !effects->empty()) { //for (MobEffectInstance effect : effects) for(auto& effect : *effects) @@ -254,7 +254,7 @@ void PotionItem::appendHoverText(shared_ptr itemInstance, shared_p MobEffect *mobEffect = MobEffect::effects[effect->getId()]; unordered_map *effectModifiers = mobEffect->getAttributeModifiers(); - if (effectModifiers != NULL && effectModifiers->size() > 0) + if (effectModifiers != nullptr && effectModifiers->size() > 0) { for(auto& it : *effectModifiers) { @@ -335,7 +335,7 @@ void PotionItem::appendHoverText(shared_ptr itemInstance, shared_p bool PotionItem::isFoil(shared_ptr itemInstance) { vector *mobEffects = getMobEffects(itemInstance); - return mobEffects != NULL && !mobEffects->empty(); + return mobEffects != nullptr && !mobEffects->empty(); } unsigned int PotionItem::getUseDescriptionId(shared_ptr instance) @@ -368,7 +368,7 @@ Icon *PotionItem::getTexture(const wstring &name) if (name.compare(DEFAULT_ICON) == 0) return Item::potion->iconDrinkable; if (name.compare(THROWABLE_ICON) == 0) return Item::potion->iconThrowable; if (name.compare(CONTENTS_ICON) == 0) return Item::potion->iconOverlay; - return NULL; + return nullptr; } @@ -381,7 +381,7 @@ vector > *PotionItem::getUniquePotionValues() { vector *effects = PotionBrewing::getEffects(brew, false); - if (effects != NULL) + if (effects != nullptr) { if(!effects->empty()) { -- cgit v1.2.3