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) {
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<ExplodePacket>(
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);
}
}
}

View file

@ -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;

View file

@ -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*, CompoundTag*>(
Vec3::newPermanent(x, y, z), (CompoundTag*)eTag->copy()));
new Vec3(x, y, z), (CompoundTag*)eTag->copy()));
}
}
delete tag;

View file

@ -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) {

View file

@ -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)) {

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -91,10 +91,11 @@ zPlayerOffs = position->get(2);
TilePos* Camera::getCameraTilePos(std::shared_ptr<LivingEntity> 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<LivingEntity> player, double alpha) {
Vec3 Camera::getCameraPos(std::shared_ptr<LivingEntity> 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<LivingEntity> 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<LivingEntity> 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);
}
}

View file

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

View file

@ -1,5 +1,6 @@
#include "../../Platform/stdafx.h"
#include "MinecartRenderer.h"
#include <optional>
#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<Entity> _cart, double x, double y,
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;
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;

View file

@ -1,6 +1,7 @@
#include "../../Platform/stdafx.h"
#include "TileRenderer.h"
#include <array>
#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<Vec3, 8> 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<Vec3, 8> 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;

View file

@ -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<std::shared_ptr<Entity> >* 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<Entity> 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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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<PathfinderMob>(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;
}

View file

@ -5,6 +5,7 @@
#include "../../Headers/net.minecraft.world.level.h"
#include "../../Headers/net.minecraft.world.phys.h"
#include "FleeSunGoal.h"
#include <optional>
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<Vec3> 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;
}
return std::nullopt;
}

View file

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

View file

@ -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<PathfinderMob>(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,

View file

@ -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<PathfinderMob>(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);

View file

@ -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<PathfinderMob>(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;

View file

@ -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<PathfinderMob>(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;

View file

@ -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<PathfinderMob>(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(); }
bool PanicGoal::canContinueToUse() { return !mob->getNavigation()->isDone(); }

View file

@ -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<PathfinderMob>(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<PathfinderMob>(
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);
}
}

View file

@ -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<PathfinderMob>(
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<PathfinderMob>(
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);
}
}

View file

@ -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<PathfinderMob>(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);
}
}
}

View file

@ -48,17 +48,17 @@ int Path::getIndex() { return 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 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<Entity> e) { return getPos(e, index); }
Vec3 Path::currentPos(std::shared_ptr<Entity> 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;
}
}

View file

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

View file

@ -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() {

View file

@ -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);
};
};

View file

@ -2,16 +2,17 @@
#include "../../Headers/net.minecraft.world.entity.h"
#include "../../Headers/net.minecraft.world.phys.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
{
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) {
tempDir->x = towardsPos->x - mob->x;
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);
}
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) {
tempDir->x = mob->x - avoidPos->x;
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);
}
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 quadrant /*=-1*/) // 4J - added quadrant
{
@ -81,8 +82,8 @@ Vec3* RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
}
}
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
#include <optional>
class PathfinderMob;
class RandomPos {
@ -7,15 +8,14 @@ private:
static Vec3* tempDir;
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
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);
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);
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 quadrant = -1); // 4J added quadrant
};
};

View file

@ -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<Entity> 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) {

View file

@ -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);
};
};

View file

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

View file

@ -6,6 +6,7 @@
#include "../Util/Vec3.h"
#include "../Util/Definitions.h"
#include <cstdint>
#include <optional>
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<Vec3> getLookAngle();
virtual void handleInsidePortal();
virtual int getDimensionChangingDelay();
virtual void lerpMotion(double xd, double yd, double zd);

View file

@ -24,6 +24,7 @@
#include "../Headers/net.minecraft.world.scores.h"
#include "../Headers/com.mojang.nbt.h"
#include "LivingEntity.h"
#include <optional>
#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<Entity> target) {
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) {
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);

View file

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

View file

@ -14,6 +14,7 @@
#include "../../Util/SharedConstants.h"
#include "EnderDragon.h"
#include <limits>
#include <optional>
#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;
}

View file

@ -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(); };

View file

@ -114,8 +114,7 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
std::shared_ptr<ItemInstance> 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> 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());
}

View file

@ -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<LivingEntity>(source->getEntity());

View file

@ -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;
}

View file

@ -13,6 +13,8 @@
#include "../../../Minecraft.Client/Level/ServerLevel.h"
#include "../../Headers/com.mojang.nbt.h"
#include "Minecart.h"
#include <cstddef>
#include <optional>
#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<Vec3> 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<Vec3> 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) {

View file

@ -1,4 +1,5 @@
#pragma once
#include <optional>
#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<Vec3> getPosOffs(double x, double y, double z, double offs);
virtual std::optional<Vec3> getPos(double x, double y, double z);
protected:
virtual void addAdditonalSaveData(CompoundTag* base);

View file

@ -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);

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;
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> 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<ItemInstance> 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<std::shared_ptr<Entity> >* 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) {

View file

@ -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; }

View file

@ -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();

View file

@ -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() {

View file

@ -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();

View file

@ -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();
}
}

View file

@ -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; }

View file

@ -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();

View file

@ -4,6 +4,7 @@
#include "../../Headers/net.minecraft.world.entity.monster.h"
#include "../../Headers/net.minecraft.world.level.h"
#include "VillageSiege.h"
#include <optional>
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<Zombie> mob;
// try
{
@ -143,9 +144,9 @@ bool VillageSiege::trySpawn() {
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();
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;
}

View file

@ -1,5 +1,7 @@
#pragma once
#include <optional>
class VillageSiege {
private:
Level* level;
@ -23,5 +25,5 @@ public:
private:
bool tryToSetupSiege();
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() {
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> player) {
Vec3 Explosion::getHitPlayerKnockback(std::shared_ptr<Player> 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;
}

View file

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

View file

@ -1884,7 +1884,7 @@ float Level::getSkyDarken(float a) {
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 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;
}
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);
}

View file

@ -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<Entity> source, float a);
Vec3 getSkyColor(std::shared_ptr<Entity> 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

View file

@ -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);

View file

@ -7,6 +7,7 @@
#include "../../Headers/net.minecraft.world.phys.h"
#include "Village.h"
#include <limits>
#include <optional>
Village::Aggressor::Aggressor(std::shared_ptr<LivingEntity> 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<VillagerGolem> vg =
std::shared_ptr<VillagerGolem>(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<Vec3> 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) {

View file

@ -1,5 +1,6 @@
#pragma once
#include <optional>
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<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);
void countGolem();
void countPopulation();
@ -78,4 +79,4 @@ public:
void resetNoBreedTimer();
bool isBreedTimerOk();
void rewardAllPlayers(int amount);
};
};