From a5ed7805429c73f8f2fec409c1947fb032210833 Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 13 Mar 2013 05:08:23 +0100 Subject: [PATCH] Attempt to fix issues with too low valid-count for velocity. --- .../nocheatplus/checks/moving/MovingData.java | 14 +++++++++++--- .../checks/moving/MovingListener.java | 2 +- .../nocheatplus/checks/moving/SurvivalFly.java | 17 +++++++++++------ .../nocheatplus/checks/moving/Velocity.java | 4 ++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index d86bd138..c838c172 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -451,13 +451,19 @@ public class MovingData extends ACheckData { final Velocity vel = it.next(); // TODO: 0.001 can be stretched somewhere else, most likely... // TODO: Somehow use tick here too (actCount, valCount)? - if (vel.valCount <= 0 || vel.value <= 0.001) it.remove(); + if (vel.valCount <= 0 || vel.value <= 0.001){ +// System.out.prsintln("Invalidate active: " + vel); + it.remove(); + } } // Queued. it = hVelQueued.iterator(); while (it.hasNext()){ final Velocity vel = it.next(); - if (vel.actCount <= 0 || vel.tick < tick) it.remove(); + if (vel.actCount <= 0 || vel.tick < tick){ +// System.out.println("Invalidate queued: " + vel); + it.remove(); + } } } @@ -466,10 +472,12 @@ public class MovingData extends ACheckData { */ public void velocityTick(){ // Decrease counts for active. + // TODO: Consider removing already invalidated here. for (final Velocity vel : hVelActive){ vel.valCount --; vel.sum += vel.value; - vel.value *= 0.9; // TODO: Actual friction. + vel.value *= 0.93; // TODO: Actual friction. + // (Altered entries should be kept, since they get used right away.) } // Decrease counts for queued. final Iterator it = hVelQueued.iterator(); diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 1aa4dcd6..02c9f2e3 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -1006,7 +1006,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo newVal = Math.sqrt(velocity.getX() * velocity.getX() + velocity.getZ() * velocity.getZ()); if (newVal > 0D) { used = true; - final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, 1 + (int) Math.round(newVal * 10.0)); + final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, Math.max(20, 1 + (int) Math.round(newVal * 10.0))); data.addHorizontalVelocity(vel); // data.horizontalFreedom += newVal; // data.horizontalVelocityCounter = Math.min(100, Math.max(data.horizontalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(newVal * 10.0)); // 30; diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index cd169563..a4bd7e3a 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -158,6 +158,7 @@ public class SurvivalFly extends Check { // Judge if horizontal speed is above limit. // double hDistanceAboveLimit = hDistance - hAllowedDistance - data.horizontalFreedom; double hDistanceAboveLimit = hDistance - hAllowedDistance; + double hFreedom = 0; // Horizontal velocity used (!). if (hDistanceAboveLimit > 0){ // Check extra buffer (!). final double extraUsed; @@ -174,7 +175,6 @@ public class SurvivalFly extends Check { extraUsed = 0.0; } // Check velocity. - double hFreedom; // Horizontal freedom if used (!). if (hDistanceAboveLimit > 0){ hFreedom = data.getHorizontalFreedom(); if (hFreedom < hDistanceAboveLimit){ @@ -186,6 +186,7 @@ public class SurvivalFly extends Check { } } else{ +// System.out.println("*** Invalidate velocity on not used (extra)"); data.hVelActive.clear(); // TODO: test/check ! hFreedom = 0; } @@ -207,6 +208,7 @@ public class SurvivalFly extends Check { } } else{ +// System.out.println("*** Invalidate velocity on not used (normal)"); data.hVelActive.clear(); // TODO: test/check ! data.sfHBufExtra = 0; } @@ -290,7 +292,7 @@ public class SurvivalFly extends Check { if (silentSetBack != null){ if (cc.debug) { tags.add("silentsbcobweb"); - outputDebug(player, to, data, cc, hDistance, hAllowedDistance, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo); + outputDebug(player, to, data, cc, hDistance, hAllowedDistance, hFreedom, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo); } return silentSetBack; } @@ -438,7 +440,7 @@ public class SurvivalFly extends Check { if (cc.debug) { // Put in a method for shorter code. - outputDebug(player, to, data, cc, hDistance, hAllowedDistance, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo); + outputDebug(player, to, data, cc, hDistance, hAllowedDistance, hFreedom, yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo); } data.sfJumpPhase++; @@ -533,6 +535,7 @@ public class SurvivalFly extends Check { // Check removal of active horizontal velocity. if (hDistance <= hAllowedDistance){ // TODO: Check conditions etc. // Invalidate used horizontal velocity. +// System.out.println("*** INVALIDATE ON SPEED"); data.hVelActive.clear(); // if (data.horizontalVelocityUsed > cc.velocityGraceTicks){ // data.horizontalFreedom = 0; @@ -560,14 +563,15 @@ public class SurvivalFly extends Check { * @param resetTo */ private void outputDebug(final Player player, final PlayerLocation to, final MovingData data, final MovingConfig cc, - final double hDistance, final double hAllowedDistance, final double yDistance, final double vAllowedDistance, + final double hDistance, final double hAllowedDistance, final double hFreedom, final double yDistance, final double vAllowedDistance, final boolean fromOnGround, final boolean resetFrom, final boolean toOnGround, final boolean resetTo) { // TODO: Show player name once (!) final StringBuilder builder = new StringBuilder(500); final String hBuf = (data.sfHorizontalBuffer < 1.0 ? ((" hbuf=" + StringUtil.fdec3.format(data.sfHorizontalBuffer))) : ""); final String hBufExtra = (data.sfHBufExtra > 0 ? (" hbufextra=" + data.sfHBufExtra) : ""); + final String hVelUsed = hFreedom > 0 ? " hVelUsed=" + StringUtil.fdec3.format(hFreedom) : ""; builder.append(player.getName() + " SurvivalFly\nground: " + (data.noFallAssumeGround ? "(assumeonground) " : "") + (fromOnGround ? "onground -> " : (resetFrom ? "resetcond -> " : "--- -> ")) + (toOnGround ? "onground" : (resetTo ? "resetcond" : "---")) + ", jumpphase: " + data.sfJumpPhase); - builder.append("\n" + " hDist: " + StringUtil.fdec3.format(hDistance) + " / " + StringUtil.fdec3.format(hAllowedDistance) + hBuf + hBufExtra + " , vDist: " + StringUtil.fdec3.format(yDistance) + " (" + StringUtil.fdec3.format(to.getY() - data.getSetBackY()) + " / " + StringUtil.fdec3.format(vAllowedDistance) + "), sby=" + (data.hasSetBack() ? data.getSetBackY() : "?")); + builder.append("\n" + " hDist: " + StringUtil.fdec3.format(hDistance) + " / " + StringUtil.fdec3.format(hAllowedDistance) + hBuf + hBufExtra + hVelUsed + " , vDist: " + StringUtil.fdec3.format(yDistance) + " (" + StringUtil.fdec3.format(to.getY() - data.getSetBackY()) + " / " + StringUtil.fdec3.format(vAllowedDistance) + "), sby=" + (data.hasSetBack() ? data.getSetBackY() : "?")); if (data.verticalVelocityCounter > 0 || data.verticalFreedom >= 0.001){ builder.append("\n" + " vertical freedom: " + StringUtil.fdec3.format(data.verticalFreedom) + " (vel=" + StringUtil.fdec3.format(data.verticalVelocity) + "/counter=" + data.verticalVelocityCounter +"/used="+data.verticalVelocityUsed); } @@ -594,7 +598,8 @@ public class SurvivalFly extends Check { private void addVeloctiy(final StringBuilder builder, final List entries) { for (final Velocity vel: entries){ - builder.append(" value=" + vel.value + " counter=" + vel.actCount); + builder.append(" "); + builder.append(vel); } } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Velocity.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Velocity.java index b9055f3b..4e2a56e1 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Velocity.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/moving/Velocity.java @@ -69,4 +69,8 @@ public class Velocity { this.valCount = valCount; } + public String toString(){ + return "Velocity(tick=" + tick + " sum=" + sum + " value=" + value + " valid=" + valCount + " activate=" + actCount + ")"; + } + }