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.Client/LivingEntityRenderer.cpp | 54 ++++++++++++++++++------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'Minecraft.Client/LivingEntityRenderer.cpp') diff --git a/Minecraft.Client/LivingEntityRenderer.cpp b/Minecraft.Client/LivingEntityRenderer.cpp index 757948a3..b3478ba9 100644 --- a/Minecraft.Client/LivingEntityRenderer.cpp +++ b/Minecraft.Client/LivingEntityRenderer.cpp @@ -17,7 +17,7 @@ LivingEntityRenderer::LivingEntityRenderer(Model *model, float shadow) { this->model = model; shadowRadius = shadow; - armor = NULL; + armor = nullptr; } void LivingEntityRenderer::setArmor(Model *armor) @@ -37,17 +37,27 @@ float LivingEntityRenderer::rotlerp(float from, float to, float a) void LivingEntityRenderer::render(shared_ptr _mob, double x, double y, double z, float rot, float a) { + if (_mob == nullptr) + { + return; + } + shared_ptr mob = dynamic_pointer_cast(_mob); + if (mob == nullptr) + { + return; + } + glPushMatrix(); glDisable(GL_CULL_FACE); model->attackTime = getAttackAnim(mob, a); - if (armor != NULL) armor->attackTime = model->attackTime; + if (armor != nullptr) armor->attackTime = model->attackTime; model->riding = mob->isRiding(); - if (armor != NULL) armor->riding = model->riding; + if (armor != nullptr) armor->riding = model->riding; model->young = mob->isBaby(); - if (armor != NULL) armor->young = model->young; + if (armor != nullptr) armor->young = model->young; /*try*/ { @@ -259,7 +269,7 @@ void LivingEntityRenderer::renderModel(shared_ptr mob, float wp, f void LivingEntityRenderer::setupPosition(shared_ptr mob, double x, double y, double z) { - glTranslatef((float) x, (float) y, (float) z); + glTranslatef(static_cast(x), static_cast(y), static_cast(z)); } void LivingEntityRenderer::setupRotations(shared_ptr mob, float bob, float bodyRot, float a) @@ -306,7 +316,7 @@ void LivingEntityRenderer::renderArrows(shared_ptr mob, float a) int arrowCount = mob->getArrowCount(); if (arrowCount > 0) { - shared_ptr arrow = shared_ptr(new Arrow(mob->level, mob->x, mob->y, mob->z)); + shared_ptr arrow = std::make_shared(mob->level, mob->x, mob->y, mob->z); Random random = Random(mob->entityId); Lighting::turnOff(); for (int i = 0; i < arrowCount; i++) @@ -405,7 +415,7 @@ void LivingEntityRenderer::renderName(shared_ptr mob, double x, do Font *font = getFont(); glPushMatrix(); - glTranslatef((float) x + 0, (float) y + mob->bbHeight + 0.5f, (float) z); + glTranslatef(static_cast(x) + 0, static_cast(y) + mob->bbHeight + 0.5f, static_cast(z)); glNormal3f(0, 1, 0); glRotatef(-entityRenderDispatcher->playerRotY, 0, 1, 0); @@ -448,7 +458,7 @@ void LivingEntityRenderer::renderName(shared_ptr mob, double x, do bool LivingEntityRenderer::shouldShowName(shared_ptr mob) { - return Minecraft::renderNames() && mob != entityRenderDispatcher->cameraEntity && !mob->isInvisibleTo(Minecraft::GetInstance()->player) && mob->rider.lock() == NULL; + return Minecraft::renderNames() && mob != entityRenderDispatcher->cameraEntity && !mob->isInvisibleTo(Minecraft::GetInstance()->player) && mob->rider.lock() == nullptr; } void LivingEntityRenderer::renderNameTags(shared_ptr mob, double x, double y, double z, const wstring &msg, float scale, double dist) @@ -595,10 +605,10 @@ void LivingEntityRenderer::renderNameTag(shared_ptr mob, const wst { t->color(0.0f, 0.0f, 0.0f, 0.25f); } - t->vertex((float)(-w - 1), (float)( -1 + offs), (float)( 0)); - t->vertex((float)(-w - 1), (float)( +8 + offs + 1), (float)( 0)); - t->vertex((float)(+w + 1), (float)( +8 + offs + 1), (float)( 0)); - t->vertex((float)(+w + 1), (float)( -1 + offs), (float)( 0)); + t->vertex(static_cast(-w - 1), static_cast(-1 + offs), static_cast(0)); + t->vertex(static_cast(-w - 1), static_cast(+8 + offs + 1), static_cast(0)); + t->vertex(static_cast(+w + 1), static_cast(+8 + offs + 1), static_cast(0)); + t->vertex(static_cast(+w + 1), static_cast(-1 + offs), static_cast(0)); t->end(); glEnable(GL_DEPTH_TEST); @@ -607,11 +617,11 @@ void LivingEntityRenderer::renderNameTag(shared_ptr mob, const wst glLineWidth(2.0f); t->begin(GL_LINE_STRIP); t->color(color, 255 * textOpacity); - t->vertex((float)(-w - 1), (float)( -1 + offs), (float)( 0)); - t->vertex((float)(-w - 1), (float)( +8 + offs + 1), (float)( 0)); - t->vertex((float)(+w + 1), (float)( +8 + offs + 1), (float)( 0)); - t->vertex((float)(+w + 1), (float)( -1 + offs), (float)( 0)); - t->vertex((float)(-w - 1), (float)( -1 + offs), (float)( 0)); + t->vertex(static_cast(-w - 1), static_cast(-1 + offs), static_cast(0)); + t->vertex(static_cast(-w - 1), static_cast(+8 + offs + 1), static_cast(0)); + t->vertex(static_cast(+w + 1), static_cast(+8 + offs + 1), static_cast(0)); + t->vertex(static_cast(+w + 1), static_cast(-1 + offs), static_cast(0)); + t->vertex(static_cast(-w - 1), static_cast(-1 + offs), static_cast(0)); t->end(); glDepthFunc(GL_LEQUAL); glDepthMask(false); @@ -632,10 +642,10 @@ void LivingEntityRenderer::renderNameTag(shared_ptr mob, const wst t->begin(); int w = font->width(playerName) / 2; t->color(color, 255); - t->vertex((float)(-w - 1), (float)( -1 + offs), (float)( 0)); - t->vertex((float)(-w - 1), (float)( +8 + offs), (float)( 0)); - t->vertex((float)(+w + 1), (float)( +8 + offs), (float)( 0)); - t->vertex((float)(+w + 1), (float)( -1 + offs), (float)( 0)); + t->vertex(static_cast(-w - 1), static_cast(-1 + offs), static_cast(0)); + t->vertex(static_cast(-w - 1), static_cast(+8 + offs), static_cast(0)); + t->vertex(static_cast(+w + 1), static_cast(+8 + offs), static_cast(0)); + t->vertex(static_cast(+w + 1), static_cast(-1 + offs), static_cast(0)); t->end(); glDepthFunc(GL_LEQUAL); glEnable(GL_TEXTURE_2D); @@ -645,7 +655,7 @@ void LivingEntityRenderer::renderNameTag(shared_ptr mob, const wst if( textOpacity > 0.0f ) { - int textColor = ( ( (int)(textOpacity*255) << 24 ) | 0xffffff ); + int textColor = ( ( static_cast(textOpacity * 255) << 24 ) | 0xffffff ); font->draw(playerName, -font->width(playerName) / 2, offs, textColor); } -- cgit v1.2.3