Improvements

Also a "rewrite" of Texture.cpp but im not happy with it
This commit is contained in:
GabsPuNs
2026-05-29 15:23:34 -04:00
parent 3ec9ae344f
commit 98dcf35e3b
4 changed files with 322 additions and 653 deletions

View File

@@ -737,26 +737,42 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
double d = 0.05;
while (xa != 0 && level->getCubes(shared, bb->cloneMove(xa, -1.0, 0))->empty())
{
if (xa < d && xa >= -d) xa = 0;
else if (xa > 0) xa -= d;
else xa += d;
if (xa < d && xa >= -d)
xa = 0;
else if (xa > 0)
xa -= d;
else
xa += d;
xaOrg = xa;
}
while (za != 0 && level->getCubes(shared, bb->cloneMove(0, -1.0, za))->empty())
{
if (za < d && za >= -d) za = 0;
else if (za > 0) za -= d;
else za += d;
if (za < d && za >= -d)
za = 0;
else if (za > 0)
za -= d;
else
za += d;
zaOrg = za;
}
while (xa != 0 && za != 0 && level->getCubes(shared, bb->cloneMove(xa, -1.0, za))->empty())
{
if (xa < d && xa >= -d) xa = 0;
else if (xa > 0) xa -= d;
else xa += d;
if (za < d && za >= -d) za = 0;
else if (za > 0) za -= d;
else za += d;
if (xa < d && xa >= -d)
xa = 0;
else if (xa > 0)
xa -= d;
else
xa += d;
if (za < d && za >= -d)
za = 0;
else if (za > 0)
za -= d;
else
za += d;
xaOrg = xa;
zaOrg = za;
}
@@ -771,36 +787,30 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
{
// 4J Stu - It's horrible that the client is doing any movement at all! But if we don't have the chunk
// data then all the collision info will be incorrect as well
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
ya = it->clipYCollide(bb, ya);
bb->move(0, ya, 0);
}
if (!slide && yaOrg != ya)
{
xa = ya = za = 0;
}
bool og = onGround || (yaOrg != ya && yaOrg < 0);
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
xa = it->clipXCollide(bb, xa);
bb->move(xa, 0, 0);
if (!slide && xaOrg != xa)
{
xa = ya = za = 0;
}
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
za = it->clipZCollide(bb, za);
bb->move(0, 0, za);
if (!slide && zaOrg != za)
{
xa = ya = za = 0;
}
if (footSize > 0 && og && (isPlayerSneaking || ySlideOffset < 0.05f) && ((xaOrg != xa) || (zaOrg != za)))
{
@@ -822,45 +832,35 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
{
// 4J Stu - It's horrible that the client is doing any movement at all! But if we don't have the chunk
// data then all the collision info will be incorrect as well
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
ya = it->clipYCollide(bb, ya);
bb->move(0, ya, 0);
}
if (!slide && yaOrg != ya)
{
xa = ya = za = 0;
}
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
xa = it->clipXCollide(bb, xa);
bb->move(xa, 0, 0);
if (!slide && xaOrg != xa)
{
xa = ya = za = 0;
}
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
za = it->clipZCollide(bb, za);
bb->move(0, 0, za);
if (!slide && zaOrg != za)
{
xa = ya = za = 0;
}
if (!slide && yaOrg != ya)
{
xa = ya = za = 0;
}
else
{
ya = -footSize;
// LAND FIRST, then x and z
for ( auto& it : *aABBs )
for ( const auto& it : *aABBs )
ya = it->clipYCollide(bb, ya);
bb->move(0, ya, 0);
}
@@ -874,7 +874,6 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
}
}
x = (bb->x0 + bb->x1) / 2.0f;
y = bb->y0 + heightOffset - ySlideOffset;
z = (bb->z0 + bb->z1) / 2.0f;
@@ -885,15 +884,17 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
collision = horizontalCollision || verticalCollision;
checkFallDamage(ya, onGround);
if (xaOrg != xa) xd = 0;
if (yaOrg != ya) yd = 0;
if (zaOrg != za) zd = 0;
if (xaOrg != xa)
xd = 0;
if (yaOrg != ya)
yd = 0;
if (zaOrg != za)
zd = 0;
double xm = x - xo;
double ym = y - yo;
double zm = z - zo;
if (makeStepSound() && !isPlayerSneaking && riding == nullptr)
{
int xt = Mth::floor(x);
@@ -904,14 +905,10 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
{
int renderShape = level->getTileRenderShape(xt, yt - 1, zt);
if (renderShape == Tile::SHAPE_FENCE || renderShape == Tile::SHAPE_WALL || renderShape == Tile::SHAPE_FENCE_GATE)
{
t = level->getTile(xt, yt - 1, zt);
}
}
if (t != Tile::ladder_Id)
{
ym = 0;
}
walkDist += Mth::sqrt(xm * xm + zm * zm) * 0.6;
moveDist += Mth::sqrt(xm * xm + ym * ym + zm * zm) * 0.6;
@@ -940,15 +937,14 @@ void Entity::move(double xa, double ya, double za, bool noEntityCubes) // 4J -
if (!water)
{
onFire++;
if (onFire == 0) setOnFire(8);
if (onFire == 0)
setOnFire(8);
}
}
else
{
if (onFire <= 0)
{
onFire = -flameTime;
}
}
if (water && onFire > 0)
@@ -967,22 +963,24 @@ void Entity::checkInsideTiles()
int y1 = Mth::floor(bb->y1 - 0.001);
int z1 = Mth::floor(bb->z1 - 0.001);
if (level->hasChunksAt(x0, y0, z0, x1, y1, z1))
if (!level->hasChunksAt(x0, y0, z0, x1, y1, z1))
return;
auto shared = shared_from_this();
for (int x = x0; x <= x1; x++)
{
for (int x = x0; x <= x1; x++)
for (int y = y0; y <= y1; y++)
for (int z = z0; z <= z1; z++)
{
int t = level->getTile(x, y, z);
if (t > 0)
{
Tile::tiles[t]->entityInside(level, x, y, z, shared_from_this());
}
}
for (int y = y0; y <= y1; y++)
{
for (int z = z0; z <= z1; z++)
{
int t = level->getTile(x, y, z);
if (t > 0)
Tile::tiles[t]->entityInside(level, x, y, z, shared);
}
}
}
}
void Entity::playStepSound(int xt, int yt, int zt, int t)
{
const Tile::SoundType *soundType = Tile::tiles[t]->soundType;
@@ -994,10 +992,7 @@ void Entity::playStepSound(int xt, int yt, int zt, int t)
unsigned int uiAnimOverrideBitmask=getAnimOverrideBitmask(); // this is masked for custom anim off, and force anim
if(( uiAnimOverrideBitmask& (1<<HumanoidModel::eAnim_NoLegAnim))!=0)
{
return;
}
}
if (level->getTile(xt, yt + 1, zt) == Tile::topSnow_Id)
{
@@ -1032,10 +1027,8 @@ void Entity::checkFallDamage(double ya, bool onGround)
fallDistance = 0;
}
}
else
{
if (ya < 0) fallDistance -= static_cast<float>(ya);
}
else if (ya < 0)
fallDistance -= static_cast<float>(ya);
}
AABB *Entity::getCollideBox()
@@ -1046,9 +1039,7 @@ AABB *Entity::getCollideBox()
void Entity::burn(int dmg)
{
if (!fireImmune)
{
hurt(DamageSource::inFire, dmg);
}
}
bool Entity::isFireImmune()
@@ -1061,7 +1052,6 @@ void Entity::causeFallDamage(float distance)
if (rider.lock() != nullptr) rider.lock()->causeFallDamage(distance);
}
bool Entity::isInWaterOrRain()
{
return wasInWater || (level->isRainingAt( Mth::floor(x), Mth::floor(y), Mth::floor(z)) || level->isRainingAt(Mth::floor(x), Mth::floor(y + bbHeight), Mth::floor(z)));