refactor: remove calls to Vec3::newTemp and Vec3::newPermanent

This commit is contained in:
orng 2026-03-26 13:29:05 -05:00
parent bee10e55a8
commit e887c8cf45
63 changed files with 407 additions and 374 deletions

View file

@ -1112,13 +1112,13 @@ std::shared_ptr<Explosion> ServerLevel::explode(std::shared_ptr<Entity> source,
} }
if (player->distanceToSqr(x, y, z) < 64 * 64) { 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", // app.DebugPrintf("Sending %s with knockback (%f,%f,%f)\n",
// knockbackOnly?"knockbackOnly":"allExplosion",knockbackVec->x,knockbackVec->y,knockbackVec->z); // knockbackOnly?"knockbackOnly":"allExplosion",knockbackVec->x,knockbackVec->y,knockbackVec->z);
// If the player is not the primary on the system, then we only // If the player is not the primary on the system, then we only
// want to send info for the knockback // want to send info for the knockback
player->connection->send(std::shared_ptr<ExplodePacket>( player->connection->send(std::shared_ptr<ExplodePacket>(
new ExplodePacket(x, y, z, r, &explosion->toBlow, knockbackVec, new ExplodePacket(x, y, z, r, &explosion->toBlow, &knockbackVec,
knockbackOnly))); knockbackOnly)));
sentTo.push_back(player); sentTo.push_back(player);
} }

View file

@ -12,7 +12,7 @@
ApplySchematicRuleDefinition::ApplySchematicRuleDefinition( ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(
LevelGenerationOptions* levelGenOptions) { LevelGenerationOptions* levelGenOptions) {
m_levelGenOptions = levelGenOptions; m_levelGenOptions = levelGenOptions;
m_location = Vec3::newPermanent(0, 0, 0); m_location = new Vec3(0, 0, 0);
m_locationBox = NULL; m_locationBox = NULL;
m_totalBlocksChanged = 0; m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0; m_totalBlocksChangedLighting = 0;

View file

@ -156,7 +156,7 @@ void ConsoleSchematicFile::load(DataInputStream* dis) {
// (%f,%f,%f)\n",(int)type,x,y,z); // (%f,%f,%f)\n",(int)type,x,y,z);
#endif #endif
m_entities.push_back(std::pair<Vec3*, CompoundTag*>( m_entities.push_back(std::pair<Vec3*, CompoundTag*>(
Vec3::newPermanent(x, y, z), (CompoundTag*)eTag->copy())); new Vec3(x, y, z), (CompoundTag*)eTag->copy()));
} }
} }
delete tag; delete tag;

View file

@ -25,8 +25,8 @@ AreaConstraint::~AreaConstraint() {
bool AreaConstraint::isConstraintSatisfied(int iPad) { bool AreaConstraint::isConstraintSatisfied(int iPad) {
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
return messageArea->contains(minecraft->localplayers[iPad]->getPos(1)) == Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
contains; return messageArea->contains(&ipad_player) == contains;
} }
bool AreaConstraint::isConstraintRestrictive(int iPad) { bool AreaConstraint::isConstraintRestrictive(int iPad) {

View file

@ -24,10 +24,12 @@ AreaHint::~AreaHint() { delete area; }
int AreaHint::tick() { int AreaHint::tick() {
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
Vec3 player_pos = minecraft->player->getPos(1);
if ((m_displayState == e_Tutorial_State_Any || if ((m_displayState == e_Tutorial_State_Any ||
m_tutorial->getCurrentState() == m_displayState) && m_tutorial->getCurrentState() == m_displayState) &&
m_hintNeeded && m_hintNeeded &&
area->contains(minecraft->player->getPos(1)) == contains) { area->contains(&player_pos) == contains) {
if (m_completeState == e_Tutorial_State_None) { if (m_completeState == e_Tutorial_State_None) {
m_hintNeeded = false; m_hintNeeded = false;
} else if (m_tutorial->isStateCompleted(m_completeState)) { } else if (m_tutorial->isStateCompleted(m_completeState)) {

View file

@ -85,8 +85,9 @@ void ChangeStateConstraint::tick(int iPad) {
break; break;
} }
} }
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
if (!m_bHasChanged && inASourceState && if (!m_bHasChanged && inASourceState &&
movementArea->contains(minecraft->localplayers[iPad]->getPos(1)) == movementArea->contains(&ipad_player) ==
contains) { contains) {
m_bHasChanged = true; m_bHasChanged = true;
m_changedFromState = m_tutorial->getCurrentState(); m_changedFromState = m_tutorial->getCurrentState();
@ -126,7 +127,7 @@ void ChangeStateConstraint::tick(int iPad) {
} }
} else if (m_bHasChanged && } else if (m_bHasChanged &&
movementArea->contains( movementArea->contains(
minecraft->localplayers[iPad]->getPos(1)) != contains) { &ipad_player) != contains) {
m_bHasChanged = false; m_bHasChanged = false;
m_tutorial->changeTutorialState(m_changedFromState); m_tutorial->changeTutorialState(m_changedFromState);

View file

@ -19,13 +19,13 @@ UIScene_DebugSetCamera::UIScene_DebugSetCamera(int iPad, void* initData,
Minecraft* pMinecraft = Minecraft::GetInstance(); Minecraft* pMinecraft = Minecraft::GetInstance();
if (pMinecraft != NULL) { 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 = currentPosition->m_camY =
vec->y - vec.y -
1.62; // pMinecraft->localplayers[playerNo]->getHeadHeight(); 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_yRot = pMinecraft->localplayers[playerNo]->yRot;
currentPosition->m_elev = pMinecraft->localplayers[playerNo]->xRot; currentPosition->m_elev = pMinecraft->localplayers[playerNo]->xRot;

View file

@ -404,25 +404,25 @@ void LocalPlayer::aiStep() {
if (abilities.flying) // minecraft->options->isFlying ) 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 // 4J-PB - To let the player build easily while flying, we need to
// change this // change this
#ifdef _DEBUG_MENUS_ENABLED #ifdef _DEBUG_MENUS_ENABLED
if (abilities.debugflying) { if (abilities.debugflying) {
flyX = (float)viewVector->x * input->ya; flyX = (float)viewVector.x * input->ya;
flyY = (float)viewVector->y * input->ya; flyY = (float)viewVector.y * input->ya;
flyZ = (float)viewVector->z * input->ya; flyZ = (float)viewVector.z * input->ya;
} else } else
#endif #endif
{ {
if (isSprinting()) { if (isSprinting()) {
// Accelrate up to full speed if we are sprinting, moving in the // Accelrate up to full speed if we are sprinting, moving in the
// direction of the view vector // direction of the view vector
flyX = (float)viewVector->x * input->ya; flyX = (float)viewVector.x * input->ya;
flyY = (float)viewVector->y * input->ya; flyY = (float)viewVector.y * input->ya;
flyZ = (float)viewVector->z * input->ya; flyZ = (float)viewVector.z * input->ya;
float scale = ((float)(SPRINT_DURATION - sprintTime)) / 10.0f; float scale = ((float)(SPRINT_DURATION - sprintTime)) / 10.0f;
scale = scale * scale; scale = scale * scale;

View file

@ -91,10 +91,11 @@ zPlayerOffs = position->get(2);
TilePos* Camera::getCameraTilePos(std::shared_ptr<LivingEntity> player, TilePos* Camera::getCameraTilePos(std::shared_ptr<LivingEntity> player,
double alpha) { 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<LivingEntity> player, double alpha) { Vec3 Camera::getCameraPos(std::shared_ptr<LivingEntity> player, double alpha) {
double xx = player->xo + (player->x - player->xo) * alpha; double xx = player->xo + (player->x - player->xo) * alpha;
double yy = double yy =
player->yo + (player->y - player->yo) * alpha + player->getHeadHeight(); player->yo + (player->y - player->yo) * alpha + player->getHeadHeight();
@ -104,19 +105,19 @@ Vec3* Camera::getCameraPos(std::shared_ptr<LivingEntity> player, double alpha) {
double yt = yy + Camera::yPlayerOffs * 1; double yt = yy + Camera::yPlayerOffs * 1;
double zt = zz + Camera::zPlayerOffs * 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<LivingEntity> player, int Camera::getBlockAt(Level* level, std::shared_ptr<LivingEntity> player,
float alpha) { float alpha) {
Vec3* p = Camera::getCameraPos(player, alpha); Vec3 p = Camera::getCameraPos(player, alpha);
TilePos tp = TilePos(p); TilePos tp = TilePos(&p);
int t = level->getTile(tp.x, tp.y, tp.z); int t = level->getTile(tp.x, tp.y, tp.z);
if (t != 0 && Tile::tiles[t]->material->isLiquid()) { if (t != 0 && Tile::tiles[t]->material->isLiquid()) {
float hh = float hh =
LiquidTile::getHeight(level->getData(tp.x, tp.y, tp.z)) - 1 / 9.0f; LiquidTile::getHeight(level->getData(tp.x, tp.y, tp.z)) - 1 / 9.0f;
float h = tp.y + 1 - hh; float h = tp.y + 1 - hh;
if (p->y >= h) { if (p.y >= h) {
t = level->getTile(tp.x, tp.y + 1, tp.z); t = level->getTile(tp.x, tp.y + 1, tp.z);
} }
} }

View file

@ -26,7 +26,7 @@ public:
static TilePos* getCameraTilePos(std::shared_ptr<LivingEntity> player, static TilePos* getCameraTilePos(std::shared_ptr<LivingEntity> player,
double alpha); double alpha);
static Vec3* getCameraPos(std::shared_ptr<LivingEntity> player, static Vec3 getCameraPos(std::shared_ptr<LivingEntity> player,
double alpha); double alpha);
static int getBlockAt(Level* level, std::shared_ptr<LivingEntity> player, static int getBlockAt(Level* level, std::shared_ptr<LivingEntity> player,
float alpha); float alpha);

View file

@ -1,5 +1,6 @@
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "MinecartRenderer.h" #include "MinecartRenderer.h"
#include <optional>
#include "../Models/MinecartModel.h" #include "../Models/MinecartModel.h"
#include "../../Textures/TextureAtlas.h" #include "../../Textures/TextureAtlas.h"
#include "../../../Minecraft.World/Headers/net.minecraft.world.entity.item.h" #include "../../../Minecraft.World/Headers/net.minecraft.world.entity.item.h"
@ -40,15 +41,15 @@ void MinecartRenderer::render(std::shared_ptr<Entity> _cart, double x, double y,
double r = 0.3f; double r = 0.3f;
Vec3* p = cart->getPos(xx, yy, zz); std::optional<Vec3> p = cart->getPos(xx, yy, zz);
float xRot = cart->xRotO + (cart->xRot - cart->xRotO) * a; float xRot = cart->xRotO + (cart->xRot - cart->xRotO) * a;
if (p != NULL) { if (p.has_value()) {
Vec3* p0 = cart->getPosOffs(xx, yy, zz, r); auto p0 = cart->getPosOffs(xx, yy, zz, r);
Vec3* p1 = cart->getPosOffs(xx, yy, zz, -r); auto p1 = cart->getPosOffs(xx, yy, zz, -r);
if (p0 == NULL) p0 = p; if (!p0.has_value()) p0 = p;
if (p1 == NULL) p1 = p; if (!p1.has_value()) p1 = p;
x += p->x - xx; x += p->x - xx;
y += (p0->y + p1->y) / 2 - yy; y += (p0->y + p1->y) / 2 - yy;

View file

@ -1,6 +1,7 @@
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "TileRenderer.h" #include "TileRenderer.h"
#include <array>
#include "../GameRenderer.h" #include "../GameRenderer.h"
#include "../../Minecraft.h" #include "../../Minecraft.h"
#include "../../Textures/Textures.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 u1 = tex->getU1(true);
float v1 = tex->getV1(true); float v1 = tex->getV1(true);
Vec3* corners[8]; std::array<Vec3, 8> corners;
float xv = 1.0f / 16.0f; float xv = 1.0f / 16.0f;
float zv = 1.0f / 16.0f; float zv = 1.0f / 16.0f;
float yv = 10.0f / 16.0f; float yv = 10.0f / 16.0f;
corners[0] = Vec3::newTemp(-xv, -0, -zv); corners[0] = Vec3(-xv, -0, -zv);
corners[1] = Vec3::newTemp(+xv, -0, -zv); corners[1] = Vec3(+xv, -0, -zv);
corners[2] = Vec3::newTemp(+xv, -0, +zv); corners[2] = Vec3(+xv, -0, +zv);
corners[3] = Vec3::newTemp(-xv, -0, +zv); corners[3] = Vec3(-xv, -0, +zv);
corners[4] = Vec3::newTemp(-xv, +yv, -zv); corners[4] = Vec3(-xv, +yv, -zv);
corners[5] = Vec3::newTemp(+xv, +yv, -zv); corners[5] = Vec3(+xv, +yv, -zv);
corners[6] = Vec3::newTemp(+xv, +yv, +zv); corners[6] = Vec3(+xv, +yv, +zv);
corners[7] = Vec3::newTemp(-xv, +yv, +zv); corners[7] = Vec3(-xv, +yv, +zv);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (flipped) { if (flipped) {
corners[i]->z -= 1 / 16.0f; corners[i].z -= 1 / 16.0f;
corners[i]->xRot(40 * PI / 180); corners[i].xRot(40 * PI / 180);
} else { } else {
corners[i]->z += 1 / 16.0f; corners[i].z += 1 / 16.0f;
corners[i]->xRot(-40 * PI / 180); corners[i].xRot(-40 * PI / 180);
} }
if (dir == 0 || dir == 7) { if (dir == 0 || dir == 7) {
corners[i]->zRot(180 * PI / 180); corners[i].zRot(180 * PI / 180);
} }
if (dir == 6 || dir == 0) { if (dir == 6 || dir == 0) {
corners[i]->yRot(90 * PI / 180); corners[i].yRot(90 * PI / 180);
} }
if (dir > 0 && dir < 5) { if (dir > 0 && dir < 5) {
corners[i]->y -= 6 / 16.0f; corners[i].y -= 6 / 16.0f;
corners[i]->xRot(90 * PI / 180); corners[i].xRot(90 * PI / 180);
if (dir == 4) corners[i]->yRot(0 * PI / 180); if (dir == 4) corners[i].yRot(0 * PI / 180);
if (dir == 3) corners[i]->yRot(180 * PI / 180); if (dir == 3) corners[i].yRot(180 * PI / 180);
if (dir == 2) corners[i]->yRot(90 * PI / 180); if (dir == 2) corners[i].yRot(90 * PI / 180);
if (dir == 1) corners[i]->yRot(-90 * PI / 180); if (dir == 1) corners[i].yRot(-90 * PI / 180);
corners[i]->x += x + 0.5; corners[i].x += x + 0.5;
corners[i]->y += y + 8 / 16.0f; corners[i].y += y + 8 / 16.0f;
corners[i]->z += z + 0.5; corners[i].z += z + 0.5;
} else if (dir == 0 || dir == 7) { } else if (dir == 0 || dir == 7) {
corners[i]->x += x + 0.5; corners[i].x += x + 0.5;
corners[i]->y += y + 14 / 16.0f; corners[i].y += y + 14 / 16.0f;
corners[i]->z += z + 0.5; corners[i].z += z + 0.5;
} else { } else {
corners[i]->x += x + 0.5; corners[i].x += x + 0.5;
corners[i]->y += y + 2 / 16.0f; corners[i].y += y + 2 / 16.0f;
corners[i]->z += z + 0.5; 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++) { for (int i = 0; i < 6; i++) {
if (i == 0) { if (i == 0) {
u0 = tex->getU(7, true); u0 = tex->getU(7, true);
@ -1912,13 +1913,13 @@ bool TileRenderer::tesselateLeverInWorld(Tile* tt, int x, int y, int z) {
c2 = corners[7]; c2 = corners[7];
c3 = corners[4]; 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)); (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)); (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)); (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)); (float)(v0));
} }
return true; return true;
@ -1976,46 +1977,46 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y,
double u1 = tex->getU1(); double u1 = tex->getU1();
double v1 = tex->getV1(); double v1 = tex->getV1();
Vec3* corners[8]; std::array<Vec3, 8> corners;
float stickWidth = 0.75f / 16.0f; float stickWidth = 0.75f / 16.0f;
float stickHeight = 0.75f / 16.0f; float stickHeight = 0.75f / 16.0f;
float stickLength = 5 / 16.0f; float stickLength = 5 / 16.0f;
corners[0] = Vec3::newTemp(-stickWidth, -0, -stickHeight); corners[0] = Vec3(-stickWidth, -0, -stickHeight);
corners[1] = Vec3::newTemp(+stickWidth, -0, -stickHeight); corners[1] = Vec3(+stickWidth, -0, -stickHeight);
corners[2] = Vec3::newTemp(+stickWidth, -0, +stickHeight); corners[2] = Vec3(+stickWidth, -0, +stickHeight);
corners[3] = Vec3::newTemp(-stickWidth, -0, +stickHeight); corners[3] = Vec3(-stickWidth, -0, +stickHeight);
corners[4] = Vec3::newTemp(-stickWidth, +stickLength, -stickHeight); corners[4] = Vec3(-stickWidth, +stickLength, -stickHeight);
corners[5] = Vec3::newTemp(+stickWidth, +stickLength, -stickHeight); corners[5] = Vec3(+stickWidth, +stickLength, -stickHeight);
corners[6] = Vec3::newTemp(+stickWidth, +stickLength, +stickHeight); corners[6] = Vec3(+stickWidth, +stickLength, +stickHeight);
corners[7] = Vec3::newTemp(-stickWidth, +stickLength, +stickHeight); corners[7] = Vec3(-stickWidth, +stickLength, +stickHeight);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
corners[i]->z += 1 / 16.0f; corners[i].z += 1 / 16.0f;
if (powered) { if (powered) {
corners[i]->xRot(30 * PI / 180); corners[i].xRot(30 * PI / 180);
corners[i]->y -= 7 / 16.0f; corners[i].y -= 7 / 16.0f;
} else if (attached) { } else if (attached) {
corners[i]->xRot(5 * PI / 180); corners[i].xRot(5 * PI / 180);
corners[i]->y -= 7 / 16.0f; corners[i].y -= 7 / 16.0f;
} else { } else {
corners[i]->xRot(-40 * PI / 180); corners[i].xRot(-40 * PI / 180);
corners[i]->y -= 6 / 16.0f; 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::NORTH) corners[i].yRot(0 * PI / 180);
if (dir == Direction::SOUTH) corners[i]->yRot(180 * 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::WEST) corners[i].yRot(90 * PI / 180);
if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180); if (dir == Direction::EAST) corners[i].yRot(-90 * PI / 180);
corners[i]->x += x + 0.5; corners[i].x += x + 0.5;
corners[i]->y += y + 5 / 16.0f; corners[i].y += y + 5 / 16.0f;
corners[i]->z += z + 0.5; corners[i].z += z + 0.5;
} }
Vec3 *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL; Vec3 c0, c1, c2, c3;
int stickX0 = 7; int stickX0 = 7;
int stickX1 = 9; int stickX1 = 9;
int stickY0 = 9; int stickY0 = 9;
@ -2061,47 +2062,47 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y,
c2 = corners[7]; c2 = corners[7];
c3 = corners[4]; c3 = corners[4];
} }
t->vertexUV(c0->x, c0->y, c0->z, u0, v1); t->vertexUV(c0.x, c0.y, c0.z, u0, v1);
t->vertexUV(c1->x, c1->y, c1->z, u1, v1); t->vertexUV(c1.x, c1.y, c1.z, u1, v1);
t->vertexUV(c2->x, c2->y, c2->z, u1, v0); t->vertexUV(c2.x, c2.y, c2.z, u1, v0);
t->vertexUV(c3->x, c3->y, c3->z, u0, v0); t->vertexUV(c3.x, c3.y, c3.z, u0, v0);
} }
float hoopWidth = 1.5f / 16.0f; float hoopWidth = 1.5f / 16.0f;
float hoopHeight = 1.5f / 16.0f; float hoopHeight = 1.5f / 16.0f;
float hoopLength = 0.5f / 16.0f; float hoopLength = 0.5f / 16.0f;
corners[0] = Vec3::newTemp(-hoopWidth, -0, -hoopHeight); corners[0] = Vec3(-hoopWidth, -0, -hoopHeight);
corners[1] = Vec3::newTemp(+hoopWidth, -0, -hoopHeight); corners[1] = Vec3(+hoopWidth, -0, -hoopHeight);
corners[2] = Vec3::newTemp(+hoopWidth, -0, +hoopHeight); corners[2] = Vec3(+hoopWidth, -0, +hoopHeight);
corners[3] = Vec3::newTemp(-hoopWidth, -0, +hoopHeight); corners[3] = Vec3(-hoopWidth, -0, +hoopHeight);
corners[4] = Vec3::newTemp(-hoopWidth, +hoopLength, -hoopHeight); corners[4] = Vec3(-hoopWidth, +hoopLength, -hoopHeight);
corners[5] = Vec3::newTemp(+hoopWidth, +hoopLength, -hoopHeight); corners[5] = Vec3(+hoopWidth, +hoopLength, -hoopHeight);
corners[6] = Vec3::newTemp(+hoopWidth, +hoopLength, +hoopHeight); corners[6] = Vec3(+hoopWidth, +hoopLength, +hoopHeight);
corners[7] = Vec3::newTemp(-hoopWidth, +hoopLength, +hoopHeight); corners[7] = Vec3(-hoopWidth, +hoopLength, +hoopHeight);
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
corners[i]->z += 3.5f / 16.0f; corners[i].z += 3.5f / 16.0f;
if (powered) { if (powered) {
corners[i]->y -= 1.5 / 16.0f; corners[i].y -= 1.5 / 16.0f;
corners[i]->z -= 2.6 / 16.0f; corners[i].z -= 2.6 / 16.0f;
corners[i]->xRot(0 * PI / 180); corners[i].xRot(0 * PI / 180);
} else if (attached) { } else if (attached) {
corners[i]->y += 0.25 / 16.0f; corners[i].y += 0.25 / 16.0f;
corners[i]->z -= 2.75 / 16.0f; corners[i].z -= 2.75 / 16.0f;
corners[i]->xRot(10 * PI / 180); corners[i].xRot(10 * PI / 180);
} else { } 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::NORTH) corners[i].yRot(0 * PI / 180);
if (dir == Direction::SOUTH) corners[i]->yRot(180 * 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::WEST) corners[i].yRot(90 * PI / 180);
if (dir == Direction::EAST) corners[i]->yRot(-90 * PI / 180); if (dir == Direction::EAST) corners[i].yRot(-90 * PI / 180);
corners[i]->x += x + 0.5; corners[i].x += x + 0.5;
corners[i]->y += y + 5 / 16.0f; corners[i].y += y + 5 / 16.0f;
corners[i]->z += z + 0.5; corners[i].z += z + 0.5;
} }
int hoopX0 = 5; int hoopX0 = 5;
@ -2149,14 +2150,14 @@ bool TileRenderer::tesselateTripwireSourceInWorld(Tile* tt, int x, int y,
c2 = corners[7]; c2 = corners[7];
c3 = corners[4]; c3 = corners[4];
} }
t->vertexUV(c0->x, c0->y, c0->z, u0, v1); t->vertexUV(c0.x, c0.y, c0.z, u0, v1);
t->vertexUV(c1->x, c1->y, c1->z, u1, v1); t->vertexUV(c1.x, c1.y, c1.z, u1, v1);
t->vertexUV(c2->x, c2->y, c2->z, u1, v0); t->vertexUV(c2.x, c2.y, c2.z, u1, v0);
t->vertexUV(c3->x, c3->y, c3->z, u0, v0); t->vertexUV(c3.x, c3.y, c3.z, u0, v0);
} }
if (attached) { if (attached) {
double hoopBottomY = corners[0]->y; double hoopBottomY = corners[0].y;
float width = 0.5f / 16.0f; float width = 0.5f / 16.0f;
float top = 0.5f - (width / 2); float top = 0.5f - (width / 2);
float bottom = top + width; float bottom = top + width;

View file

@ -90,7 +90,7 @@ GameRenderer::GameRenderer(Minecraft* mc) {
tickSmoothYO = 0; tickSmoothYO = 0;
lastTickA = 0; lastTickA = 0;
cameraPos = Vec3::newPermanent(0.0f, 0.0f, 0.0f); cameraPos = new Vec3(0.0f, 0.0f, 0.0f);
fovOffset = 0; fovOffset = 0;
fovOffsetO = 0; fovOffsetO = 0;
@ -291,7 +291,7 @@ void GameRenderer::pick(float a) {
} }
double dist = range; double dist = range;
Vec3* from = mc->cameraTargetPlayer->getPos(a); Vec3 from = mc->cameraTargetPlayer->getPos(a);
if (mc->gameMode->hasFarPickRange()) { if (mc->gameMode->hasFarPickRange()) {
dist = range = 6; dist = range = 6;
@ -301,18 +301,18 @@ void GameRenderer::pick(float a) {
} }
if (mc->hitResult != NULL) { if (mc->hitResult != NULL) {
dist = mc->hitResult->pos.distanceTo(*from); dist = mc->hitResult->pos.distanceTo(from);
} }
Vec3* b = mc->cameraTargetPlayer->getViewVector(a); Vec3 b = mc->cameraTargetPlayer->getViewVector(a);
Vec3 to(b->x * range, b->y * range, b->z * range); Vec3 to(b.x * range, b.y * range, b.z * range);
to = to.add(from->x, from->y, from->z); to = to.add(from.x, from.y, from.z);
hovered = nullptr; hovered = nullptr;
float overlap = 1; float overlap = 1;
std::vector<std::shared_ptr<Entity> >* objects = mc->level->getEntities( std::vector<std::shared_ptr<Entity> >* objects = mc->level->getEntities(
mc->cameraTargetPlayer, mc->cameraTargetPlayer,
mc->cameraTargetPlayer->bb 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)); ->grow(overlap, overlap, overlap));
double nearest = dist; double nearest = dist;
@ -323,14 +323,14 @@ void GameRenderer::pick(float a) {
float rr = e->getPickRadius(); float rr = e->getPickRadius();
AABB* bb = e->bb->grow(rr, rr, rr); AABB* bb = e->bb->grow(rr, rr, rr);
HitResult* p = bb->clip(from, &to); HitResult* p = bb->clip(&from, &to);
if (bb->contains(from)) { if (bb->contains(&from)) {
if (0 < nearest || nearest == 0) { if (0 < nearest || nearest == 0) {
hovered = e; hovered = e;
nearest = 0; nearest = 0;
} }
} else if (p != NULL) { } else if (p != NULL) {
double dd = from->distanceTo(p->pos); double dd = from.distanceTo(p->pos);
std::shared_ptr<Entity> ridingEntity = std::shared_ptr<Entity> ridingEntity =
mc->cameraTargetPlayer->riding; mc->cameraTargetPlayer->riding;
// 4jcraft: compare the mounted entity explicitly so riding the hit // 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: // storing the camera position Fix for #77745 - TU9: Content:
// Gameplay: Items and mobs not belonging to end world are // Gameplay: Items and mobs not belonging to end world are
// disappearing when Enderdragon is damaged. // disappearing when Enderdragon is damaged.
Vec3* cameraPosTemp = cameraEntity->getPos(a); Vec3 cameraPosTemp = cameraEntity->getPos(a);
cameraPos->x = cameraPosTemp->x; cameraPos->x = cameraPosTemp.x;
cameraPos->y = cameraPosTemp->y; cameraPos->y = cameraPosTemp.y;
cameraPos->z = cameraPosTemp->z; cameraPos->z = cameraPosTemp.z;
levelRenderer->renderEntities(cameraPos, frustum, a); levelRenderer->renderEntities(cameraPos, frustum, a);
#ifdef __PSVITA__ #ifdef __PSVITA__
// AP - make sure we're using the Alpha cut out effect for particles // 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); float whiteness = 1.0f / (4 - mc->options->viewDistance);
whiteness = 1 - (float)pow((double)whiteness, 0.25); whiteness = 1 - (float)pow((double)whiteness, 0.25);
Vec3* skyColor = level->getSkyColor(mc->cameraTargetPlayer, a); Vec3 skyColor = level->getSkyColor(mc->cameraTargetPlayer, a);
float sr = (float)skyColor->x; float sr = (float)skyColor.x;
float sg = (float)skyColor->y; float sg = (float)skyColor.y;
float sb = (float)skyColor->z; float sb = (float)skyColor.z;
Vec3* fogColor = level->getFogColor(a); Vec3 fogColor = level->getFogColor(a);
fr = (float)fogColor->x; fr = (float)fogColor.x;
fg = (float)fogColor->y; fg = (float)fogColor.y;
fb = (float)fogColor->z; fb = (float)fogColor.z;
if (mc->options->viewDistance < 2) { if (mc->options->viewDistance < 2) {
Vec3 sunAngle = Mth::sin(level->getSunAngle(a)) > 0 Vec3 sunAngle = Mth::sin(level->getSunAngle(a)) > 0
? Vec3(-1, 0, 0) ? Vec3(-1, 0, 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) d = 0;
if (d > 0) { if (d > 0) {
float* c = float* c =
@ -1905,10 +1905,10 @@ void GameRenderer::setupClearColor(float a) {
int t = Camera::getBlockAt(mc->level, player, a); int t = Camera::getBlockAt(mc->level, player, a);
if (isInClouds) { if (isInClouds) {
Vec3* cc = level->getCloudColor(a); Vec3 cc = level->getCloudColor(a);
fr = (float)cc->x; fr = (float)cc.x;
fg = (float)cc->y; fg = (float)cc.y;
fb = (float)cc->z; fb = (float)cc.z;
} else if (t != 0 && Tile::tiles[t]->material == Material::water) { } else if (t != 0 && Tile::tiles[t]->material == Material::water) {
float clearness = EnchantmentHelper::getOxygenBonus(player) * 0.2f; float clearness = EnchantmentHelper::getOxygenBonus(player) * 0.2f;

View file

@ -1035,10 +1035,10 @@ void LevelRenderer::renderSky(float alpha) {
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
int playerIndex = mc->player->GetXboxPad(); int playerIndex = mc->player->GetXboxPad();
Vec3* sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha); Vec3 sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha);
float sr = (float)sc->x; float sr = (float)sc.x;
float sg = (float)sc->y; float sg = (float)sc.y;
float sb = (float)sc->z; float sb = (float)sc.z;
if (mc->options->anaglyph3d) { if (mc->options->anaglyph3d) {
float srr = (sr * 30 + sg * 59 + sb * 11) / 100; float srr = (sr * 30 + sg * 59 + sb * 11) / 100;
@ -1185,7 +1185,7 @@ void LevelRenderer::renderSky(float alpha) {
glColor3f(0, 0, 0); glColor3f(0, 0, 0);
double yy = double yy =
mc->player->getPos(alpha)->y - mc->player->getPos(alpha).y -
level[playerIndex]->getHorizonHeight(); // 4J - getHorizonHeight moved level[playerIndex]->getHorizonHeight(); // 4J - getHorizonHeight moved
// forward from 1.2.3 // forward from 1.2.3
if (yy < 0) { if (yy < 0) {
@ -1259,10 +1259,10 @@ void LevelRenderer::renderHaloRing(float alpha) {
int playerIndex = mc->player->GetXboxPad(); int playerIndex = mc->player->GetXboxPad();
Vec3* sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha); Vec3 sc = level[playerIndex]->getSkyColor(mc->cameraTargetPlayer, alpha);
float sr = (float)sc->x; float sr = (float)sc.x;
float sg = (float)sc->y; float sg = (float)sc.y;
float sb = (float)sc->z; float sb = (float)sc.z;
// Rough lumninance calculation // Rough lumninance calculation
float Y = (sr + sr + sb + sg + sg + sg) / 6; float Y = (sr + sr + sb + sg + sg + sg) / 6;
@ -1335,10 +1335,10 @@ void LevelRenderer::renderClouds(float alpha) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Vec3* cc = level[playerIndex]->getCloudColor(alpha); Vec3 cc = level[playerIndex]->getCloudColor(alpha);
float cr = (float)cc->x; float cr = (float)cc.x;
float cg = (float)cc->y; float cg = (float)cc.y;
float cb = (float)cc->z; float cb = (float)cc.z;
if (mc->options->anaglyph3d) { if (mc->options->anaglyph3d) {
float crr = (cr * 30 + cg * 59 + cb * 11) / 100; float crr = (cr * 30 + cg * 59 + cb * 11) / 100;
@ -1632,10 +1632,10 @@ void LevelRenderer::renderAdvancedClouds(float alpha) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Vec3* cc = level[playerIndex]->getCloudColor(alpha); Vec3 cc = level[playerIndex]->getCloudColor(alpha);
float cr = (float)cc->x; float cr = (float)cc.x;
float cg = (float)cc->y; float cg = (float)cc.y;
float cb = (float)cc->z; float cb = (float)cc.z;
if (mc->options->anaglyph3d) { if (mc->options->anaglyph3d) {
float crr = (cr * 30 + cg * 59 + cb * 11) / 100; float crr = (cr * 30 + cg * 59 + cb * 11) / 100;

View file

@ -2,7 +2,7 @@
#include "Vertex.h" #include "Vertex.h"
Vertex::Vertex(float x, float y, float z, float u, float v) { 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->u = u;
this->v = v; this->v = v;
} }

View file

@ -65,17 +65,17 @@ bool AvoidPlayerGoal::canUse() {
} }
Vec3 avoid_pos(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z); Vec3 avoid_pos(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z);
Vec3* pos = RandomPos::getPosAvoid( auto pos = RandomPos::getPosAvoid(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, &avoid_pos); 7, &avoid_pos);
if (pos == NULL) return false; if (!pos.has_value()) return false;
if (toAvoid.lock()->distanceToSqr(pos->x, pos->y, pos->z) < if (toAvoid.lock()->distanceToSqr(pos->x, pos->y, pos->z) <
toAvoid.lock()->distanceToSqr(mob->shared_from_this())) toAvoid.lock()->distanceToSqr(mob->shared_from_this()))
return false; return false;
delete path; delete path;
path = pathNav->createPath(pos->x, pos->y, pos->z); path = pathNav->createPath(pos->x, pos->y, pos->z);
if (path == NULL) return false; if (path == NULL) return false;
if (!path->endsInXZ(pos)) return false; if (!path->endsInXZ(&*pos)) return false;
return true; return true;
} }

View file

@ -5,6 +5,7 @@
#include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.level.h"
#include "../../Headers/net.minecraft.world.phys.h" #include "../../Headers/net.minecraft.world.phys.h"
#include "FleeSunGoal.h" #include "FleeSunGoal.h"
#include <optional>
FleeSunGoal::FleeSunGoal(PathfinderMob* mob, double speedModifier) { FleeSunGoal::FleeSunGoal(PathfinderMob* mob, double speedModifier) {
this->mob = mob; this->mob = mob;
@ -20,8 +21,8 @@ bool FleeSunGoal::canUse() {
Mth::floor(mob->z))) Mth::floor(mob->z)))
return false; return false;
Vec3* pos = getHidePos(); auto pos = getHidePos();
if (pos == NULL) return false; if (!pos.has_value()) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;
wantedZ = pos->z; wantedZ = pos->z;
@ -34,7 +35,7 @@ void FleeSunGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier); mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
} }
Vec3* FleeSunGoal::getHidePos() { std::optional<Vec3> FleeSunGoal::getHidePos() {
Random* random = mob->getRandom(); Random* random = mob->getRandom();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
int xt = Mth::floor(mob->x + random->nextInt(20) - 10); 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); int zt = Mth::floor(mob->z + random->nextInt(20) - 10);
if (!level->canSeeSky(xt, yt, zt) && if (!level->canSeeSky(xt, yt, zt) &&
mob->getWalkTargetValue(xt, yt, zt) < 0) mob->getWalkTargetValue(xt, yt, zt) < 0)
return Vec3::newTemp(xt, yt, zt); return Vec3(xt, yt, zt);
} }
return NULL; return std::nullopt;
} }

View file

@ -1,5 +1,8 @@
#pragma once #pragma once
#include <optional>
#include "../../Util/Vec3.h"
#include "Goal.h" #include "Goal.h"
class FleeSunGoal : public Goal { class FleeSunGoal : public Goal {
@ -17,7 +20,7 @@ public:
virtual void start(); virtual void start();
private: private:
Vec3* getHidePos(); std::optional<Vec3> getHidePos();
public: public:
// 4J Added override to update ai elements when loading entity from // 4J Added override to update ai elements when loading entity from

View file

@ -46,10 +46,10 @@ void MoveIndoorsGoal::start() {
_doorInfo->getIndoorZ()) > 16 * 16) { _doorInfo->getIndoorZ()) > 16 * 16) {
Vec3 towards(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(), Vec3 towards(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(),
_doorInfo->getIndoorZ() + 0.5); _doorInfo->getIndoorZ() + 0.5);
Vec3* pos = RandomPos::getPosTowards( auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()),
14, 3, &towards); 14, 3, &towards);
if (pos != NULL) if (pos.has_value())
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, 1.0f); mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, 1.0f);
} else } else
mob->getNavigation()->moveTo(_doorInfo->getIndoorX() + 0.5, mob->getNavigation()->moveTo(_doorInfo->getIndoorX() + 0.5,

View file

@ -48,10 +48,10 @@ bool MoveThroughVillageGoal::canUse() {
if (path != NULL) return true; if (path != NULL) return true;
Vec3 towards(_doorInfo->x, _doorInfo->y, _doorInfo->z); Vec3 towards(_doorInfo->x, _doorInfo->y, _doorInfo->z);
Vec3* pos = RandomPos::getPosTowards( auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10,
7, &towards); 7, &towards);
if (pos == NULL) return false; if (!pos.has_value()) return false;
mob->getNavigation()->setCanOpenDoors(false); mob->getNavigation()->setCanOpenDoors(false);
delete path; delete path;
path = mob->getNavigation()->createPath(pos->x, pos->y, pos->z); path = mob->getNavigation()->createPath(pos->x, pos->y, pos->z);

View file

@ -19,10 +19,10 @@ bool MoveTowardsRestrictionGoal::canUse() {
if (mob->isWithinRestriction()) return false; if (mob->isWithinRestriction()) return false;
Pos* toward = mob->getRestrictCenter(); Pos* toward = mob->getRestrictCenter();
Vec3 towards(toward->x, toward->y, toward->z); Vec3 towards(toward->x, toward->y, toward->z);
Vec3* pos = RandomPos::getPosTowards( auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, &towards); 7, &towards);
if (pos == NULL) return false; if (!pos.has_value()) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;
wantedZ = pos->z; wantedZ = pos->z;

View file

@ -21,10 +21,10 @@ bool MoveTowardsTargetGoal::canUse() {
if (target.lock()->distanceToSqr(mob->shared_from_this()) > within * within) if (target.lock()->distanceToSqr(mob->shared_from_this()) > within * within)
return false; return false;
Vec3 towards(target.lock()->x, target.lock()->y, target.lock()->z); Vec3 towards(target.lock()->x, target.lock()->y, target.lock()->z);
Vec3* pos = RandomPos::getPosTowards( auto pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, &towards); 7, &towards);
if (pos == NULL) return false; if (!pos.has_value()) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;
wantedZ = pos->z; wantedZ = pos->z;

View file

@ -14,10 +14,10 @@ PanicGoal::PanicGoal(PathfinderMob* mob, double speedModifier) {
bool PanicGoal::canUse() { bool PanicGoal::canUse() {
if (mob->getLastHurtByMob() == NULL && !mob->isOnFire()) return false; if (mob->getLastHurtByMob() == NULL && !mob->isOnFire()) return false;
Vec3* pos = RandomPos::getPos( auto pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5,
4); 4);
if (pos == NULL) return false; if (!pos.has_value()) return false;
posX = pos->x; posX = pos->x;
posY = pos->y; posY = pos->y;
posZ = pos->z; posZ = pos->z;

View file

@ -43,10 +43,10 @@ bool PlayGoal::canUse() {
delete children; delete children;
if (followFriend.lock() == NULL) { if (followFriend.lock() == NULL) {
Vec3* pos = RandomPos::getPos( auto pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()),
16, 3); 16, 3);
if (pos == NULL) return false; if (!pos.has_value()) return false;
} }
return true; return true;
} }
@ -72,11 +72,11 @@ void PlayGoal::tick() {
mob->getNavigation()->moveTo(followFriend.lock(), speedModifier); mob->getNavigation()->moveTo(followFriend.lock(), speedModifier);
} else { } else {
if (mob->getNavigation()->isDone()) { if (mob->getNavigation()->isDone()) {
Vec3* pos = auto pos =
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>( RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
mob->shared_from_this()), mob->shared_from_this()),
16, 3); 16, 3);
if (pos == NULL) return; if (!pos.has_value()) return;
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier); mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier);
} }
} }

View file

@ -20,11 +20,11 @@ bool RandomStrollGoal::canUse() {
// fenced-off region far enough to determine we can despawn them // fenced-off region far enough to determine we can despawn them
if (mob->getNoActionTime() < SharedConstants::TICKS_PER_SECOND * 5) { if (mob->getNoActionTime() < SharedConstants::TICKS_PER_SECOND * 5) {
if (mob->getRandom()->nextInt(120) == 0) { if (mob->getRandom()->nextInt(120) == 0) {
Vec3* pos = auto pos =
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>( RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
mob->shared_from_this()), mob->shared_from_this()),
10, 7); 10, 7);
if (pos == NULL) return false; if (!pos.has_value()) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;
wantedZ = pos->z; wantedZ = pos->z;
@ -38,11 +38,11 @@ bool RandomStrollGoal::canUse() {
// a given area and so waiting around is just wasting time // a given area and so waiting around is just wasting time
if (mob->isExtraWanderingEnabled()) { if (mob->isExtraWanderingEnabled()) {
Vec3* pos = auto pos =
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>( RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
mob->shared_from_this()), mob->shared_from_this()),
10, 7, mob->getWanderingQuadrant()); 10, 7, mob->getWanderingQuadrant());
if (pos == NULL) return false; if (!pos.has_value()) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;
wantedZ = pos->z; wantedZ = pos->z;

View file

@ -17,10 +17,10 @@ RunAroundLikeCrazyGoal::RunAroundLikeCrazyGoal(EntityHorse* mob,
bool RunAroundLikeCrazyGoal::canUse() { bool RunAroundLikeCrazyGoal::canUse() {
if (horse->isTamed() || horse->rider.lock() == NULL) return false; if (horse->isTamed() || horse->rider.lock() == NULL) return false;
Vec3* pos = RandomPos::getPos( auto pos = RandomPos::getPos(
std::dynamic_pointer_cast<PathfinderMob>(horse->shared_from_this()), 5, std::dynamic_pointer_cast<PathfinderMob>(horse->shared_from_this()), 5,
4); 4);
if (pos == NULL) return false; if (!pos.has_value()) return false;
posX = pos->x; posX = pos->x;
posY = pos->y; posY = pos->y;
posZ = pos->z; posZ = pos->z;

View file

@ -48,17 +48,17 @@ int Path::getIndex() { return index; }
void Path::setIndex(int index) { this->index = index; } void Path::setIndex(int index) { this->index = index; }
Vec3* Path::getPos(std::shared_ptr<Entity> e, int index) { Vec3 Path::getPos(std::shared_ptr<Entity> e, int index) {
double x = nodes[index]->x + (int)(e->bbWidth + 1) * 0.5; double x = nodes[index]->x + (int)(e->bbWidth + 1) * 0.5;
double y = nodes[index]->y; double y = nodes[index]->y;
double z = nodes[index]->z + (int)(e->bbWidth + 1) * 0.5; 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<Entity> e) { return getPos(e, index); } Vec3 Path::currentPos(std::shared_ptr<Entity> e) { return getPos(e, index); }
Vec3* Path::currentPos() { Vec3 Path::currentPos() {
return Vec3::newTemp(nodes[index]->x, nodes[index]->y, nodes[index]->z); return Vec3(nodes[index]->x, nodes[index]->y, nodes[index]->z);
} }
bool Path::sameAs(Path* path) { bool Path::sameAs(Path* path) {

View file

@ -20,10 +20,10 @@ public:
void setSize(int length); void setSize(int length);
int getIndex(); int getIndex();
void setIndex(int index); void setIndex(int index);
Vec3* getPos(std::shared_ptr<Entity> e, int index); Vec3 getPos(std::shared_ptr<Entity> e, int index);
NodeArray Getarray(); NodeArray Getarray();
Vec3* currentPos(std::shared_ptr<Entity> e); Vec3 currentPos(std::shared_ptr<Entity> e);
Vec3* currentPos(); Vec3 currentPos();
bool sameAs(Path* path); bool sameAs(Path* path);
bool endsIn(Vec3* pos); bool endsIn(Vec3* pos);
bool endsInXZ(Vec3* pos); bool endsInXZ(Vec3* pos);

View file

@ -20,7 +20,7 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
avoidSun = false; avoidSun = false;
_tick = 0; _tick = 0;
lastStuckCheck = 0; lastStuckCheck = 0;
lastStuckCheckPos = Vec3::newPermanent(0, 0, 0); lastStuckCheckPos = new Vec3(0, 0, 0);
_canPassDoors = true; _canPassDoors = true;
_canOpenDoors = false; _canOpenDoors = false;
avoidWater = false; avoidWater = false;
@ -110,11 +110,11 @@ bool PathNavigation::moveTo(Path* newPath, double speedModifier) {
if (path->getSize() == 0) return false; if (path->getSize() == 0) return false;
this->speedModifier = speedModifier; this->speedModifier = speedModifier;
Vec3* mobPos = getTempMobPos(); Vec3 mobPos = getTempMobPos();
lastStuckCheck = _tick; lastStuckCheck = _tick;
lastStuckCheckPos->x = mobPos->x; lastStuckCheckPos->x = mobPos.x;
lastStuckCheckPos->y = mobPos->y; lastStuckCheckPos->y = mobPos.y;
lastStuckCheckPos->z = mobPos->z; lastStuckCheckPos->z = mobPos.z;
return true; return true;
} }
@ -127,20 +127,19 @@ void PathNavigation::tick() {
if (canUpdatePath()) updatePath(); if (canUpdatePath()) updatePath();
if (isDone()) return; if (isDone()) return;
Vec3* target = path->currentPos(mob->shared_from_this()); Vec3 target = path->currentPos(mob->shared_from_this());
if (target == NULL) return;
mob->getMoveControl()->setWantedPosition(target->x, target->y, target->z, mob->getMoveControl()->setWantedPosition(target.x, target.y, target.z,
speedModifier); speedModifier);
} }
void PathNavigation::updatePath() { void PathNavigation::updatePath() {
Vec3* mobPos = getTempMobPos(); Vec3 mobPos = getTempMobPos();
// find first elevations in path // find first elevations in path
int firstElevation = path->getSize(); int firstElevation = path->getSize();
for (int i = path->getIndex(); path != NULL && i < path->getSize(); ++i) { 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; firstElevation = i;
break; break;
} }
@ -150,8 +149,8 @@ void PathNavigation::updatePath() {
// check canWalkDirectly also) possibly only check next as well // check canWalkDirectly also) possibly only check next as well
float waypointRadiusSqr = mob->bbWidth * mob->bbWidth; float waypointRadiusSqr = mob->bbWidth * mob->bbWidth;
for (int i = path->getIndex(); i < firstElevation; ++i) { for (int i = path->getIndex(); i < firstElevation; ++i) {
Vec3* pathPos = path->getPos(mob->shared_from_this(), i); Vec3 pathPos = path->getPos(mob->shared_from_this(), i);
if (mobPos->distanceToSqr(*pathPos) < waypointRadiusSqr) { if (mobPos.distanceToSqr(pathPos) < waypointRadiusSqr) {
path->setIndex(i + 1); path->setIndex(i + 1);
} }
} }
@ -161,7 +160,8 @@ void PathNavigation::updatePath() {
int sy = (int)mob->bbHeight + 1; int sy = (int)mob->bbHeight + 1;
int sz = sx; int sz = sx;
for (int i = firstElevation - 1; i >= path->getIndex(); --i) { 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)) { sx, sy, sz)) {
path->setIndex(i); path->setIndex(i);
break; break;
@ -170,11 +170,11 @@ void PathNavigation::updatePath() {
// stuck detection (probably pushed off path) // stuck detection (probably pushed off path)
if (_tick - lastStuckCheck > 100) { if (_tick - lastStuckCheck > 100) {
if (mobPos->distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop(); if (mobPos.distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop();
lastStuckCheck = _tick; lastStuckCheck = _tick;
lastStuckCheckPos->x = mobPos->x; lastStuckCheckPos->x = mobPos.x;
lastStuckCheckPos->y = mobPos->y; lastStuckCheckPos->y = mobPos.y;
lastStuckCheckPos->z = mobPos->z; lastStuckCheckPos->z = mobPos.z;
} }
} }
@ -185,8 +185,8 @@ void PathNavigation::stop() {
path = NULL; path = NULL;
} }
Vec3* PathNavigation::getTempMobPos() { Vec3 PathNavigation::getTempMobPos() {
return Vec3::newTemp(mob->x, getSurfaceY(), mob->z); return Vec3(mob->x, getSurfaceY(), mob->z);
} }
int PathNavigation::getSurfaceY() { int PathNavigation::getSurfaceY() {

View file

@ -52,7 +52,7 @@ public:
void stop(); void stop();
private: private:
Vec3* getTempMobPos(); Vec3 getTempMobPos();
int getSurfaceY(); int getSurfaceY();
bool canUpdatePath(); bool canUpdatePath();
bool isInLiquid(); bool isInLiquid();

View file

@ -2,16 +2,17 @@
#include "../../Headers/net.minecraft.world.entity.h" #include "../../Headers/net.minecraft.world.entity.h"
#include "../../Headers/net.minecraft.world.phys.h" #include "../../Headers/net.minecraft.world.phys.h"
#include "RandomPos.h" #include "RandomPos.h"
#include <optional>
Vec3* RandomPos::tempDir = Vec3::newPermanent(0, 0, 0); Vec3* RandomPos::tempDir = new Vec3(0, 0, 0);
Vec3* RandomPos::getPos(std::shared_ptr<PathfinderMob> mob, int xzDist, std::optional<Vec3> RandomPos::getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, int quadrant /*=-1*/) // 4J - added quadrant int yDist, int quadrant /*=-1*/) // 4J - added quadrant
{ {
return generateRandomPos(mob, xzDist, yDist, NULL, quadrant); return generateRandomPos(mob, xzDist, yDist, NULL, quadrant);
} }
Vec3* RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist, std::optional<Vec3> RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* towardsPos) { int yDist, Vec3* towardsPos) {
tempDir->x = towardsPos->x - mob->x; tempDir->x = towardsPos->x - mob->x;
tempDir->y = towardsPos->y - mob->y; tempDir->y = towardsPos->y - mob->y;
@ -19,7 +20,7 @@ Vec3* RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
return generateRandomPos(mob, xzDist, yDist, tempDir); return generateRandomPos(mob, xzDist, yDist, tempDir);
} }
Vec3* RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist, std::optional<Vec3> RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* avoidPos) { int yDist, Vec3* avoidPos) {
tempDir->x = mob->x - avoidPos->x; tempDir->x = mob->x - avoidPos->x;
tempDir->y = mob->y - avoidPos->y; tempDir->y = mob->y - avoidPos->y;
@ -27,7 +28,7 @@ Vec3* RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
return generateRandomPos(mob, xzDist, yDist, tempDir); return generateRandomPos(mob, xzDist, yDist, tempDir);
} }
Vec3* RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob, std::optional<Vec3> RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist, Vec3* dir, int xzDist, int yDist, Vec3* dir,
int quadrant /*=-1*/) // 4J - added quadrant int quadrant /*=-1*/) // 4J - added quadrant
{ {
@ -81,8 +82,8 @@ Vec3* RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
} }
} }
if (hasBest) { if (hasBest) {
return Vec3::newTemp(xBest, yBest, zBest); return Vec3(xBest, yBest, zBest);
} }
return NULL; return std::nullopt;
} }

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <optional>
class PathfinderMob; class PathfinderMob;
class RandomPos { class RandomPos {
@ -7,15 +8,14 @@ private:
static Vec3* tempDir; static Vec3* tempDir;
public: public:
static Vec3* getPos(std::shared_ptr<PathfinderMob> mob, int xzDist, static std::optional<Vec3> getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, int quadrant = -1); // 4J added quadrant int yDist, int quadrant = -1); // 4J added quadrant
static Vec3* getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist, static std::optional<Vec3> getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* towardsPos); int yDist, Vec3* towardsPos);
static Vec3* getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist, static std::optional<Vec3> getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
int yDist, Vec3* avoidPos); int yDist, Vec3* avoidPos);
private: private:
static Vec3* generateRandomPos(std::shared_ptr<PathfinderMob> mob, static std::optional<Vec3> generateRandomPos(std::shared_ptr<PathfinderMob> mob,
int xzDist, int yDist, Vec3* dir, int xzDist, int yDist, Vec3* dir,
int quadrant = -1); // 4J added quadrant int quadrant = -1); // 4J added quadrant
}; };

View file

@ -7,6 +7,7 @@
#include "LiquidTile.h" #include "LiquidTile.h"
#include "../Util/Facing.h" #include "../Util/Facing.h"
#include "../Util/SoundTypes.h" #include "../Util/SoundTypes.h"
#include "Blocks/Material.h"
const std::wstring LiquidTile::TEXTURE_LAVA_STILL = L"lava"; const std::wstring LiquidTile::TEXTURE_LAVA_STILL = L"lava";
const std::wstring LiquidTile::TEXTURE_WATER_STILL = L"water"; 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; } int LiquidTile::getResourceCount(Random* random) { return 0; }
Vec3* LiquidTile::getFlow(LevelSource* level, int x, int y, int z) { Vec3 LiquidTile::getFlow(LevelSource* level, int x, int y, int z) {
Vec3* flow = Vec3::newTemp(0, 0, 0); Vec3 flow(0, 0, 0);
int mid = getRenderedDepth(level, x, y, z); int mid = getRenderedDepth(level, x, y, z);
for (int d = 0; d < 4; d++) { for (int d = 0; d < 4; d++) {
int xt = x; 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); t = getRenderedDepth(level, xt, yt - 1, zt);
if (t >= 0) { if (t >= 0) {
int dir = t - (mid - 8); 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); (zt - z) * dir);
} }
} }
} else { } else {
if (t >= 0) { if (t >= 0) {
int dir = t - mid; int dir = t - mid;
*flow = flow =
flow->add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); 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, 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, 4)) ok = true;
if (ok || isSolidFace(level, x + 1, y + 1, z, 5)) 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; return flow;
} }
void LiquidTile::handleEntityInside(Level* level, int x, int y, int z, void LiquidTile::handleEntityInside(Level* level, int x, int y, int z,
std::shared_ptr<Entity> e, Vec3* current) { std::shared_ptr<Entity> e, Vec3* current) {
Vec3* flow = getFlow(level, x, y, z); Vec3 flow = getFlow(level, x, y, z);
current->x += flow->x; current->x += flow.x;
current->y += flow->y; current->y += flow.y;
current->z += flow->z; current->z += flow.z;
} }
int LiquidTile::getTickDelay(Level* level) { 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, double LiquidTile::getSlopeAngle(LevelSource* level, int x, int y, int z,
Material* m) { Material* m) {
Vec3* flow = NULL; Vec3 flow;
if (m == Material::water) 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) if (m == Material::lava)
flow = ((LiquidTile*)Tile::lava)->getFlow(level, x, y, z); flow = Tile::lava->getFlow(level, x, y, z);
if (flow->x == 0 && flow->z == 0) return -1000; if (flow.x == 0 && flow.z == 0) return -1000;
return atan2(flow->z, flow->x) - PI / 2; return atan2(flow.z, flow.x) - PI / 2;
} }
void LiquidTile::onPlace(Level* level, int x, int y, int z) { void LiquidTile::onPlace(Level* level, int x, int y, int z) {

View file

@ -46,7 +46,7 @@ public:
virtual int getResourceCount(Random* random); virtual int getResourceCount(Random* random);
private: private:
virtual Vec3* getFlow(LevelSource* level, int x, int y, int z); virtual Vec3 getFlow(LevelSource* level, int x, int y, int z);
public: public:
virtual void handleEntityInside(Level* level, int x, int y, int z, virtual void handleEntityInside(Level* level, int x, int y, int z,

View file

@ -23,6 +23,7 @@
#include "../../Minecraft.Client/Level/MultiPlayerLevel.h" #include "../../Minecraft.Client/Level/MultiPlayerLevel.h"
#include "../../Minecraft.Client/Player/MultiPlayerLocalPlayer.h" #include "../../Minecraft.Client/Player/MultiPlayerLocalPlayer.h"
#include <cstdint> #include <cstdint>
#include <optional>
#include "../../Minecraft.Client/Level/ServerLevel.h" #include "../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Minecraft.Client/Network/PlayerList.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; } float Entity::getPickRadius() { return 0.1f; }
Vec3* Entity::getLookAngle() { return NULL; } std::optional<Vec3> Entity::getLookAngle() { return std::nullopt; }
void Entity::handleInsidePortal() { void Entity::handleInsidePortal() {
if (changingDimensionDelay > 0) { if (changingDimensionDelay > 0) {

View file

@ -6,6 +6,7 @@
#include "../Util/Vec3.h" #include "../Util/Vec3.h"
#include "../Util/Definitions.h" #include "../Util/Definitions.h"
#include <cstdint> #include <cstdint>
#include <optional>
class LivingEntity; class LivingEntity;
class LightningBolt; class LightningBolt;
@ -342,7 +343,7 @@ public:
virtual void lerpTo(double x, double y, double z, float yRot, float xRot, virtual void lerpTo(double x, double y, double z, float yRot, float xRot,
int steps); int steps);
virtual float getPickRadius(); virtual float getPickRadius();
virtual Vec3* getLookAngle(); virtual std::optional<Vec3> getLookAngle();
virtual void handleInsidePortal(); virtual void handleInsidePortal();
virtual int getDimensionChangingDelay(); virtual int getDimensionChangingDelay();
virtual void lerpMotion(double xd, double yd, double zd); virtual void lerpMotion(double xd, double yd, double zd);

View file

@ -24,6 +24,7 @@
#include "../Headers/net.minecraft.world.scores.h" #include "../Headers/net.minecraft.world.scores.h"
#include "../Headers/com.mojang.nbt.h" #include "../Headers/com.mojang.nbt.h"
#include "LivingEntity.h" #include "LivingEntity.h"
#include <optional>
#include "../../Minecraft.Client/Textures/Textures.h" #include "../../Minecraft.Client/Textures/Textures.h"
#include "../../Minecraft.Client/Level/ServerLevel.h" #include "../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Minecraft.Client/Player/EntityTracker.h" #include "../../Minecraft.Client/Player/EntityTracker.h"
@ -1650,16 +1651,16 @@ bool LivingEntity::canSee(std::shared_ptr<Entity> target) {
return retVal; return retVal;
} }
Vec3* LivingEntity::getLookAngle() { return getViewVector(1); } std::optional<Vec3> LivingEntity::getLookAngle() { return getViewVector(1); }
Vec3* LivingEntity::getViewVector(float a) { Vec3 LivingEntity::getViewVector(float a) {
if (a == 1) { if (a == 1) {
float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI); float yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
float ySin = Mth::sin(-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 xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
float xSin = Mth::sin(-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 xRot = xRotO + (this->xRot - xRotO) * a;
float yRot = yRotO + (this->yRot - yRotO) * 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 xCos = -Mth::cos(-xRot * Mth::RAD_TO_GRAD);
float xSin = Mth::sin(-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) { float LivingEntity::getAttackAnim(float a) {
@ -1678,20 +1679,20 @@ float LivingEntity::getAttackAnim(float a) {
return oAttackAnim + diff * a; return oAttackAnim + diff * a;
} }
Vec3* LivingEntity::getPos(float a) { Vec3 LivingEntity::getPos(float a) {
if (a == 1) { if (a == 1) {
return Vec3::newTemp(x, y, z); return Vec3(x, y, z);
} }
double x = xo + (this->x - xo) * a; double x = xo + (this->x - xo) * a;
double y = yo + (this->y - yo) * a; double y = yo + (this->y - yo) * a;
double z = zo + (this->z - zo) * 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) { HitResult* LivingEntity::pick(double range, float a) {
Vec3 from = *getPos(a); Vec3 from = getPos(a);
Vec3 b = *getViewVector(a); Vec3 b = getViewVector(a);
Vec3 to{b.x * range, b.y * range, b.z * range}; Vec3 to{b.x * range, b.y * range, b.z * range};
to = to.add(from.x, from.y, from.z); to = to.add(from.x, from.y, from.z);
return level->clip(&from, &to); return level->clip(&from, &to);

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <optional>
#include "Entity.h" #include "Entity.h"
#include "MobType.h" #include "MobType.h"
#include "../AI/Goals/GoalSelector.h" #include "../AI/Goals/GoalSelector.h"
@ -304,10 +305,10 @@ public:
virtual bool canSee(std::shared_ptr<Entity> target); virtual bool canSee(std::shared_ptr<Entity> target);
public: public:
virtual Vec3* getLookAngle(); virtual std::optional<Vec3> getLookAngle();
virtual Vec3* getViewVector(float a); virtual Vec3 getViewVector(float a);
virtual float getAttackAnim(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 HitResult* pick(double range, float a);
virtual bool isEffectiveAi(); virtual bool isEffectiveAi();

View file

@ -14,6 +14,7 @@
#include "../../Util/SharedConstants.h" #include "../../Util/SharedConstants.h"
#include "EnderDragon.h" #include "EnderDragon.h"
#include <limits> #include <limits>
#include <optional>
#define PRINT_DRAGON_STATE_CHANGE_MESSAGES 1 #define PRINT_DRAGON_STATE_CHANGE_MESSAGES 1
@ -309,12 +310,12 @@ void EnderDragon::aiStep() {
double xP = 0.0; double xP = 0.0;
double yP = 0.0; double yP = 0.0;
double zP = 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, // 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; // v->y, v->z, lSteps); unsigned int d = 0; for(unsigned int d = 1;
// d < 3; ++d) // 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); vN.yRot(-PI / 4);
for (unsigned int i = 0; i < 8; ++i) { for (unsigned int i = 0; i < 8; ++i) {
@ -746,10 +747,10 @@ void EnderDragon::aiStep() {
if (m_fireballCharge >= 20 && if (m_fireballCharge >= 20 &&
(angleDegs >= 0 && angleDegs < 10)) { (angleDegs >= 0 && angleDegs < 10)) {
double d = 1; double d = 1;
Vec3* v = getViewVector(1); Vec3 v = getViewVector(1);
float startingX = head->x - v->x * d; float startingX = head->x - v.x * d;
float startingY = head->y + head->bbHeight / 2 + 0.5f; 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 xdd = attackTarget->x - startingX;
double ydd = double ydd =
@ -1022,9 +1023,9 @@ void EnderDragon::findNewTarget() {
// !m_holdingPatternClockwise; // !m_holdingPatternClockwise;
if (getSynchedAction() == e_EnderdragonAction_Takeoff) { if (getSynchedAction() == e_EnderdragonAction_Takeoff) {
Vec3* v = getHeadLookVector(1); Vec3 v = getHeadLookVector(1);
targetNodeIndex = targetNodeIndex =
findClosestNode(-v->x * 40, 105.0, -v->z * 40); findClosestNode(-v.x * 40, 105.0, -v.z * 40);
} else { } else {
if (random->nextInt(8) == 0) { if (random->nextInt(8) == 0) {
m_holdingPatternClockwise = !m_holdingPatternClockwise; m_holdingPatternClockwise = !m_holdingPatternClockwise;
@ -1488,24 +1489,24 @@ void EnderDragon::strafeAttackTarget() {
void EnderDragon::navigateToNextPathNode() { void EnderDragon::navigateToNextPathNode() {
if (m_currentPath != NULL && !m_currentPath->isDone()) { if (m_currentPath != NULL && !m_currentPath->isDone()) {
Vec3* curr = m_currentPath->currentPos(); Vec3 curr = m_currentPath->currentPos();
m_currentPath->next(); m_currentPath->next();
xTarget = curr->x; xTarget = curr.x;
if (getSynchedAction() == e_EnderdragonAction_LandingApproach && if (getSynchedAction() == e_EnderdragonAction_LandingApproach &&
m_currentPath->isDone()) { m_currentPath->isDone()) {
// When heading to the last node on the landing approach, we want // When heading to the last node on the landing approach, we want
// the yCoord to be exact // the yCoord to be exact
yTarget = curr->y; yTarget = curr.y;
} else { } else {
do { do {
yTarget = curr->y + random->nextFloat() * 20; yTarget = curr.y + random->nextFloat() * 20;
} while (yTarget < (curr->y)); } while (yTarget < (curr.y));
} }
zTarget = curr->z; zTarget = curr.z;
app.DebugPrintf("Path node pos is (%f,%f,%f)\n", curr->x, curr->y, app.DebugPrintf("Path node pos is (%f,%f,%f)\n", curr.x, curr.y,
curr->z); curr.z);
app.DebugPrintf("Setting new target to (%f,%f,%f)\n", xTarget, yTarget, app.DebugPrintf("Setting new target to (%f,%f,%f)\n", xTarget, yTarget,
zTarget); zTarget);
} }
@ -1846,8 +1847,8 @@ double EnderDragon::getHeadPartYRotDiff(int partIndex, doubleArray bodyPos,
return result; return result;
} }
Vec3* EnderDragon::getHeadLookVector(float a) { Vec3 EnderDragon::getHeadLookVector(float a) {
Vec3* result = NULL; Vec3 result;
if (getSynchedAction() == e_EnderdragonAction_Landing || if (getSynchedAction() == e_EnderdragonAction_Landing ||
getSynchedAction() == e_EnderdragonAction_Takeoff) { getSynchedAction() == e_EnderdragonAction_Takeoff) {
@ -1888,5 +1889,6 @@ Vec3* EnderDragon::getHeadLookVector(float a) {
} else { } else {
result = getViewVector(a); result = getViewVector(a);
} }
return result; return result;
} }

View file

@ -188,7 +188,7 @@ public:
doubleArray partPos); doubleArray partPos);
double getHeadPartYRotDiff(int partIndex, doubleArray bodyPos, double getHeadPartYRotDiff(int partIndex, doubleArray bodyPos,
doubleArray partPos); doubleArray partPos);
Vec3* getHeadLookVector(float a); Vec3 getHeadLookVector(float a);
virtual std::wstring getAName() { return app.GetString(IDS_ENDERDRAGON); }; virtual std::wstring getAName() { return app.GetString(IDS_ENDERDRAGON); };
virtual float getHealth() { return LivingEntity::getHealth(); }; virtual float getHealth() { return LivingEntity::getHealth(); };

View file

@ -114,8 +114,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
std::shared_ptr<ItemInstance> helmet = player->inventory->armor[3]; std::shared_ptr<ItemInstance> helmet = player->inventory->armor[3];
if (helmet != NULL && helmet->id == Tile::pumpkin_Id) return false; if (helmet != NULL && helmet->id == Tile::pumpkin_Id) return false;
Vec3* look = player->getViewVector(1); Vec3 look = player->getViewVector(1).normalize();
*look = look->normalize();
Vec3 dir{x - player->x, Vec3 dir{x - player->x,
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), (bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
@ -123,7 +122,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
double dist = dir.length(); double dist = dir.length();
dir = dir.normalize(); dir = dir.normalize();
double dot = look->dot(dir); double dot = look.dot(dir);
if (dot > 1 - 0.025 / dist) { if (dot > 1 - 0.025 / dist) {
return player->canSee(shared_from_this()); return player->canSee(shared_from_this());
} }

View file

@ -300,8 +300,8 @@ bool Fireball::hurt(DamageSource* source, float damage) {
markHurt(); markHurt();
if (source->getEntity() != NULL) { if (source->getEntity() != NULL) {
Vec3* lookAngle = source->getEntity()->getLookAngle(); auto lookAngle = source->getEntity()->getLookAngle();
if (lookAngle != NULL) { if (lookAngle.has_value()) {
xd = lookAngle->x; xd = lookAngle->x;
yd = lookAngle->y; yd = lookAngle->y;
zd = lookAngle->z; zd = lookAngle->z;
@ -309,6 +309,7 @@ bool Fireball::hurt(DamageSource* source, float damage) {
yPower = yd * 0.1; yPower = yd * 0.1;
zPower = zd * 0.1; zPower = zd * 0.1;
} }
if (source->getEntity()->instanceof(eTYPE_LIVINGENTITY)) { if (source->getEntity()->instanceof(eTYPE_LIVINGENTITY)) {
owner = owner =
std::dynamic_pointer_cast<LivingEntity>(source->getEntity()); std::dynamic_pointer_cast<LivingEntity>(source->getEntity());

View file

@ -141,10 +141,10 @@ void Ghast::serverAiStep() {
ydd, zdd)); ydd, zdd));
ie->explosionPower = explosionPower; ie->explosionPower = explosionPower;
double d = 4; double d = 4;
Vec3* v = getViewVector(1); Vec3 v = getViewVector(1);
ie->x = x + v->x * d; ie->x = x + v.x * d;
ie->y = y + bbHeight / 2 + 0.5f; ie->y = y + bbHeight / 2 + 0.5f;
ie->z = z + v->z * d; ie->z = z + v.z * d;
level->addEntity(ie); level->addEntity(ie);
charge = -40; charge = -40;
} }

View file

@ -13,6 +13,8 @@
#include "../../../Minecraft.Client/Level/ServerLevel.h" #include "../../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Headers/com.mojang.nbt.h" #include "../../Headers/com.mojang.nbt.h"
#include "Minecart.h" #include "Minecart.h"
#include <cstddef>
#include <optional>
#include "../../Util/SharedConstants.h" #include "../../Util/SharedConstants.h"
const int Minecart::EXITS[][2][3] = { 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) { double slideSpeed, int tile, int data) {
fallDistance = 0; fallDistance = 0;
Vec3* oldPos = getPos(x, y, z); auto oldPos = getPos(x, y, z);
y = yt; y = yt;
bool powerTrack = false; bool powerTrack = false;
@ -489,8 +491,8 @@ void Minecart::moveAlongTrack(int xt, int yt, int zt, double maxSpeed,
applyNaturalSlowdown(); applyNaturalSlowdown();
Vec3* newPos = getPos(x, y, z); auto newPos = getPos(x, y, z);
if (newPos != NULL && oldPos != NULL) { if (newPos.has_value() && oldPos.has_value()) {
double speed = (oldPos->y - newPos->y) * 0.05; double speed = (oldPos->y - newPos->y) * 0.05;
pow = sqrt(xd * xd + zd * zd); 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<Vec3> Minecart::getPosOffs(double x, double y, double z, double offs) {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(y); int yt = Mth::floor(y);
int zt = Mth::floor(z); 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 getPos(x, y, z);
} }
return NULL;
return std::nullopt;
} }
Vec3* Minecart::getPos(double x, double y, double z) { std::optional<Vec3> Minecart::getPos(double x, double y, double z) {
int xt = Mth::floor(x); int xt = Mth::floor(x);
int yt = Mth::floor(y); int yt = Mth::floor(y);
int zt = Mth::floor(z); int zt = Mth::floor(z);
@ -653,9 +656,10 @@ Vec3* Minecart::getPos(double x, double y, double z) {
z = z0 + zD * progress; z = z0 + zD * progress;
if (yD < 0) y += 1; if (yD < 0) y += 1;
if (yD > 0) y += 0.5; 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) { void Minecart::readAdditionalSaveData(CompoundTag* tag) {

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <optional>
#include "../Entity.h" #include "../Entity.h"
class DamageSource; class DamageSource;
@ -77,8 +78,8 @@ protected:
virtual void moveAlongTrack(int xt, int yt, int zt, double maxSpeed, virtual void moveAlongTrack(int xt, int yt, int zt, double maxSpeed,
double slideSpeed, int tile, int data); double slideSpeed, int tile, int data);
virtual void applyNaturalSlowdown(); virtual void applyNaturalSlowdown();
virtual Vec3* getPosOffs(double x, double y, double z, double offs); virtual std::optional<Vec3> getPosOffs(double x, double y, double z, double offs);
virtual Vec3* getPos(double x, double y, double z); virtual std::optional<Vec3> getPos(double x, double y, double z);
protected: protected:
virtual void addAdditonalSaveData(CompoundTag* base); virtual void addAdditonalSaveData(CompoundTag* base);

View file

@ -120,18 +120,20 @@ void PathfinderMob::serverAiStep() {
return; return;
} }
Vec3* target = path->currentPos(shared_from_this()); Vec3 target = path->currentPos(shared_from_this());
double r = bbWidth * 2; 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(); path->next();
if (path->isDone()) { if (path->isDone()) {
target = NULL;
setPath(NULL); // 4J - changed to setPath from path = setPath(NULL); // 4J - changed to setPath from path =
break;
} else } else
target = path->currentPos(shared_from_this()); target = path->currentPos(shared_from_this());
} }
jumping = false; jumping = false;
// 4jcraft - refactoring Vec3 shows this branch never hits
/*
if (target != NULL) { if (target != NULL) {
double xd = target->x - x; double xd = target->x - x;
double zd = target->z - z; double zd = target->z - z;
@ -165,6 +167,7 @@ void PathfinderMob::serverAiStep() {
jumping = true; jumping = true;
} }
} }
*/
if (attackTarget != NULL) { if (attackTarget != NULL) {
lookAt(attackTarget, 30, 30); lookAt(attackTarget, 30, 30);

View file

@ -25,7 +25,7 @@ bool BoatItem::TestUse(std::shared_ptr<ItemInstance> itemInstance, Level* level,
player->yo + (player->y - player->yo) + 1.62 - player->heightOffset; player->yo + (player->y - player->yo) + 1.62 - player->heightOffset;
double z = player->zo + (player->z - player->zo); 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 yCos = Mth::cos(-yRot * Mth::RAD_TO_GRAD - PI);
float ySin = Mth::sin(-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> itemInstance, Level* level,
float za = yCos * xCos; float za = yCos * xCos;
double range = 5; double range = 5;
Vec3* to = Vec3::newTemp(xa * range, ya * range, za * range); Vec3 to(xa * range, ya * range, za * range);
*to = to->add(from->x, from->y, from->z); to = to.add(from.x, from.y, from.z);
HitResult* hr = level->clip(from, to, true); HitResult* hr = level->clip(&from, &to, true);
if (hr == NULL) return false; if (hr == NULL) return false;
if (hr->type == HitResult::TILE) { if (hr->type == HitResult::TILE) {
@ -80,12 +80,12 @@ std::shared_ptr<ItemInstance> BoatItem::use(
if (hr == NULL) return itemInstance; if (hr == NULL) return itemInstance;
// check entity collision // check entity collision
Vec3* b = player->getViewVector(a); Vec3 b = player->getViewVector(a);
bool hitEntity = false; bool hitEntity = false;
float overlap = 1; float overlap = 1;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities( std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
player, 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)); ->grow(overlap, overlap, overlap));
// for (int i = 0; i < objects.size(); i++) { // for (int i = 0; i < objects.size(); i++) {
for (AUTO_VAR(it, objects->begin()); it != objects->end(); ++it) { for (AUTO_VAR(it, objects->begin()); it != objects->end(); ++it) {

View file

@ -157,7 +157,7 @@ float* Dimension::getSunriseColor(float td, float a) {
return NULL; 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; float br = Mth::cos(td * PI * 2) * 2 + 0.5f;
if (br < 0.0f) br = 0.0f; if (br < 0.0f) br = 0.0f;
if (br > 1.0f) br = 1.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; g *= br * 0.94f + 0.06f;
b *= br * 0.91f + 0.09f; b *= br * 0.91f + 0.09f;
return Vec3::newTemp(r, g, b); return Vec3(r, g, b);
} }
bool Dimension::mayRespawn() const { return true; } bool Dimension::mayRespawn() const { return true; }

View file

@ -48,7 +48,7 @@ private:
public: public:
virtual float* getSunriseColor(float td, float a); 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; virtual bool mayRespawn() const;
static Dimension* getNew(int id); static Dimension* getNew(int id);
virtual float getCloudHeight(); virtual float getCloudHeight();

View file

@ -15,7 +15,7 @@ void HellDimension::init() {
id = -1; id = -1;
} }
Vec3* HellDimension::getFogColor(float td, float a) const { Vec3 HellDimension::getFogColor(float td, float a) const {
int colour = Minecraft::GetInstance()->getColourTable()->getColor( int colour = Minecraft::GetInstance()->getColourTable()->getColor(
eMinecraftColour_Nether_Fog_Colour); eMinecraftColour_Nether_Fog_Colour);
uint8_t redComponent = ((colour >> 16) & 0xFF); 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 rr = (float)redComponent / 256; // 0.2f;
float gg = (float)greenComponent / 256; // 0.03f; float gg = (float)greenComponent / 256; // 0.03f;
float bb = (float)blueComponent / 256; // 0.03f; float bb = (float)blueComponent / 256; // 0.03f;
return Vec3::newTemp(rr, gg, bb); return Vec3(rr, gg, bb);
} }
void HellDimension::updateLightRamp() { void HellDimension::updateLightRamp() {

View file

@ -4,7 +4,7 @@
class HellDimension : public Dimension { class HellDimension : public Dimension {
public: public:
virtual void init(); virtual void init();
virtual Vec3* getFogColor(float td, float a) const; virtual Vec3 getFogColor(float td, float a) const;
protected: protected:
virtual void updateLightRamp(); virtual void updateLightRamp();

View file

@ -20,7 +20,7 @@ float SkyIslandDimension::getTimeOfDay(int64_t time, float a) const {
float* SkyIslandDimension::getSunriseColor(float td, float a) { return NULL; } 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; int fogColor = 0x8080a0;
float br = Mth::cos(td * PI * 2) * 2 + 0.5f; float br = Mth::cos(td * PI * 2) * 2 + 0.5f;
if (br < 0.0f) br = 0.0f; 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; g *= br * 0.94f + 0.06f;
b *= br * 0.91f + 0.09f; b *= br * 0.91f + 0.09f;
return Vec3::newTemp(r, g, b); return Vec3(r, g, b);
} }
bool SkyIslandDimension::hasGround() { return false; } bool SkyIslandDimension::hasGround() { return false; }

View file

@ -23,7 +23,7 @@ float TheEndDimension::getTimeOfDay(int64_t time, float a) const {
float* TheEndDimension::getSunriseColor(float td, float a) { return NULL; } 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( int fogColor = Minecraft::GetInstance()->getColourTable()->getColor(
eMinecraftColour_End_Fog_Colour); // 0xa080a0; eMinecraftColour_End_Fog_Colour); // 0xa080a0;
float br = Mth::cos(td * PI * 2) * 2 + 0.5f; 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; g *= br * 0.0f + 0.15f;
b *= 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; } bool TheEndDimension::hasGround() { return false; }

View file

@ -7,7 +7,7 @@ public:
virtual ChunkSource* createRandomLevelSource() const; virtual ChunkSource* createRandomLevelSource() const;
virtual float getTimeOfDay(int64_t time, float a) const; virtual float getTimeOfDay(int64_t time, float a) const;
virtual float* getSunriseColor(float td, float a); 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 hasGround();
virtual bool mayRespawn() const; virtual bool mayRespawn() const;
virtual bool isNaturalDimension(); virtual bool isNaturalDimension();

View file

@ -4,6 +4,7 @@
#include "../../Headers/net.minecraft.world.entity.monster.h" #include "../../Headers/net.minecraft.world.entity.monster.h"
#include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.level.h"
#include "VillageSiege.h" #include "VillageSiege.h"
#include <optional>
VillageSiege::VillageSiege(Level* level) { VillageSiege::VillageSiege(Level* level) {
hasSetupSiege = false; hasSetupSiege = false;
@ -108,8 +109,8 @@ bool VillageSiege::tryToSetupSiege() {
} }
if (overlaps) return false; if (overlaps) return false;
Vec3* spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ); auto spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ);
if (spawnPos == NULL) continue; if (!spawnPos.has_value()) continue;
nextSpawnTime = 0; nextSpawnTime = 0;
siegeCount = 20; siegeCount = 20;
@ -119,8 +120,8 @@ bool VillageSiege::tryToSetupSiege() {
} }
bool VillageSiege::trySpawn() { bool VillageSiege::trySpawn() {
Vec3* spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ); auto spawnPos = findRandomSpawnPos(spawnX, spawnY, spawnZ);
if (spawnPos == NULL) return false; if (!spawnPos.has_value()) return false;
std::shared_ptr<Zombie> mob; std::shared_ptr<Zombie> mob;
// try // try
{ {
@ -143,9 +144,9 @@ bool VillageSiege::trySpawn() {
return true; return true;
} }
Vec3* VillageSiege::findRandomSpawnPos(int x, int y, int z) { std::optional<Vec3> VillageSiege::findRandomSpawnPos(int x, int y, int z) {
std::shared_ptr<Village> _village = village.lock(); std::shared_ptr<Village> _village = village.lock();
if (_village == NULL) return NULL; if (_village == NULL) return std::nullopt;
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
int xx = x + level->random->nextInt(16) - 8; 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 (!_village->isInside(xx, yy, zz)) continue;
if (MobSpawner::isSpawnPositionOk(MobCategory::monster, level, xx, yy, if (MobSpawner::isSpawnPositionOk(MobCategory::monster, level, xx, yy,
zz)) zz))
return Vec3::newTemp(xx, yy, zz); return Vec3(xx, yy, zz);
} }
return NULL;
return std::nullopt;
} }

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <optional>
class VillageSiege { class VillageSiege {
private: private:
Level* level; Level* level;
@ -23,5 +25,5 @@ public:
private: private:
bool tryToSetupSiege(); bool tryToSetupSiege();
bool trySpawn(); bool trySpawn();
Vec3* findRandomSpawnPos(int x, int y, int z); std::optional<Vec3> findRandomSpawnPos(int x, int y, int z);
}; };

View file

@ -28,9 +28,6 @@ Explosion::Explosion(Level* level, std::shared_ptr<Entity> source, double x,
Explosion::~Explosion() { Explosion::~Explosion() {
delete random; delete random;
for (AUTO_VAR(it, hitPlayers.begin()); it != hitPlayers.end(); ++it) {
delete it->second;
}
} }
void Explosion::explode() { void Explosion::explode() {
@ -165,7 +162,7 @@ void Explosion::explode() {
// app.DebugPrintf("Adding player knockback (%f,%f,%f)\n", xa * // app.DebugPrintf("Adding player knockback (%f,%f,%f)\n", xa *
// pow, ya * pow, za * pow); // pow, ya * pow, za * pow);
hitPlayers.insert(playerVec3Map::value_type( 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; } Explosion::playerVec3Map* Explosion::getHitPlayers() { return &hitPlayers; }
Vec3* Explosion::getHitPlayerKnockback(std::shared_ptr<Player> player) { Vec3 Explosion::getHitPlayerKnockback(std::shared_ptr<Player> player) {
AUTO_VAR(it, hitPlayers.find(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; return it->second;
} }

View file

@ -24,7 +24,7 @@ public:
std::unordered_set<TilePos, TilePosKeyHash, TilePosKeyEq> toBlow; std::unordered_set<TilePos, TilePosKeyHash, TilePosKeyEq> toBlow;
private: private:
typedef std::unordered_map<std::shared_ptr<Player>, Vec3*, PlayerKeyHash, typedef std::unordered_map<std::shared_ptr<Player>, Vec3, PlayerKeyHash,
PlayerKeyEq> PlayerKeyEq>
playerVec3Map; playerVec3Map;
playerVec3Map hitPlayers; playerVec3Map hitPlayers;
@ -42,6 +42,6 @@ public:
std::vector<TilePos>* toBlowDirect = std::vector<TilePos>* toBlowDirect =
NULL); // 4J - added toBlow parameter NULL); // 4J - added toBlow parameter
playerVec3Map* getHitPlayers(); playerVec3Map* getHitPlayers();
Vec3* getHitPlayerKnockback(std::shared_ptr<Player> player); Vec3 getHitPlayerKnockback(std::shared_ptr<Player> player);
std::shared_ptr<LivingEntity> getSourceMob(); std::shared_ptr<LivingEntity> getSourceMob();
}; };

View file

@ -1884,7 +1884,7 @@ float Level::getSkyDarken(float a) {
return br * 0.8f + 0.2f; return br * 0.8f + 0.2f;
} }
Vec3* Level::getSkyColor(std::shared_ptr<Entity> source, float a) { Vec3 Level::getSkyColor(std::shared_ptr<Entity> source, float a) {
float td = getTimeOfDay(a); float td = getTimeOfDay(a);
float br = Mth::cos(td * PI * 2) * 2 + 0.5f; float br = Mth::cos(td * PI * 2) * 2 + 0.5f;
@ -1932,7 +1932,7 @@ Vec3* Level::getSkyColor(std::shared_ptr<Entity> source, float a) {
b = b * (1 - f) + 1 * f; b = b * (1 - f) + 1 * f;
} }
return Vec3::newTemp(r, g, b); return Vec3(r, g, b);
} }
float Level::getTimeOfDay(float a) { float Level::getTimeOfDay(float a) {
@ -1963,7 +1963,7 @@ float Level::getSunAngle(float a) {
return td * PI * 2; return td * PI * 2;
} }
Vec3* Level::getCloudColor(float a) { Vec3 Level::getCloudColor(float a) {
float td = getTimeOfDay(a); float td = getTimeOfDay(a);
float br = Mth::cos(td * PI * 2) * 2.0f + 0.5f; 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); 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); float td = getTimeOfDay(a);
return dimension->getFogColor(td, a); return dimension->getFogColor(td, a);
} }

View file

@ -365,13 +365,13 @@ public:
false); // 4J: Added noEntities & blockAtEdge parameters false); // 4J: Added noEntities & blockAtEdge parameters
int getOldSkyDarken(float a); // 4J - change brought forward from 1.8.2 int getOldSkyDarken(float a); // 4J - change brought forward from 1.8.2
float getSkyDarken(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<Entity> source, float a); Vec3 getSkyColor(std::shared_ptr<Entity> source, float a);
float getTimeOfDay(float a); float getTimeOfDay(float a);
int getMoonPhase(); int getMoonPhase();
float getMoonBrightness(); float getMoonBrightness();
float getSunAngle(float a); float getSunAngle(float a);
Vec3* getCloudColor(float a); Vec3 getCloudColor(float a);
Vec3* getFogColor(float a); Vec3 getFogColor(float a);
int getTopRainBlock(int x, int z); int getTopRainBlock(int x, int z);
int getTopSolidBlock(int x, int z); int getTopSolidBlock(int x, int z);
bool biomeHasRain(int x, int z); // 4J added bool biomeHasRain(int x, int z); // 4J added

View file

@ -34,6 +34,7 @@ void Vec3::ReleaseThreadStorage() {
} }
Vec3* Vec3::newPermanent(double x, double y, double z) { Vec3* Vec3::newPermanent(double x, double y, double z) {
assert(0);
return new Vec3(x, y, z); return new Vec3(x, y, z);
}; };
@ -42,6 +43,7 @@ void Vec3::clearPool() {}
void Vec3::resetPool() {} void Vec3::resetPool() {}
Vec3* Vec3::newTemp(double x, double y, double z) { Vec3* Vec3::newTemp(double x, double y, double z) {
assert(0);
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx); ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
Vec3* thisVec = &tls->pool[tls->poolPointer]; Vec3* thisVec = &tls->pool[tls->poolPointer];
thisVec->set(x, y, z); thisVec->set(x, y, z);

View file

@ -7,6 +7,7 @@
#include "../../Headers/net.minecraft.world.phys.h" #include "../../Headers/net.minecraft.world.phys.h"
#include "Village.h" #include "Village.h"
#include <limits> #include <limits>
#include <optional>
Village::Aggressor::Aggressor(std::shared_ptr<LivingEntity> mob, Village::Aggressor::Aggressor(std::shared_ptr<LivingEntity> mob,
int timeStamp) { int timeStamp) {
@ -60,9 +61,9 @@ void Village::tick(int tick) {
int idealGolemCount = populationSize / 10; int idealGolemCount = populationSize / 10;
if (golemCount < idealGolemCount && doorInfos.size() > 20 && if (golemCount < idealGolemCount && doorInfos.size() > 20 &&
level->random->nextInt(7000) == 0) { level->random->nextInt(7000) == 0) {
Vec3* spawnPos = auto spawnPos =
findRandomSpawnPos(center->x, center->y, center->z, 2, 4, 2); findRandomSpawnPos(center->x, center->y, center->z, 2, 4, 2);
if (spawnPos != NULL) { if (spawnPos.has_value()) {
std::shared_ptr<VillagerGolem> vg = std::shared_ptr<VillagerGolem> vg =
std::shared_ptr<VillagerGolem>(new VillagerGolem(level)); std::shared_ptr<VillagerGolem>(new VillagerGolem(level));
vg->setPos(spawnPos->x, spawnPos->y, spawnPos->z); 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<Vec3> Village::findRandomSpawnPos(int x, int y, int z, int sx,
int sy, int sz) {
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
int xx = x + level->random->nextInt(16) - 8; int xx = x + level->random->nextInt(16) - 8;
int yy = y + level->random->nextInt(6) - 3; int yy = y + level->random->nextInt(6) - 3;
int zz = z + level->random->nextInt(16) - 8; int zz = z + level->random->nextInt(16) - 8;
if (!isInside(xx, yy, zz)) continue; if (!isInside(xx, yy, zz)) continue;
if (canSpawnAt(xx, yy, zz, sx, sy, sz)) if (canSpawnAt(xx, yy, zz, sx, sy, sz)) return Vec3(xx, yy, zz);
return Vec3::newTemp(xx, yy, zz);
} }
return NULL;
return std::nullopt;
} }
bool Village::canSpawnAt(int x, int y, int z, int sx, int sy, int sz) { bool Village::canSpawnAt(int x, int y, int z, int sx, int sy, int sz) {

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <optional>
class Village { class Village {
private: private:
Level* level; Level* level;
@ -36,7 +37,7 @@ public:
void tick(int tick); void tick(int tick);
private: private:
Vec3* findRandomSpawnPos(int x, int y, int z, int sx, int sy, int sz); std::optional<Vec3> 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); bool canSpawnAt(int x, int y, int z, int sx, int sy, int sz);
void countGolem(); void countGolem();
void countPopulation(); void countPopulation();