Move some code off SurvivalFly.check.

This commit is contained in:
asofold 2014-02-22 13:24:22 +01:00
parent 888c18a908
commit 1284fffdf1
2 changed files with 19 additions and 13 deletions

View File

@ -236,20 +236,12 @@ public class SurvivalFly extends Check {
if (sprinting && data.lostSprintCount == 0 && !cc.assumeSprint && hDistance > walkSpeed && data.hVelActive.isEmpty()) {
// (Ignore some cases, in order to prevent false positives.)
// TODO: speed effects ?
final float yaw = from.getYaw();
if (xDistance < 0D && zDistance > 0D && yaw > 180F && yaw < 270F
|| xDistance < 0D && zDistance < 0D && yaw > 270F && yaw < 360F
|| xDistance > 0D && zDistance < 0D && yaw > 0F && yaw < 90F
|| xDistance > 0D && zDistance > 0D && yaw > 90F && yaw < 180F) {
if (TrigUtil.isMovingBackwards(xDistance, zDistance, from.getYaw()) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_SPRINTING)) {
// (Might have to account for speeding permissions.)
if (!player.hasPermission(Permissions.MOVING_SURVIVALFLY_SPRINTING)) {
// Expect full distance to be covered by buffers/velocity.
// TODO: Should this exclusively allow velocity (someone calculate margin)?
// TODO: Check if moving below is ok now (since sprinting flag was fixed).
hDistanceAboveLimit = Math.max(hDistanceAboveLimit, hDistance);
tags.add("sprintback"); // Might add it anyway.
}
}
// TODO: hDistance is too harsh?
hDistanceAboveLimit = Math.max(hDistanceAboveLimit, hDistance);
tags.add("sprintback"); // Might add it anyway.
}
}
//////////////////////////

View File

@ -435,5 +435,19 @@ public class TrigUtil {
public static double maxDistance(final double x1, final double y1, final double z1, final double x2, final double y2, final double z2){
return Math.max(Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2)), Math.abs(z1 - z2));
}
/**
* Check if the x-z plane move is "any backwards" regarding the yaw direction.
* @param xDistance
* @param zDistance
* @param yaw
* @return
*/
public static boolean isMovingBackwards(final double xDistance, final double zDistance, final float yaw) {
return xDistance < 0D && zDistance > 0D && yaw > 180F && yaw < 270F
|| xDistance < 0D && zDistance < 0D && yaw > 270F && yaw < 360F
|| xDistance > 0D && zDistance < 0D && yaw > 0F && yaw < 90F
|| xDistance > 0D && zDistance > 0D && yaw > 90F && yaw < 180F;
}
}