diff --git a/Minecraft.World/Util/JavaMath.cpp b/Minecraft.World/Util/JavaMath.cpp index 3037d5a57..21389bb2b 100644 --- a/Minecraft.World/Util/JavaMath.cpp +++ b/Minecraft.World/Util/JavaMath.cpp @@ -36,7 +36,20 @@ double Math::random() //the value of the argument rounded to the nearest long value. __int64 Math::round( double d ) { - return (__int64)floor( d + 0.5 ); + // 4jcraft fixes the fact that if double is a huge + // number than the cast of d to int64_t overflows + + d = floor( d + 0.5 ); + + // if smaller or bigger than representable int64 than return the max + if(d >= (double)INT64_MAX) { + return INT64_MAX; + + } else if (d <= (double)INT64_MIN) { + return INT64_MIN; + } + + return (int64_t) d; } int Math::_max(int a, int b) @@ -73,4 +86,4 @@ double Math::wrapDegrees(double input) if (input >= 180.0) input -= 360.0; if (input < -180.0) input += 360.0; return input; -} \ No newline at end of file +} diff --git a/Minecraft.World/Util/Mth.cpp b/Minecraft.World/Util/Mth.cpp index 8dd22cc72..54f7fb605 100644 --- a/Minecraft.World/Util/Mth.cpp +++ b/Minecraft.World/Util/Mth.cpp @@ -25,13 +25,13 @@ void Mth::init() float Mth::sin(float i) { if(_sin == NULL) init(); // 4J - added - return _sin[(int) (i * sinScale) & 65535]; + return _sin[(int)fmodf(i * sinScale, 65536.0f) & 65535]; } float Mth::cos(float i) { if(_sin == NULL) init(); // 4J - added - return _sin[(int) (i * sinScale + 65536 / 4) & 65535]; + return _sin[(int)fmodf(i * sinScale + 16384.0f, 65536.0f) & 65535]; } float Mth::sqrt(float x) @@ -169,4 +169,4 @@ double Mth::wrapDegrees(double input) bool Mth::almostEquals( double double1, double double2, double precision) { return (std::abs(double1 - double2) <= precision); -} \ No newline at end of file +}