summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Minecart.cpp66
1 files changed, 28 insertions, 38 deletions
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 45b9782f3..8e11d8a07 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -873,80 +873,70 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
case E_META_RAIL_CURVED_ZM_XM:
case E_META_RAIL_CURVED_ZP_XP:
{
- Vector3d Distance(
- MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(),
- 0,
- MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
- );
+ Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
- if (Distance.z == 0.)
- {
- Distance.z = 0.0001;
- }
+ Distance.z = std::max(Distance.z, 0.001);
- if (((Distance.z >= 0) && ((Distance.x / Distance.z) >= 1)) ||
- ((Distance.z<0) && ((Distance.x / Distance.z) <= 1)))
+ if (
+ ((Distance.z > 0) && ((Distance.x / Distance.z) >= 1)) ||
+ ((Distance.z < 0) && ((Distance.x / Distance.z) <= 1))
+ )
{
if ((-GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( -4/sqrt(2) );
- AddSpeedZ( 4/sqrt(2) );
+ AddSpeedX(-4/sqrt(2));
+ AddSpeedZ(4/sqrt(2));
}
else
{
- SetSpeedX( -GetSpeedX() * 0.4 );
- SetSpeedZ( GetSpeedZ() * 0.4 );
+ SetSpeedX(-GetSpeedX() * 0.4);
+ SetSpeedZ(GetSpeedZ() * 0.4);
}
}
else if ((GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( 4/sqrt(2) );
- AddSpeedZ( -4/sqrt(2) );
+ AddSpeedX(4/sqrt(2));
+ AddSpeedZ(-4/sqrt(2));
}
else
{
- SetSpeedX( GetSpeedX() * 0.4 );
- SetSpeedZ( -GetSpeedZ() * 0.4 );
+ SetSpeedX(GetSpeedX() * 0.4);
+ SetSpeedZ(-GetSpeedZ() * 0.4);
}
break;
}
case E_META_RAIL_CURVED_ZM_XP:
case E_META_RAIL_CURVED_ZP_XM:
{
- Vector3d Distance(
- MinecartCollisionCallback.GetCollidedEntityPosition().x - GetPosX(),
- 0,
- MinecartCollisionCallback.GetCollidedEntityPosition().z - GetPosZ()
- );
+ Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ());
- if (Distance.z == 0.)
- {
- Distance.z = 0.0001;
- }
+ Distance.z = std::max(Distance.z, 0.001);
- if (((Distance.z >= 0) && ((Distance.x / Distance.z) <= -1)) ||
- ((Distance.z<0) && ((Distance.x / Distance.z) >= -1)))
+ if (
+ ((Distance.z > 0) && ((Distance.x / Distance.z) <= -1)) ||
+ ((Distance.z < 0) && ((Distance.x / Distance.z) >= -1))
+ )
{
if ((GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( 4/sqrt(2) );
- AddSpeedZ( 4/sqrt(2) );
+ AddSpeedX(4/sqrt(2));
+ AddSpeedZ(4/sqrt(2));
}
else
{
- SetSpeedX( GetSpeedX() * 0.4 );
- SetSpeedZ( GetSpeedZ() * 0.4 );
+ SetSpeedX(GetSpeedX() * 0.4);
+ SetSpeedZ(GetSpeedZ() * 0.4);
}
}
else if ((-GetSpeedX() * 0.4) < 0.01)
{
- AddSpeedX( -4/sqrt(2) );
- AddSpeedZ( -4/sqrt(2) );
+ AddSpeedX(-4/sqrt(2));
+ AddSpeedZ(-4/sqrt(2));
}
else
{
- SetSpeedX( -GetSpeedX() * 0.4 );
- SetSpeedZ( -GetSpeedZ() * 0.4 );
+ SetSpeedX(-GetSpeedX() * 0.4);
+ SetSpeedZ(-GetSpeedZ() * 0.4);
}
break;
}