refactor: remove calls to Vec3::newTemp when not returned

This commit is contained in:
orng 2026-03-26 04:19:04 -05:00
parent 9405f38f80
commit bee10e55a8
37 changed files with 6791 additions and 6831 deletions

View file

@ -6332,7 +6332,7 @@ int CMinecraftApp::WarningTrialTexturePackReturned(
DLCPack *pDLCPack=pDLCTexPack->getDLCInfoParentPack();//tPack->getDLCPack(); DLCPack *pDLCPack=pDLCTexPack->getDLCInfoParentPack();//tPack->getDLCPack();
const char *pchPackName=wstringtofilename(pDLCPack->getName()); const char *pchPackName=wstringtofilename(pDLCPack->getName());
app.DebugPrintf("Texture Pack - %s\n",pchPackName); app.DebugPrintf("Texture Pack - %s\n",pchPackName);
SONYDLC *pSONYDLCInfo=app.GetSONYDLCInfo((char *)pchPackName); SONYDLC *pSONYDLCInfo=app.GetSONYDLCInfo((char *)pchPackName);
if(pSONYDLCInfo!=NULL) if(pSONYDLCInfo!=NULL)
{ {
@ -6353,14 +6353,14 @@ int CMinecraftApp::WarningTrialTexturePackReturned(
#if defined __ORBIS__ || defined __PSVITA__ || defined __PS3__ #if defined __ORBIS__ || defined __PSVITA__ || defined __PS3__
if(app.CheckForEmptyStore(iPad)==false) if(app.CheckForEmptyStore(iPad)==false)
#endif #endif
{ {
if(app.DLCAlreadyPurchased(chSkuID)) if(app.DLCAlreadyPurchased(chSkuID))
{ {
app.DownloadAlreadyPurchased(chSkuID); app.DownloadAlreadyPurchased(chSkuID);
} }
else else
{ {
app.Checkout(chSkuID); app.Checkout(chSkuID);
} }
} }
} }
@ -10355,4 +10355,4 @@ std::wstring CMinecraftApp::getRootPath(std::uint32_t packId,
void CMinecraftApp::SetReachedMainMenu() { m_hasReachedMainMenu = true; } void CMinecraftApp::SetReachedMainMenu() { m_hasReachedMainMenu = true; }
bool CMinecraftApp::HasReachedMainMenu() { return m_hasReachedMainMenu; } bool CMinecraftApp::HasReachedMainMenu() { return m_hasReachedMainMenu; }
#endif #endif

View file

@ -251,4 +251,4 @@ void ApplySchematicRuleDefinition::reset() {
m_totalBlocksChanged = 0; m_totalBlocksChanged = 0;
m_totalBlocksChangedLighting = 0; m_totalBlocksChangedLighting = 0;
m_completed = false; m_completed = false;
} }

View file

@ -463,8 +463,8 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
schematicCoordToChunkCoord(destinationBox, te->x, te->z, rot, targetX, schematicCoordToChunkCoord(destinationBox, te->x, te->z, rot, targetX,
targetZ); targetZ);
Vec3* pos = Vec3::newTemp(targetX, targetY, targetZ); Vec3 pos(targetX, targetY, targetZ);
if (chunkBox->containsIncludingLowerBound(pos)) { if (chunkBox->containsIncludingLowerBound(&pos)) {
std::shared_ptr<TileEntity> teCopy = chunk->getTileEntity( std::shared_ptr<TileEntity> teCopy = chunk->getTileEntity(
(int)targetX & 15, (int)targetY & 15, (int)targetZ & 15); (int)targetX & 15, (int)targetY & 15, (int)targetZ & 15);
@ -510,9 +510,8 @@ void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox,
// Add 0.01 as the AABB::contains function returns false if a value is // Add 0.01 as the AABB::contains function returns false if a value is
// <= the lower bound // <= the lower bound
Vec3* pos = Vec3 pos(targetX + 0.01, targetY + 0.01, targetZ + 0.01);
Vec3::newTemp(targetX + 0.01, targetY + 0.01, targetZ + 0.01); if (!chunkBox->containsIncludingLowerBound(&pos)) {
if (!chunkBox->containsIncludingLowerBound(pos)) {
++it; ++it;
continue; continue;
} }
@ -800,8 +799,8 @@ void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data,
// if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH) // if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH)
//{ //{
// byteArray blockData = byteArray(data->data + blocksP, // byteArray blockData = byteArray(data->data + blocksP,
//Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); blocksP += // Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData);
//blockData.length; // blocksP += blockData.length;
// byteArray dataData = byteArray(data->data + dataP, 16384); // byteArray dataData = byteArray(data->data + dataP, 16384);
// chunk->getBlockLightData(dataData); // chunk->getBlockLightData(dataData);

View file

@ -37,15 +37,15 @@ bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
double xt, double yt, double zt) { double xt, double yt, double zt) {
if (!m_restrictsMovement) return true; if (!m_restrictsMovement) return true;
Vec3* targetPos = Vec3::newTemp(xt, yt, zt); Vec3 targetPos(xt, yt, zt);
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
if (movementArea->contains(targetPos) == contains) { if (movementArea->contains(&targetPos) == contains) {
return true; return true;
} }
Vec3* origPos = Vec3::newTemp(xo, yo, zo); Vec3 origPos(xo, yo, zo);
double currDist = origPos->distanceTo(movementArea); double currDist = origPos.distanceTo(movementArea);
double targetDist = targetPos->distanceTo(movementArea); double targetDist = targetPos.distanceTo(movementArea);
return targetDist < currDist; return targetDist < currDist;
} }

View file

@ -246,4 +246,4 @@ HRESULT CScene_Death::OnCustomMessage_Splitscreenplayer(bool bJoining,
bHandled = true; bHandled = true;
return app.AdjustSplitscreenScene_PlayerChanged(m_hObj, &m_OriginalPosition, return app.AdjustSplitscreenScene_PlayerChanged(m_hObj, &m_OriginalPosition,
m_iPad, bJoining); m_iPad, bJoining);
} }

View file

@ -1326,4 +1326,4 @@ void UIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) {
void UIScene_PauseMenu::SetIgnoreInput(bool ignoreInput) { void UIScene_PauseMenu::SetIgnoreInput(bool ignoreInput) {
m_bIgnoreInput = ignoreInput; m_bIgnoreInput = ignoreInput;
} }

View file

@ -121,4 +121,4 @@ int Camera::getBlockAt(Level* level, std::shared_ptr<LivingEntity> player,
} }
} }
return t; return t;
} }

View file

@ -58,22 +58,22 @@ void FishingHookRenderer::render(std::shared_ptr<Entity> _hook, double x,
float swing = hook->owner->getAttackAnim(a); float swing = hook->owner->getAttackAnim(a);
float swing2 = (float)Mth::sin(sqrt(swing) * PI); float swing2 = (float)Mth::sin(sqrt(swing) * PI);
Vec3* vv = Vec3::newTemp(-0.5, 0.03, 0.8); Vec3 vv(-0.5, 0.03, 0.8);
vv->xRot(-(hook->owner->xRotO + vv.xRot(-(hook->owner->xRotO +
(hook->owner->xRot - hook->owner->xRotO) * a) * (hook->owner->xRot - hook->owner->xRotO) * a) *
PI / 180); PI / 180);
vv->yRot(-(hook->owner->yRotO + vv.yRot(-(hook->owner->yRotO +
(hook->owner->yRot - hook->owner->yRotO) * a) * (hook->owner->yRot - hook->owner->yRotO) * a) *
PI / 180); PI / 180);
vv->yRot(swing2 * 0.5f); vv.yRot(swing2 * 0.5f);
vv->xRot(-swing2 * 0.7f); vv.xRot(-swing2 * 0.7f);
double xp = double xp =
hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv->x; hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv.x;
double yp = double yp =
hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv->y; hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv.y;
double zp = double zp =
hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv->z; hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv.z;
double yOffset = hook->owner == std::dynamic_pointer_cast<Player>( double yOffset = hook->owner == std::dynamic_pointer_cast<Player>(
Minecraft::GetInstance()->player) Minecraft::GetInstance()->player)
? 0 ? 0

View file

@ -54,13 +54,13 @@ void MinecartRenderer::render(std::shared_ptr<Entity> _cart, double x, double y,
y += (p0->y + p1->y) / 2 - yy; y += (p0->y + p1->y) / 2 - yy;
z += p->z - zz; z += p->z - zz;
Vec3* dir = Vec3::newTemp(-p0->x, -p0->y, -p0->z); Vec3 dir(-p0->x, -p0->y, -p0->z);
*dir = dir->add(p1->x, p1->y, p1->z); dir = dir.add(p1->x, p1->y, p1->z);
if (dir->length() == 0) { if (dir.length() == 0) {
} else { } else {
*dir = dir->normalize(); dir = dir.normalize();
rot = (float)(atan2(dir->z, dir->x) * 180 / PI); rot = (float)(atan2(dir.z, dir.x) * 180 / PI);
xRot = (float)(atan(dir->y) * 73); xRot = (float)(atan(dir.y) * 73);
} }
} }
glTranslatef((float)x, (float)y, (float)z); glTranslatef((float)x, (float)y, (float)z);

View file

@ -1045,9 +1045,8 @@ bool TileRenderer::tesselateAnvilInWorld(AnvilTile* tt, int x, int y, int z,
float TileRenderer::tesselateAnvilPiece(AnvilTile* tt, int x, int y, int z, float TileRenderer::tesselateAnvilPiece(AnvilTile* tt, int x, int y, int z,
int part, float bottom, float width, int part, float bottom, float width,
float height, float length, float height, float length, bool rotate,
bool rotate, bool render, bool render, int data) {
int data) {
if (rotate) { if (rotate) {
float swap = width; float swap = width;
width = length; width = length;
@ -4068,9 +4067,11 @@ bool TileRenderer::tesselateCrossInWorld(Tile* tt, int x, int y, int z) {
float zt = (float)z; float zt = (float)z;
if (tt == Tile::tallgrass) { if (tt == Tile::tallgrass) {
// 4jcraft add a bunch of casts to prevent overflow (i pray to god) // 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed = ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y); int64_t seed =
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) + ((uint64_t)seed * 11ULL)); ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) +
((uint64_t)seed * 11ULL));
xt += ((((seed >> 16) & 0xf) / 15.0f) - 0.5f) * 0.5f; xt += ((((seed >> 16) & 0xf) / 15.0f) - 0.5f) * 0.5f;
yt += ((((seed >> 20) & 0xf) / 15.0f) - 1.0f) * 0.2f; yt += ((((seed >> 20) & 0xf) / 15.0f) - 1.0f) * 0.2f;
@ -4326,8 +4327,10 @@ bool TileRenderer::tesselateLilypadInWorld(Tile* tt, int x, int y, int z) {
float v1 = tex->getV1(true); float v1 = tex->getV1(true);
// 4jcraft add a bunch of casts to prevent overflow (i pray to god) // 4jcraft add a bunch of casts to prevent overflow (i pray to god)
int64_t seed = ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y); int64_t seed =
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) + ((uint64_t)seed * 11ULL)); ((int64_t)x * 3129871) ^ ((int64_t)z * 116129781L) ^ ((int64_t)y);
seed = (int64_t)(((uint64_t)seed * (uint64_t)seed * 42317861ULL) +
((uint64_t)seed * 11ULL));
int dir = (int)((seed >> 16) & 0x3); int dir = (int)((seed >> 16) & 0x3);

View file

@ -305,8 +305,8 @@ void GameRenderer::pick(float a) {
} }
Vec3* b = mc->cameraTargetPlayer->getViewVector(a); Vec3* b = mc->cameraTargetPlayer->getViewVector(a);
Vec3* to = Vec3::newTemp(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(
@ -323,7 +323,7 @@ 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;
@ -524,11 +524,12 @@ void GameRenderer::moveCameraToPlayer(float a) {
// 4J - corrected bug here where zo was also added to x // 4J - corrected bug here where zo was also added to x
// component // component
HitResult* hr = mc->level->clip( Vec3 a(x + xo, y + yo, z + zo);
Vec3::newTemp(x + xo, y + yo, z + zo), Vec3 b(x - xd + xo, y - yd + yo, z - zd + zo);
Vec3::newTemp(x - xd + xo, y - yd + yo, z - zd + zo)); HitResult* hr = mc->level->clip(&a, &b);
if (hr != NULL) { if (hr != NULL) {
double dist = hr->pos.distanceTo(*Vec3::newTemp(x, y, z)); Vec3 p(x, y, z);
double dist = hr->pos.distanceTo(p);
if (dist < cameraDist) cameraDist = dist; if (dist < cameraDist) cameraDist = dist;
delete hr; delete hr;
} }
@ -1865,10 +1866,10 @@ void GameRenderer::setupClearColor(float a) {
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::newTemp(-1, 0, 0) ? Vec3(-1, 0, 0)
: Vec3::newTemp(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 =

View file

@ -22,16 +22,16 @@ void Lighting::turnOn() {
float d = 0.6f; float d = 0.6f;
float s = 0.0f; float s = 0.0f;
Vec3* l = Vec3::newTemp(0.2f, 1.0f, -0.7f); Vec3 l(0.2f, 1.0f, -0.7f);
*l = l->normalize(); l = l.normalize();
glLight(GL_LIGHT0, GL_POSITION, getBuffer(l->x, l->y, l->z, 0)); glLight(GL_LIGHT0, GL_POSITION, getBuffer(l.x, l.y, l.z, 0));
glLight(GL_LIGHT0, GL_DIFFUSE, getBuffer(d, d, d, 1)); glLight(GL_LIGHT0, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT0, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f)); glLight(GL_LIGHT0, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT0, GL_SPECULAR, getBuffer(s, s, s, 1.0f)); glLight(GL_LIGHT0, GL_SPECULAR, getBuffer(s, s, s, 1.0f));
l = Vec3::newTemp(-0.2f, 1.0f, 0.7f); l = Vec3(-0.2f, 1.0f, 0.7f);
*l = l->normalize(); l = l.normalize();
glLight(GL_LIGHT1, GL_POSITION, getBuffer(l->x, l->y, l->z, 0)); glLight(GL_LIGHT1, GL_POSITION, getBuffer(l.x, l.y, l.z, 0));
glLight(GL_LIGHT1, GL_DIFFUSE, getBuffer(d, d, d, 1)); glLight(GL_LIGHT1, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT1, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f)); glLight(GL_LIGHT1, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT1, GL_SPECULAR, getBuffer(s, s, s, 1.0f)); glLight(GL_LIGHT1, GL_SPECULAR, getBuffer(s, s, s, 1.0f));

View file

@ -19,4 +19,4 @@ Vertex::Vertex(Vec3* pos, float u, float v) {
this->pos = pos; this->pos = pos;
this->u = u; this->u = u;
this->v = v; this->v = v;
} }

View file

@ -64,10 +64,10 @@ bool AvoidPlayerGoal::canUse() {
delete entities; delete entities;
} }
Vec3 avoid_pos(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z);
Vec3* pos = RandomPos::getPosAvoid( Vec3* pos = RandomPos::getPosAvoid(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, 7, &avoid_pos);
Vec3::newTemp(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z));
if (pos == NULL) return false; if (pos == NULL) 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()))

View file

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

View file

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

View file

@ -17,10 +17,11 @@ MoveTowardsRestrictionGoal::MoveTowardsRestrictionGoal(PathfinderMob* mob,
bool MoveTowardsRestrictionGoal::canUse() { bool MoveTowardsRestrictionGoal::canUse() {
if (mob->isWithinRestriction()) return false; if (mob->isWithinRestriction()) return false;
Pos* towards = mob->getRestrictCenter(); Pos* toward = mob->getRestrictCenter();
Vec3 towards(toward->x, toward->y, toward->z);
Vec3* pos = RandomPos::getPosTowards( Vec3* pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, Vec3::newTemp(towards->x, towards->y, towards->z)); 7, &towards);
if (pos == NULL) return false; if (pos == NULL) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;
@ -34,4 +35,4 @@ bool MoveTowardsRestrictionGoal::canContinueToUse() {
void MoveTowardsRestrictionGoal::start() { void MoveTowardsRestrictionGoal::start() {
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier); mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speedModifier);
} }

View file

@ -20,9 +20,10 @@ bool MoveTowardsTargetGoal::canUse() {
if (target.lock() == NULL) return false; if (target.lock() == NULL) return false;
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* pos = RandomPos::getPosTowards( Vec3* pos = RandomPos::getPosTowards(
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16,
7, Vec3::newTemp(target.lock()->x, target.lock()->y, target.lock()->z)); 7, &towards);
if (pos == NULL) return false; if (pos == NULL) return false;
wantedX = pos->x; wantedX = pos->x;
wantedY = pos->y; wantedY = pos->y;

View file

@ -792,18 +792,18 @@ void LivingEntity::breakItem(std::shared_ptr<ItemInstance> itemInstance) {
0.8f + level->random->nextFloat() * 0.4f); 0.8f + level->random->nextFloat() * 0.4f);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
Vec3* d = Vec3::newTemp((random->nextFloat() - 0.5) * 0.1, Vec3 d = Vec3((random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0); Math::random() * 0.1 + 0.1, 0);
d->xRot(-xRot * PI / 180); d.xRot(-xRot * PI / 180);
d->yRot(-yRot * PI / 180); d.yRot(-yRot * PI / 180);
Vec3* p = Vec3::newTemp((random->nextFloat() - 0.5) * 0.3, Vec3 p = Vec3((random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6); -random->nextFloat() * 0.6 - 0.3, 0.6);
p->xRot(-xRot * PI / 180); p.xRot(-xRot * PI / 180);
p->yRot(-yRot * PI / 180); p.yRot(-yRot * PI / 180);
*p = p->add(x, y + getHeadHeight(), z); p = p.add(x, y + getHeadHeight(), z);
level->addParticle(PARTICLE_ICONCRACK(itemInstance->getItem()->id, 0), level->addParticle(PARTICLE_ICONCRACK(itemInstance->getItem()->id, 0),
p->x, p->y, p->z, d->x, d->y + 0.05, d->z); p.x, p.y, p.z, d.x, d.y + 0.05, d.z);
} }
} }
@ -1641,10 +1641,10 @@ void LivingEntity::take(std::shared_ptr<Entity> e, int orgCount) {
} }
bool LivingEntity::canSee(std::shared_ptr<Entity> target) { bool LivingEntity::canSee(std::shared_ptr<Entity> target) {
HitResult* hres = level->clip( Vec3 a{x, y + getHeadHeight(), z};
Vec3::newTemp(x, y + getHeadHeight(), z), Vec3 b{target->x, target->y + target->getHeadHeight(), target->z};
Vec3::newTemp(target->x, target->y + target->getHeadHeight(),
target->z)); HitResult* hres = level->clip(&a, &b);
bool retVal = (hres == NULL); bool retVal = (hres == NULL);
delete hres; delete hres;
return retVal; return retVal;
@ -1690,11 +1690,11 @@ Vec3* LivingEntity::getPos(float a) {
} }
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 = Vec3::newTemp(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);
} }
bool LivingEntity::isEffectiveAi() { return !level->isClientSide; } bool LivingEntity::isEffectiveAi() { return !level->isClientSide; }

View file

@ -184,7 +184,8 @@ void Arrow::tick() {
if (t > 0) { if (t > 0) {
Tile::tiles[t]->updateShape(level, xTile, yTile, zTile); Tile::tiles[t]->updateShape(level, xTile, yTile, zTile);
AABB* aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile); AABB* aabb = Tile::tiles[t]->getAABB(level, xTile, yTile, zTile);
if (aabb != NULL && aabb->contains(Vec3::newTemp(x, y, z))) { Vec3 pos{x, y, z};
if (aabb != NULL && aabb->contains(&pos)) {
inGround = true; inGround = true;
} }
} }
@ -217,15 +218,17 @@ void Arrow::tick() {
flightTime++; flightTime++;
} }
Vec3* from = Vec3::newTemp(x, y, z); Vec3 from{x, y, z};
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd); Vec3 to{x + xd, y + yd, z + zd};
HitResult* res = level->clip(from, to, false, true); HitResult* res = level->clip(&from, &to, false, true);
from = Vec3{x, y, z};
to = Vec3{x + xd, y + yd, z + zd};
from = Vec3::newTemp(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd);
if (res != NULL) { if (res != NULL) {
to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z); to = Vec3{res->pos.x, res->pos.y, res->pos.z};
} }
std::shared_ptr<Entity> hitEntity = nullptr; std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities( std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
shared_from_this(), this->bb->expand(xd, yd, zd)->grow(1, 1, 1)); shared_from_this(), this->bb->expand(xd, yd, zd)->grow(1, 1, 1));
@ -237,9 +240,9 @@ void Arrow::tick() {
float rr = 0.3f; float rr = 0.3f;
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 (p != NULL) { if (p != NULL) {
double dd = from->distanceTo(p->pos); double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) { if (dd < nearest || nearest == 0) {
hitEntity = e; hitEntity = e;
nearest = dd; nearest = dd;

View file

@ -314,9 +314,9 @@ void EnderDragon::aiStep() {
// 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::newTemp(v->x, v->y, v->z); Vec3 vN = Vec3{v->x, v->y, v->z}.normalize();
*vN = v->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) {
if (getSynchedAction() == e_EnderdragonAction_Landing) { if (getSynchedAction() == e_EnderdragonAction_Landing) {
// for(unsigned int j = 0; j < 6; ++j) // for(unsigned int j = 0; j < 6; ++j)
@ -335,9 +335,9 @@ void EnderDragon::aiStep() {
zP += (level->random->nextBoolean() ? 1 : -1) * zP += (level->random->nextBoolean() ? 1 : -1) *
level->random->nextFloat() / 2; level->random->nextFloat() / 2;
level->addParticle(eParticleType_dragonbreath, xP, level->addParticle(eParticleType_dragonbreath, xP,
yP, zP, (-vN->x * 0.08) + xd, yP, zP, (-vN.x * 0.08) + xd,
(-vN->y * 0.3) + yd, (-vN.y * 0.3) + yd,
(-vN->z * 0.08) + zd); (-vN.z * 0.08) + zd);
} }
} else { } else {
double yVelocity = 0.6; double yVelocity = 0.6;
@ -357,12 +357,12 @@ void EnderDragon::aiStep() {
zP += (level->random->nextBoolean() ? 1 : -1) * zP += (level->random->nextBoolean() ? 1 : -1) *
level->random->nextFloat() / 2; level->random->nextFloat() / 2;
level->addParticle(eParticleType_dragonbreath, xP, level->addParticle(eParticleType_dragonbreath, xP,
yP, zP, -vN->x * xzVelocity * j, yP, zP, -vN.x * xzVelocity * j,
-vN->y * yVelocity, -vN.y * yVelocity,
-vN->z * xzVelocity * j); -vN.z * xzVelocity * j);
} }
} }
vN->yRot(PI / (2 * 8)); vN.yRot(PI / (2 * 8));
} }
} }
} else if (getSynchedAction() == } else if (getSynchedAction() ==
@ -478,15 +478,13 @@ void EnderDragon::aiStep() {
// No movement // No movement
} else if (getSynchedAction() == e_EnderdragonAction_Sitting_Scanning) { } else if (getSynchedAction() == e_EnderdragonAction_Sitting_Scanning) {
if (attackTarget != NULL) { if (attackTarget != NULL) {
Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0, Vec3 aim = Vec3((attackTarget->x - x), 0, (attackTarget->z - z))
(attackTarget->z - z)); .normalize();
*aim = aim->normalize();
Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0, Vec3 dir = Vec3(sin(yRot * PI / 180), 0, -cos(yRot * PI / 180))
-cos(yRot * PI / 180)); .normalize();
*dir = dir->normalize(); float dot = (float)dir.dot(aim);
float dot = (float)dir->dot(*aim);
float angleDegs = acos(dot) * 180 / PI; float angleDegs = acos(dot) * 180 / PI;
angleDegs = angleDegs + 0.5f; angleDegs = angleDegs + 0.5f;
@ -564,14 +562,12 @@ void EnderDragon::aiStep() {
if (yRotD > 50) yRotD = 50; if (yRotD > 50) yRotD = 50;
if (yRotD < -50) yRotD = -50; if (yRotD < -50) yRotD = -50;
Vec3* aim = Vec3 aim =
Vec3::newTemp((xTarget - x), (yTarget - y), (zTarget - z)); Vec3((xTarget - x), (yTarget - y), (zTarget - z)).normalize();
*aim = aim->normalize();
Vec3* dir = Vec3 dir = Vec3(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180))
Vec3::newTemp(sin(yRot * PI / 180), yd, -cos(yRot * PI / 180)); .normalize();
*dir = dir->normalize(); float dot = (float)(dir.dot(aim) + 0.5f) / 1.5f;
float dot = (float)(dir->dot(*aim) + 0.5f) / 1.5f;
if (dot < 0) dot = 0; if (dot < 0) dot = 0;
yRotA *= 0.80f; yRotA *= 0.80f;
@ -595,9 +591,8 @@ void EnderDragon::aiStep() {
move(xd, yd, zd); move(xd, yd, zd);
} }
Vec3* actual = Vec3::newTemp(xd, yd, zd); Vec3 actual = Vec3(xd, yd, zd).normalize();
*actual = actual->normalize(); float slide = (float)(actual.dot(dir) + 1) / 2.0f;
float slide = (float)(actual->dot(*dir) + 1) / 2.0f;
slide = 0.8f + 0.15f * slide; slide = 0.8f + 0.15f * slide;
xd *= slide; xd *= slide;
@ -738,15 +733,13 @@ void EnderDragon::aiStep() {
maxDist * maxDist) { maxDist * maxDist) {
if (this->canSee(attackTarget)) { if (this->canSee(attackTarget)) {
m_fireballCharge++; m_fireballCharge++;
Vec3* aim = Vec3::newTemp((attackTarget->x - x), 0, Vec3 aim = Vec3((attackTarget->x - x), 0, (attackTarget->z - z))
(attackTarget->z - z)); .normalize();
*aim = aim->normalize();
Vec3* dir = Vec3::newTemp(sin(yRot * PI / 180), 0, Vec3 dir = Vec3(sin(yRot * PI / 180), 0, -cos(yRot * PI / 180))
-cos(yRot * PI / 180)); .normalize();
*dir = dir->normalize();
float dot = (float)dir->dot(*aim); float dot = (float)dir.dot(aim);
float angleDegs = acos(dot) * 180 / PI; float angleDegs = acos(dot) * 180 / PI;
angleDegs = angleDegs + 0.5f; angleDegs = angleDegs + 0.5f;
@ -985,13 +978,13 @@ void EnderDragon::findNewTarget() {
int targetNodeIndex = 0; int targetNodeIndex = 0;
if (playerNearestToEgg != NULL) { if (playerNearestToEgg != NULL) {
Vec3* aim = Vec3::newTemp(playerNearestToEgg->x, 0, Vec3 aim = Vec3(playerNearestToEgg->x, 0, playerNearestToEgg->z)
playerNearestToEgg->z); .normalize();
*aim = aim->normalize();
// app.DebugPrintf("Final marker node near (%f,%d,%f)\n", // app.DebugPrintf("Final marker node near (%f,%d,%f)\n",
// -aim->x*40,105,-aim->z*40 ); // -aim->x*40,105,-aim->z*40 );
targetNodeIndex = targetNodeIndex =
findClosestNode(-aim->x * 40, 105.0, -aim->z * 40); findClosestNode(-aim.x * 40, 105.0, -aim.z * 40);
} else { } else {
targetNodeIndex = findClosestNode(40.0, eggHeight, 0.0); targetNodeIndex = findClosestNode(40.0, eggHeight, 0.0);
} }

View file

@ -117,13 +117,13 @@ bool EnderMan::isLookingAtMe(std::shared_ptr<Player> player) {
Vec3* look = player->getViewVector(1); Vec3* look = player->getViewVector(1);
*look = look->normalize(); *look = look->normalize();
Vec3* dir = Vec3::newTemp( Vec3 dir{x - player->x,
x - player->x, (bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()),
(bb->y0 + bbHeight / 2) - (player->y + player->getHeadHeight()), z - player->z};
z - player->z);
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());
} }
@ -251,13 +251,13 @@ bool EnderMan::teleport() {
} }
bool EnderMan::teleportTowards(std::shared_ptr<Entity> e) { bool EnderMan::teleportTowards(std::shared_ptr<Entity> e) {
Vec3* dir = Vec3::newTemp( Vec3 dir{x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(),
x - e->x, bb->y0 + bbHeight / 2 - e->y + e->getHeadHeight(), z - e->z); z - e->z};
*dir = dir->normalize(); dir = dir.normalize();
double d = 16; double d = 16;
double xx = x + (random->nextDouble() - 0.5) * 8 - dir->x * d; double xx = x + (random->nextDouble() - 0.5) * 8 - dir.x * d;
double yy = y + (random->nextInt(16) - 8) - dir->y * d; double yy = y + (random->nextInt(16) - 8) - dir.y * d;
double zz = z + (random->nextDouble() - 0.5) * 8 - dir->z * d; double zz = z + (random->nextDouble() - 0.5) * 8 - dir.z * d;
return teleport(xx, yy, zz); return teleport(xx, yy, zz);
} }

View file

@ -166,14 +166,14 @@ void Fireball::tick() {
} }
MemSect(41); MemSect(41);
Vec3* from = Vec3::newTemp(x, y, z); Vec3 from(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd); Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to); HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z); from = Vec3(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd); to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) { if (res != NULL) {
*to = Vec3{res->pos.x, res->pos.y, res->pos.z}; to = Vec3{res->pos.x, res->pos.y, res->pos.z};
} }
std::shared_ptr<Entity> hitEntity = nullptr; std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities( std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
@ -188,9 +188,9 @@ void Fireball::tick() {
float rr = 0.3f; float rr = 0.3f;
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 (p != NULL) { if (p != NULL) {
double dd = from->distanceTo(p->pos); double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) { if (dd < nearest || nearest == 0) {
hitEntity = e; hitEntity = e;
nearest = dd; nearest = dd;

View file

@ -203,14 +203,14 @@ void FishingHook::tick() {
flightTime++; flightTime++;
} }
Vec3* from = Vec3::newTemp(x, y, z); Vec3 from(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd); Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to); HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z); from = Vec3(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd); to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) { if (res != NULL) {
to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z); to = Vec3(res->pos.x, res->pos.y, res->pos.z);
} }
std::shared_ptr<Entity> hitEntity = nullptr; std::shared_ptr<Entity> hitEntity = nullptr;
std::vector<std::shared_ptr<Entity> >* objects = level->getEntities( std::vector<std::shared_ptr<Entity> >* objects = level->getEntities(
@ -223,9 +223,9 @@ void FishingHook::tick() {
float rr = 0.3f; float rr = 0.3f;
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 (p != NULL) { if (p != NULL) {
double dd = from->distanceTo(p->pos); double dd = from.distanceTo(p->pos);
if (dd < nearest || nearest == 0) { if (dd < nearest || nearest == 0) {
hitEntity = e; hitEntity = e;
nearest = dd; nearest = dd;

View file

@ -724,13 +724,13 @@ void Minecart::push(std::shared_ptr<Entity> e) {
// other // other
// Fix for #38882 - TU5: Gameplay: Minecart with furnace is not // Fix for #38882 - TU5: Gameplay: Minecart with furnace is not
// able to move another minecart on the rail. // able to move another minecart on the rail.
Vec3* dir = Vec3::newTemp(xo, 0, zo); Vec3 dir(xo, 0, zo);
*dir = dir->normalize(); dir = dir.normalize();
Vec3* facing =
Vec3::newTemp(cos(yRot * PI / 180), 0, sin(yRot * PI / 180));
*facing = facing->normalize();
double dot = abs(dir->dot(*facing)); Vec3 facing(cos(yRot * PI / 180), 0, sin(yRot * PI / 180));
facing = facing.normalize();
double dot = abs(dir.dot(facing));
if (dot < 0.8f) { if (dot < 0.8f) {
return; return;

View file

@ -135,14 +135,14 @@ void Throwable::tick() {
flightTime++; flightTime++;
} }
Vec3* from = Vec3::newTemp(x, y, z); Vec3 from(x, y, z);
Vec3* to = Vec3::newTemp(x + xd, y + yd, z + zd); Vec3 to(x + xd, y + yd, z + zd);
HitResult* res = level->clip(from, to); HitResult* res = level->clip(&from, &to);
from = Vec3::newTemp(x, y, z); from = Vec3(x, y, z);
to = Vec3::newTemp(x + xd, y + yd, z + zd); to = Vec3(x + xd, y + yd, z + zd);
if (res != NULL) { if (res != NULL) {
to = Vec3::newTemp(res->pos.x, res->pos.y, res->pos.z); to = Vec3(res->pos.x, res->pos.y, res->pos.z);
} }
if (!level->isClientSide) { if (!level->isClientSide) {
@ -157,9 +157,9 @@ void Throwable::tick() {
float rr = 0.3f; float rr = 0.3f;
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 (p != NULL) { if (p != NULL) {
double dd = from->distanceTo(p->pos); double dd = from.distanceTo(p->pos);
delete p; delete p;
if (dd < nearest || nearest == 0) { if (dd < nearest || nearest == 0) {
hitEntity = e; hitEntity = e;

View file

@ -62,7 +62,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset; player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
double z = player->zo + (player->z - player->zo) * a; double z = player->zo + (player->z - player->zo) * a;
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);
@ -74,9 +74,9 @@ std::shared_ptr<ItemInstance> BoatItem::use(
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 itemInstance; if (hr == NULL) return itemInstance;
// check entity collision // check entity collision
@ -94,7 +94,7 @@ std::shared_ptr<ItemInstance> BoatItem::use(
float rr = e->getPickRadius(); float rr = e->getPickRadius();
AABB* bb = e->bb->grow(rr, rr, rr); AABB* bb = e->bb->grow(rr, rr, rr);
if (bb->contains(from)) { if (bb->contains(&from)) {
hitEntity = true; hitEntity = true;
} }
} }

View file

@ -1603,7 +1603,7 @@ HitResult* Item::getPlayerPOVHitResult(Level* level,
player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset; player->yo + (player->y - player->yo) * a + 1.62 - player->heightOffset;
double z = player->zo + (player->z - player->zo) * a; double z = player->zo + (player->z - player->zo) * a;
Vec3* from = Vec3::newTemp(x, y, z); Vec3 from(x, y, z);
float yCos = (float)cos(-yRot * Mth::RAD_TO_GRAD - PI); float yCos = (float)cos(-yRot * Mth::RAD_TO_GRAD - PI);
float ySin = (float)sin(-yRot * Mth::RAD_TO_GRAD - PI); float ySin = (float)sin(-yRot * Mth::RAD_TO_GRAD - PI);
@ -1615,9 +1615,9 @@ HitResult* Item::getPlayerPOVHitResult(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);
return level->clip(from, to, alsoPickLiquid, !alsoPickLiquid); return level->clip(&from, &to, alsoPickLiquid, !alsoPickLiquid);
} }
int Item::getEnchantmentValue() { return 0; } int Item::getEnchantmentValue() { return 0; }

View file

@ -60,4 +60,4 @@ Pos* TheEndDimension::getSpawnPos() { return new Pos(100, 50, 0); }
bool TheEndDimension::isFoggyAt(int x, int z) { return true; } bool TheEndDimension::isFoggyAt(int x, int z) { return true; }
int TheEndDimension::getSpawnYPosition() { return 50; } int TheEndDimension::getSpawnYPosition() { return 50; }

View file

@ -157,4 +157,4 @@ Vec3* VillageSiege::findRandomSpawnPos(int x, int y, int z) {
return Vec3::newTemp(xx, yy, zz); return Vec3::newTemp(xx, yy, zz);
} }
return NULL; return NULL;
} }

View file

@ -108,7 +108,7 @@ void Explosion::explode() {
level->getEntities(source, AABB::newTemp(x0, y0, z0, x1, y1, z1)); level->getEntities(source, AABB::newTemp(x0, y0, z0, x1, y1, z1));
std::vector<std::shared_ptr<Entity> > entities(levelEntities->begin(), std::vector<std::shared_ptr<Entity> > entities(levelEntities->begin(),
levelEntities->end()); levelEntities->end());
Vec3* center = Vec3::newTemp(x, y, z); Vec3 center(x, y, z);
AUTO_VAR(itEnd, entities.end()); AUTO_VAR(itEnd, entities.end());
for (AUTO_VAR(it, entities.begin()); it != itEnd; it++) { for (AUTO_VAR(it, entities.begin()); it != itEnd; it++) {
@ -146,7 +146,7 @@ void Explosion::explode() {
za /= da; za /= da;
} }
double sp = level->getSeenPercent(center, e->bb); double sp = level->getSeenPercent(&center, e->bb);
double pow = (1 - dist) * sp; double pow = (1 - dist) * sp;
if (canDamage) if (canDamage)
e->hurt(DamageSource::explosion(this), e->hurt(DamageSource::explosion(this),
@ -298,4 +298,4 @@ std::shared_ptr<LivingEntity> Explosion::getSourceMob() {
if (source->instanceof(eTYPE_LIVINGENTITY)) if (source->instanceof(eTYPE_LIVINGENTITY))
return std::dynamic_pointer_cast<LivingEntity>(source); return std::dynamic_pointer_cast<LivingEntity>(source);
return nullptr; return nullptr;
} }

View file

@ -1478,21 +1478,21 @@ HitResult* Level::clip(Vec3* a, Vec3* b, bool liquid, bool solidOnly) {
a->z = zClip; a->z = zClip;
} }
Vec3* tPos = Vec3::newTemp(a->x, a->y, a->z); Vec3 tPos(a->x, a->y, a->z);
xTile0 = (int)(tPos->x = floor(a->x)); xTile0 = (int)(tPos.x = floor(a->x));
if (face == 5) { if (face == 5) {
xTile0--; xTile0--;
tPos->x++; tPos.x++;
} }
yTile0 = (int)(tPos->y = floor(a->y)); yTile0 = (int)(tPos.y = floor(a->y));
if (face == 1) { if (face == 1) {
yTile0--; yTile0--;
tPos->y++; tPos.y++;
} }
zTile0 = (int)(tPos->z = floor(a->z)); zTile0 = (int)(tPos.z = floor(a->z));
if (face == 3) { if (face == 3) {
zTile0--; zTile0--;
tPos->z++; tPos.z++;
} }
int t = getTile(xTile0, yTile0, zTile0); int t = getTile(xTile0, yTile0, zTile0);
@ -2473,7 +2473,7 @@ bool Level::checkAndHandleWater(AABB* box, Material* material,
} }
bool ok = false; bool ok = false;
Vec3* current = Vec3::newTemp(0, 0, 0); Vec3 current(0, 0, 0);
for (int x = x0; x < x1; x++) { for (int x = x0; x < x1; x++) {
for (int y = y0; y < y1; y++) { for (int y = y0; y < y1; y++) {
for (int z = z0; z < z1; z++) { for (int z = z0; z < z1; z++) {
@ -2483,18 +2483,18 @@ bool Level::checkAndHandleWater(AABB* box, Material* material,
y + 1 - LiquidTile::getHeight(getData(x, y, z)); y + 1 - LiquidTile::getHeight(getData(x, y, z));
if (y1 >= yt0) { if (y1 >= yt0) {
ok = true; ok = true;
tile->handleEntityInside(this, x, y, z, e, current); tile->handleEntityInside(this, x, y, z, e, &current);
} }
} }
} }
} }
} }
if (current->length() > 0 && e->isPushedByWater()) { if (current.length() > 0 && e->isPushedByWater()) {
*current = current->normalize(); current = current.normalize();
double pow = 0.014; double pow = 0.014;
e->xd += current->x * pow; e->xd += current.x * pow;
e->yd += current->y * pow; e->yd += current.y * pow;
e->zd += current->z * pow; e->zd += current.z * pow;
} }
return ok; return ok;
} }
@ -2580,7 +2580,8 @@ float Level::getSeenPercent(Vec3* center, AABB* bb) {
double x = bb->x0 + (bb->x1 - bb->x0) * xx; double x = bb->x0 + (bb->x1 - bb->x0) * xx;
double y = bb->y0 + (bb->y1 - bb->y0) * yy; double y = bb->y0 + (bb->y1 - bb->y0) * yy;
double z = bb->z0 + (bb->z1 - bb->z0) * zz; double z = bb->z0 + (bb->z1 - bb->z0) * zz;
HitResult* res = clip(Vec3::newTemp(x, y, z), center); Vec3 a(x, y, z);
HitResult* res = clip(&a, center);
if (res == NULL) hits++; if (res == NULL) hits++;
delete res; delete res;
count++; count++;

View file

@ -109,32 +109,34 @@ int RandomLevelSource::getMinDistanceToEdge(int xxx, int zzz, int worldSize,
// // only check if either x or z values are within the falloff // // only check if either x or z values are within the falloff
// if(xxx > (min - falloffStart) // if(xxx > (min - falloffStart)
Vec3* topLeft = Vec3::newTemp(min, 0, min); Vec3 topLeft(min, 0, min);
Vec3* topRight = Vec3::newTemp(max, 0, min); Vec3 topRight(max, 0, min);
Vec3* bottomLeft = Vec3::newTemp(min, 0, max); Vec3 bottomLeft(min, 0, max);
Vec3* bottomRight = Vec3::newTemp(max, 0, max); Vec3 bottomRight(max, 0, max);
float closest = falloffStart; float closest = falloffStart;
float dist; float dist;
// make sure we're in range of the edges before we do a full distance check // make sure we're in range of the edges before we do a full distance check
if ((xxx > (min - falloffStart) && xxx < (min + falloffStart)) || if ((xxx > (min - falloffStart) && xxx < (min + falloffStart)) ||
(xxx > (max - falloffStart) && xxx < (max + falloffStart))) { (xxx > (max - falloffStart) && xxx < (max + falloffStart))) {
Vec3* point = Vec3::newTemp(xxx, 0, zzz); Vec3 point(xxx, 0, zzz);
if (xxx > 0) if (xxx > 0)
dist = point->distanceFromLine(*topRight, *bottomRight); dist = point.distanceFromLine(topRight, bottomRight);
else else
dist = point->distanceFromLine(*topLeft, *bottomLeft); dist = point.distanceFromLine(topLeft, bottomLeft);
closest = dist; closest = dist;
} }
// make sure we're in range of the edges before we do a full distance check // make sure we're in range of the edges before we do a full distance check
if ((zzz > (min - falloffStart) && zzz < (min + falloffStart)) || if ((zzz > (min - falloffStart) && zzz < (min + falloffStart)) ||
(zzz > (max - falloffStart) && zzz < (max + falloffStart))) { (zzz > (max - falloffStart) && zzz < (max + falloffStart))) {
Vec3* point = Vec3::newTemp(xxx, 0, zzz); Vec3 point(xxx, 0, zzz);
if (zzz > 0) if (zzz > 0)
dist = point->distanceFromLine(*bottomLeft, *bottomRight); dist = point.distanceFromLine(bottomLeft, bottomRight);
else else
dist = point->distanceFromLine(*topLeft, *topRight); dist = point.distanceFromLine(topLeft, topRight);
if (dist < closest) closest = dist; if (dist < closest) closest = dist;
} }

View file

@ -527,20 +527,20 @@ void Player::spawnEatParticles(std::shared_ptr<ItemInstance> useItem,
} }
if (useItem->getUseAnimation() == UseAnim_eat) { if (useItem->getUseAnimation() == UseAnim_eat) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Vec3* d = Vec3::newTemp((random->nextFloat() - 0.5) * 0.1, Vec3 d{(random->nextFloat() - 0.5) * 0.1,
Math::random() * 0.1 + 0.1, 0); Math::random() * 0.1 + 0.1, 0};
d->xRot(-xRot * PI / 180); d.xRot(-xRot * PI / 180);
d->yRot(-yRot * PI / 180); d.yRot(-yRot * PI / 180);
Vec3* p = Vec3::newTemp((random->nextFloat() - 0.5) * 0.3, Vec3 p{(random->nextFloat() - 0.5) * 0.3,
-random->nextFloat() * 0.6 - 0.3, 0.6); -random->nextFloat() * 0.6 - 0.3, 0.6};
p->xRot(-xRot * PI / 180); p.xRot(-xRot * PI / 180);
p->yRot(-yRot * PI / 180); p.yRot(-yRot * PI / 180);
*p = p->add(x, y + getHeadHeight(), z); p = p.add(x, y + getHeadHeight(), z);
level->addParticle(PARTICLE_ICONCRACK(useItem->getItem()->id, 0), level->addParticle(PARTICLE_ICONCRACK(useItem->getItem()->id, 0),
p->x, p->y, p->z, d->x, d->y + 0.05, d->z); p.x, p.y, p.z, d.x, d.y + 0.05, d.z);
} }
// 4J Stu - Was L"mob.eat" which doesnt exist // 4J Stu - Was L"mob.eat" which doesnt exist

View file

@ -1,7 +1,8 @@
#include "../Platform/stdafx.h"
#include "Vec3.h" #include "Vec3.h"
#include <format> #include <format>
#include <optional> #include <optional>
#include "AABB.h" #include "AABB.h"
unsigned int Vec3::tlsIdx = 0; unsigned int Vec3::tlsIdx = 0;

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <optional> #include <optional>
#include <string>
class AABB; class AABB;
class Vec3 { class Vec3 {