summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorChristophe Piveteau <chripiveteau@gmail.com>2014-08-14 14:29:46 +0200
committerChristophe Piveteau <chripiveteau@gmail.com>2014-08-14 14:29:46 +0200
commite3a74f379fc103f40e6bf85e626d7bac7db236af (patch)
treebbf6928976cfa84ee96e1948bbd24d58119b9d2e /src/Entities
parentFurther fixing of coding style errors (diff)
downloadcuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.tar
cuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.tar.gz
cuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.tar.bz2
cuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.tar.lz
cuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.tar.xz
cuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.tar.zst
cuberite-e3a74f379fc103f40e6bf85e626d7bac7db236af.zip
Diffstat (limited to '')
-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;
}