aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/PotionBrewing.cpp
diff options
context:
space:
mode:
authorModMaker101 <119018978+ModMaker101@users.noreply.github.com>2026-03-08 19:08:36 -0400
committerGitHub <noreply@github.com>2026-03-08 18:08:36 -0500
commit28614b922fb77149a54da1a87bebfbc98736f296 (patch)
tree7f828ba86a4ee18d0a80d29de64f6199a5412512 /Minecraft.World/PotionBrewing.cpp
parent88798b501d0cf6287b6f87acb2592676e3cec58d (diff)
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
Diffstat (limited to 'Minecraft.World/PotionBrewing.cpp')
-rw-r--r--Minecraft.World/PotionBrewing.cpp50
1 files changed, 25 insertions, 25 deletions
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<MobEffectInstance *> *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<MobEffectInstance *> *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<float>((potionColor >> 16) & 0xff) / 255.0f;
+ green += static_cast<float>((potionColor >> 8) & 0xff) / 255.0f;
+ blue += static_cast<float>((potionColor >> 0) & 0xff) / 255.0f;
count++;
}
}
@@ -214,7 +214,7 @@ int PotionBrewing::getColorValue(vector<MobEffectInstance *> *effects)
green = (green / count) * 255.0f;
blue = (blue / count) * 255.0f;
- return ((int) red) << 16 | ((int) green) << 8 | ((int) blue);
+ return static_cast<int>(red) << 16 | static_cast<int>(green) << 8 | static_cast<int>(blue);
}
bool PotionBrewing::areAllEffectsAmbient(vector<MobEffectInstance *> *effects)
@@ -238,7 +238,7 @@ int PotionBrewing::getColorValue(int brew, bool includeDisabledEffects)
}
vector<MobEffectInstance *> *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<size_t>(end))
{
- int leftSide = parseEffectFormulaValue(definition, start, andIndex - 1, brew);
+ int leftSide = parseEffectFormulaValue(definition, start, static_cast<int>(andIndex) - 1, brew);
if (leftSide <= 0)
{
return 0;
}
- int rightSide = parseEffectFormulaValue(definition, andIndex + 1, end, brew);
+ int rightSide = parseEffectFormulaValue(definition, static_cast<int>(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<size_t>(end))
{
- int leftSide = parseEffectFormulaValue(definition, start, orIndex - 1, brew);
+ int leftSide = parseEffectFormulaValue(definition, start, static_cast<int>(orIndex) - 1, brew);
if (leftSide > 0)
{
return leftSide;
}
- int rightSide = parseEffectFormulaValue(definition, orIndex + 1, end, brew);
+ int rightSide = parseEffectFormulaValue(definition, static_cast<int>(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<size_t>(end))
{
- int leftSide = parseEffectFormulaValue(definition, start, andIndex - 1, brew);
+ int leftSide = parseEffectFormulaValue(definition, start, static_cast<int>(andIndex) - 1, brew);
if (leftSide <= 0)
{
return 0;
@@ -552,13 +552,13 @@ int PotionBrewing::parseEffectFormulaValue(const wstring &definition, int start,
vector<MobEffectInstance *> *PotionBrewing::getEffects(int brew, bool includeDisabledEffects)
{
- vector<MobEffectInstance *> *list = NULL;
+ vector<MobEffectInstance *> *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<MobEffectInstance *> *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<int>(durationString.length()), brew);
if (duration > 0)
{
int amplifier = 0;
@@ -578,7 +578,7 @@ vector<MobEffectInstance *> *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<int>(amplifierString.length()), brew);
if (amplifier < 0)
{
amplifier = 0;
@@ -594,15 +594,15 @@ vector<MobEffectInstance *> *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<int>(Math::round((double)duration * effect->getDurationModifier()));
if ((brew & THROWABLE_MASK) != 0)
{
- duration = (int) Math::round((double) duration * .75 + .5);
+ duration = static_cast<int>(Math::round((double)duration * .75 + .5));
}
}
- if (list == NULL)
+ if (list == nullptr)
{
list = new vector<MobEffectInstance *>();
}
@@ -756,7 +756,7 @@ int PotionBrewing::applyBrew(int currentBrew, const wstring &formula)
{
int start = 0;
- int end = (int)formula.length();
+ int end = static_cast<int>(formula.length());
bool hasValue = false;
bool isNot = false;