use of fr.neatmonster.nocheatplus.checks.moving.model.LocationData in project NoCheatPlus by NoCheatPlus.
the class SurvivalFly method setNextFriction.
/**
* Set data.nextFriction according to media.
* @param from
* @param to
* @param data
* @param cc
*/
private void setNextFriction(final PlayerMoveData thisMove, final MovingData data, final MovingConfig cc) {
// NOTE: Other methods might still override nextFriction to 1.0 due to burst/lift-off envelope.
// TODO: Other media / medium transitions / friction by block.
final LocationData from = thisMove.from;
final LocationData to = thisMove.to;
if (from.inWeb || to.inWeb) {
data.nextFrictionHorizontal = data.nextFrictionVertical = 0.0;
} else if (from.onClimbable || to.onClimbable) {
// TODO: Not sure about horizontal (!).
data.nextFrictionHorizontal = data.nextFrictionVertical = 0.0;
} else if (from.inLiquid) {
// TODO: Exact conditions ?!
if (from.inLava) {
data.nextFrictionHorizontal = data.nextFrictionVertical = Magic.FRICTION_MEDIUM_LAVA;
} else {
data.nextFrictionHorizontal = data.nextFrictionVertical = Magic.FRICTION_MEDIUM_WATER;
}
} else // TODO: consider setting minimum friction last (air), do add ground friction.
if (!from.onGround && !to.onGround) {
data.nextFrictionHorizontal = data.nextFrictionVertical = Magic.FRICTION_MEDIUM_AIR;
} else {
// TODO: Friction for walking on blocks (!).
data.nextFrictionHorizontal = 0.0;
data.nextFrictionVertical = Magic.FRICTION_MEDIUM_AIR;
}
}
use of fr.neatmonster.nocheatplus.checks.moving.model.LocationData in project NoCheatPlus by NoCheatPlus.
the class NoFall method check.
/**
* Checks a player. Expects from and to using cc.yOnGround.
*
* @param player
* the player
* @param from
* the from
* @param to
* the to
* @param previousSetBackY
* The set back y from lift-off. If not present:
* Double.NEGATIVE_INFINITY.
*/
public void check(final Player player, final PlayerLocation pFrom, final PlayerLocation pTo, final double previousSetBackY, final MovingData data, final MovingConfig cc, final IPlayerData pData) {
final boolean debug = pData.isDebugActive(type);
final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
final LocationData from = thisMove.from;
final LocationData to = thisMove.to;
final double fromY = from.getY();
final double toY = to.getY();
final double yDiff = toY - fromY;
final double oldNFDist = data.noFallFallDistance;
// Reset-cond is not touched by yOnGround.
// TODO: Distinguish water depth vs. fall distance ?
/*
* TODO: Account for flags instead (F_FALLDIST_ZERO and
* F_FALLDIST_HALF). Resetcond as trigger: if (resetFrom) { ...
*/
// TODO: Also handle from and to independently (rather fire twice than wait for next time).
final boolean fromReset = from.resetCond;
final boolean toReset = to.resetCond;
final boolean fromOnGround, toOnGround;
// Adapt yOnGround if necessary (sf uses another setting).
if (yDiff < 0 && cc.yOnGround < cc.noFallyOnGround) {
// In fact this is somewhat heuristic, but it seems to work well.
// Missing on-ground seems to happen with running down pyramids rather.
// TODO: Should be obsolete.
adjustYonGround(pFrom, pTo, cc.noFallyOnGround);
fromOnGround = pFrom.isOnGround();
toOnGround = pTo.isOnGround();
} else {
fromOnGround = from.onGround;
toOnGround = to.onGround;
}
// TODO: early returns (...)
final double minY = Math.min(fromY, toY);
if (fromReset) {
// Just reset.
data.clearNoFallData();
// Ensure very big/strange moves don't yield violations.
if (toY - fromY <= -Magic.FALL_DAMAGE_DIST) {
data.noFallSkipAirCheck = true;
}
} else if (fromOnGround || !toOnGround && thisMove.touchedGround) {
// Check if to deal damage (fall back damage check).
// Includes the current y-distance on descend!
touchDown(player, minY, previousSetBackY, data, cc, pData);
// Ensure very big/strange moves don't yield violations.
if (toY - fromY <= -Magic.FALL_DAMAGE_DIST) {
data.noFallSkipAirCheck = true;
}
} else if (toReset) {
// Just reset.
data.clearNoFallData();
} else if (toOnGround) {
// Check if to deal damage.
if (yDiff < 0) {
// In this case the player has traveled further: add the difference.
data.noFallFallDistance -= yDiff;
}
touchDown(player, minY, previousSetBackY, data, cc, pData);
} else {
// Ensure fall distance is correct, or "anyway"?
}
// Set reference y for nofall (always).
/*
* TODO: Consider setting this before handleOnGround (at least for
* resetTo). This is after dealing damage, needs to be done differently.
*/
data.noFallMaxY = Math.max(Math.max(fromY, toY), data.noFallMaxY);
// TODO: fall distance might be behind (!)
// TODO: should be the data.noFallMaxY be counted in ?
// Note: it has to be fetched here.
final float mcFallDistance = player.getFallDistance();
// Add y distance.
if (!toReset && !toOnGround && yDiff < 0) {
data.noFallFallDistance -= yDiff;
} else if (cc.noFallAntiCriticals && (toReset || toOnGround || (fromReset || fromOnGround || thisMove.touchedGround) && yDiff >= 0)) {
final double max = Math.max(data.noFallFallDistance, mcFallDistance);
if (max > 0.0 && max < 0.75) {
// (Ensure this does not conflict with deal-damage set to false.)
if (debug) {
debug(player, "NoFall: Reset fall distance (anticriticals): mc=" + mcFallDistance + " / nf=" + data.noFallFallDistance);
}
if (data.noFallFallDistance > 0) {
data.noFallFallDistance = 0;
}
if (mcFallDistance > 0f) {
player.setFallDistance(0f);
}
}
}
if (debug) {
debug(player, "NoFall: mc=" + mcFallDistance + " / nf=" + data.noFallFallDistance + (oldNFDist < data.noFallFallDistance ? " (+" + (data.noFallFallDistance - oldNFDist) + ")" : "") + " | ymax=" + data.noFallMaxY);
}
}
Aggregations