From e887c8cf453566fe030a15de5532e799bf47a476 Mon Sep 17 00:00:00 2001 From: orng Date: Thu, 26 Mar 2026 13:29:05 -0500 Subject: [PATCH] refactor: remove calls to `Vec3::newTemp` and `Vec3::newPermanent` --- Minecraft.Client/Level/ServerLevel.cpp | 6 +- .../ApplySchematicRuleDefinition.cpp | 2 +- .../Common/GameRules/ConsoleSchematicFile.cpp | 2 +- .../Common/Tutorial/AreaConstraint.cpp | 4 +- .../Platform/Common/Tutorial/AreaHint.cpp | 4 +- .../Common/Tutorial/ChangeStateConstraint.cpp | 5 +- .../Common/UI/UIScene_DebugSetCamera.cpp | 8 +- Minecraft.Client/Player/LocalPlayer.cpp | 14 +- Minecraft.Client/Rendering/Camera.cpp | 13 +- Minecraft.Client/Rendering/Camera.h | 4 +- .../EntityRenderers/MinecartRenderer.cpp | 13 +- .../EntityRenderers/TileRenderer.cpp | 185 +++++++++--------- Minecraft.Client/Rendering/GameRenderer.cpp | 54 ++--- Minecraft.Client/Rendering/LevelRenderer.cpp | 34 ++-- Minecraft.Client/Rendering/Vertex.cpp | 2 +- Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp | 6 +- Minecraft.World/AI/Goals/FleeSunGoal.cpp | 13 +- Minecraft.World/AI/Goals/FleeSunGoal.h | 7 +- Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp | 4 +- .../AI/Goals/MoveThroughVillageGoal.cpp | 4 +- .../AI/Goals/MoveTowardsRestrictionGoal.cpp | 4 +- .../AI/Goals/MoveTowardsTargetGoal.cpp | 4 +- Minecraft.World/AI/Goals/PanicGoal.cpp | 6 +- Minecraft.World/AI/Goals/PlayGoal.cpp | 8 +- Minecraft.World/AI/Goals/RandomStrollGoal.cpp | 10 +- .../AI/Goals/RunAroundLikeCrazyGoal.cpp | 6 +- Minecraft.World/AI/Navigation/Path.cpp | 12 +- Minecraft.World/AI/Navigation/Path.h | 6 +- .../AI/Navigation/PathNavigation.cpp | 38 ++-- .../AI/Navigation/PathNavigation.h | 4 +- Minecraft.World/AI/Navigation/RandomPos.cpp | 17 +- Minecraft.World/AI/Navigation/RandomPos.h | 12 +- Minecraft.World/Blocks/LiquidTile.cpp | 34 ++-- Minecraft.World/Blocks/LiquidTile.h | 4 +- Minecraft.World/Entities/Entity.cpp | 3 +- Minecraft.World/Entities/Entity.h | 3 +- Minecraft.World/Entities/LivingEntity.cpp | 19 +- Minecraft.World/Entities/LivingEntity.h | 7 +- Minecraft.World/Entities/Mobs/EnderDragon.cpp | 36 ++-- Minecraft.World/Entities/Mobs/EnderDragon.h | 2 +- Minecraft.World/Entities/Mobs/EnderMan.cpp | 5 +- Minecraft.World/Entities/Mobs/Fireball.cpp | 5 +- Minecraft.World/Entities/Mobs/Ghast.cpp | 6 +- Minecraft.World/Entities/Mobs/Minecart.cpp | 20 +- Minecraft.World/Entities/Mobs/Minecart.h | 5 +- Minecraft.World/Entities/PathfinderMob.cpp | 9 +- Minecraft.World/Items/BoatItem.cpp | 12 +- .../Level/Dimensions/Dimension.cpp | 4 +- Minecraft.World/Level/Dimensions/Dimension.h | 2 +- .../Level/Dimensions/HellDimension.cpp | 4 +- .../Level/Dimensions/HellDimension.h | 2 +- .../Level/Dimensions/SkyIslandDimension.cpp | 6 +- .../Level/Dimensions/TheEndDimension.cpp | 4 +- .../Level/Dimensions/TheEndDimension.h | 2 +- Minecraft.World/Level/Events/VillageSiege.cpp | 18 +- Minecraft.World/Level/Events/VillageSiege.h | 6 +- Minecraft.World/Level/Explosion.cpp | 9 +- Minecraft.World/Level/Explosion.h | 6 +- Minecraft.World/Level/Level.cpp | 10 +- Minecraft.World/Level/Level.h | 6 +- Minecraft.World/Util/Vec3.cpp | 2 + .../WorldGen/Structures/Village.cpp | 14 +- Minecraft.World/WorldGen/Structures/Village.h | 5 +- 63 files changed, 407 insertions(+), 374 deletions(-) diff --git a/Minecraft.Client/Level/ServerLevel.cpp b/Minecraft.Client/Level/ServerLevel.cpp index 025190b7f..1b8ec2782 100644 --- a/Minecraft.Client/Level/ServerLevel.cpp +++ b/Minecraft.Client/Level/ServerLevel.cpp @@ -1112,13 +1112,13 @@ std::shared_ptr ServerLevel::explode(std::shared_ptr source, } if (player->distanceToSqr(x, y, z) < 64 * 64) { - Vec3* knockbackVec = explosion->getHitPlayerKnockback(player); + Vec3 knockbackVec = explosion->getHitPlayerKnockback(player); // app.DebugPrintf("Sending %s with knockback (%f,%f,%f)\n", // knockbackOnly?"knockbackOnly":"allExplosion",knockbackVec->x,knockbackVec->y,knockbackVec->z); // If the player is not the primary on the system, then we only // want to send info for the knockback player->connection->send(std::shared_ptr( - new ExplodePacket(x, y, z, r, &explosion->toBlow, knockbackVec, + new ExplodePacket(x, y, z, r, &explosion->toBlow, &knockbackVec, knockbackOnly))); sentTo.push_back(player); } @@ -1584,4 +1584,4 @@ void ServerLevel::flagEntitiesToBeRemoved(unsigned int* flags, if (chunkMap) { chunkMap->flagEntitiesToBeRemoved(flags, removedFound); } -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp index 9139bfce7..c7b2c0230 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp @@ -12,7 +12,7 @@ ApplySchematicRuleDefinition::ApplySchematicRuleDefinition( LevelGenerationOptions* levelGenOptions) { m_levelGenOptions = levelGenOptions; - m_location = Vec3::newPermanent(0, 0, 0); + m_location = new Vec3(0, 0, 0); m_locationBox = NULL; m_totalBlocksChanged = 0; m_totalBlocksChangedLighting = 0; diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index 62476d8ab..b9fec3328 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -156,7 +156,7 @@ void ConsoleSchematicFile::load(DataInputStream* dis) { // (%f,%f,%f)\n",(int)type,x,y,z); #endif m_entities.push_back(std::pair( - Vec3::newPermanent(x, y, z), (CompoundTag*)eTag->copy())); + new Vec3(x, y, z), (CompoundTag*)eTag->copy())); } } delete tag; diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp index 2057080b5..016cc71ff 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaConstraint.cpp @@ -25,8 +25,8 @@ AreaConstraint::~AreaConstraint() { bool AreaConstraint::isConstraintSatisfied(int iPad) { Minecraft* minecraft = Minecraft::GetInstance(); - return messageArea->contains(minecraft->localplayers[iPad]->getPos(1)) == - contains; + Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1); + return messageArea->contains(&ipad_player) == contains; } bool AreaConstraint::isConstraintRestrictive(int iPad) { diff --git a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp index 729b361d0..ced909db9 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/AreaHint.cpp @@ -24,10 +24,12 @@ AreaHint::~AreaHint() { delete area; } int AreaHint::tick() { Minecraft* minecraft = Minecraft::GetInstance(); + Vec3 player_pos = minecraft->player->getPos(1); + if ((m_displayState == e_Tutorial_State_Any || m_tutorial->getCurrentState() == m_displayState) && m_hintNeeded && - area->contains(minecraft->player->getPos(1)) == contains) { + area->contains(&player_pos) == contains) { if (m_completeState == e_Tutorial_State_None) { m_hintNeeded = false; } else if (m_tutorial->isStateCompleted(m_completeState)) { diff --git a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp index 9d8d75e1d..252d85f7d 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/ChangeStateConstraint.cpp @@ -85,8 +85,9 @@ void ChangeStateConstraint::tick(int iPad) { break; } } + Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1); if (!m_bHasChanged && inASourceState && - movementArea->contains(minecraft->localplayers[iPad]->getPos(1)) == + movementArea->contains(&ipad_player) == contains) { m_bHasChanged = true; m_changedFromState = m_tutorial->getCurrentState(); @@ -126,7 +127,7 @@ void ChangeStateConstraint::tick(int iPad) { } } else if (m_bHasChanged && movementArea->contains( - minecraft->localplayers[iPad]->getPos(1)) != contains) { + &ipad_player) != contains) { m_bHasChanged = false; m_tutorial->changeTutorialState(m_changedFromState); diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_DebugSetCamera.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_DebugSetCamera.cpp index 89e872eb9..af850cb67 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_DebugSetCamera.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_DebugSetCamera.cpp @@ -19,13 +19,13 @@ UIScene_DebugSetCamera::UIScene_DebugSetCamera(int iPad, void* initData, Minecraft* pMinecraft = Minecraft::GetInstance(); if (pMinecraft != NULL) { - Vec3* vec = pMinecraft->localplayers[playerNo]->getPos(1.0); + Vec3 vec = pMinecraft->localplayers[playerNo]->getPos(1.0); - currentPosition->m_camX = vec->x; + currentPosition->m_camX = vec.x; currentPosition->m_camY = - vec->y - + vec.y - 1.62; // pMinecraft->localplayers[playerNo]->getHeadHeight(); - currentPosition->m_camZ = vec->z; + currentPosition->m_camZ = vec.z; currentPosition->m_yRot = pMinecraft->localplayers[playerNo]->yRot; currentPosition->m_elev = pMinecraft->localplayers[playerNo]->xRot; diff --git a/Minecraft.Client/Player/LocalPlayer.cpp b/Minecraft.Client/Player/LocalPlayer.cpp index f264a55af..1f6e17a08 100644 --- a/Minecraft.Client/Player/LocalPlayer.cpp +++ b/Minecraft.Client/Player/LocalPlayer.cpp @@ -404,25 +404,25 @@ void LocalPlayer::aiStep() { if (abilities.flying) // minecraft->options->isFlying ) { - Vec3* viewVector = getViewVector(1.0f); + Vec3 viewVector = getViewVector(1.0f); // 4J-PB - To let the player build easily while flying, we need to // change this #ifdef _DEBUG_MENUS_ENABLED if (abilities.debugflying) { - flyX = (float)viewVector->x * input->ya; - flyY = (float)viewVector->y * input->ya; - flyZ = (float)viewVector->z * input->ya; + flyX = (float)viewVector.x * input->ya; + flyY = (float)viewVector.y * input->ya; + flyZ = (float)viewVector.z * input->ya; } else #endif { if (isSprinting()) { // Accelrate up to full speed if we are sprinting, moving in the // direction of the view vector - flyX = (float)viewVector->x * input->ya; - flyY = (float)viewVector->y * input->ya; - flyZ = (float)viewVector->z * input->ya; + flyX = (float)viewVector.x * input->ya; + flyY = (float)viewVector.y * input->ya; + flyZ = (float)viewVector.z * input->ya; float scale = ((float)(SPRINT_DURATION - sprintTime)) / 10.0f; scale = scale * scale; diff --git a/Minecraft.Client/Rendering/Camera.cpp b/Minecraft.Client/Rendering/Camera.cpp index fdfbb1dad..f728f3f09 100644 --- a/Minecraft.Client/Rendering/Camera.cpp +++ b/Minecraft.Client/Rendering/Camera.cpp @@ -91,10 +91,11 @@ zPlayerOffs = position->get(2); TilePos* Camera::getCameraTilePos(std::shared_ptr player, double alpha) { - return new TilePos(getCameraPos(player, alpha)); + Vec3 cam_pos = getCameraPos(player, alpha); + return new TilePos(&cam_pos); } -Vec3* Camera::getCameraPos(std::shared_ptr player, double alpha) { +Vec3 Camera::getCameraPos(std::shared_ptr player, double alpha) { double xx = player->xo + (player->x - player->xo) * alpha; double yy = player->yo + (player->y - player->yo) * alpha + player->getHeadHeight(); @@ -104,19 +105,19 @@ Vec3* Camera::getCameraPos(std::shared_ptr player, double alpha) { double yt = yy + Camera::yPlayerOffs * 1; double zt = zz + Camera::zPlayerOffs * 1; - return Vec3::newTemp(xt, yt, zt); + return Vec3(xt, yt, zt); } int Camera::getBlockAt(Level* level, std::shared_ptr player, float alpha) { - Vec3* p = Camera::getCameraPos(player, alpha); - TilePos tp = TilePos(p); + Vec3 p = Camera::getCameraPos(player, alpha); + TilePos tp = TilePos(&p); int t = level->getTile(tp.x, tp.y, tp.z); if (t != 0 && Tile::tiles[t]->material->isLiquid()) { float hh = LiquidTile::getHeight(level->getData(tp.x, tp.y, tp.z)) - 1 / 9.0f; float h = tp.y + 1 - hh; - if (p->y >= h) { + if (p.y >= h) { t = level->getTile(tp.x, tp.y + 1, tp.z); } } diff --git a/Minecraft.Client/Rendering/Camera.h b/Minecraft.Client/Rendering/Camera.h index ce2dcb6ce..4ce2d8419 100644 --- a/Minecraft.Client/Rendering/Camera.h +++ b/Minecraft.Client/Rendering/Camera.h @@ -26,8 +26,8 @@ public: static TilePos* getCameraTilePos(std::shared_ptr player, double alpha); - static Vec3* getCameraPos(std::shared_ptr player, + static Vec3 getCameraPos(std::shared_ptr player, double alpha); static int getBlockAt(Level* level, std::shared_ptr player, float alpha); -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp index f5ed5b766..5868a654e 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/MinecartRenderer.cpp @@ -1,5 +1,6 @@ #include "../../Platform/stdafx.h" #include "MinecartRenderer.h" +#include #include "../Models/MinecartModel.h" #include "../../Textures/TextureAtlas.h" #include "../../../Minecraft.World/Headers/net.minecraft.world.entity.item.h" @@ -40,15 +41,15 @@ void MinecartRenderer::render(std::shared_ptr _cart, double x, double y, double r = 0.3f; - Vec3* p = cart->getPos(xx, yy, zz); + std::optional p = cart->getPos(xx, yy, zz); float xRot = cart->xRotO + (cart->xRot - cart->xRotO) * a; - if (p != NULL) { - Vec3* p0 = cart->getPosOffs(xx, yy, zz, r); - Vec3* p1 = cart->getPosOffs(xx, yy, zz, -r); - if (p0 == NULL) p0 = p; - if (p1 == NULL) p1 = p; + if (p.has_value()) { + auto p0 = cart->getPosOffs(xx, yy, zz, r); + auto p1 = cart->getPosOffs(xx, yy, zz, -r); + if (!p0.has_value()) p0 = p; + if (!p1.has_value()) p1 = p; x += p->x - xx; y += (p0->y + p1->y) / 2 - yy; diff --git a/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp index 08ae72935..3ee4ff71a 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp @@ -1,6 +1,7 @@ #include "../../Platform/stdafx.h" #include "TileRenderer.h" +#include #include "../GameRenderer.h" #include "../../Minecraft.h" #include "../../Textures/Textures.h" @@ -1817,58 +1818,58 @@ bool TileRenderer::tesselateLeverInWorld(Tile* tt, int x, int y, int z) { float u1 = tex->getU1(true); float v1 = tex->getV1(true); - Vec3* corners[8]; + std::array corners; float xv = 1.0f / 16.0f; float zv = 1.0f / 16.0f; float yv = 10.0f / 16.0f; - corners[0] = Vec3::newTemp(-xv, -0, -zv); - corners[1] = Vec3::newTemp(+xv, -0, -zv); - corners[2] = Vec3::newTemp(+xv, -0, +zv); - corners[3] = Vec3::newTemp(-xv, -0, +zv); - corners[4] = Vec3::newTemp(-xv, +yv, -zv); - corners[5] = Vec3::newTemp(+xv, +yv, -zv); - corners[6] = Vec3::newTemp(+xv, +yv, +zv); - corners[7] = Vec3::newTemp(-xv, +yv, +zv); + corners[0] = Vec3(-xv, -0, -zv); + corners[1] = Vec3(+xv, -0, -zv); + corners[2] = Vec3(+xv, -0, +zv); + corners[3] = Vec3(-xv, -0, +zv); + corners[4] = Vec3(-xv, +yv, -zv); + corners[5] = Vec3(+xv, +yv, -zv); + corners[6] = Vec3(+xv, +yv, +zv); + corners[7] = Vec3(-xv, +yv, +zv); for (int i = 0; i < 8; i++) { if (flipped) { - corners[i]->z -= 1 / 16.0f; - corners[i]->xRot(40 * PI / 180); + corners[i].z -= 1 / 16.0f; + corners[i].xRot(40 * PI / 180); } else { - corners[i]->z += 1 / 16.0f; - corners[i]->xRot(-40 * PI / 180); + corners[i].z += 1 / 16.0f; + corners[i].xRot(-40 * PI / 180); } if (dir == 0 || dir == 7) { - corners[i]->zRot(180 * PI / 180); + corners[i].zRot(180 * PI / 180); } if (dir == 6 || dir == 0) { - corners[i]->yRot(90 * PI / 180); + corners[i].yRot(90 * PI / 180); } if (dir > 0 && dir < 5) { - corners[i]->y -= 6 / 16.0f; - corners[i]->xRot(90 * PI / 180); + corners[i].y -= 6 / 16.0f; + corners[i].xRot(90 * PI / 180); - if (dir == 4) corners[i]->yRot(0 * PI / 180); - if (dir == 3) corners[i]->yRot(180 * PI / 180); - if (dir == 2) corners[i]->yRot(90 * PI / 180); - if (dir == 1) corners[i]->yRot(-90 * PI / 180); + if (dir == 4) corners[i].yRot(0 * PI / 180); + if (dir == 3) corners[i].yRot(180 * PI / 180); + if (dir == 2) corners[i].yRot(90 * PI / 180); + if (dir == 1) corners[i].yRot(-90 * PI / 180); - corners[i]->x += x + 0.5; - corners[i]->y += y + 8 / 16.0f; - corners[i]->z += z + 0.5; + corners[i].x += x + 0.5; + corners[i].y += y + 8 / 16.0f; + corners[i].z += z + 0.5; } else if (dir == 0 || dir == 7) { - corners[i]->x += x + 0.5; - corners[i]->y += y + 14 / 16.0f; - corners[i]->z += z + 0.5; + corners[i].x += x + 0.5; + corners[i].y += y + 14 / 16.0f; + corners[i].z += z + 0.5; } else { - corners[i]->x += x + 0.5; - corners[i]->y += y + 2 / 16.0f; - corners[i]->z += z + 0.5; + corners[i].x += x + 0.5; + corners[i].y += y + 2 / 16.0f; + corners[i].z += z + 0.5; } } - Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL; + Vec3 c0, c1, c2, c3; for (int i = 0; i < 6; i++) { if (i == 0) { u0 = tex->getU(7, true); @@ -1912,13 +1913,13 @@ bool TileRenderer::tesselateLeverInWorld(Tile* tt, int x, int y, int z) { c2 = corners[7]; c3 = corners[4]; } - t->vertexUV((float)(c0->x), (float)(c0->y), (float)(c0->z), (float)(u0), + t->vertexUV((float)(c0.x), (float)(c0.y), (float)(c0.z), (float)(u0), (float)(v1)); - t->vertexUV((float)(c1->x), (float)(c1->y), (float)(c1->z), (float)(u1), + t->vertexUV((float)(c1.x), (float)(c1.y), (float)(c1.z), (float)(u1), (float)(v1)); - t->vertexUV((float)(c2->x), (float)(c2->y), (float)(c2->z), (float)(u1), + t->vertexUV((float)(c2.x), (float)(c2.y), (float)(c2.z), (float)(u1), (float)(v0)); - t->vertexUV((float)(c3->x), (float)(c3->y), (float)(c3->z), (float)(u0), + t->vertexUV((float)(c3.x), (float)(c3.y), (float)(c3.z), (float)(u0), (float)(v0)); } return true; @@ -1976,46 +1977,46 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y, double u1 = tex->getU1(); double v1 = tex->getV1(); - Vec3* corners[8]; + std::array corners; float stickWidth = 0.75f / 16.0f; float stickHeight = 0.75f / 16.0f; float stickLength = 5 / 16.0f; - corners[0] = Vec3::newTemp(-stickWidth, -0, -stickHeight); - corners[1] = Vec3::newTemp(+stickWidth, -0, -stickHeight); - corners[2] = Vec3::newTemp(+stickWidth, -0, +stickHeight); - corners[3] = Vec3::newTemp(-stickWidth, -0, +stickHeight); - corners[4] = Vec3::newTemp(-stickWidth, +stickLength, -stickHeight); - corners[5] = Vec3::newTemp(+stickWidth, +stickLength, -stickHeight); - corners[6] = Vec3::newTemp(+stickWidth, +stickLength, +stickHeight); - corners[7] = Vec3::newTemp(-stickWidth, +stickLength, +stickHeight); + corners[0] = Vec3(-stickWidth, -0, -stickHeight); + corners[1] = Vec3(+stickWidth, -0, -stickHeight); + corners[2] = Vec3(+stickWidth, -0, +stickHeight); + corners[3] = Vec3(-stickWidth, -0, +stickHeight); + corners[4] = Vec3(-stickWidth, +stickLength, -stickHeight); + corners[5] = Vec3(+stickWidth, +stickLength, -stickHeight); + corners[6] = Vec3(+stickWidth, +stickLength, +stickHeight); + corners[7] = Vec3(-stickWidth, +stickLength, +stickHeight); for (int i = 0; i < 8; i++) { - corners[i]->z += 1 / 16.0f; + corners[i].z += 1 / 16.0f; if (powered) { - corners[i]->xRot(30 * PI / 180); - corners[i]->y -= 7 / 16.0f; + corners[i].xRot(30 * PI / 180); + corners[i].y -= 7 / 16.0f; } else if (attached) { - corners[i]->xRot(5 * PI / 180); - corners[i]->y -= 7 / 16.0f; + corners[i].xRot(5 * PI / 180); + corners[i].y -= 7 / 16.0f; } else { - corners[i]->xRot(-40 * PI / 180); - corners[i]->y -= 6 / 16.0f; + corners[i].xRot(-40 * PI / 180); + corners[i].y -= 6 / 16.0f; } - corners[i]->xRot(90 * PI / 180); + corners[i].xRot(90 * PI / 180); - if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180); - if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180); - if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180); - if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180); + if (dir == Direction::NORTH) corners[i].yRot(0 * PI / 180); + if (dir == Direction::SOUTH) corners[i].yRot(180 * PI / 180); + if (dir == Direction::WEST) corners[i].yRot(90 * PI / 180); + if (dir == Direction::EAST) corners[i].yRot(-90 * PI / 180); - corners[i]->x += x + 0.5; - corners[i]->y += y + 5 / 16.0f; - corners[i]->z += z + 0.5; + corners[i].x += x + 0.5; + corners[i].y += y + 5 / 16.0f; + corners[i].z += z + 0.5; } - Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL; + Vec3 c0, c1, c2, c3; int stickX0 = 7; int stickX1 = 9; int stickY0 = 9; @@ -2061,47 +2062,47 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y, c2 = corners[7]; c3 = corners[4]; } - t->vertexUV(c0->x, c0->y, c0->z, u0, v1); - t->vertexUV(c1->x, c1->y, c1->z, u1, v1); - t->vertexUV(c2->x, c2->y, c2->z, u1, v0); - t->vertexUV(c3->x, c3->y, c3->z, u0, v0); + t->vertexUV(c0.x, c0.y, c0.z, u0, v1); + t->vertexUV(c1.x, c1.y, c1.z, u1, v1); + t->vertexUV(c2.x, c2.y, c2.z, u1, v0); + t->vertexUV(c3.x, c3.y, c3.z, u0, v0); } float hoopWidth = 1.5f / 16.0f; float hoopHeight = 1.5f / 16.0f; float hoopLength = 0.5f / 16.0f; - corners[0] = Vec3::newTemp(-hoopWidth, -0, -hoopHeight); - corners[1] = Vec3::newTemp(+hoopWidth, -0, -hoopHeight); - corners[2] = Vec3::newTemp(+hoopWidth, -0, +hoopHeight); - corners[3] = Vec3::newTemp(-hoopWidth, -0, +hoopHeight); - corners[4] = Vec3::newTemp(-hoopWidth, +hoopLength, -hoopHeight); - corners[5] = Vec3::newTemp(+hoopWidth, +hoopLength, -hoopHeight); - corners[6] = Vec3::newTemp(+hoopWidth, +hoopLength, +hoopHeight); - corners[7] = Vec3::newTemp(-hoopWidth, +hoopLength, +hoopHeight); + corners[0] = Vec3(-hoopWidth, -0, -hoopHeight); + corners[1] = Vec3(+hoopWidth, -0, -hoopHeight); + corners[2] = Vec3(+hoopWidth, -0, +hoopHeight); + corners[3] = Vec3(-hoopWidth, -0, +hoopHeight); + corners[4] = Vec3(-hoopWidth, +hoopLength, -hoopHeight); + corners[5] = Vec3(+hoopWidth, +hoopLength, -hoopHeight); + corners[6] = Vec3(+hoopWidth, +hoopLength, +hoopHeight); + corners[7] = Vec3(-hoopWidth, +hoopLength, +hoopHeight); for (int i = 0; i < 8; i++) { - corners[i]->z += 3.5f / 16.0f; + corners[i].z += 3.5f / 16.0f; if (powered) { - corners[i]->y -= 1.5 / 16.0f; - corners[i]->z -= 2.6 / 16.0f; - corners[i]->xRot(0 * PI / 180); + corners[i].y -= 1.5 / 16.0f; + corners[i].z -= 2.6 / 16.0f; + corners[i].xRot(0 * PI / 180); } else if (attached) { - corners[i]->y += 0.25 / 16.0f; - corners[i]->z -= 2.75 / 16.0f; - corners[i]->xRot(10 * PI / 180); + corners[i].y += 0.25 / 16.0f; + corners[i].z -= 2.75 / 16.0f; + corners[i].xRot(10 * PI / 180); } else { - corners[i]->xRot(50 * PI / 180); + corners[i].xRot(50 * PI / 180); } - if (dir == Direction::NORTH) corners[i]->yRot(0 * PI / 180); - if (dir == Direction::SOUTH) corners[i]->yRot(180 * PI / 180); - if (dir == Direction::WEST) corners[i]->yRot(90 * PI / 180); - if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180); + if (dir == Direction::NORTH) corners[i].yRot(0 * PI / 180); + if (dir == Direction::SOUTH) corners[i].yRot(180 * PI / 180); + if (dir == Direction::WEST) corners[i].yRot(90 * PI / 180); + if (dir == Direction::EAST) corners[i].yRot(-90 * PI / 180); - corners[i]->x += x + 0.5; - corners[i]->y += y + 5 / 16.0f; - corners[i]->z += z + 0.5; + corners[i].x += x + 0.5; + corners[i].y += y + 5 / 16.0f; + corners[i].z += z + 0.5; } int hoopX0 = 5; @@ -2149,14 +2150,14 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y, c2 = corners[7]; c3 = corners[4]; } - t->vertexUV(c0->x, c0->y, c0->z, u0, v1); - t->vertexUV(c1->x, c1->y, c1->z, u1, v1); - t->vertexUV(c2->x, c2->y, c2->z, u1, v0); - t->vertexUV(c3->x, c3->y, c3->z, u0, v0); + t->vertexUV(c0.x, c0.y, c0.z, u0, v1); + t->vertexUV(c1.x, c1.y, c1.z, u1, v1); + t->vertexUV(c2.x, c2.y, c2.z, u1, v0); + t->vertexUV(c3.x, c3.y, c3.z, u0, v0); } if (attached) { - double hoopBottomY = corners[0]->y; + double hoopBottomY = corners[0].y; float width = 0.5f / 16.0f; float top = 0.5f - (width / 2); float bottom = top + width; diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index 2938a092f..30137286f 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -90,7 +90,7 @@ GameRenderer::GameRenderer(Minecraft* mc) { tickSmoothYO = 0; lastTickA = 0; - cameraPos = Vec3::newPermanent(0.0f, 0.0f, 0.0f); + cameraPos = new Vec3(0.0f, 0.0f, 0.0f); fovOffset = 0; fovOffsetO = 0; @@ -291,7 +291,7 @@ void GameRenderer::pick(float a) { } double dist = range; - Vec3* from = mc->cameraTargetPlayer->getPos(a); + Vec3 from = mc->cameraTargetPlayer->getPos(a); if (mc->gameMode->hasFarPickRange()) { dist = range = 6; @@ -301,18 +301,18 @@ void GameRenderer::pick(float a) { } if (mc->hitResult != NULL) { - dist = mc->hitResult->pos.distanceTo(*from); + dist = mc->hitResult->pos.distanceTo(from); } - Vec3* b = mc->cameraTargetPlayer->getViewVector(a); - Vec3 to(b->x * range, b->y * range, b->z * range); - to = to.add(from->x, from->y, from->z); + Vec3 b = mc->cameraTargetPlayer->getViewVector(a); + Vec3 to(b.x * range, b.y * range, b.z * range); + to = to.add(from.x, from.y, from.z); hovered = nullptr; float overlap = 1; std::vector >* objects = mc->level->getEntities( mc->cameraTargetPlayer, mc->cameraTargetPlayer->bb - ->expand(b->x * (range), b->y * (range), b->z * (range)) + ->expand(b.x * (range), b.y * (range), b.z * (range)) ->grow(overlap, overlap, overlap)); double nearest = dist; @@ -323,14 +323,14 @@ void GameRenderer::pick(float a) { float rr = e->getPickRadius(); AABB* bb = e->bb->grow(rr, rr, rr); - HitResult* p = bb->clip(from, &to); - if (bb->contains(from)) { + HitResult* p = bb->clip(&from, &to); + if (bb->contains(&from)) { if (0 < nearest || nearest == 0) { hovered = e; nearest = 0; } } else if (p != NULL) { - double dd = from->distanceTo(p->pos); + double dd = from.distanceTo(p->pos); std::shared_ptr ridingEntity = mc->cameraTargetPlayer->riding; // 4jcraft: compare the mounted entity explicitly so riding the hit @@ -1371,10 +1371,10 @@ void GameRenderer::renderLevel(float a, int64_t until) { // storing the camera position Fix for #77745 - TU9: Content: // Gameplay: Items and mobs not belonging to end world are // disappearing when Enderdragon is damaged. - Vec3* cameraPosTemp = cameraEntity->getPos(a); - cameraPos->x = cameraPosTemp->x; - cameraPos->y = cameraPosTemp->y; - cameraPos->z = cameraPosTemp->z; + Vec3 cameraPosTemp = cameraEntity->getPos(a); + cameraPos->x = cameraPosTemp.x; + cameraPos->y = cameraPosTemp.y; + cameraPos->z = cameraPosTemp.z; levelRenderer->renderEntities(cameraPos, frustum, a); #ifdef __PSVITA__ // AP - make sure we're using the Alpha cut out effect for particles @@ -1855,21 +1855,21 @@ void GameRenderer::setupClearColor(float a) { float whiteness = 1.0f / (4 - mc->options->viewDistance); whiteness = 1 - (float)pow((double)whiteness, 0.25); - Vec3* skyColor = level->getSkyColor(mc->cameraTargetPlayer, a); - float sr = (float)skyColor->x; - float sg = (float)skyColor->y; - float sb = (float)skyColor->z; + Vec3 skyColor = level->getSkyColor(mc->cameraTargetPlayer, a); + float sr = (float)skyColor.x; + float sg = (float)skyColor.y; + float sb = (float)skyColor.z; - Vec3* fogColor = level->getFogColor(a); - fr = (float)fogColor->x; - fg = (float)fogColor->y; - fb = (float)fogColor->z; + Vec3 fogColor = level->getFogColor(a); + fr = (float)fogColor.x; + fg = (float)fogColor.y; + fb = (float)fogColor.z; if (mc->options->viewDistance < 2) { Vec3 sunAngle = Mth::sin(level->getSunAngle(a)) > 0 ? Vec3(-1, 0, 0) : Vec3(1, 0, 0); - float d = (float)player->getViewVector(a)->dot(sunAngle); + float d = (float)player->getViewVector(a).dot(sunAngle); if (d < 0) d = 0; if (d > 0) { float* c = @@ -1905,10 +1905,10 @@ void GameRenderer::setupClearColor(float a) { int t = Camera::getBlockAt(mc->level, player, a); if (isInClouds) { - Vec3* cc = level->getCloudColor(a); - fr = (float)cc->x; - fg = (float)cc->y; - fb = (float)cc->z; + Vec3 cc = level->getCloudColor(a); + fr = (float)cc.x; + fg = (float)cc.y; + fb = (float)cc.z; } else if (t != 0 && Tile::tiles[t]->material == Material::water) { float clearness = EnchantmentHelper::getOxygenBonus(player) * 0.2f; diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 2554b3532..902cee656 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -1035,10 +1035,10 @@ void LevelRenderer::renderSky(float alpha) { glDisable(GL_TEXTURE_2D); int playerIndex = mc->player->GetXboxPad(); - Vec3* sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha); - float sr = (float)sc->x; - float sg = (float)sc->y; - float sb = (float)sc->z; + Vec3 sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha); + float sr = (float)sc.x; + float sg = (float)sc.y; + float sb = (float)sc.z; if (mc->options->anaglyph3d) { float srr = (sr * 30 + sg * 59 + sb * 11) / 100; @@ -1185,7 +1185,7 @@ void LevelRenderer::renderSky(float alpha) { glColor3f(0, 0, 0); double yy = - mc->player->getPos(alpha)->y - + mc->player->getPos(alpha).y - level[playerIndex]->getHorizonHeight(); // 4J - getHorizonHeight moved // forward from 1.2.3 if (yy < 0) { @@ -1259,10 +1259,10 @@ void LevelRenderer::renderHaloRing(float alpha) { int playerIndex = mc->player->GetXboxPad(); - Vec3* sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha); - float sr = (float)sc->x; - float sg = (float)sc->y; - float sb = (float)sc->z; + Vec3 sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha); + float sr = (float)sc.x; + float sg = (float)sc.y; + float sb = (float)sc.z; // Rough lumninance calculation float Y = (sr + sr + sb + sg + sg + sg) / 6; @@ -1335,10 +1335,10 @@ void LevelRenderer::renderClouds(float alpha) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Vec3* cc = level[playerIndex]->getCloudColor(alpha); - float cr = (float)cc->x; - float cg = (float)cc->y; - float cb = (float)cc->z; + Vec3 cc = level[playerIndex]->getCloudColor(alpha); + float cr = (float)cc.x; + float cg = (float)cc.y; + float cb = (float)cc.z; if (mc->options->anaglyph3d) { float crr = (cr * 30 + cg * 59 + cb * 11) / 100; @@ -1632,10 +1632,10 @@ void LevelRenderer::renderAdvancedClouds(float alpha) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - Vec3* cc = level[playerIndex]->getCloudColor(alpha); - float cr = (float)cc->x; - float cg = (float)cc->y; - float cb = (float)cc->z; + Vec3 cc = level[playerIndex]->getCloudColor(alpha); + float cr = (float)cc.x; + float cg = (float)cc.y; + float cb = (float)cc.z; if (mc->options->anaglyph3d) { float crr = (cr * 30 + cg * 59 + cb * 11) / 100; diff --git a/Minecraft.Client/Rendering/Vertex.cpp b/Minecraft.Client/Rendering/Vertex.cpp index 0145619e5..aaf37cc93 100644 --- a/Minecraft.Client/Rendering/Vertex.cpp +++ b/Minecraft.Client/Rendering/Vertex.cpp @@ -2,7 +2,7 @@ #include "Vertex.h" Vertex::Vertex(float x, float y, float z, float u, float v) { - this->pos = Vec3::newPermanent(x, y, z); + this->pos = new Vec3(x, y, z); this->u = u; this->v = v; } diff --git a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp index ab5af98d0..59045d029 100644 --- a/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp +++ b/Minecraft.World/AI/Goals/AvoidPlayerGoal.cpp @@ -65,17 +65,17 @@ bool AvoidPlayerGoal::canUse() { } Vec3 avoid_pos(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z); - Vec3* pos = RandomPos::getPosAvoid( + auto pos = RandomPos::getPosAvoid( std::dynamic_pointer_cast(mob->shared_from_this()), 16, 7, &avoid_pos); - if (pos == NULL) return false; + if (!pos.has_value()) return false; if (toAvoid.lock()->distanceToSqr(pos->x, pos->y, pos->z) < toAvoid.lock()->distanceToSqr(mob->shared_from_this())) return false; delete path; path = pathNav->createPath(pos->x, pos->y, pos->z); if (path == NULL) return false; - if (!path->endsInXZ(pos)) return false; + if (!path->endsInXZ(&*pos)) return false; return true; } diff --git a/Minecraft.World/AI/Goals/FleeSunGoal.cpp b/Minecraft.World/AI/Goals/FleeSunGoal.cpp index 70a77fe77..fdddfd6e0 100644 --- a/Minecraft.World/AI/Goals/FleeSunGoal.cpp +++ b/Minecraft.World/AI/Goals/FleeSunGoal.cpp @@ -5,6 +5,7 @@ #include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.phys.h" #include "FleeSunGoal.h" +#include FleeSunGoal::FleeSunGoal(PathfinderMob* mob, double speedModifier) { this->mob = mob; @@ -20,8 +21,8 @@ bool FleeSunGoal::canUse() { Mth::floor(mob->z))) return false; - Vec3* pos = getHidePos(); - if (pos == NULL) return false; + auto pos = getHidePos(); + if (!pos.has_value()) return false; wantedX = pos->x; wantedY = pos->y; wantedZ = pos->z; @@ -34,7 +35,7 @@ void FleeSunGoal::start() { mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier); } -Vec3* FleeSunGoal::getHidePos() { +std::optional FleeSunGoal::getHidePos() { Random* random = mob->getRandom(); for (int i = 0; i < 10; i++) { int xt = Mth::floor(mob->x + random->nextInt(20) - 10); @@ -42,7 +43,7 @@ Vec3* FleeSunGoal::getHidePos() { int zt = Mth::floor(mob->z + random->nextInt(20) - 10); if (!level->canSeeSky(xt, yt, zt) && mob->getWalkTargetValue(xt, yt, zt) < 0) - return Vec3::newTemp(xt, yt, zt); + return Vec3(xt, yt, zt); } - return NULL; -} \ No newline at end of file + return std::nullopt; +} diff --git a/Minecraft.World/AI/Goals/FleeSunGoal.h b/Minecraft.World/AI/Goals/FleeSunGoal.h index cdd6f8612..e9cce5983 100644 --- a/Minecraft.World/AI/Goals/FleeSunGoal.h +++ b/Minecraft.World/AI/Goals/FleeSunGoal.h @@ -1,5 +1,8 @@ #pragma once +#include + +#include "../../Util/Vec3.h" #include "Goal.h" class FleeSunGoal : public Goal { @@ -17,10 +20,10 @@ public: virtual void start(); private: - Vec3* getHidePos(); + std::optional getHidePos(); public: // 4J Added override to update ai elements when loading entity from // schematics virtual void setLevel(Level* level) { this->level = level; } -}; \ No newline at end of file +}; diff --git a/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp b/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp index 6ebcef842..6451e21e4 100644 --- a/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveIndoorsGoal.cpp @@ -46,10 +46,10 @@ void MoveIndoorsGoal::start() { _doorInfo->getIndoorZ()) > 16 * 16) { Vec3 towards(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(), _doorInfo->getIndoorZ() + 0.5); - Vec3* pos = RandomPos::getPosTowards( + auto pos = RandomPos::getPosTowards( std::dynamic_pointer_cast(mob->shared_from_this()), 14, 3, &towards); - if (pos != NULL) + if (pos.has_value()) mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, 1.0f); } else mob->getNavigation()->moveTo(_doorInfo->getIndoorX() + 0.5, diff --git a/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp b/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp index 82f0308ff..03fe6795a 100644 --- a/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveThroughVillageGoal.cpp @@ -48,10 +48,10 @@ bool MoveThroughVillageGoal::canUse() { if (path != NULL) return true; Vec3 towards(_doorInfo->x, _doorInfo->y, _doorInfo->z); - Vec3* pos = RandomPos::getPosTowards( + auto pos = RandomPos::getPosTowards( std::dynamic_pointer_cast(mob->shared_from_this()), 10, 7, &towards); - if (pos == NULL) return false; + if (!pos.has_value()) return false; mob->getNavigation()->setCanOpenDoors(false); delete path; path = mob->getNavigation()->createPath(pos->x, pos->y, pos->z); diff --git a/Minecraft.World/AI/Goals/MoveTowardsRestrictionGoal.cpp b/Minecraft.World/AI/Goals/MoveTowardsRestrictionGoal.cpp index 5b8efe271..cb52d4c3b 100644 --- a/Minecraft.World/AI/Goals/MoveTowardsRestrictionGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveTowardsRestrictionGoal.cpp @@ -19,10 +19,10 @@ bool MoveTowardsRestrictionGoal::canUse() { if (mob->isWithinRestriction()) return false; Pos* toward = mob->getRestrictCenter(); Vec3 towards(toward->x, toward->y, toward->z); - Vec3* pos = RandomPos::getPosTowards( + auto pos = RandomPos::getPosTowards( std::dynamic_pointer_cast(mob->shared_from_this()), 16, 7, &towards); - if (pos == NULL) return false; + if (!pos.has_value()) return false; wantedX = pos->x; wantedY = pos->y; wantedZ = pos->z; diff --git a/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp b/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp index bc3be03d8..22babe6ca 100644 --- a/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp +++ b/Minecraft.World/AI/Goals/MoveTowardsTargetGoal.cpp @@ -21,10 +21,10 @@ bool MoveTowardsTargetGoal::canUse() { if (target.lock()->distanceToSqr(mob->shared_from_this()) > within * within) return false; Vec3 towards(target.lock()->x, target.lock()->y, target.lock()->z); - Vec3* pos = RandomPos::getPosTowards( + auto pos = RandomPos::getPosTowards( std::dynamic_pointer_cast(mob->shared_from_this()), 16, 7, &towards); - if (pos == NULL) return false; + if (!pos.has_value()) return false; wantedX = pos->x; wantedY = pos->y; wantedZ = pos->z; diff --git a/Minecraft.World/AI/Goals/PanicGoal.cpp b/Minecraft.World/AI/Goals/PanicGoal.cpp index 9c32c1c6e..a05d0fcfc 100644 --- a/Minecraft.World/AI/Goals/PanicGoal.cpp +++ b/Minecraft.World/AI/Goals/PanicGoal.cpp @@ -14,10 +14,10 @@ PanicGoal::PanicGoal(PathfinderMob* mob, double speedModifier) { bool PanicGoal::canUse() { if (mob->getLastHurtByMob() == NULL && !mob->isOnFire()) return false; - Vec3* pos = RandomPos::getPos( + auto pos = RandomPos::getPos( std::dynamic_pointer_cast(mob->shared_from_this()), 5, 4); - if (pos == NULL) return false; + if (!pos.has_value()) return false; posX = pos->x; posY = pos->y; posZ = pos->z; @@ -28,4 +28,4 @@ void PanicGoal::start() { mob->getNavigation()->moveTo(posX, posY, posZ, speedModifier); } -bool PanicGoal::canContinueToUse() { return !mob->getNavigation()->isDone(); } \ No newline at end of file +bool PanicGoal::canContinueToUse() { return !mob->getNavigation()->isDone(); } diff --git a/Minecraft.World/AI/Goals/PlayGoal.cpp b/Minecraft.World/AI/Goals/PlayGoal.cpp index 4c933d513..0259d5c93 100644 --- a/Minecraft.World/AI/Goals/PlayGoal.cpp +++ b/Minecraft.World/AI/Goals/PlayGoal.cpp @@ -43,10 +43,10 @@ bool PlayGoal::canUse() { delete children; if (followFriend.lock() == NULL) { - Vec3* pos = RandomPos::getPos( + auto pos = RandomPos::getPos( std::dynamic_pointer_cast(mob->shared_from_this()), 16, 3); - if (pos == NULL) return false; + if (!pos.has_value()) return false; } return true; } @@ -72,11 +72,11 @@ void PlayGoal::tick() { mob->getNavigation()->moveTo(followFriend.lock(), speedModifier); } else { if (mob->getNavigation()->isDone()) { - Vec3* pos = + auto pos = RandomPos::getPos(std::dynamic_pointer_cast( mob->shared_from_this()), 16, 3); - if (pos == NULL) return; + if (!pos.has_value()) return; mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier); } } diff --git a/Minecraft.World/AI/Goals/RandomStrollGoal.cpp b/Minecraft.World/AI/Goals/RandomStrollGoal.cpp index ba81c5442..2e95918bd 100644 --- a/Minecraft.World/AI/Goals/RandomStrollGoal.cpp +++ b/Minecraft.World/AI/Goals/RandomStrollGoal.cpp @@ -20,11 +20,11 @@ bool RandomStrollGoal::canUse() { // fenced-off region far enough to determine we can despawn them if (mob->getNoActionTime() < SharedConstants::TICKS_PER_SECOND * 5) { if (mob->getRandom()->nextInt(120) == 0) { - Vec3* pos = + auto pos = RandomPos::getPos(std::dynamic_pointer_cast( mob->shared_from_this()), 10, 7); - if (pos == NULL) return false; + if (!pos.has_value()) return false; wantedX = pos->x; wantedY = pos->y; wantedZ = pos->z; @@ -38,11 +38,11 @@ bool RandomStrollGoal::canUse() { // a given area and so waiting around is just wasting time if (mob->isExtraWanderingEnabled()) { - Vec3* pos = + auto pos = RandomPos::getPos(std::dynamic_pointer_cast( mob->shared_from_this()), 10, 7, mob->getWanderingQuadrant()); - if (pos == NULL) return false; + if (!pos.has_value()) return false; wantedX = pos->x; wantedY = pos->y; wantedZ = pos->z; @@ -58,4 +58,4 @@ bool RandomStrollGoal::canContinueToUse() { void RandomStrollGoal::start() { mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier); -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Goals/RunAroundLikeCrazyGoal.cpp b/Minecraft.World/AI/Goals/RunAroundLikeCrazyGoal.cpp index 84c35dd41..c24d376cd 100644 --- a/Minecraft.World/AI/Goals/RunAroundLikeCrazyGoal.cpp +++ b/Minecraft.World/AI/Goals/RunAroundLikeCrazyGoal.cpp @@ -17,10 +17,10 @@ RunAroundLikeCrazyGoal::RunAroundLikeCrazyGoal(EntityHorse* mob, bool RunAroundLikeCrazyGoal::canUse() { if (horse->isTamed() || horse->rider.lock() == NULL) return false; - Vec3* pos = RandomPos::getPos( + auto pos = RandomPos::getPos( std::dynamic_pointer_cast(horse->shared_from_this()), 5, 4); - if (pos == NULL) return false; + if (!pos.has_value()) return false; posX = pos->x; posY = pos->y; posZ = pos->z; @@ -57,4 +57,4 @@ void RunAroundLikeCrazyGoal::tick() { horse->level->broadcastEntityEvent(horse->shared_from_this(), EntityEvent::TAMING_FAILED); } -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Navigation/Path.cpp b/Minecraft.World/AI/Navigation/Path.cpp index eaef6b8a9..672839665 100644 --- a/Minecraft.World/AI/Navigation/Path.cpp +++ b/Minecraft.World/AI/Navigation/Path.cpp @@ -48,17 +48,17 @@ int Path::getIndex() { return index; } void Path::setIndex(int index) { this->index = index; } -Vec3* Path::getPos(std::shared_ptr e, int index) { +Vec3 Path::getPos(std::shared_ptr e, int index) { double x = nodes[index]->x + (int)(e->bbWidth + 1) * 0.5; double y = nodes[index]->y; double z = nodes[index]->z + (int)(e->bbWidth + 1) * 0.5; - return Vec3::newTemp(x, y, z); + return Vec3(x, y, z); } -Vec3* Path::currentPos(std::shared_ptr e) { return getPos(e, index); } +Vec3 Path::currentPos(std::shared_ptr e) { return getPos(e, index); } -Vec3* Path::currentPos() { - return Vec3::newTemp(nodes[index]->x, nodes[index]->y, nodes[index]->z); +Vec3 Path::currentPos() { + return Vec3(nodes[index]->x, nodes[index]->y, nodes[index]->z); } bool Path::sameAs(Path* path) { @@ -83,4 +83,4 @@ bool Path::endsInXZ(Vec3* pos) { Node* lastNode = last(); if (lastNode == NULL) return false; return lastNode->x == (int)pos->x && lastNode->z == (int)pos->z; -} \ No newline at end of file +} diff --git a/Minecraft.World/AI/Navigation/Path.h b/Minecraft.World/AI/Navigation/Path.h index 0e5697959..ab0a013be 100644 --- a/Minecraft.World/AI/Navigation/Path.h +++ b/Minecraft.World/AI/Navigation/Path.h @@ -20,10 +20,10 @@ public: void setSize(int length); int getIndex(); void setIndex(int index); - Vec3* getPos(std::shared_ptr e, int index); + Vec3 getPos(std::shared_ptr e, int index); NodeArray Getarray(); - Vec3* currentPos(std::shared_ptr e); - Vec3* currentPos(); + Vec3 currentPos(std::shared_ptr e); + Vec3 currentPos(); bool sameAs(Path* path); bool endsIn(Vec3* pos); bool endsInXZ(Vec3* pos); diff --git a/Minecraft.World/AI/Navigation/PathNavigation.cpp b/Minecraft.World/AI/Navigation/PathNavigation.cpp index 0160d92f0..5b670ec7d 100644 --- a/Minecraft.World/AI/Navigation/PathNavigation.cpp +++ b/Minecraft.World/AI/Navigation/PathNavigation.cpp @@ -20,7 +20,7 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) { avoidSun = false; _tick = 0; lastStuckCheck = 0; - lastStuckCheckPos = Vec3::newPermanent(0, 0, 0); + lastStuckCheckPos = new Vec3(0, 0, 0); _canPassDoors = true; _canOpenDoors = false; avoidWater = false; @@ -110,11 +110,11 @@ bool PathNavigation::moveTo(Path* newPath, double speedModifier) { if (path->getSize() == 0) return false; this->speedModifier = speedModifier; - Vec3* mobPos = getTempMobPos(); + Vec3 mobPos = getTempMobPos(); lastStuckCheck = _tick; - lastStuckCheckPos->x = mobPos->x; - lastStuckCheckPos->y = mobPos->y; - lastStuckCheckPos->z = mobPos->z; + lastStuckCheckPos->x = mobPos.x; + lastStuckCheckPos->y = mobPos.y; + lastStuckCheckPos->z = mobPos.z; return true; } @@ -127,20 +127,19 @@ void PathNavigation::tick() { if (canUpdatePath()) updatePath(); if (isDone()) return; - Vec3* target = path->currentPos(mob->shared_from_this()); - if (target == NULL) return; + Vec3 target = path->currentPos(mob->shared_from_this()); - mob->getMoveControl()->setWantedPosition(target->x, target->y, target->z, + mob->getMoveControl()->setWantedPosition(target.x, target.y, target.z, speedModifier); } void PathNavigation::updatePath() { - Vec3* mobPos = getTempMobPos(); + Vec3 mobPos = getTempMobPos(); // find first elevations in path int firstElevation = path->getSize(); for (int i = path->getIndex(); path != NULL && i < path->getSize(); ++i) { - if ((int)path->get(i)->y != (int)mobPos->y) { + if ((int)path->get(i)->y != (int)mobPos.y) { firstElevation = i; break; } @@ -150,8 +149,8 @@ void PathNavigation::updatePath() { // check canWalkDirectly also) possibly only check next as well float waypointRadiusSqr = mob->bbWidth * mob->bbWidth; for (int i = path->getIndex(); i < firstElevation; ++i) { - Vec3* pathPos = path->getPos(mob->shared_from_this(), i); - if (mobPos->distanceToSqr(*pathPos) < waypointRadiusSqr) { + Vec3 pathPos = path->getPos(mob->shared_from_this(), i); + if (mobPos.distanceToSqr(pathPos) < waypointRadiusSqr) { path->setIndex(i + 1); } } @@ -161,7 +160,8 @@ void PathNavigation::updatePath() { int sy = (int)mob->bbHeight + 1; int sz = sx; for (int i = firstElevation - 1; i >= path->getIndex(); --i) { - if (canMoveDirectly(mobPos, path->getPos(mob->shared_from_this(), i), + Vec3 mob_pos = path->getPos(mob->shared_from_this(), i); + if (canMoveDirectly(&mobPos, &mob_pos, sx, sy, sz)) { path->setIndex(i); break; @@ -170,11 +170,11 @@ void PathNavigation::updatePath() { // stuck detection (probably pushed off path) if (_tick - lastStuckCheck > 100) { - if (mobPos->distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop(); + if (mobPos.distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop(); lastStuckCheck = _tick; - lastStuckCheckPos->x = mobPos->x; - lastStuckCheckPos->y = mobPos->y; - lastStuckCheckPos->z = mobPos->z; + lastStuckCheckPos->x = mobPos.x; + lastStuckCheckPos->y = mobPos.y; + lastStuckCheckPos->z = mobPos.z; } } @@ -185,8 +185,8 @@ void PathNavigation::stop() { path = NULL; } -Vec3* PathNavigation::getTempMobPos() { - return Vec3::newTemp(mob->x, getSurfaceY(), mob->z); +Vec3 PathNavigation::getTempMobPos() { + return Vec3(mob->x, getSurfaceY(), mob->z); } int PathNavigation::getSurfaceY() { diff --git a/Minecraft.World/AI/Navigation/PathNavigation.h b/Minecraft.World/AI/Navigation/PathNavigation.h index d9d731532..25130e1b0 100644 --- a/Minecraft.World/AI/Navigation/PathNavigation.h +++ b/Minecraft.World/AI/Navigation/PathNavigation.h @@ -52,7 +52,7 @@ public: void stop(); private: - Vec3* getTempMobPos(); + Vec3 getTempMobPos(); int getSurfaceY(); bool canUpdatePath(); bool isInLiquid(); @@ -67,4 +67,4 @@ public: // 4J Added override to update ai elements when loading entity from // schematics void setLevel(Level* level); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/AI/Navigation/RandomPos.cpp b/Minecraft.World/AI/Navigation/RandomPos.cpp index d092d0e82..1a804fbb9 100644 --- a/Minecraft.World/AI/Navigation/RandomPos.cpp +++ b/Minecraft.World/AI/Navigation/RandomPos.cpp @@ -2,16 +2,17 @@ #include "../../Headers/net.minecraft.world.entity.h" #include "../../Headers/net.minecraft.world.phys.h" #include "RandomPos.h" +#include -Vec3* RandomPos::tempDir = Vec3::newPermanent(0, 0, 0); +Vec3* RandomPos::tempDir = new Vec3(0, 0, 0); -Vec3* RandomPos::getPos(std::shared_ptr mob, int xzDist, +std::optional RandomPos::getPos(std::shared_ptr mob, int xzDist, int yDist, int quadrant /*=-1*/) // 4J - added quadrant { return generateRandomPos(mob, xzDist, yDist, NULL, quadrant); } -Vec3* RandomPos::getPosTowards(std::shared_ptr mob, int xzDist, +std::optional RandomPos::getPosTowards(std::shared_ptr mob, int xzDist, int yDist, Vec3* towardsPos) { tempDir->x = towardsPos->x - mob->x; tempDir->y = towardsPos->y - mob->y; @@ -19,7 +20,7 @@ Vec3* RandomPos::getPosTowards(std::shared_ptr mob, int xzDist, return generateRandomPos(mob, xzDist, yDist, tempDir); } -Vec3* RandomPos::getPosAvoid(std::shared_ptr mob, int xzDist, +std::optional RandomPos::getPosAvoid(std::shared_ptr mob, int xzDist, int yDist, Vec3* avoidPos) { tempDir->x = mob->x - avoidPos->x; tempDir->y = mob->y - avoidPos->y; @@ -27,7 +28,7 @@ Vec3* RandomPos::getPosAvoid(std::shared_ptr mob, int xzDist, return generateRandomPos(mob, xzDist, yDist, tempDir); } -Vec3* RandomPos::generateRandomPos(std::shared_ptr mob, +std::optional RandomPos::generateRandomPos(std::shared_ptr mob, int xzDist, int yDist, Vec3* dir, int quadrant /*=-1*/) // 4J - added quadrant { @@ -81,8 +82,8 @@ Vec3* RandomPos::generateRandomPos(std::shared_ptr mob, } } if (hasBest) { - return Vec3::newTemp(xBest, yBest, zBest); + return Vec3(xBest, yBest, zBest); } - return NULL; -} \ No newline at end of file + return std::nullopt; +} diff --git a/Minecraft.World/AI/Navigation/RandomPos.h b/Minecraft.World/AI/Navigation/RandomPos.h index 8baa8e50f..48e278ad0 100644 --- a/Minecraft.World/AI/Navigation/RandomPos.h +++ b/Minecraft.World/AI/Navigation/RandomPos.h @@ -1,5 +1,6 @@ #pragma once +#include class PathfinderMob; class RandomPos { @@ -7,15 +8,14 @@ private: static Vec3* tempDir; public: - static Vec3* getPos(std::shared_ptr mob, int xzDist, + static std::optional getPos(std::shared_ptr mob, int xzDist, int yDist, int quadrant = -1); // 4J added quadrant - static Vec3* getPosTowards(std::shared_ptr mob, int xzDist, + static std::optional getPosTowards(std::shared_ptr mob, int xzDist, int yDist, Vec3* towardsPos); - static Vec3* getPosAvoid(std::shared_ptr mob, int xzDist, + static std::optional getPosAvoid(std::shared_ptr mob, int xzDist, int yDist, Vec3* avoidPos); - private: - static Vec3* generateRandomPos(std::shared_ptr mob, + static std::optional generateRandomPos(std::shared_ptr mob, int xzDist, int yDist, Vec3* dir, int quadrant = -1); // 4J added quadrant -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Blocks/LiquidTile.cpp b/Minecraft.World/Blocks/LiquidTile.cpp index 348982c5f..2b3cda562 100644 --- a/Minecraft.World/Blocks/LiquidTile.cpp +++ b/Minecraft.World/Blocks/LiquidTile.cpp @@ -7,6 +7,7 @@ #include "LiquidTile.h" #include "../Util/Facing.h" #include "../Util/SoundTypes.h" +#include "Blocks/Material.h" const std::wstring LiquidTile::TEXTURE_LAVA_STILL = L"lava"; const std::wstring LiquidTile::TEXTURE_WATER_STILL = L"water"; @@ -116,8 +117,8 @@ int LiquidTile::getResource(int data, Random* random, int playerBonusLevel) { int LiquidTile::getResourceCount(Random* random) { return 0; } -Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { - Vec3* flow = Vec3::newTemp(0, 0, 0); +Vec3 LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { + Vec3 flow(0, 0, 0); int mid = getRenderedDepth(level, x, y, z); for (int d = 0; d < 4; d++) { int xt = x; @@ -135,15 +136,15 @@ Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { t = getRenderedDepth(level, xt, yt - 1, zt); if (t >= 0) { int dir = t - (mid - 8); - *flow = flow->add((xt - x) * dir, (yt - y) * dir, + flow = flow.add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); } } } else { if (t >= 0) { int dir = t - mid; - *flow = - flow->add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); + flow = + flow.add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); } } } @@ -157,18 +158,19 @@ Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { if (ok || isSolidFace(level, x, y + 1, z + 1, 3)) ok = true; if (ok || isSolidFace(level, x - 1, y + 1, z, 4)) ok = true; if (ok || isSolidFace(level, x + 1, y + 1, z, 5)) ok = true; - if (ok) *flow = flow->normalize().add(0, -6, 0); + if (ok) flow = flow.normalize().add(0, -6, 0); } - *flow = flow->normalize(); + flow = flow.normalize(); + return flow; } void LiquidTile::handleEntityInside(Level* level, int x, int y, int z, std::shared_ptr e, Vec3* current) { - Vec3* flow = getFlow(level, x, y, z); - current->x += flow->x; - current->y += flow->y; - current->z += flow->z; + Vec3 flow = getFlow(level, x, y, z); + current->x += flow.x; + current->y += flow.y; + current->z += flow.z; } int LiquidTile::getTickDelay(Level* level) { @@ -305,13 +307,13 @@ void LiquidTile::animateTick(Level* level, int x, int y, int z, double LiquidTile::getSlopeAngle(LevelSource* level, int x, int y, int z, Material* m) { - Vec3* flow = NULL; + Vec3 flow; if (m == Material::water) - flow = ((LiquidTile*)Tile::water)->getFlow(level, x, y, z); + flow = Tile::water->getFlow(level, x, y, z); if (m == Material::lava) - flow = ((LiquidTile*)Tile::lava)->getFlow(level, x, y, z); - if (flow->x == 0 && flow->z == 0) return -1000; - return atan2(flow->z, flow->x) - PI / 2; + flow = Tile::lava->getFlow(level, x, y, z); + if (flow.x == 0 && flow.z == 0) return -1000; + return atan2(flow.z, flow.x) - PI / 2; } void LiquidTile::onPlace(Level* level, int x, int y, int z) { diff --git a/Minecraft.World/Blocks/LiquidTile.h b/Minecraft.World/Blocks/LiquidTile.h index 24c3d8f17..1d59d274a 100644 --- a/Minecraft.World/Blocks/LiquidTile.h +++ b/Minecraft.World/Blocks/LiquidTile.h @@ -46,7 +46,7 @@ public: virtual int getResourceCount(Random* random); private: - virtual Vec3* getFlow(LevelSource* level, int x, int y, int z); + virtual Vec3 getFlow(LevelSource* level, int x, int y, int z); public: virtual void handleEntityInside(Level* level, int x, int y, int z, @@ -72,4 +72,4 @@ protected: public: void registerIcons(IconRegister* iconRegister); static Icon* getTexture(const std::wstring& name); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Entities/Entity.cpp b/Minecraft.World/Entities/Entity.cpp index dc3ee4dd7..51ed60e8f 100644 --- a/Minecraft.World/Entities/Entity.cpp +++ b/Minecraft.World/Entities/Entity.cpp @@ -23,6 +23,7 @@ #include "../../Minecraft.Client/Level/MultiPlayerLevel.h" #include "../../Minecraft.Client/Player/MultiPlayerLocalPlayer.h" #include +#include #include "../../Minecraft.Client/Level/ServerLevel.h" #include "../../Minecraft.Client/Network/PlayerList.h" @@ -1533,7 +1534,7 @@ void Entity::lerpTo(double x, double y, double z, float yRot, float xRot, float Entity::getPickRadius() { return 0.1f; } -Vec3* Entity::getLookAngle() { return NULL; } +std::optional Entity::getLookAngle() { return std::nullopt; } void Entity::handleInsidePortal() { if (changingDimensionDelay > 0) { diff --git a/Minecraft.World/Entities/Entity.h b/Minecraft.World/Entities/Entity.h index bc7d0a4dc..df348f5cd 100644 --- a/Minecraft.World/Entities/Entity.h +++ b/Minecraft.World/Entities/Entity.h @@ -6,6 +6,7 @@ #include "../Util/Vec3.h" #include "../Util/Definitions.h" #include +#include class LivingEntity; class LightningBolt; @@ -342,7 +343,7 @@ public: virtual void lerpTo(double x, double y, double z, float yRot, float xRot, int steps); virtual float getPickRadius(); - virtual Vec3* getLookAngle(); + virtual std::optional getLookAngle(); virtual void handleInsidePortal(); virtual int getDimensionChangingDelay(); virtual void lerpMotion(double xd, double yd, double zd); diff --git a/Minecraft.World/Entities/LivingEntity.cpp b/Minecraft.World/Entities/LivingEntity.cpp index 47a004096..00a5de704 100644 --- a/Minecraft.World/Entities/LivingEntity.cpp +++ b/Minecraft.World/Entities/LivingEntity.cpp @@ -24,6 +24,7 @@ #include "../Headers/net.minecraft.world.scores.h" #include "../Headers/com.mojang.nbt.h" #include "LivingEntity.h" +#include #include "../../Minecraft.Client/Textures/Textures.h" #include "../../Minecraft.Client/Level/ServerLevel.h" #include "../../Minecraft.Client/Player/EntityTracker.h" @@ -1650,16 +1651,16 @@ bool LivingEntity::canSee(std::shared_ptr target) { return retVal; } -Vec3* LivingEntity::getLookAngle() { return getViewVector(1); } +std::optional LivingEntity::getLookAngle() { return getViewVector(1); } -Vec3* LivingEntity::getViewVector(float a) { +Vec3 LivingEntity::getViewVector(float a) { if (a == 1) { float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI); float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI); float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD); float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD); - return Vec3::newTemp(ySin * xCos, xSin, yCos * xCos); + return Vec3(ySin * xCos, xSin, yCos * xCos); } float xRot = xRotO + (this->xRot - xRotO) * a; float yRot = yRotO + (this->yRot - yRotO) * a; @@ -1669,7 +1670,7 @@ Vec3* LivingEntity::getViewVector(float a) { float xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD); float xSin = Mth::sin(-xRot * Mth::RAD_TO_GRAD); - return Vec3::newTemp(ySin * xCos, xSin, yCos * xCos); + return Vec3(ySin * xCos, xSin, yCos * xCos); } float LivingEntity::getAttackAnim(float a) { @@ -1678,20 +1679,20 @@ float LivingEntity::getAttackAnim(float a) { return oAttackAnim + diff * a; } -Vec3* LivingEntity::getPos(float a) { +Vec3 LivingEntity::getPos(float a) { if (a == 1) { - return Vec3::newTemp(x, y, z); + return Vec3(x, y, z); } double x = xo + (this->x - xo) * a; double y = yo + (this->y - yo) * a; double z = zo + (this->z - zo) * a; - return Vec3::newTemp(x, y, z); + return Vec3(x, y, z); } HitResult* LivingEntity::pick(double range, float a) { - Vec3 from = *getPos(a); - Vec3 b = *getViewVector(a); + Vec3 from = getPos(a); + Vec3 b = getViewVector(a); Vec3 to{b.x * range, b.y * range, b.z * range}; to = to.add(from.x, from.y, from.z); return level->clip(&from, &to); diff --git a/Minecraft.World/Entities/LivingEntity.h b/Minecraft.World/Entities/LivingEntity.h index ead873ce3..30ad389b3 100644 --- a/Minecraft.World/Entities/LivingEntity.h +++ b/Minecraft.World/Entities/LivingEntity.h @@ -1,5 +1,6 @@ #pragma once +#include #include "Entity.h" #include "MobType.h" #include "../AI/Goals/GoalSelector.h" @@ -304,10 +305,10 @@ public: virtual bool canSee(std::shared_ptr target); public: - virtual Vec3* getLookAngle(); - virtual Vec3* getViewVector(float a); + virtual std::optional getLookAngle(); + virtual Vec3 getViewVector(float a); virtual float getAttackAnim(float a); - virtual Vec3* getPos(float a); + virtual Vec3 getPos(float a); virtual HitResult* pick(double range, float a); virtual bool isEffectiveAi(); diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.cpp b/Minecraft.World/Entities/Mobs/EnderDragon.cpp index 5ef66d371..828eeb982 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.cpp +++ b/Minecraft.World/Entities/Mobs/EnderDragon.cpp @@ -14,6 +14,7 @@ #include "../../Util/SharedConstants.h" #include "EnderDragon.h" #include +#include #define PRINT_DRAGON_STATE_CHANGE_MESSAGES 1 @@ -309,12 +310,12 @@ void EnderDragon::aiStep() { double xP = 0.0; double yP = 0.0; double zP = 0.0; - Vec3* v = getHeadLookVector(1); // getViewVector(1); + Vec3 v = getHeadLookVector(1); // getViewVector(1); // app.DebugPrintf("View vector is (%f,%f,%f) - lsteps %d\n", v->x, // v->y, v->z, lSteps); unsigned int d = 0; for(unsigned int d = 1; // d < 3; ++d) { - Vec3 vN = Vec3{v->x, v->y, v->z}.normalize(); + Vec3 vN = Vec3{v.x, v.y, v.z}.normalize(); vN.yRot(-PI / 4); for (unsigned int i = 0; i < 8; ++i) { @@ -746,10 +747,10 @@ void EnderDragon::aiStep() { if (m_fireballCharge >= 20 && (angleDegs >= 0 && angleDegs < 10)) { double d = 1; - Vec3* v = getViewVector(1); - float startingX = head->x - v->x * d; + Vec3 v = getViewVector(1); + float startingX = head->x - v.x * d; float startingY = head->y + head->bbHeight / 2 + 0.5f; - float startingZ = head->z - v->z * d; + float startingZ = head->z - v.z * d; double xdd = attackTarget->x - startingX; double ydd = @@ -1022,9 +1023,9 @@ void EnderDragon::findNewTarget() { // !m_holdingPatternClockwise; if (getSynchedAction() == e_EnderdragonAction_Takeoff) { - Vec3* v = getHeadLookVector(1); + Vec3 v = getHeadLookVector(1); targetNodeIndex = - findClosestNode(-v->x * 40, 105.0, -v->z * 40); + findClosestNode(-v.x * 40, 105.0, -v.z * 40); } else { if (random->nextInt(8) == 0) { m_holdingPatternClockwise = !m_holdingPatternClockwise; @@ -1488,24 +1489,24 @@ void EnderDragon::strafeAttackTarget() { void EnderDragon::navigateToNextPathNode() { if (m_currentPath != NULL && !m_currentPath->isDone()) { - Vec3* curr = m_currentPath->currentPos(); + Vec3 curr = m_currentPath->currentPos(); m_currentPath->next(); - xTarget = curr->x; + xTarget = curr.x; if (getSynchedAction() == e_EnderdragonAction_LandingApproach && m_currentPath->isDone()) { // When heading to the last node on the landing approach, we want // the yCoord to be exact - yTarget = curr->y; + yTarget = curr.y; } else { do { - yTarget = curr->y + random->nextFloat() * 20; - } while (yTarget < (curr->y)); + yTarget = curr.y + random->nextFloat() * 20; + } while (yTarget < (curr.y)); } - zTarget = curr->z; - app.DebugPrintf("Path node pos is (%f,%f,%f)\n", curr->x, curr->y, - curr->z); + zTarget = curr.z; + app.DebugPrintf("Path node pos is (%f,%f,%f)\n", curr.x, curr.y, + curr.z); app.DebugPrintf("Setting new target to (%f,%f,%f)\n", xTarget, yTarget, zTarget); } @@ -1846,8 +1847,8 @@ double EnderDragon::getHeadPartYRotDiff(int partIndex, doubleArray bodyPos, return result; } -Vec3* EnderDragon::getHeadLookVector(float a) { - Vec3* result = NULL; +Vec3 EnderDragon::getHeadLookVector(float a) { + Vec3 result; if (getSynchedAction() == e_EnderdragonAction_Landing || getSynchedAction() == e_EnderdragonAction_Takeoff) { @@ -1888,5 +1889,6 @@ Vec3* EnderDragon::getHeadLookVector(float a) { } else { result = getViewVector(a); } + return result; } diff --git a/Minecraft.World/Entities/Mobs/EnderDragon.h b/Minecraft.World/Entities/Mobs/EnderDragon.h index 90056ce63..e8270dcae 100644 --- a/Minecraft.World/Entities/Mobs/EnderDragon.h +++ b/Minecraft.World/Entities/Mobs/EnderDragon.h @@ -188,7 +188,7 @@ public: doubleArray partPos); double getHeadPartYRotDiff(int partIndex, doubleArray bodyPos, doubleArray partPos); - Vec3* getHeadLookVector(float a); + Vec3 getHeadLookVector(float a); virtual std::wstring getAName() { return app.GetString(IDS_ENDERDRAGON); }; virtual float getHealth() { return LivingEntity::getHealth(); }; diff --git a/Minecraft.World/Entities/Mobs/EnderMan.cpp b/Minecraft.World/Entities/Mobs/EnderMan.cpp index d559c2056..9762254f9 100644 --- a/Minecraft.World/Entities/Mobs/EnderMan.cpp +++ b/Minecraft.World/Entities/Mobs/EnderMan.cpp @@ -114,8 +114,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr player) { std::shared_ptr helmet = player->inventory->armor[3]; if (helmet != NULL && helmet->id == Tile::pumpkin_Id) return false; - Vec3* look = player->getViewVector(1); - *look = look->normalize(); + Vec3 look = player->getViewVector(1).normalize(); Vec3 dir{x - player->x, (bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), @@ -123,7 +122,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr player) { double dist = dir.length(); dir = dir.normalize(); - double dot = look->dot(dir); + double dot = look.dot(dir); if (dot > 1 - 0.025 / dist) { return player->canSee(shared_from_this()); } diff --git a/Minecraft.World/Entities/Mobs/Fireball.cpp b/Minecraft.World/Entities/Mobs/Fireball.cpp index 68b12a435..91bfe34f7 100644 --- a/Minecraft.World/Entities/Mobs/Fireball.cpp +++ b/Minecraft.World/Entities/Mobs/Fireball.cpp @@ -300,8 +300,8 @@ bool Fireball::hurt(DamageSource* source, float damage) { markHurt(); if (source->getEntity() != NULL) { - Vec3* lookAngle = source->getEntity()->getLookAngle(); - if (lookAngle != NULL) { + auto lookAngle = source->getEntity()->getLookAngle(); + if (lookAngle.has_value()) { xd = lookAngle->x; yd = lookAngle->y; zd = lookAngle->z; @@ -309,6 +309,7 @@ bool Fireball::hurt(DamageSource* source, float damage) { yPower = yd * 0.1; zPower = zd * 0.1; } + if (source->getEntity()->instanceof(eTYPE_LIVINGENTITY)) { owner = std::dynamic_pointer_cast(source->getEntity()); diff --git a/Minecraft.World/Entities/Mobs/Ghast.cpp b/Minecraft.World/Entities/Mobs/Ghast.cpp index a44e29e60..6dedd39ef 100644 --- a/Minecraft.World/Entities/Mobs/Ghast.cpp +++ b/Minecraft.World/Entities/Mobs/Ghast.cpp @@ -141,10 +141,10 @@ void Ghast::serverAiStep() { ydd, zdd)); ie->explosionPower = explosionPower; double d = 4; - Vec3* v = getViewVector(1); - ie->x = x + v->x * d; + Vec3 v = getViewVector(1); + ie->x = x + v.x * d; ie->y = y + bbHeight / 2 + 0.5f; - ie->z = z + v->z * d; + ie->z = z + v.z * d; level->addEntity(ie); charge = -40; } diff --git a/Minecraft.World/Entities/Mobs/Minecart.cpp b/Minecraft.World/Entities/Mobs/Minecart.cpp index 273845676..511764cb6 100644 --- a/Minecraft.World/Entities/Mobs/Minecart.cpp +++ b/Minecraft.World/Entities/Mobs/Minecart.cpp @@ -13,6 +13,8 @@ #include "../../../Minecraft.Client/Level/ServerLevel.h" #include "../../Headers/com.mojang.nbt.h" #include "Minecart.h" +#include +#include #include "../../Util/SharedConstants.h" const int Minecart::EXITS[][2][3] = { @@ -361,7 +363,7 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed, double slideSpeed, int tile, int data) { fallDistance = 0; - Vec3* oldPos = getPos(x, y, z); + auto oldPos = getPos(x, y, z); y = yt; bool powerTrack = false; @@ -489,8 +491,8 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed, applyNaturalSlowdown(); - Vec3* newPos = getPos(x, y, z); - if (newPos != NULL && oldPos != NULL) { + auto newPos = getPos(x, y, z); + if (newPos.has_value() && oldPos.has_value()) { double speed = (oldPos->y - newPos->y) * 0.05; pow = sqrt(xd * xd + zd * zd); @@ -549,7 +551,7 @@ void Minecart::applyNaturalSlowdown() { } } -Vec3* Minecart::getPosOffs(double x, double y, double z, double offs) { +std::optional Minecart::getPosOffs(double x, double y, double z, double offs) { int xt = Mth::floor(x); int yt = Mth::floor(y); int zt = Mth::floor(z); @@ -594,10 +596,11 @@ Vec3* Minecart::getPosOffs(double x, double y, double z, double offs) { return getPos(x, y, z); } - return NULL; + + return std::nullopt; } -Vec3* Minecart::getPos(double x, double y, double z) { +std::optional Minecart::getPos(double x, double y, double z) { int xt = Mth::floor(x); int yt = Mth::floor(y); int zt = Mth::floor(z); @@ -653,9 +656,10 @@ Vec3* Minecart::getPos(double x, double y, double z) { z = z0 + zD * progress; if (yD < 0) y += 1; if (yD > 0) y += 0.5; - return Vec3::newTemp(x, y, z); + return Vec3(x, y, z); } - return NULL; + + return std::nullopt; } void Minecart::readAdditionalSaveData(CompoundTag* tag) { diff --git a/Minecraft.World/Entities/Mobs/Minecart.h b/Minecraft.World/Entities/Mobs/Minecart.h index 353df82dc..3e96f1fc3 100644 --- a/Minecraft.World/Entities/Mobs/Minecart.h +++ b/Minecraft.World/Entities/Mobs/Minecart.h @@ -1,4 +1,5 @@ #pragma once +#include #include "../Entity.h" class DamageSource; @@ -77,8 +78,8 @@ protected: virtual void moveAlongTrack(int xt, int yt, int zt, double maxSpeed, double slideSpeed, int tile, int data); virtual void applyNaturalSlowdown(); - virtual Vec3* getPosOffs(double x, double y, double z, double offs); - virtual Vec3* getPos(double x, double y, double z); + virtual std::optional getPosOffs(double x, double y, double z, double offs); + virtual std::optional getPos(double x, double y, double z); protected: virtual void addAdditonalSaveData(CompoundTag* base); diff --git a/Minecraft.World/Entities/PathfinderMob.cpp b/Minecraft.World/Entities/PathfinderMob.cpp index 6abf6a2ac..aec748483 100644 --- a/Minecraft.World/Entities/PathfinderMob.cpp +++ b/Minecraft.World/Entities/PathfinderMob.cpp @@ -120,18 +120,20 @@ void PathfinderMob::serverAiStep() { return; } - Vec3* target = path->currentPos(shared_from_this()); + Vec3 target = path->currentPos(shared_from_this()); double r = bbWidth * 2; - while (target != NULL && target->distanceToSqr(x, target->y, z) < r * r) { + while (target.distanceToSqr(x, target.y, z) < r * r) { path->next(); if (path->isDone()) { - target = NULL; setPath(NULL); // 4J - changed to setPath from path = + break; } else target = path->currentPos(shared_from_this()); } jumping = false; + // 4jcraft - refactoring Vec3 shows this branch never hits + /* if (target != NULL) { double xd = target->x - x; double zd = target->z - z; @@ -165,6 +167,7 @@ void PathfinderMob::serverAiStep() { jumping = true; } } + */ if (attackTarget != NULL) { lookAt(attackTarget, 30, 30); diff --git a/Minecraft.World/Items/BoatItem.cpp b/Minecraft.World/Items/BoatItem.cpp index 6e0b358b1..0d3b1749c 100644 --- a/Minecraft.World/Items/BoatItem.cpp +++ b/Minecraft.World/Items/BoatItem.cpp @@ -25,7 +25,7 @@ bool BoatItem::TestUse(std::shared_ptr itemInstance, Level* level, player->yo + (player->y - player->yo) + 1.62 - player->heightOffset; double z = player->zo + (player->z - player->zo); - Vec3* from = Vec3::newTemp(x, y, z); + Vec3 from(x, y, z); float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI); float ySin = Mth::sin(-yRot * Mth::RAD_TO_GRAD - PI); @@ -37,9 +37,9 @@ bool BoatItem::TestUse(std::shared_ptr itemInstance, Level* level, float za = yCos * xCos; double range = 5; - Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range); - *to = to->add(from->x, from->y, from->z); - HitResult* hr = level->clip(from, to, true); + Vec3 to(xa * range, ya * range, za * range); + to = to.add(from.x, from.y, from.z); + HitResult* hr = level->clip(&from, &to, true); if (hr == NULL) return false; if (hr->type == HitResult::TILE) { @@ -80,12 +80,12 @@ std::shared_ptr BoatItem::use( if (hr == NULL) return itemInstance; // check entity collision - Vec3* b = player->getViewVector(a); + Vec3 b = player->getViewVector(a); bool hitEntity = false; float overlap = 1; std::vector >* objects = level->getEntities( player, - player->bb->expand(b->x * (range), b->y * (range), b->z * (range)) + player->bb->expand(b.x * (range), b.y * (range), b.z * (range)) ->grow(overlap, overlap, overlap)); // for (int i = 0; i < objects.size(); i++) { for (AUTO_VAR(it, objects->begin()); it != objects->end(); ++it) { diff --git a/Minecraft.World/Level/Dimensions/Dimension.cpp b/Minecraft.World/Level/Dimensions/Dimension.cpp index a4447878c..0af723d87 100644 --- a/Minecraft.World/Level/Dimensions/Dimension.cpp +++ b/Minecraft.World/Level/Dimensions/Dimension.cpp @@ -157,7 +157,7 @@ float* Dimension::getSunriseColor(float td, float a) { return NULL; } -Vec3* Dimension::getFogColor(float td, float a) const { +Vec3 Dimension::getFogColor(float td, float a) const { float br = Mth::cos(td * PI * 2) * 2 + 0.5f; if (br < 0.0f) br = 0.0f; if (br > 1.0f) br = 1.0f; @@ -172,7 +172,7 @@ Vec3* Dimension::getFogColor(float td, float a) const { g *= br * 0.94f + 0.06f; b *= br * 0.91f + 0.09f; - return Vec3::newTemp(r, g, b); + return Vec3(r, g, b); } bool Dimension::mayRespawn() const { return true; } diff --git a/Minecraft.World/Level/Dimensions/Dimension.h b/Minecraft.World/Level/Dimensions/Dimension.h index b5d1f4674..0aea9e38c 100644 --- a/Minecraft.World/Level/Dimensions/Dimension.h +++ b/Minecraft.World/Level/Dimensions/Dimension.h @@ -48,7 +48,7 @@ private: public: virtual float* getSunriseColor(float td, float a); - virtual Vec3* getFogColor(float td, float a) const; + virtual Vec3 getFogColor(float td, float a) const; virtual bool mayRespawn() const; static Dimension* getNew(int id); virtual float getCloudHeight(); diff --git a/Minecraft.World/Level/Dimensions/HellDimension.cpp b/Minecraft.World/Level/Dimensions/HellDimension.cpp index f2869a58b..87d8ae155 100644 --- a/Minecraft.World/Level/Dimensions/HellDimension.cpp +++ b/Minecraft.World/Level/Dimensions/HellDimension.cpp @@ -15,7 +15,7 @@ void HellDimension::init() { id = -1; } -Vec3* HellDimension::getFogColor(float td, float a) const { +Vec3 HellDimension::getFogColor(float td, float a) const { int colour = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Nether_Fog_Colour); uint8_t redComponent = ((colour >> 16) & 0xFF); @@ -25,7 +25,7 @@ Vec3* HellDimension::getFogColor(float td, float a) const { float rr = (float)redComponent / 256; // 0.2f; float gg = (float)greenComponent / 256; // 0.03f; float bb = (float)blueComponent / 256; // 0.03f; - return Vec3::newTemp(rr, gg, bb); + return Vec3(rr, gg, bb); } void HellDimension::updateLightRamp() { diff --git a/Minecraft.World/Level/Dimensions/HellDimension.h b/Minecraft.World/Level/Dimensions/HellDimension.h index 93f374687..caa6ff55f 100644 --- a/Minecraft.World/Level/Dimensions/HellDimension.h +++ b/Minecraft.World/Level/Dimensions/HellDimension.h @@ -4,7 +4,7 @@ class HellDimension : public Dimension { public: virtual void init(); - virtual Vec3* getFogColor(float td, float a) const; + virtual Vec3 getFogColor(float td, float a) const; protected: virtual void updateLightRamp(); diff --git a/Minecraft.World/Level/Dimensions/SkyIslandDimension.cpp b/Minecraft.World/Level/Dimensions/SkyIslandDimension.cpp index 74ebb817a..07cb4fe4b 100644 --- a/Minecraft.World/Level/Dimensions/SkyIslandDimension.cpp +++ b/Minecraft.World/Level/Dimensions/SkyIslandDimension.cpp @@ -20,7 +20,7 @@ float SkyIslandDimension::getTimeOfDay(int64_t time, float a) const { float* SkyIslandDimension::getSunriseColor(float td, float a) { return NULL; } -Vec3* SkyIslandDimension::getFogColor(float td, float a) const { +Vec3 SkyIslandDimension::getFogColor(float td, float a) const { int fogColor = 0x8080a0; float br = Mth::cos(td * PI * 2) * 2 + 0.5f; if (br < 0.0f) br = 0.0f; @@ -33,7 +33,7 @@ Vec3* SkyIslandDimension::getFogColor(float td, float a) const { g *= br * 0.94f + 0.06f; b *= br * 0.91f + 0.09f; - return Vec3::newTemp(r, g, b); + return Vec3(r, g, b); } bool SkyIslandDimension::hasGround() { return false; } @@ -46,4 +46,4 @@ bool SkyIslandDimension::isValidSpawn(int x, int z) const { if (topTile == 0) return false; return Tile::tiles[topTile]->material->blocksMotion(); -} \ No newline at end of file +} diff --git a/Minecraft.World/Level/Dimensions/TheEndDimension.cpp b/Minecraft.World/Level/Dimensions/TheEndDimension.cpp index 28fa68ba2..d1b40addb 100644 --- a/Minecraft.World/Level/Dimensions/TheEndDimension.cpp +++ b/Minecraft.World/Level/Dimensions/TheEndDimension.cpp @@ -23,7 +23,7 @@ float TheEndDimension::getTimeOfDay(int64_t time, float a) const { float* TheEndDimension::getSunriseColor(float td, float a) { return NULL; } -Vec3* TheEndDimension::getFogColor(float td, float a) const { +Vec3 TheEndDimension::getFogColor(float td, float a) const { int fogColor = Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_End_Fog_Colour); // 0xa080a0; float br = Mth::cos(td * PI * 2) * 2 + 0.5f; @@ -37,7 +37,7 @@ Vec3* TheEndDimension::getFogColor(float td, float a) const { g *= br * 0.0f + 0.15f; b *= br * 0.0f + 0.15f; - return Vec3::newTemp(r, g, b); + return Vec3(r, g, b); } bool TheEndDimension::hasGround() { return false; } diff --git a/Minecraft.World/Level/Dimensions/TheEndDimension.h b/Minecraft.World/Level/Dimensions/TheEndDimension.h index c6c601e99..304974106 100644 --- a/Minecraft.World/Level/Dimensions/TheEndDimension.h +++ b/Minecraft.World/Level/Dimensions/TheEndDimension.h @@ -7,7 +7,7 @@ public: virtual ChunkSource* createRandomLevelSource() const; virtual float getTimeOfDay(int64_t time, float a) const; virtual float* getSunriseColor(float td, float a); - virtual Vec3* getFogColor(float td, float a) const; + virtual Vec3 getFogColor(float td, float a) const; virtual bool hasGround(); virtual bool mayRespawn() const; virtual bool isNaturalDimension(); diff --git a/Minecraft.World/Level/Events/VillageSiege.cpp b/Minecraft.World/Level/Events/VillageSiege.cpp index 67410f7b3..abf2dc517 100644 --- a/Minecraft.World/Level/Events/VillageSiege.cpp +++ b/Minecraft.World/Level/Events/VillageSiege.cpp @@ -4,6 +4,7 @@ #include "../../Headers/net.minecraft.world.entity.monster.h" #include "../../Headers/net.minecraft.world.level.h" #include "VillageSiege.h" +#include VillageSiege::VillageSiege(Level* level) { hasSetupSiege = false; @@ -108,8 +109,8 @@ bool VillageSiege::tryToSetupSiege() { } if (overlaps) return false; - Vec3* spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ); - if (spawnPos == NULL) continue; + auto spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ); + if (!spawnPos.has_value()) continue; nextSpawnTime = 0; siegeCount = 20; @@ -119,8 +120,8 @@ bool VillageSiege::tryToSetupSiege() { } bool VillageSiege::trySpawn() { - Vec3* spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ); - if (spawnPos == NULL) return false; + auto spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ); + if (!spawnPos.has_value()) return false; std::shared_ptr mob; // try { @@ -143,9 +144,9 @@ bool VillageSiege::trySpawn() { return true; } -Vec3* VillageSiege::findRandomSpawnPos(int x, int y, int z) { +std::optional VillageSiege::findRandomSpawnPos(int x, int y, int z) { std::shared_ptr _village = village.lock(); - if (_village == NULL) return NULL; + if (_village == NULL) return std::nullopt; for (int i = 0; i < 10; ++i) { int xx = x + level->random->nextInt(16) - 8; @@ -154,7 +155,8 @@ Vec3* VillageSiege::findRandomSpawnPos(int x, int y, int z) { if (!_village->isInside(xx, yy, zz)) continue; if (MobSpawner::isSpawnPositionOk(MobCategory::monster, level, xx, yy, zz)) - return Vec3::newTemp(xx, yy, zz); + return Vec3(xx, yy, zz); } - return NULL; + + return std::nullopt; } diff --git a/Minecraft.World/Level/Events/VillageSiege.h b/Minecraft.World/Level/Events/VillageSiege.h index f6a978824..35456c3aa 100644 --- a/Minecraft.World/Level/Events/VillageSiege.h +++ b/Minecraft.World/Level/Events/VillageSiege.h @@ -1,5 +1,7 @@ #pragma once +#include + class VillageSiege { private: Level* level; @@ -23,5 +25,5 @@ public: private: bool tryToSetupSiege(); bool trySpawn(); - Vec3* findRandomSpawnPos(int x, int y, int z); -}; \ No newline at end of file + std::optional findRandomSpawnPos(int x, int y, int z); +}; diff --git a/Minecraft.World/Level/Explosion.cpp b/Minecraft.World/Level/Explosion.cpp index 1b3686a4b..752586bd6 100644 --- a/Minecraft.World/Level/Explosion.cpp +++ b/Minecraft.World/Level/Explosion.cpp @@ -28,9 +28,6 @@ Explosion::Explosion(Level* level, std::shared_ptr source, double x, Explosion::~Explosion() { delete random; - for (AUTO_VAR(it, hitPlayers.begin()); it != hitPlayers.end(); ++it) { - delete it->second; - } } void Explosion::explode() { @@ -165,7 +162,7 @@ void Explosion::explode() { // app.DebugPrintf("Adding player knockback (%f,%f,%f)\n", xa * // pow, ya * pow, za * pow); hitPlayers.insert(playerVec3Map::value_type( - player, Vec3::newPermanent(xa * pow, ya * pow, za * pow))); + player, Vec3(xa * pow, ya * pow, za * pow))); } } } @@ -283,10 +280,10 @@ void Explosion::finalizeExplosion( Explosion::playerVec3Map* Explosion::getHitPlayers() { return &hitPlayers; } -Vec3* Explosion::getHitPlayerKnockback(std::shared_ptr player) { +Vec3 Explosion::getHitPlayerKnockback(std::shared_ptr player) { AUTO_VAR(it, hitPlayers.find(player)); - if (it == hitPlayers.end()) return Vec3::newTemp(0.0, 0.0, 0.0); + if (it == hitPlayers.end()) return Vec3(0.0, 0.0, 0.0); return it->second; } diff --git a/Minecraft.World/Level/Explosion.h b/Minecraft.World/Level/Explosion.h index 46c67f272..1c250e6b3 100644 --- a/Minecraft.World/Level/Explosion.h +++ b/Minecraft.World/Level/Explosion.h @@ -24,7 +24,7 @@ public: std::unordered_set toBlow; private: - typedef std::unordered_map, Vec3*, PlayerKeyHash, + typedef std::unordered_map, Vec3, PlayerKeyHash, PlayerKeyEq> playerVec3Map; playerVec3Map hitPlayers; @@ -42,6 +42,6 @@ public: std::vector* toBlowDirect = NULL); // 4J - added toBlow parameter playerVec3Map* getHitPlayers(); - Vec3* getHitPlayerKnockback(std::shared_ptr player); + Vec3 getHitPlayerKnockback(std::shared_ptr player); std::shared_ptr getSourceMob(); -}; \ No newline at end of file +}; diff --git a/Minecraft.World/Level/Level.cpp b/Minecraft.World/Level/Level.cpp index 82317c5c5..f61f88c8b 100644 --- a/Minecraft.World/Level/Level.cpp +++ b/Minecraft.World/Level/Level.cpp @@ -1884,7 +1884,7 @@ float Level::getSkyDarken(float a) { return br * 0.8f + 0.2f; } -Vec3* Level::getSkyColor(std::shared_ptr source, float a) { +Vec3 Level::getSkyColor(std::shared_ptr source, float a) { float td = getTimeOfDay(a); float br = Mth::cos(td * PI * 2) * 2 + 0.5f; @@ -1932,7 +1932,7 @@ Vec3* Level::getSkyColor(std::shared_ptr source, float a) { b = b * (1 - f) + 1 * f; } - return Vec3::newTemp(r, g, b); + return Vec3(r, g, b); } float Level::getTimeOfDay(float a) { @@ -1963,7 +1963,7 @@ float Level::getSunAngle(float a) { return td * PI * 2; } -Vec3* Level::getCloudColor(float a) { +Vec3 Level::getCloudColor(float a) { float td = getTimeOfDay(a); float br = Mth::cos(td * PI * 2) * 2.0f + 0.5f; @@ -2001,10 +2001,10 @@ Vec3* Level::getCloudColor(float a) { b = b * ba + mid * (1 - ba); } - return Vec3::newTemp(r, g, b); + return Vec3(r, g, b); } -Vec3* Level::getFogColor(float a) { +Vec3 Level::getFogColor(float a) { float td = getTimeOfDay(a); return dimension->getFogColor(td, a); } diff --git a/Minecraft.World/Level/Level.h b/Minecraft.World/Level/Level.h index 840e3ae1d..d28d1cda5 100644 --- a/Minecraft.World/Level/Level.h +++ b/Minecraft.World/Level/Level.h @@ -365,13 +365,13 @@ public: false); // 4J: Added noEntities & blockAtEdge parameters int getOldSkyDarken(float a); // 4J - change brought forward from 1.8.2 float getSkyDarken(float a); // 4J - change brought forward from 1.8.2 - Vec3* getSkyColor(std::shared_ptr source, float a); + Vec3 getSkyColor(std::shared_ptr source, float a); float getTimeOfDay(float a); int getMoonPhase(); float getMoonBrightness(); float getSunAngle(float a); - Vec3* getCloudColor(float a); - Vec3* getFogColor(float a); + Vec3 getCloudColor(float a); + Vec3 getFogColor(float a); int getTopRainBlock(int x, int z); int getTopSolidBlock(int x, int z); bool biomeHasRain(int x, int z); // 4J added diff --git a/Minecraft.World/Util/Vec3.cpp b/Minecraft.World/Util/Vec3.cpp index eb9dededa..7017db739 100644 --- a/Minecraft.World/Util/Vec3.cpp +++ b/Minecraft.World/Util/Vec3.cpp @@ -34,6 +34,7 @@ void Vec3::ReleaseThreadStorage() { } Vec3* Vec3::newPermanent(double x, double y, double z) { + assert(0); return new Vec3(x, y, z); }; @@ -42,6 +43,7 @@ void Vec3::clearPool() {} void Vec3::resetPool() {} Vec3* Vec3::newTemp(double x, double y, double z) { + assert(0); ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx); Vec3* thisVec = &tls->pool[tls->poolPointer]; thisVec->set(x, y, z); diff --git a/Minecraft.World/WorldGen/Structures/Village.cpp b/Minecraft.World/WorldGen/Structures/Village.cpp index 07e505908..16a6a2283 100644 --- a/Minecraft.World/WorldGen/Structures/Village.cpp +++ b/Minecraft.World/WorldGen/Structures/Village.cpp @@ -7,6 +7,7 @@ #include "../../Headers/net.minecraft.world.phys.h" #include "Village.h" #include +#include Village::Aggressor::Aggressor(std::shared_ptr mob, int timeStamp) { @@ -60,9 +61,9 @@ void Village::tick(int tick) { int idealGolemCount = populationSize / 10; if (golemCount < idealGolemCount && doorInfos.size() > 20 && level->random->nextInt(7000) == 0) { - Vec3* spawnPos = + auto spawnPos = findRandomSpawnPos(center->x, center->y, center->z, 2, 4, 2); - if (spawnPos != NULL) { + if (spawnPos.has_value()) { std::shared_ptr vg = std::shared_ptr(new VillagerGolem(level)); vg->setPos(spawnPos->x, spawnPos->y, spawnPos->z); @@ -88,16 +89,17 @@ void Village::tick(int tick) { // } } -Vec3* Village::findRandomSpawnPos(int x, int y, int z, int sx, int sy, int sz) { +std::optional Village::findRandomSpawnPos(int x, int y, int z, int sx, + int sy, int sz) { for (int i = 0; i < 10; ++i) { int xx = x + level->random->nextInt(16) - 8; int yy = y + level->random->nextInt(6) - 3; int zz = z + level->random->nextInt(16) - 8; if (!isInside(xx, yy, zz)) continue; - if (canSpawnAt(xx, yy, zz, sx, sy, sz)) - return Vec3::newTemp(xx, yy, zz); + if (canSpawnAt(xx, yy, zz, sx, sy, sz)) return Vec3(xx, yy, zz); } - return NULL; + + return std::nullopt; } bool Village::canSpawnAt(int x, int y, int z, int sx, int sy, int sz) { diff --git a/Minecraft.World/WorldGen/Structures/Village.h b/Minecraft.World/WorldGen/Structures/Village.h index fb35335f7..b63f3e8e9 100644 --- a/Minecraft.World/WorldGen/Structures/Village.h +++ b/Minecraft.World/WorldGen/Structures/Village.h @@ -1,5 +1,6 @@ #pragma once +#include class Village { private: Level* level; @@ -36,7 +37,7 @@ public: void tick(int tick); private: - Vec3* findRandomSpawnPos(int x, int y, int z, int sx, int sy, int sz); + std::optional findRandomSpawnPos(int x, int y, int z, int sx, int sy, int sz); bool canSpawnAt(int x, int y, int z, int sx, int sy, int sz); void countGolem(); void countPopulation(); @@ -78,4 +79,4 @@ public: void resetNoBreedTimer(); bool isBreedTimerOk(); void rewardAllPlayers(int amount); -}; \ No newline at end of file +};