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/Slot.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Minecraft.World/Slot.cpp') diff --git a/Minecraft.World/Slot.cpp b/Minecraft.World/Slot.cpp index a5a53a48..2f42a27d 100644 --- a/Minecraft.World/Slot.cpp +++ b/Minecraft.World/Slot.cpp @@ -15,7 +15,7 @@ Slot::Slot(shared_ptr container, int slot, int x, int y) : container( void Slot::onQuickCraft(shared_ptr picked, shared_ptr original) { - if (picked == NULL || original == NULL) + if (picked == nullptr || original == nullptr) { return; } @@ -44,14 +44,14 @@ void Slot::swap(Slot *other) shared_ptr item1 = container->getItem(slot); shared_ptr item2 = other->container->getItem(other->slot); - if (item1 != NULL && item1->count > other->getMaxStackSize()) + if (item1 != nullptr && item1->count > other->getMaxStackSize()) { - if (item2 != NULL) return; + if (item2 != nullptr) return; item2 = item1->remove(item1->count - other->getMaxStackSize()); } - if (item2 != NULL && item2->count > getMaxStackSize()) + if (item2 != nullptr && item2->count > getMaxStackSize()) { - if (item1 != NULL) return; + if (item1 != nullptr) return; item1 = item2->remove(item2->count - getMaxStackSize()); } other->container->setItem(other->slot, item1); @@ -77,7 +77,7 @@ shared_ptr Slot::getItem() bool Slot::hasItem() { - return getItem() != NULL; + return getItem() != nullptr; } void Slot::set(shared_ptr item) @@ -98,7 +98,7 @@ int Slot::getMaxStackSize() const Icon *Slot::getNoItemIcon() { - return NULL; + return nullptr; } shared_ptr Slot::remove(int c) @@ -125,7 +125,7 @@ bool Slot::mayCombine(shared_ptr second) { shared_ptr first = getItem(); - if(first == NULL || second == NULL) return false; + if(first == nullptr || second == nullptr) return false; ArmorItem *thisItem = dynamic_cast(first->getItem()); if(thisItem) @@ -135,7 +135,7 @@ bool Slot::mayCombine(shared_ptr second) return thisIsDyableArmor && itemIsDye; } // 4J Stu - This condition taken from Recipes::getItemFor to repair items, but added the damaged check to skip when the result is pointless - else if (first != NULL && second != NULL && first->id == second->id && first->count == 1 && second->count == 1 && Item::items[first->id]->canBeDepleted() && (first->isDamaged() || second->isDamaged()) ) + else if (first != nullptr && second != nullptr && first->id == second->id && first->count == 1 && second->count == 1 && Item::items[first->id]->canBeDepleted() && (first->isDamaged() || second->isDamaged()) ) { // 4J Stu - Don't allow combinining enchanted items, the enchantment will be lost. They can use the anvil for this return !first->isEnchanted() && !second->isEnchanted(); @@ -148,7 +148,7 @@ shared_ptr Slot::combine(shared_ptr item) shared_ptr result = nullptr; shared_ptr first = getItem(); - shared_ptr craftSlots = shared_ptr( new CraftingContainer(NULL, 2, 2) ); + shared_ptr craftSlots = std::make_shared(nullptr, 2, 2); craftSlots->setItem(0, item); craftSlots->setItem(1, first); @@ -159,7 +159,7 @@ shared_ptr Slot::combine(shared_ptr item) } else { - result = Recipes::getInstance()->getItemFor(craftSlots, NULL); + result = Recipes::getInstance()->getItemFor(craftSlots, nullptr); } craftSlots->setItem(0, nullptr); -- cgit v1.2.3