public class Strafe extends ModuleStorage {
private static final MinecraftClient mc = MinecraftClient.getInstance();
private final Random random = new Random();
private int tickCounter = 0;
@Subscribe
public void onTick(TickEvent event) {
if (!getEnabled() || mc.world == null || mc.player == null || mc.player.isOnGround() || mc.player.isSubmergedInWater()) {
tickCounter = 0;
return;
}
tickCounter++;
float moveStrafe = mc.player.input.movementSideways;
float moveForward = mc.player.input.movementForward;
if (moveStrafe == 0 && moveForward == 0) {
return;
}
float yaw = mc.player.getYaw();
float speedMultiplier = 0.4f;
float baseSpeed = 0.2873f;
float strafeSpeed = baseSpeed * (0.7f + speedMultiplier * 0.3f);
yaw += random.nextFloat() * 2.0f - 1.0f;
moveStrafe *= 0.95f + random.nextFloat() * 0.1f;
moveForward *= 0.95f + random.nextFloat() * 0.1f;
strafeSpeed *= 0.7f;
if (random.nextInt(100) < 20 || (tickCounter % random.nextInt(6) + 5) < 2) {
strafeSpeed = 0.0f;
} else if (tickCounter % (random.nextInt(3) + 2) == 0) {
strafeSpeed *= 0.9f + random.nextFloat() * 0.2f;
}
float strafe = moveStrafe * MathHelper.cos(yaw * 0.017453292F) - moveForward * MathHelper.sin(yaw * 0.017453292F);
float forward = moveForward * MathHelper.cos(yaw * 0.017453292F) + moveStrafe * MathHelper.sin(yaw * 0.017453292F);
float direction = (float) Math.sqrt(strafe * strafe + forward * forward);
if (direction < 0.01F) {
return;
}
strafe /= direction;
forward /= direction;
Vec3d velocity = mc.player.getVelocity();
double motionX = strafe * strafeSpeed;
double motionY = velocity.y;
double motionZ = forward * strafeSpeed;
if (motionY < 0) {
motionY *= 0.98;
motionY += 0.005 * speedMultiplier;
}
float maxSpeed = 0.24f;
float currentSpeed = (float) Math.sqrt(motionX * motionX + motionZ * motionZ);
if (currentSpeed > maxSpeed) {
float scale = maxSpeed / currentSpeed;
motionX *= scale;
motionZ *= scale;
}
mc.player.setVelocity(motionX, motionY, motionZ);
}
public void onModeChange() {
}
public void onDisable() {
tickCounter = 0;
if (mc.player != null) {
mc.player.setVelocity(mc.player.getVelocity().x, mc.player.getVelocity().y, mc.player.getVelocity().z);
}
}
}