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/Pig.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Minecraft.World/Pig.cpp') diff --git a/Minecraft.World/Pig.cpp b/Minecraft.World/Pig.cpp index cc042f58..a99af826 100644 --- a/Minecraft.World/Pig.cpp +++ b/Minecraft.World/Pig.cpp @@ -64,13 +64,13 @@ bool Pig::canBeControlledByRider() { shared_ptr item = dynamic_pointer_cast(rider.lock())->getCarriedItem(); - return item != NULL && item->id == Item::carrotOnAStick_Id; + return item != nullptr && item->id == Item::carrotOnAStick_Id; } void Pig::defineSynchedData() { Animal::defineSynchedData(); - entityData->define(DATA_SADDLE_ID, (byte) 0); + entityData->define(DATA_SADDLE_ID, static_cast(0)); } void Pig::addAdditonalSaveData(CompoundTag *tag) @@ -109,7 +109,7 @@ bool Pig::mobInteract(shared_ptr player) { if(!Animal::mobInteract(player)) { - if (hasSaddle() && !level->isClientSide && (rider.lock() == NULL || rider.lock() == player)) + if (hasSaddle() && !level->isClientSide && (rider.lock() == nullptr || rider.lock() == player)) { // 4J HEG - Fixed issue with player not being able to dismount pig (issue #4479) player->ride( rider.lock() == player ? nullptr : shared_from_this() ); @@ -153,18 +153,18 @@ void Pig::setSaddle(bool value) { if (value) { - entityData->set(DATA_SADDLE_ID, (byte) 1); + entityData->set(DATA_SADDLE_ID, static_cast(1)); } else { - entityData->set(DATA_SADDLE_ID, (byte) 0); + entityData->set(DATA_SADDLE_ID, static_cast(0)); } } void Pig::thunderHit(const LightningBolt *lightningBolt) { if (level->isClientSide) return; - shared_ptr pz = shared_ptr( new PigZombie(level) ); + shared_ptr pz = std::make_shared(level); pz->moveTo(x, y, z, yRot, xRot); level->addEntity(pz); remove(); @@ -173,7 +173,7 @@ void Pig::thunderHit(const LightningBolt *lightningBolt) void Pig::causeFallDamage(float distance) { Animal::causeFallDamage(distance); - if ( (distance > 5) && rider.lock() != NULL && rider.lock()->instanceof(eTYPE_PLAYER) ) + if ( (distance > 5) && rider.lock() != nullptr && rider.lock()->instanceof(eTYPE_PLAYER) ) { (dynamic_pointer_cast(rider.lock()))->awardStat(GenericStats::flyPig(),GenericStats::param_flyPig()); } @@ -184,7 +184,7 @@ shared_ptr Pig::getBreedOffspring(shared_ptr target) // 4J - added limit to number of animals that can be bred if( level->canCreateMore( GetType(), Level::eSpawnType_Breed) ) { - return shared_ptr( new Pig(level) ); + return std::make_shared(level); } else { @@ -194,7 +194,7 @@ shared_ptr Pig::getBreedOffspring(shared_ptr target) bool Pig::isFood(shared_ptr itemInstance) { - return itemInstance != NULL && itemInstance->id == Item::carrots_Id; + return itemInstance != nullptr && itemInstance->id == Item::carrots_Id; } ControlledByPlayerGoal *Pig::getControlGoal() -- cgit v1.2.3