Skip to content

Commit

Permalink
Tackle some of the issues with Elytra but without end rod (unfinished).
Browse files Browse the repository at this point in the history
Missing:
* More testing and adjusting.
* Other cases found, but not yet done. E.g. multiple 0-ydistchange.
* Jumping with oddd gain (2x 3.8 instead 0.42 + 0.33333).
* Lost ground and all the cases apply here (use only sf or refactor).
  • Loading branch information
asofold committed Mar 20, 2016
1 parent 2c46f52 commit 48bf891
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
Expand Up @@ -68,6 +68,7 @@
import fr.neatmonster.nocheatplus.checks.moving.velocity.SimpleEntry;
import fr.neatmonster.nocheatplus.checks.net.NetConfig;
import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
import fr.neatmonster.nocheatplus.compat.BridgeEnchant;
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
Expand Down Expand Up @@ -942,9 +943,9 @@ private Location checkExtremeMove(final Player player, final PlayerLocation from
* @param tick
* @param data
*/
private static void workaroundFlyNoFlyTransition(final Player player, final int tick, final MovingData data) {
private void workaroundFlyNoFlyTransition(final Player player, final int tick, final MovingData data) {
final MoveData lastMove = data.moveData.getFirst();
final double amount = lastMove.hDistance * (1.0 + Magic.FRICTION_MEDIUM_AIR) / 2.0; // Allow same speed instead?
final double amount = guessFlyNoFlyVelocity(player, data.thisMove, lastMove, data);
data.clearActiveHorVel(); // Clear active velocity due to adding actual speed here.
data.addHorizontalVelocity(new AccountEntry(tick, amount, 1, MovingData.getHorVelValCount(amount)));
data.addVerticalVelocity(new SimpleEntry(lastMove.yDistance, 2));
Expand All @@ -953,7 +954,32 @@ private static void workaroundFlyNoFlyTransition(final Player player, final int
// Reset fall height.
// TODO: Later (e.g. 1.9) check for the ModelFlying, if fall damage is intended.
data.clearNoFallData();
player.setFallDistance(0f);
player.setFallDistance(0f); // TODO: Might do without this in case of elytra, needs ensure NoFall doesn't kill the player (...).
if (data.debug){
debug(player, "Fly-nofly transition: Add velocity.");
}
}

private static double guessFlyNoFlyVelocity(final Player player, final MoveData thisMove, final MoveData lastMove, final MovingData data) {
// Default margin: Allow slightly less than the previous speed.
final double defaultAmount = lastMove.hDistance * (1.0 + Magic.FRICTION_MEDIUM_AIR) / 2.0;
// Test for exceptions.
if (Bridge1_9.isWearingElytra(player) && thisMove.hDistance > defaultAmount) {
// Allowing the same speed won't always work on elytra (still increasing, differing modeling on client side with motXYZ).
final MoveData pastMove1 = data.moveData.get(1);
if (pastMove1.toIsValid && lastMove.modelFlying != null && pastMove1.modelFlying != null
&& thisMove.yDistance < Magic.GLIDE_DESCEND_PHASE_MIN
&& lastMove.yDistance < Magic.GLIDE_DESCEND_PHASE_MIN
&& pastMove1.yDistance < Magic.GLIDE_DESCEND_PHASE_MIN
&& Math.abs(pastMove1.yDistance - lastMove.yDistance) < Magic.GLIDE_DESCEND_GAIN_MAX
&& Math.abs(lastMove.yDistance - thisMove.yDistance) < Magic.GLIDE_DESCEND_GAIN_MAX
&& lastMove.hDistance > pastMove1.hDistance && thisMove.hDistance > lastMove.hDistance
&& Math.abs(lastMove.hDistance - pastMove1.hDistance) < Magic.GLIDE_HORIZONTAL_GAIN_MAX
&& Math.abs(thisMove.hDistance - lastMove.hDistance) < Magic.GLIDE_HORIZONTAL_GAIN_MAX) {
return thisMove.hDistance + Magic.GLIDE_HORIZONTAL_GAIN_MAX;
}
}
return defaultAmount;
}

/**
Expand Down
Expand Up @@ -45,8 +45,24 @@ public class Magic {
/** Maximal horizontal buffer. It can be higher, but normal resetting should keep this limit. */

public static final double hBufMax = 1.0;

/**
* Somewhat arbitrary horizontal speed gain maximum for advance glide phase.
*/
public static final double GLIDE_HORIZONTAL_GAIN_MAX = GRAVITY_SPAN;

// Vertical speeds/modifiers.
public static final double climbSpeed = WALK_SPEED * 1.3; // TODO: Check if the factor is needed!
/**
* Some kind of minimum y descend speed (note the negative sign), for an
* already advanced gliding/falling phase with elytra.
*/
public static final double GLIDE_DESCEND_PHASE_MIN = -Magic.GRAVITY_MAX - Magic.GRAVITY_SPAN;
/**
* Somewhat arbitrary, advanced glide phase, maximum descend speed gain.
* This value is positive.
*/
public static final double GLIDE_DESCEND_GAIN_MAX = GRAVITY_MAX;

// On-ground.
public static final double Y_ON_GROUND_MIN = 0.00001;
Expand Down
Expand Up @@ -5,6 +5,7 @@
import fr.neatmonster.nocheatplus.checks.moving.model.LiftOffEnvelope;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveData;
import fr.neatmonster.nocheatplus.checks.workaround.WRPT;
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;

public class MagicAir {
Expand Down Expand Up @@ -327,6 +328,56 @@ private static boolean oddFriction(final double yDistance, final double yDistDif
;
}

/**
* Odd behavior with/after wearing elytra. End rod is not in either hand,
* elytra is equipped (not checked in here).
*
* @param yDistance
* @param yDistDiffEx
* @param lastMove
* @param data
* @return
*/
private static boolean oddElytra(final double yDistance, final double yDistDiffEx, final MoveData lastMove, final MovingData data) {
// Organize cases differently here, at the cost of reaching some nesting level, in order to see if it's better to overview.
final MoveData thisMove = data.thisMove;
final MoveData pastMove1 = data.moveData.get(1); // Checked below, if needed.
// Both descending moves.
if (thisMove.yDistance < 0.0 && lastMove.yDistance < 0.0) {
// Falling too slow.
if (yDistDiffEx > 0.0) {
final double yDistChange = thisMove.yDistance - lastMove.yDistance;
// Increase falling speed somehow.
if (yDistChange < 0.0) {
// pastMove1 valid, decreasing speed envelope like above.
if (pastMove1.toIsValid && pastMove1.yDistance < 0.0) {
final double lastDecrease = lastMove.yDistance - pastMove1.yDistance;
// Increase falling speed from past to last.
if (lastDecrease < 0.0) {
// Relate sum of decrease to gravity somehow.
// TODO: Inaugurate by the one below?
if (Math.abs(yDistChange + lastDecrease) > Magic.GRAVITY_ODD / 2.0) {
// TODO: Might further test for a workaround count down or relate to total gain / jump phase.
return true;
}
}
}
}
// Independently of increasing/decreasing.
// Gliding possibly.
if (thisMove.yDistance < Magic.GLIDE_DESCEND_PHASE_MIN
&& lastMove.yDistance < Magic.GLIDE_DESCEND_PHASE_MIN
&& Math.abs(yDistChange) < Magic.GLIDE_DESCEND_GAIN_MAX) {
// Restrict to early falling.
if (data.sfJumpPhase < 20) {
return true;
}
}
}
}
return false;
}

/**
* Several types of odd in-air moves, mostly with gravity near maximum,
* friction, medium change. Needs lastMove.toIsValid.
Expand Down Expand Up @@ -364,6 +415,10 @@ public static boolean oddJunction(final PlayerLocation from, final PlayerLocatio
// Odd behavior with moving up or (slightly) down, accounting for more than one past move.
return true;
}
if (Bridge1_9.isWearingElytra(from.getPlayer()) && MagicAir.oddElytra(yDistance, yDistDiffEx, lastMove, data)) {
// Odd behavior with/after wearing elytra.
return true;
}
return false;
}

Expand Down

0 comments on commit 48bf891

Please sign in to comment.