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/Recipes.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'Minecraft.World/Recipes.cpp') diff --git a/Minecraft.World/Recipes.cpp b/Minecraft.World/Recipes.cpp index ce026359..24faaebe 100644 --- a/Minecraft.World/Recipes.cpp +++ b/Minecraft.World/Recipes.cpp @@ -8,15 +8,15 @@ #include "net.minecraft.world.level.tile.h" #include "net.minecraft.world.item.crafting.h" -Recipes *Recipes::instance = NULL; -ArmorRecipes *Recipes::pArmorRecipes=NULL; -ClothDyeRecipes *Recipes::pClothDyeRecipes=NULL; -FoodRecipies *Recipes::pFoodRecipies=NULL; -OreRecipies *Recipes::pOreRecipies=NULL; -StructureRecipies *Recipes::pStructureRecipies=NULL; -ToolRecipies *Recipes::pToolRecipies=NULL; -WeaponRecipies *Recipes::pWeaponRecipies=NULL; -FireworksRecipe *Recipes::pFireworksRecipes=NULL; +Recipes *Recipes::instance = nullptr; +ArmorRecipes *Recipes::pArmorRecipes=nullptr; +ClothDyeRecipes *Recipes::pClothDyeRecipes=nullptr; +FoodRecipies *Recipes::pFoodRecipies=nullptr; +OreRecipies *Recipes::pOreRecipies=nullptr; +StructureRecipies *Recipes::pStructureRecipies=nullptr; +ToolRecipies *Recipes::pToolRecipies=nullptr; +WeaponRecipies *Recipes::pWeaponRecipies=nullptr; +FireworksRecipe *Recipes::pFireworksRecipes=nullptr; void Recipes::staticCtor() { @@ -950,7 +950,7 @@ Recipes::Recipes() L'D'); // 4J - TODO - put these new 1.7.3 items in required place within recipes - addShapedRecipy(new ItemInstance((Tile *)Tile::pistonBase, 1), // + addShapedRecipy(new ItemInstance(static_cast(Tile::pistonBase), 1), // L"sssctcicictg", L"TTT", // L"#X#", // @@ -959,7 +959,7 @@ Recipes::Recipes() L'#', Tile::cobblestone, L'X', Item::ironIngot, L'R', Item::redStone, L'T', Tile::wood, L'M'); - addShapedRecipy(new ItemInstance((Tile *)Tile::pistonStickyBase, 1), // + addShapedRecipy(new ItemInstance(static_cast(Tile::pistonStickyBase), 1), // L"sscictg", L"S", // L"P", // @@ -1042,7 +1042,7 @@ ShapedRecipy *Recipes::addShapedRecipy(ItemInstance *result, ...) Item *pItem; wchar_t wchFrom; int iCount; - ItemInstance **ids = NULL; + ItemInstance **ids = nullptr; myMap *mappings = new unordered_map(); @@ -1072,14 +1072,14 @@ ShapedRecipy *Recipes::addShapedRecipy(ItemInstance *result, ...) pwchString=va_arg(vl,wchar_t *); wString=pwchString; height++; - width = (int)wString.length(); + width = static_cast(wString.length()); map += wString; break; case L's': pwchString=va_arg(vl,wchar_t *); wString=pwchString; height++; - width = (int)wString.length(); + width = static_cast(wString.length()); map += wString; break; case L'w': @@ -1091,7 +1091,7 @@ ShapedRecipy *Recipes::addShapedRecipy(ItemInstance *result, ...) if(!wString.empty()) { height++; - width = (int)wString.length(); + width = static_cast(wString.length()); map += wString; } } @@ -1163,7 +1163,7 @@ ShapedRecipy *Recipes::addShapedRecipy(ItemInstance *result, ...) } else { - ids[j] = NULL; + ids[j] = nullptr; } } } @@ -1248,7 +1248,7 @@ void Recipes::addShapelessRecipy(ItemInstance *result,... ) recipies->push_back(new ShapelessRecipy(result, ingredients, group)); } -shared_ptr Recipes::getItemFor(shared_ptr craftSlots, Level *level, Recipy *recipesClass /*= NULL*/) +shared_ptr Recipes::getItemFor(shared_ptr craftSlots, Level *level, Recipy *recipesClass /*= nullptr*/) { int count = 0; shared_ptr first = nullptr; @@ -1256,7 +1256,7 @@ shared_ptr Recipes::getItemFor(shared_ptr craft for (int i = 0; i < craftSlots->getContainerSize(); i++) { shared_ptr item = craftSlots->getItem(i); - if (item != NULL) + if (item != nullptr) { if (count == 0) first = item; if (count == 1) second = item; @@ -1272,10 +1272,10 @@ shared_ptr Recipes::getItemFor(shared_ptr craft int remaining = (remaining1 + remaining2) + item->getMaxDamage() * 5 / 100; int resultDamage = item->getMaxDamage() - remaining; if (resultDamage < 0) resultDamage = 0; - return shared_ptr( new ItemInstance(first->id, 1, resultDamage) ); + return std::make_shared(first->id, 1, resultDamage); } - if(recipesClass != NULL) + if(recipesClass != nullptr) { if (recipesClass->matches(craftSlots, level)) return recipesClass->assemble(craftSlots); } @@ -1305,7 +1305,7 @@ void Recipes::buildRecipeIngredientsArray(void) { //RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - int iRecipeC=(int)recipies->size(); + int iRecipeC=static_cast(recipies->size()); m_pRecipeIngredientsRequired= new Recipy::INGREDIENTS_REQUIRED [iRecipeC]; -- cgit v1.2.3