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 --- .../Common/UI/UIScene_AbstractContainerMenu.cpp | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp') diff --git a/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp index 7001ab81..0c3b6096 100644 --- a/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_AbstractContainerMenu.cpp @@ -50,15 +50,15 @@ void UIScene_AbstractContainerMenu::handleDestroy() #endif Minecraft *pMinecraft = Minecraft::GetInstance(); - if( pMinecraft->localgameModes[m_iPad] != NULL ) + if( pMinecraft->localgameModes[m_iPad] != nullptr ) { - TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; - if(gameMode != NULL) gameMode->getTutorial()->changeTutorialState(m_previousTutorialState); + TutorialMode *gameMode = static_cast(pMinecraft->localgameModes[m_iPad]); + if(gameMode != nullptr) gameMode->getTutorial()->changeTutorialState(m_previousTutorialState); } // 4J Stu - Fix for #11302 - TCR 001: Network Connectivity: Host crashed after being killed by the client while accessing a chest during burst packet loss. // We need to make sure that we call closeContainer() anytime this menu is closed, even if it is forced to close by some other reason (like the player dying) - if(pMinecraft->localplayers[m_iPad] != NULL && pMinecraft->localplayers[m_iPad]->containerMenu->containerId == m_menu->containerId) + if(pMinecraft->localplayers[m_iPad] != nullptr && pMinecraft->localplayers[m_iPad]->containerMenu->containerId == m_menu->containerId) { pMinecraft->localplayers[m_iPad]->closeContainer(); } @@ -150,8 +150,8 @@ void UIScene_AbstractContainerMenu::PlatformInitialize(int iPad, int startIndex) m_fPointerMaxX = m_fPanelMaxX + fPointerWidth; m_fPointerMaxY = m_fPanelMaxY + (fPointerHeight/2); -// m_hPointerText=NULL; -// m_hPointerTextBkg=NULL; +// m_hPointerText=nullptr; +// m_hPointerTextBkg=nullptr; // Put the pointer over first item in use row to start with. UIVec2D itemPos; @@ -193,8 +193,8 @@ void UIScene_AbstractContainerMenu::PlatformInitialize(int iPad, int startIndex) if(vp != C4JRender::VIEWPORT_TYPE_FULLSCREEN) Fit16x9(width, height); - S32 x = m_pointerPos.x*((float)width/m_movieWidth); - S32 y = m_pointerPos.y*((float)height/m_movieHeight); + S32 x = m_pointerPos.x*(static_cast(width)/m_movieWidth); + S32 y = m_pointerPos.y*(static_cast(height)/m_movieHeight); IggyMakeEventMouseMove( &mouseEvent, x, y); IggyEventResult result; @@ -222,8 +222,8 @@ void UIScene_AbstractContainerMenu::tick() if(vp != C4JRender::VIEWPORT_TYPE_FULLSCREEN) Fit16x9(width, height); - S32 x = (S32)(m_pointerPos.x * ((float)width / m_movieWidth)); - S32 y = (S32)(m_pointerPos.y * ((float)height / m_movieHeight)); + S32 x = static_cast(m_pointerPos.x * (static_cast(width) / m_movieWidth)); + S32 y = static_cast(m_pointerPos.y * (static_cast(height) / m_movieHeight)); IggyMakeEventMouseMove( &mouseEvent, x, y); @@ -278,14 +278,14 @@ void UIScene_AbstractContainerMenu::getMouseToSWFScale(float &scaleX, float &sca float screenW = (float)ui.getScreenWidth(); float screenH = (float)ui.getScreenHeight(); - scaleX = (float)m_movieWidth * screenW / ((float)renderW * (float)winW); - scaleY = (float)m_movieHeight * screenH / ((float)renderH * (float)winH); + scaleX = static_cast(m_movieWidth) * screenW / (static_cast(renderW) * static_cast(winW)); + scaleY = static_cast(m_movieHeight) * screenH / (static_cast(renderH) * static_cast(winH)); } void UIScene_AbstractContainerMenu::customDraw(IggyCustomDrawCallbackRegion *region) { Minecraft *pMinecraft = Minecraft::GetInstance(); - if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return; + if(pMinecraft->localplayers[m_iPad] == nullptr || pMinecraft->localgameModes[m_iPad] == nullptr) return; shared_ptr item = nullptr; int slotId = -1; @@ -296,7 +296,7 @@ void UIScene_AbstractContainerMenu::customDraw(IggyCustomDrawCallbackRegion *reg } else { - swscanf((wchar_t*)region->name,L"slot_%d",&slotId); + swscanf(static_cast(region->name),L"slot_%d",&slotId); if (slotId == -1) { app.DebugPrintf("This is not the control we are looking for\n"); @@ -309,7 +309,7 @@ void UIScene_AbstractContainerMenu::customDraw(IggyCustomDrawCallbackRegion *reg } } - if(item != NULL) customDrawSlotControl(region,m_iPad,item,m_menu->isValidIngredient(item, slotId)?1.0f:0.5f,item->isFoil(),true); + if(item != nullptr) customDrawSlotControl(region,m_iPad,item,m_menu->isValidIngredient(item, slotId)?1.0f:0.5f,item->isFoil(),true); } void UIScene_AbstractContainerMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) @@ -368,7 +368,7 @@ Slot *UIScene_AbstractContainerMenu::getSlot(ESceneSection eSection, int iSlot) { Slot *slot = m_menu->getSlot( getSectionStartOffset(eSection) + iSlot ); if(slot) return slot; - else return NULL; + else return nullptr; } bool UIScene_AbstractContainerMenu::isSlotEmpty(ESceneSection eSection, int iSlot) -- cgit v1.2.3