something to chew on
This commit is contained in:
parent
c315eb5c63
commit
fd43b29b1d
1 changed files with 101 additions and 153 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.baseband.client.feature.movement;
|
||||
|
||||
import com.baseband.client.event.Priority;
|
||||
import com.baseband.client.event.events.MoveEvent;
|
||||
import com.baseband.client.event.events.PacketEvent;
|
||||
import com.baseband.client.feature.Feature;
|
||||
|
@ -10,16 +9,15 @@ import com.baseband.client.feature.client.Timer;
|
|||
import com.baseband.client.mixins.IMinecraft;
|
||||
import com.baseband.client.mixins.ITimer;
|
||||
import com.baseband.client.registry.annotation.Config;
|
||||
import com.baseband.client.registry.annotation.Gate;
|
||||
import com.baseband.client.registry.annotation.Range;
|
||||
import com.baseband.client.util.adapt.Marker;
|
||||
import com.baseband.client.util.interact.MotionUtil;
|
||||
import net.minecraft.network.play.server.SPacketEntityVelocity;
|
||||
import net.minecraft.network.play.server.SPacketExplosion;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.network.play.server.SPacketPlayerPosLook;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
|
||||
//the horror but also not quite "the horror"
|
||||
@Movement
|
||||
public class Speed extends Feature {
|
||||
@Override
|
||||
|
@ -27,169 +25,119 @@ public class Speed extends Feature {
|
|||
return "Speed";
|
||||
}
|
||||
|
||||
@Config("Boost")
|
||||
@Marker(0)
|
||||
public boolean boost;
|
||||
|
||||
@Config("Boost Reduction")
|
||||
@Range("0..1")
|
||||
@Gate(0)
|
||||
public float boostReduction;
|
||||
@Config("CollideInhibit")
|
||||
public boolean collideInhibit;
|
||||
|
||||
@Config("Strict")
|
||||
public boolean strict;
|
||||
@Config("UseTimer")
|
||||
public boolean useTimer;
|
||||
|
||||
@Config("SlowOnLag")
|
||||
public boolean lagBack;
|
||||
int strafePhase;
|
||||
double playerSpeed;
|
||||
double lastDistance;
|
||||
boolean wasInWater;
|
||||
boolean alternatingHop;
|
||||
|
||||
boolean slow = false;
|
||||
int jumps = 0;
|
||||
double bunnySpeed = .2873;
|
||||
int groundTick = 0;
|
||||
double lastDist = 0;
|
||||
double dmgBoost = 0;
|
||||
boolean isDmgBoostAbsolute = false;
|
||||
public void onEnable() {
|
||||
wasInWater = false;
|
||||
}
|
||||
|
||||
public void onMove(MoveEvent event) {
|
||||
if (!collideInhibit && (isInLiquid() || isOnWater(true) || mc.player.isOnLadder() || mc.player.isEntityInsideOpaqueBlock())) {
|
||||
playerSpeed = 0.0;
|
||||
wasInWater = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mc.player.moveForward == 0.0f && mc.player.moveStrafing == 0.0f) {
|
||||
return;
|
||||
}
|
||||
if (useTimer) {
|
||||
Features.getFeature(Timer.class).timerLock = true;
|
||||
Features.getFeature(Timer.class).multiplierLock = 20f * 1.088f;
|
||||
} else {
|
||||
Features.getFeature(Timer.class).timerLock = false;
|
||||
Features.getFeature(Timer.class).multiplierLock = 20f;
|
||||
}
|
||||
if (strafePhase == 1) {
|
||||
playerSpeed = 1.35 * MotionUtil.applySpeed(0.2873) - 0.01;
|
||||
} else if (strafePhase == 2) {
|
||||
event.y = (mc.player.motionY = 0.3999 + MotionUtil.applyJumpBoost(0.0));
|
||||
playerSpeed *= (alternatingHop ? 1.6835 : 1.395);
|
||||
} else if (strafePhase == 3) {
|
||||
playerSpeed = lastDistance - 0.66 * (lastDistance - MotionUtil.applySpeed(0.2873));
|
||||
alternatingHop = !alternatingHop;
|
||||
} else {
|
||||
if ((!mc.world.getCollisionBoxes(mc.player, mc.player.getEntityBoundingBox().offset(0.0, mc.player.motionY, 0.0)).isEmpty() || mc.player.collidedVertically) && strafePhase > 0) {
|
||||
strafePhase = ((mc.player.moveForward != 0.0f || mc.player.moveStrafing != 0.0f) ? 1 : 0);
|
||||
}
|
||||
playerSpeed = lastDistance - lastDistance / 159.0;
|
||||
}
|
||||
playerSpeed = Math.max(playerSpeed, MotionUtil.applySpeed(0.2873));
|
||||
final double[] dir = MotionUtil.getMotion(playerSpeed);
|
||||
event.x = (dir[0]);
|
||||
event.z = (dir[1]);
|
||||
if (mc.player.moveForward != 0.0f || mc.player.moveStrafing != 0.0f) {
|
||||
++strafePhase;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isOnWater(boolean bl) {
|
||||
int minY = MathHelper.floor(mc.player.getEntityBoundingBox().minY - (bl ? 0.03 : 0.2));
|
||||
int minX = MathHelper.floor(mc.player.getEntityBoundingBox().minX);
|
||||
int maxX = MathHelper.ceil(mc.player.getEntityBoundingBox().maxX);
|
||||
int minZ = MathHelper.floor(mc.player.getEntityBoundingBox().minZ);
|
||||
int maxZ = MathHelper.ceil(mc.player.getEntityBoundingBox().maxZ);
|
||||
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
IBlockState iBlockState = mc.world.getBlockState(new BlockPos(x, minY, z));
|
||||
if (iBlockState.getBlock() instanceof BlockLiquid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInLiquid() {
|
||||
int minX = MathHelper.floor(mc.player.getEntityBoundingBox().minX);
|
||||
int maxX = MathHelper.ceil(mc.player.getEntityBoundingBox().maxX);
|
||||
int minZ = MathHelper.floor(mc.player.getEntityBoundingBox().minZ);
|
||||
int maxZ = MathHelper.ceil(mc.player.getEntityBoundingBox().maxZ);
|
||||
int minY = MathHelper.floor(mc.player.getEntityBoundingBox().minY + 0.01);
|
||||
|
||||
for (int x = minX; x < maxX; x++) {
|
||||
for (int z = minZ; z < maxZ; z++) {
|
||||
IBlockState iBlockState = mc.world.getBlockState(new BlockPos(x, minY, z));
|
||||
if (iBlockState.getBlock() instanceof BlockLiquid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onPacketReceive(final PacketEvent.Receive event) {
|
||||
if (event.getPacket() instanceof SPacketPlayerPosLook) {
|
||||
playerSpeed = MotionUtil.applySpeed(0.2873);
|
||||
lastDistance = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEveryTick() {
|
||||
if(enabled && !notIngame()) {
|
||||
text = this + "§7 [" + String.format("%.2f", getSpeed()) + " KM/H]";
|
||||
text = this + "§7 [" + String.format("%.2f", getSpeed()) + " km/h]";
|
||||
} else {
|
||||
text = toString();
|
||||
}
|
||||
|
||||
if(enabled && Features.getFeature(Timer.class).enabled) {
|
||||
Features.getFeature(Timer.class).timerLock = true;
|
||||
Features.getFeature(Timer.class).multiplierLock = 20f * 1.088f;
|
||||
} else if (!enabled && Features.getFeature(Timer.class).enabled){
|
||||
Features.getFeature(Timer.class).timerLock = false;
|
||||
Features.getFeature(Timer.class).multiplierLock = 20f;
|
||||
}
|
||||
}
|
||||
|
||||
public double getSpeed() {
|
||||
return MathHelper.sqrt(Math.pow(mc.player.posX - mc.player.prevPosX, 2.0f) + Math.pow(mc.player.posZ - mc.player.prevPosZ, 2.0)) / (((ITimer) ((IMinecraft) mc).getTimer()).getTickLength() / 1000.0f) * 3.6;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
bunnySpeed = lastDist = dmgBoost = jumps = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onTick() {
|
||||
if (mc.player != null) {
|
||||
lastDist = Math.hypot(mc.player.posX - mc.player.prevPosX, mc.player.posZ - mc.player.prevPosZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Time will tell.
|
||||
//higher priority than default, so we can get explosion packets before velocity fucks with them
|
||||
@Priority(value = 2)
|
||||
public void onPacketReceive(PacketEvent.Receive event) {
|
||||
if(notIngame()) {
|
||||
return;
|
||||
}
|
||||
if (event.getPacket() instanceof SPacketPlayerPosLook && lagBack) {
|
||||
bunnySpeed = 0;
|
||||
}
|
||||
|
||||
if (mc.player.isInWater() || mc.player.isInLava())
|
||||
return;
|
||||
|
||||
if (!boost)
|
||||
return;
|
||||
|
||||
if (event.getPacket() instanceof SPacketExplosion) {
|
||||
SPacketExplosion packet = (SPacketExplosion) event.getPacket();
|
||||
dmgBoost = Math.hypot(packet.getMotionX(), packet.getMotionZ());
|
||||
} else if (event.getPacket() instanceof SPacketEntityVelocity) {
|
||||
SPacketEntityVelocity packet = (SPacketEntityVelocity) event.getPacket();
|
||||
|
||||
if (packet.getEntityID() == mc.player.getEntityId()) {
|
||||
dmgBoost = Math.hypot(packet.getMotionX() / 8000D, packet.getMotionZ() / 8000D);
|
||||
isDmgBoostAbsolute = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onMove(MoveEvent event) {
|
||||
if (mc.player.isInWater() || mc.player.isInLava())
|
||||
return;
|
||||
|
||||
double xzSpeed;
|
||||
|
||||
double base = MotionUtil.applySpeed(.2873);
|
||||
|
||||
if (mc.player.moveForward == 0 && mc.player.moveStrafing == 0 || mc.player.collidedHorizontally)
|
||||
jumps = 0;
|
||||
|
||||
if (mc.player.onGround && (mc.player.moveForward != 0 || mc.player.moveStrafing != 0)) {
|
||||
|
||||
bunnySpeed = Math.max(
|
||||
// current speed multiplied by a condensed version of mc friction code
|
||||
bunnySpeed = .2 + bunnySpeed * (double) (mc.world.getBlockState(BlockPos.PooledMutableBlockPos.retain(mc.player.posX, mc.player.getEntityBoundingBox().minY - 1.0D, mc.player.posZ).setPos(mc.player.posX, mc.player.getEntityBoundingBox().minY - 1.0D, mc.player.posZ)).getBlock().getSlipperiness(mc.world.getBlockState(BlockPos.PooledMutableBlockPos.retain(mc.player.posX, mc.player.getEntityBoundingBox().minY - 1.0D, mc.player.posZ).setPos(mc.player.posX, mc.player.getEntityBoundingBox().minY - 1.0D, mc.player.posZ)), mc.world, BlockPos.PooledMutableBlockPos.retain(mc.player.posX, mc.player.getEntityBoundingBox().minY - 1.0D, mc.player.posZ), mc.player) * 0.91F),
|
||||
getBunnySpeed(MotionUtil.applySpeed(.2873))
|
||||
);
|
||||
|
||||
// jump
|
||||
event.y = (mc.player.motionY = MotionUtil.applyJumpBoost(.42F));
|
||||
|
||||
groundTick = 0;
|
||||
slow = true;
|
||||
|
||||
if (++jumps == 1)
|
||||
bunnySpeed *= .95;
|
||||
|
||||
} else if (slow || mc.player.collidedHorizontally) {
|
||||
|
||||
// https://github.com/NoCheatPlus/NoCheatPlus/blob/f7b2c017fd66838ed2542fba483d7268ff01c2cf/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/player/SurvivalFly.java#L1692
|
||||
bunnySpeed -= 0.66 * base;
|
||||
slow = false;
|
||||
|
||||
} else
|
||||
// https://github.com/NoCheatPlus/NoCheatPlus/blob/f7b2c017fd66838ed2542fba483d7268ff01c2cf/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/player/SurvivalFly.java#L1698
|
||||
// we use a little less so that we don't flag
|
||||
bunnySpeed = lastDist - lastDist / 159;
|
||||
|
||||
double oldSpeed = bunnySpeed;
|
||||
if (dmgBoost >= 0) {
|
||||
if (isDmgBoostAbsolute) {
|
||||
bunnySpeed = dmgBoost - ((dmgBoost - bunnySpeed) * (1 - boostReduction));
|
||||
} else {
|
||||
bunnySpeed += dmgBoost * (1 - boostReduction);
|
||||
}
|
||||
dmgBoost = 0;
|
||||
}
|
||||
|
||||
bunnySpeed = Math.max(oldSpeed, bunnySpeed);
|
||||
|
||||
xzSpeed = bunnySpeed = Math.max(base, bunnySpeed);
|
||||
|
||||
// should never happen
|
||||
|
||||
if (xzSpeed == Double.MIN_VALUE)
|
||||
return;
|
||||
|
||||
double[] dir = MotionUtil.getMotion(xzSpeed);
|
||||
event.x = (dir[0]);
|
||||
event.z = (dir[1]);
|
||||
|
||||
}
|
||||
|
||||
double getBunnySpeed(double base) {
|
||||
// prevent too aggressive acceleration causing flags
|
||||
base = Math.min(1, base);
|
||||
|
||||
if (strict)
|
||||
return base * 1.87;
|
||||
else
|
||||
return base * 1.935;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue