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/Animal.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'Minecraft.World/Animal.cpp') diff --git a/Minecraft.World/Animal.cpp b/Minecraft.World/Animal.cpp index ecda8fc5..68278162 100644 --- a/Minecraft.World/Animal.cpp +++ b/Minecraft.World/Animal.cpp @@ -72,13 +72,13 @@ void Animal::checkHurtTarget(shared_ptr target, float d) { double xd = target->x - x; double zd = target->z - z; - yRot = (float) (atan2(zd, xd) * 180 / PI) - 90; + yRot = static_cast(atan2(zd, xd) * 180 / PI) - 90; holdGround = true; } shared_ptr p = dynamic_pointer_cast(target); - if (p->getSelectedItem() == NULL || !isFood(p->getSelectedItem())) + if (p->getSelectedItem() == nullptr || !isFood(p->getSelectedItem())) { attackTarget = nullptr; } @@ -97,7 +97,7 @@ void Animal::checkHurtTarget(shared_ptr target, float d) } else if (getInLoveValue() > 0 && a->getInLoveValue() > 0) { - if (a->attackTarget == NULL) a->attackTarget = shared_from_this(); + if (a->attackTarget == nullptr) a->attackTarget = shared_from_this(); if (a->attackTarget == shared_from_this() && d < 3.5) { @@ -134,9 +134,9 @@ void Animal::breedWith(shared_ptr target) target->loveTime = 0; target->setInLoveValue(0); - // 4J - we have offspring of NULL returned when we have hit our limits of spawning any particular type of animal. In these cases try and do everything we can apart from actually + // 4J - we have offspring of nullptr returned when we have hit our limits of spawning any particular type of animal. In these cases try and do everything we can apart from actually // spawning the entity. - if (offspring != NULL) + if (offspring != nullptr) { // Only want to set the age to this +ve value if something is actually spawned, as during this period the animal will attempt to follow offspring and ignore players. setAge(5 * 60 * 20); @@ -154,7 +154,7 @@ void Animal::breedWith(shared_ptr target) } level->addEntity(offspring); - level->addEntity( shared_ptr( new ExperienceOrb(level, x, y, z, random->nextInt(4) + 1) ) ); + level->addEntity(std::make_shared(level, x, y, z, random->nextInt(4) + 1)); } setDespawnProtected(); @@ -169,7 +169,7 @@ float Animal::getWalkTargetValue(int x, int y, int z) bool Animal::hurt(DamageSource *dmgSource, float dmg) { if (isInvulnerable()) return false; - if (dynamic_cast(dmgSource) != NULL) + if (dynamic_cast(dmgSource) != nullptr) { shared_ptr source = dmgSource->getDirectEntity(); @@ -179,12 +179,12 @@ bool Animal::hurt(DamageSource *dmgSource, float dmg) return false; } - if ( (source != NULL) && source->instanceof(eTYPE_ARROW) ) + if ( (source != nullptr) && source->instanceof(eTYPE_ARROW) ) { shared_ptr arrow = dynamic_pointer_cast(source); // 4J: Check that the arrow's owner can attack animals (dispenser arrows are not owned) - if (arrow->owner != NULL && arrow->owner->instanceof(eTYPE_PLAYER) && !dynamic_pointer_cast(arrow->owner)->isAllowedToAttackAnimals() ) + if (arrow->owner != nullptr && arrow->owner->instanceof(eTYPE_PLAYER) && !dynamic_pointer_cast(arrow->owner)->isAllowedToAttackAnimals() ) { return false; } @@ -196,7 +196,7 @@ bool Animal::hurt(DamageSource *dmgSource, float dmg) if (!useNewAi()) { AttributeInstance *speed = getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED); - if (speed->getModifier(eModifierId_MOB_FLEEING) == NULL) + if (speed->getModifier(eModifierId_MOB_FLEEING) == nullptr) { speed->addModifier(new AttributeModifier(*Animal::SPEED_MODIFIER_FLEEING)); } @@ -255,7 +255,7 @@ shared_ptr Animal::findAttackTarget() setDespawnProtected(); shared_ptr p = dynamic_pointer_cast(it); - if (p->getSelectedItem() != NULL && this->isFood(p->getSelectedItem())) + if (p->getSelectedItem() != nullptr && this->isFood(p->getSelectedItem())) { delete players; return p; @@ -317,7 +317,7 @@ bool Animal::isFood(shared_ptr itemInstance) bool Animal::mobInteract(shared_ptr player) { shared_ptr item = player->inventory->getSelected(); - if (item != NULL && isFood(item) && getAge() == 0 && getInLoveValue() <= 0) + if (item != nullptr && isFood(item) && getAge() == 0 && getInLoveValue() <= 0) { if (!player->abilities.instabuild) { -- cgit v1.2.3