aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/ThrownPotion.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/ThrownPotion.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/ThrownPotion.cpp')
-rw-r--r--Minecraft.World/ThrownPotion.cpp20
1 files changed, 10 insertions, 10 deletions
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<LivingEntity> mob, int potio
{
_init();
- potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, potionValue));
+ potionItem = std::make_shared<ItemInstance>(Item::potion, 1, potionValue);
}
ThrownPotion::ThrownPotion(Level *level, shared_ptr<LivingEntity> mob, shared_ptr<ItemInstance> potion) : Throwable(level, mob)
@@ -45,7 +45,7 @@ ThrownPotion::ThrownPotion(Level *level, double x, double y, double z, int potio
{
_init();
- potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, potionValue));
+ potionItem = std::make_shared<ItemInstance>(Item::potion, 1, potionValue);
}
ThrownPotion::ThrownPotion(Level *level, double x, double y, double z, shared_ptr<ItemInstance> potion) : Throwable(level, x, y, z)
@@ -72,13 +72,13 @@ float ThrownPotion::getThrowUpAngleOffset()
void ThrownPotion::setPotionValue(int potionValue)
{
- if (potionItem == NULL) potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, 0) );
+ if (potionItem == nullptr) potionItem = std::make_shared<ItemInstance>(Item::potion, 1, 0);
potionItem->setAuxValue(potionValue);
}
int ThrownPotion::getPotionValue()
{
- if (potionItem == NULL) potionItem = shared_ptr<ItemInstance>( new ItemInstance(Item::potion, 1, 0) );
+ if (potionItem == nullptr) potionItem = std::make_shared<ItemInstance>(Item::potion, 1, 0);
return potionItem->getAuxValue();
}
@@ -88,12 +88,12 @@ void ThrownPotion::onHit(HitResult *res)
{
vector<MobEffectInstance *> *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<shared_ptr<Entity> > *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<int>(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<int>(Math::round(x)), static_cast<int>(Math::round(y)), static_cast<int>(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