Bleeding: Attempt to fix jump boost handling.

This commit is contained in:
asofold 2012-10-31 05:52:14 +01:00
parent 6262ec2551
commit e3d9b693b3
4 changed files with 36 additions and 40 deletions

View File

@ -100,23 +100,7 @@ public class CreativeFly extends Check {
resultH *= 100D;
// Is the player affected by the "jumping" potion. This is really just a very, very crude estimation and far
// from reality.
double jumpAmplifier = 1D;
if (entity.hasEffect(MobEffectList.JUMP)) {
final int amplifier = entity.getEffect(MobEffectList.JUMP).getAmplifier();
if (amplifier > 20)
jumpAmplifier = 1.5D * (amplifier + 1D);
else
jumpAmplifier = 1.2D * (amplifier + 1D);
}
if (jumpAmplifier > data.jumpAmplifier)
data.jumpAmplifier = jumpAmplifier;
final double limitV = cc.creativeFlyVerticalSpeed / 100D * VERTICAL_SPEED * data.jumpAmplifier;
if (from.getY() >= to.getY() && data.jumpAmplifier > 0D)
data.jumpAmplifier--;
final double limitV = cc.creativeFlyVerticalSpeed / 100D * VERTICAL_SPEED; // * data.jumpAmplifier;
// Super simple, just check distance compared to max distance vertical.
final double resultV = Math.max(0D, yDistance - data.verticalFreedom - limitV) * 100D;

View File

@ -145,6 +145,7 @@ public class MovingData extends ACheckData {
public void clearFlyData() {
bunnyhopDelay = 0;
survivalFlyJumpPhase = 0;
jumpAmplifier = 0;
setBack = null;
survivalFlyLastYDist = Double.MAX_VALUE;
fromX = toX = Double.MAX_VALUE;

View File

@ -3,10 +3,14 @@ package fr.neatmonster.nocheatplus.checks.moving;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
@ -346,6 +350,21 @@ public class MovingListener implements Listener {
data.noFallAssumeGround = false;
data.teleported = null;
final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
// Potion effect "Jump".
final double jumpAmplifier;
if (mcPlayer.hasEffect(MobEffectList.JUMP)) {
// final int amplifier = mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier();
// if (amplifier > 20)
// jumpAmplifier = 1.5D * (amplifier + 1D);
// else
// jumpAmplifier = 1.2D * (amplifier + 1D);
jumpAmplifier = 1D + mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier();
if (cc.debug) System.out.println(player.getName() + " Jump effect: " + data.jumpAmplifier);
}
else jumpAmplifier = 1D;
if (jumpAmplifier > data.jumpAmplifier) data.jumpAmplifier = jumpAmplifier;
// Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do
// general data modifications one for each event.
if (data.horizontalVelocityCounter > 0D)
@ -378,7 +397,7 @@ public class MovingListener implements Listener {
if ((cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && (cc.ignoreAllowFlight || !player.getAllowFlight())
&& cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY)){
// If he is handled by the survival fly check, execute it.
newTo = survivalFly.check(player, pFrom, pTo, data, cc);
newTo = survivalFly.check(player, mcPlayer, pFrom, pTo, data, cc);
// If don't have a new location and if he is handled by the no fall check, execute it.
if (newTo == null && cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL))
// NOTE: noFall might set yOnGround for the positions.

View File

@ -6,7 +6,6 @@ import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
@ -90,7 +89,7 @@ public class SurvivalFly extends Check {
* the to
* @return the location
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
public Location check(final Player player, final EntityPlayer mcPlayer, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
final long now = System.currentTimeMillis();
// A player is considered sprinting if the flag is set and if he has enough food level.
@ -150,6 +149,7 @@ public class SurvivalFly extends Check {
// data.ground ?
// ? set jumpphase to height / 0.15 ?
data.survivalFlyJumpPhase = 0;
data.jumpAmplifier = 0;
data.clearAccounting();
// Tell NoFall that we assume the player to have been on ground somehow.
data.noFallAssumeGround = true;
@ -198,10 +198,10 @@ public class SurvivalFly extends Check {
hAllowedDistance *= modIce;
// Taken directly from Minecraft code, should work.
final EntityPlayer entity = ((CraftPlayer) player).getHandle();
// player.hasPotionEffect(PotionEffectType.SPEED);
if (entity.hasEffect(MobEffectList.FASTER_MOVEMENT))
hAllowedDistance *= 1.0D + 0.2D * (entity.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT))
hAllowedDistance *= 1.0D + 0.2D * (mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
// Account for flowing liquids (only if needed).
if (hDistance > swimmingSpeed && from.isInLiquid() && from.isDownStream(xDistance, zDistance)){
@ -250,19 +250,6 @@ public class SurvivalFly extends Check {
} else
data.horizontalBuffer = Math.min(1D, data.horizontalBuffer - hDistanceAboveLimit);
// Potion effect "Jump".
double jumpAmplifier = 1D;
// player.hasPotionEffect(PotionEffectType.JUMP)
if (entity.hasEffect(MobEffectList.JUMP)) {
final int amplifier = entity.getEffect(MobEffectList.JUMP).getAmplifier();
if (amplifier > 20)
jumpAmplifier = 1.5D * (amplifier + 1D);
else
jumpAmplifier = 1.2D * (amplifier + 1D);
}
if (jumpAmplifier > data.jumpAmplifier)
data.jumpAmplifier = jumpAmplifier;
// Calculate the vertical speed limit based on the current jump phase.
double vAllowedDistance, vDistanceAboveLimit;
if (from.isInWeb()){
@ -290,9 +277,14 @@ public class SurvivalFly extends Check {
}
else{
vAllowedDistance = (!(fromOnGround || data.noFallAssumeGround) && !toOnGround ? 1.45D : 1.35D) + data.verticalFreedom;
vAllowedDistance *= data.jumpAmplifier;
if (data.survivalFlyJumpPhase > 6 + data.jumpAmplifier && data.verticalVelocityCounter <= 0){
vAllowedDistance -= (data.survivalFlyJumpPhase - 6) * 0.15D;
final int maxJumpPhase;
if (data.jumpAmplifier > 0){
vAllowedDistance += 0.5 + data.jumpAmplifier - 1.0;
maxJumpPhase = (int) (9 + (data.jumpAmplifier - 1.0) * 6);
}
else maxJumpPhase = 6;
if (data.survivalFlyJumpPhase > maxJumpPhase && data.verticalVelocityCounter <= 0){
vAllowedDistance -= Math.max(0, (data.survivalFlyJumpPhase - maxJumpPhase) * 0.15D);
}
vDistanceAboveLimit = to.getY() - data.setBack.getY() - vAllowedDistance;