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/PotionBrewing.cpp | 50 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'Minecraft.World/PotionBrewing.cpp') diff --git a/Minecraft.World/PotionBrewing.cpp b/Minecraft.World/PotionBrewing.cpp index 8e27a601..bc5fd8c7 100644 --- a/Minecraft.World/PotionBrewing.cpp +++ b/Minecraft.World/PotionBrewing.cpp @@ -186,7 +186,7 @@ int PotionBrewing::getColorValue(vector *effects) int baseColor = colourTable->getColor( eMinecraftColour_Potion_BaseColour ); - if (effects == NULL || effects->empty()) + if (effects == nullptr || effects->empty()) { return baseColor; } @@ -203,9 +203,9 @@ int PotionBrewing::getColorValue(vector *effects) for (int potency = 0; potency <= effect->getAmplifier(); potency++) { - red += (float) ((potionColor >> 16) & 0xff) / 255.0f; - green += (float) ((potionColor >> 8) & 0xff) / 255.0f; - blue += (float) ((potionColor >> 0) & 0xff) / 255.0f; + red += static_cast((potionColor >> 16) & 0xff) / 255.0f; + green += static_cast((potionColor >> 8) & 0xff) / 255.0f; + blue += static_cast((potionColor >> 0) & 0xff) / 255.0f; count++; } } @@ -214,7 +214,7 @@ int PotionBrewing::getColorValue(vector *effects) green = (green / count) * 255.0f; blue = (blue / count) * 255.0f; - return ((int) red) << 16 | ((int) green) << 8 | ((int) blue); + return static_cast(red) << 16 | static_cast(green) << 8 | static_cast(blue); } bool PotionBrewing::areAllEffectsAmbient(vector *effects) @@ -238,7 +238,7 @@ int PotionBrewing::getColorValue(int brew, bool includeDisabledEffects) } vector *effects = getEffects(brew, false); int color = getColorValue(effects); - if(effects != NULL) + if(effects != nullptr) { for(auto& effect : *effects) { @@ -325,16 +325,16 @@ int PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start, } // split by and - int andIndex = (int)definition.find_first_of(L'&', start); - if (andIndex >= 0 && andIndex < end) + size_t andIndex = definition.find_first_of(L'&', start); + if (andIndex != wstring::npos && andIndex < static_cast(end)) { - int leftSide = parseEffectFormulaValue(definition, start, andIndex - 1, brew); + int leftSide = parseEffectFormulaValue(definition, start, static_cast(andIndex) - 1, brew); if (leftSide <= 0) { return 0; } - int rightSide = parseEffectFormulaValue(definition, andIndex + 1, end, brew); + int rightSide = parseEffectFormulaValue(definition, static_cast(andIndex) + 1, end, brew); if (rightSide <= 0) { return 0; @@ -413,16 +413,16 @@ int PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start, } // split by or - int orIndex = definition.find_first_of(L'|', start); - if (orIndex >= 0 && orIndex < end) + size_t orIndex = definition.find_first_of(L'|', start); + if (orIndex != wstring::npos && orIndex < static_cast(end)) { - int leftSide = parseEffectFormulaValue(definition, start, orIndex - 1, brew); + int leftSide = parseEffectFormulaValue(definition, start, static_cast(orIndex) - 1, brew); if (leftSide > 0) { return leftSide; } - int rightSide = parseEffectFormulaValue(definition, orIndex + 1, end, brew); + int rightSide = parseEffectFormulaValue(definition, static_cast(orIndex) + 1, end, brew); if (rightSide > 0) { return rightSide; @@ -430,10 +430,10 @@ int PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start, return 0; } // split by and - int andIndex = definition.find_first_of(L'&', start); - if (andIndex >= 0 && andIndex < end) + size_t andIndex = definition.find_first_of(L'&', start); + if (andIndex != wstring::npos && andIndex < static_cast(end)) { - int leftSide = parseEffectFormulaValue(definition, start, andIndex - 1, brew); + int leftSide = parseEffectFormulaValue(definition, start, static_cast(andIndex) - 1, brew); if (leftSide <= 0) { return 0; @@ -552,13 +552,13 @@ int PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start, vector *PotionBrewing::getEffects(int brew, bool includeDisabledEffects) { - vector *list = NULL; + vector *list = nullptr; //for (MobEffect effect : MobEffect.effects) for(unsigned int i = 0; i < MobEffect::NUM_EFFECTS; ++i) { MobEffect *effect = MobEffect::effects[i]; - if (effect == NULL || (effect->isDisabled() && !includeDisabledEffects)) + if (effect == nullptr || (effect->isDisabled() && !includeDisabledEffects)) { continue; } @@ -570,7 +570,7 @@ vector *PotionBrewing::getEffects(int brew, bool includeDis } wstring durationString = effIt->second; - int duration = parseEffectFormulaValue(durationString, 0, (int)durationString.length(), brew); + int duration = parseEffectFormulaValue(durationString, 0, static_cast(durationString.length()), brew); if (duration > 0) { int amplifier = 0; @@ -578,7 +578,7 @@ vector *PotionBrewing::getEffects(int brew, bool includeDis if (ampIt != potionEffectAmplifier.end()) { wstring amplifierString = ampIt->second; - amplifier = parseEffectFormulaValue(amplifierString, 0, (int)amplifierString.length(), brew); + amplifier = parseEffectFormulaValue(amplifierString, 0, static_cast(amplifierString.length()), brew); if (amplifier < 0) { amplifier = 0; @@ -594,15 +594,15 @@ vector *PotionBrewing::getEffects(int brew, bool includeDis // 3, 8, 13, 18.. minutes duration = (SharedConstants::TICKS_PER_SECOND * 60) * (duration * 3 + (duration - 1) * 2); duration >>= amplifier; - duration = (int) Math::round((double) duration * effect->getDurationModifier()); + duration = static_cast(Math::round((double)duration * effect->getDurationModifier())); if ((brew & THROWABLE_MASK) != 0) { - duration = (int) Math::round((double) duration * .75 + .5); + duration = static_cast(Math::round((double)duration * .75 + .5)); } } - if (list == NULL) + if (list == nullptr) { list = new vector(); } @@ -756,7 +756,7 @@ int PotionBrewing::applyBrew(int currentBrew, const wstring &formula) { int start = 0; - int end = (int)formula.length(); + int end = static_cast(formula.length()); bool hasValue = false; bool isNot = false; -- cgit v1.2.3