mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-06-06 22:42:53 +00:00
fix: crashing on world join
This commit is contained in:
parent
7b021bc99d
commit
9405f38f80
|
|
@ -17,6 +17,7 @@
|
|||
#include "../Headers/net.minecraft.h"
|
||||
#include "Util/Vec3.h"
|
||||
#include "Tile.h"
|
||||
#include <optional>
|
||||
|
||||
std::wstring Tile::TILE_DESCRIPTION_PREFIX = L"Tile.";
|
||||
|
||||
|
|
@ -2134,52 +2135,51 @@ HitResult* Tile::clip(Level* level, int xt, int yt, int zt, Vec3* a, Vec3* b) {
|
|||
auto zh0 = a->clipZ(*b, tls->zz0);
|
||||
auto zh1 = a->clipZ(*b, tls->zz1);
|
||||
|
||||
Vec3* closest = nullptr;
|
||||
std::optional<Vec3> closest = std::nullopt;
|
||||
|
||||
if (xh0.has_value() and containsX(&*xh0) and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*xh0) < a->distanceToSqr(*closest)))
|
||||
*closest = *xh0;
|
||||
closest = xh0;
|
||||
|
||||
if (xh1.has_value() and containsX(&*xh1) and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*xh1) < a->distanceToSqr(*closest)))
|
||||
*closest = *xh1;
|
||||
closest = xh1;
|
||||
|
||||
if (yh0.has_value() and containsY(&*yh0) and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*yh0) < a->distanceToSqr(*closest)))
|
||||
*closest = *yh0;
|
||||
closest = yh0;
|
||||
|
||||
if (yh1.has_value() and containsY(&*yh1) and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*yh1) < a->distanceToSqr(*closest)))
|
||||
*closest = *yh1;
|
||||
closest = yh1;
|
||||
|
||||
if (zh0.has_value() and containsZ(&*zh0) and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*zh0) < a->distanceToSqr(*closest)))
|
||||
*closest = *zh0;
|
||||
closest = zh0;
|
||||
|
||||
if (zh1.has_value() and containsZ(&*zh1) and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*zh1) < a->distanceToSqr(*closest)))
|
||||
*closest = *zh1;
|
||||
closest = zh1;
|
||||
|
||||
if (closest == NULL) return NULL;
|
||||
if (!closest.has_value()) return nullptr;
|
||||
|
||||
int face = -1;
|
||||
|
||||
if (*closest == xh0) face = Facing::WEST;
|
||||
if (*closest == xh1) face = Facing::EAST;
|
||||
if (*closest == yh0) face = Facing::DOWN;
|
||||
if (*closest == yh1) face = Facing::UP;
|
||||
if (*closest == zh0) face = Facing::NORTH;
|
||||
if (*closest == zh1) face = Facing::SOUTH;
|
||||
if (closest == xh0) face = Facing::WEST;
|
||||
if (closest == xh1) face = Facing::EAST;
|
||||
if (closest == yh0) face = Facing::DOWN;
|
||||
if (closest == yh1) face = Facing::UP;
|
||||
if (closest == zh0) face = Facing::NORTH;
|
||||
if (closest == zh1) face = Facing::SOUTH;
|
||||
|
||||
*closest = closest->add(xt, yt, zt);
|
||||
|
||||
return new HitResult(xt, yt, zt, face, *closest);
|
||||
Vec3 res = closest->add(xt, yt, zt);
|
||||
return new HitResult(xt, yt, zt, face, res);
|
||||
}
|
||||
|
||||
bool Tile::containsX(Vec3* v) {
|
||||
|
|
|
|||
|
|
@ -255,45 +255,49 @@ HitResult* AABB::clip(Vec3* a, Vec3* b) {
|
|||
if (!(yh1.has_value() and containsY(&*yh1))) yh1 = std::nullopt;
|
||||
if (!(zh0.has_value() and containsZ(&*zh0))) zh0 = std::nullopt;
|
||||
if (!(zh1.has_value() and containsZ(&*zh1))) zh1 = std::nullopt;
|
||||
Vec3* closest = nullptr;
|
||||
|
||||
std::optional<Vec3> closest = std::nullopt;
|
||||
|
||||
if (xh0.has_value() and
|
||||
(closest == nullptr or
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*xh0) < a->distanceToSqr(*closest)))
|
||||
*closest = *xh0;
|
||||
if (xh1.has_value() and
|
||||
(closest == nullptr or
|
||||
a->distanceToSqr(*xh1) < a->distanceToSqr(*closest)))
|
||||
*closest = *xh1;
|
||||
if (yh0.has_value() and
|
||||
(closest == nullptr or
|
||||
a->distanceToSqr(*yh0) < a->distanceToSqr(*closest)))
|
||||
*closest = *yh0;
|
||||
if (yh1.has_value() and
|
||||
(closest == nullptr or
|
||||
a->distanceToSqr(*yh1) < a->distanceToSqr(*closest)))
|
||||
*closest = *yh1;
|
||||
if (zh0.has_value() and
|
||||
(closest == nullptr or
|
||||
a->distanceToSqr(*zh0) < a->distanceToSqr(*closest)))
|
||||
*closest = *zh0;
|
||||
if (zh1.has_value() and
|
||||
(closest == nullptr or
|
||||
a->distanceToSqr(*zh1) < a->distanceToSqr(*closest)))
|
||||
*closest = *zh1;
|
||||
closest = xh0;
|
||||
|
||||
if (closest == nullptr) return nullptr;
|
||||
if (xh1.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*xh1) < a->distanceToSqr(*closest)))
|
||||
closest = xh1;
|
||||
|
||||
if (yh0.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*yh0) < a->distanceToSqr(*closest)))
|
||||
closest = yh0;
|
||||
|
||||
if (yh1.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*yh1) < a->distanceToSqr(*closest)))
|
||||
closest = yh1;
|
||||
|
||||
if (zh0.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*zh0) < a->distanceToSqr(*closest)))
|
||||
closest = zh0;
|
||||
|
||||
if (zh1.has_value() and
|
||||
(!closest.has_value() or
|
||||
a->distanceToSqr(*zh1) < a->distanceToSqr(*closest)))
|
||||
closest = zh1;
|
||||
|
||||
if (!closest.has_value()) return nullptr;
|
||||
|
||||
int face = -1;
|
||||
|
||||
if (*closest == xh0) face = 4;
|
||||
if (*closest == xh1) face = 5;
|
||||
if (*closest == yh0) face = 0;
|
||||
if (*closest == yh1) face = 1;
|
||||
if (*closest == zh0) face = 2;
|
||||
if (*closest == zh1) face = 3;
|
||||
|
||||
closest = Vec3::newTemp(closest->x, closest->y, closest->z);
|
||||
if (closest == xh0) face = 4;
|
||||
if (closest == xh1) face = 5;
|
||||
if (closest == yh0) face = 0;
|
||||
if (closest == yh1) face = 1;
|
||||
if (closest == zh0) face = 2;
|
||||
if (closest == zh1) face = 3;
|
||||
|
||||
return new HitResult(0, 0, 0, face, *closest);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue