| 1 | /*
|
| 2 | * This file is part of the Combatant Client distribution.
|
| 3 | * Combatant modifications copyright (c) 2026 pivosos2007.
|
| 4 | *
|
| 5 | * Portions of this file are based on LiquidBounce
|
| 6 | * (https://github.com/CCBlueX/LiquidBounce).
|
| 7 | * Copyright (c) 2015-2026 CCBlueX.
|
| 8 | *
|
| 9 | * LiquidBounce portions are licensed under GPLv3-or-later.
|
| 10 | * Combatant modifications are licensed under GPLv3.
|
| 11 | * See THIRD_PARTY_NOTICES.md for details.
|
| 12 | */
|
| 13 |
|
| 14 | package combatant.client.mixins;
|
| 15 |
|
| 16 | /*
|
| 17 | * Parts of sprint control, silent rotations, and movement-input correction
|
| 18 | * are adapted from LiquidBounce (https://github.com/CCBlueX/LiquidBounce).
|
| 19 | * Original copyright (c) CCBlueX.
|
| 20 | */
|
| 21 |
|
| 22 | import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
| 23 | import combatant.client.events.impl.*;
|
| 24 | import combatant.client.features.module.modules.movement.*;
|
| 25 | import combatant.client.util.combat.SprintController;
|
| 26 | import combatant.client.util.screen.ClientScreen;
|
| 27 | import net.minecraft.client.player.ClientInput;
|
| 28 | import net.minecraft.client.player.LocalPlayer;
|
| 29 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
| 30 | import net.minecraft.util.Mth;
|
| 31 | import net.minecraft.world.entity.Entity;
|
| 32 | import net.minecraft.world.entity.LivingEntity;
|
| 33 | import net.minecraft.world.entity.PortalProcessor;
|
| 34 | import net.minecraft.world.entity.player.Input;
|
| 35 | import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEnderpearl;
|
| 36 | import net.minecraft.world.inventory.InventoryMenu;
|
| 37 | import net.minecraft.world.level.entity.EntityTypeTest;
|
| 38 | import net.minecraft.world.phys.Vec2;
|
| 39 | import net.minecraft.world.phys.Vec3;
|
| 40 | import org.spongepowered.asm.mixin.Mixin;
|
| 41 | import org.spongepowered.asm.mixin.Shadow;
|
| 42 | import org.spongepowered.asm.mixin.Unique;
|
| 43 | import org.spongepowered.asm.mixin.injection.At;
|
| 44 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 45 | import org.spongepowered.asm.mixin.injection.Redirect;
|
| 46 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 47 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 48 | import combatant.client.events.Events;
|
| 49 | import combatant.client.events.impl.*;
|
| 50 | import combatant.client.features.module.Modules;
|
| 51 | import combatant.client.features.module.modules.movement.*;
|
| 52 | import combatant.client.features.module.modules.player.XCarry;
|
| 53 | import combatant.client.features.module.modules.visuals.Freecam;
|
| 54 | import combatant.client.mixininterface.ILocalPlayer;
|
| 55 | import combatant.client.mixins.accessors.EntityAccessor;
|
| 56 | import combatant.client.mixins.accessors.InputAccessor;
|
| 57 | import combatant.client.mixins.accessors.LocalPlayerAccessor;
|
| 58 | import combatant.client.runtime.RuntimeGate;
|
| 59 | import combatant.client.util.aiming.RotationManager;
|
| 60 | import combatant.client.util.aiming.data.Rotation;
|
| 61 |
|
| 62 | import java.util.ArrayList;
|
| 63 | import java.util.List;
|
| 64 |
|
| 65 | @Mixin(LocalPlayer.class)
|
| 66 | public abstract class LocalPlayerMixin implements ILocalPlayer {
|
| 67 |
|
| 68 | @Shadow
|
| 69 | public ClientInput input;
|
| 70 | @Unique
|
| 71 | private float combatant$lastYaw;
|
| 72 | @Unique
|
| 73 | private float combatant$lastPitch;
|
| 74 | @Unique
|
| 75 | private double combatant$rotationPrevX;
|
| 76 | @Unique
|
| 77 | private double combatant$rotationPrevZ;
|
| 78 | @Unique
|
| 79 | private float combatant$rotationPrevBodyYaw;
|
| 80 | @Unique
|
| 81 | private boolean combatant$rotationBodyYawInitialized;
|
| 82 | @Unique
|
| 83 | private float freecam$lastHealth = Float.NaN;
|
| 84 | @Unique
|
| 85 | private boolean frozen = false;
|
| 86 | @Unique
|
| 87 | private Vec3 savedVelocity = Vec3.ZERO;
|
| 88 | @Unique
|
| 89 | private double savedX, savedY, savedZ;
|
| 90 | @Unique
|
| 91 | private float savedBodyYaw;
|
| 92 | @Unique
|
| 93 | private float savedHeadYaw;
|
| 94 | @Unique
|
| 95 | private Runnable combatant$eventPostAction;
|
| 96 | @Unique
|
| 97 | private EventSync combatant$activeSyncEvent;
|
| 98 | @Unique
|
| 99 | private boolean combatant$postUpdateLock = false;
|
| 100 | @Unique
|
| 101 | private Input lastInput;
|
| 102 | @Unique
|
| 103 | private boolean pendingSpoof = false;
|
| 104 | @Unique
|
| 105 | private int boostTicks = 0;
|
| 106 | @Unique
|
| 107 | private double boostX = 0, boostZ = 0;
|
| 108 | @Unique
|
| 109 | private boolean wasGround = true;
|
| 110 |
|
| 111 | @Unique
|
| 112 | private static boolean combatant$sameInput(Input a, Input b) {
|
| 113 | if (a == b) return true;
|
| 114 | if (a == null || b == null) return false;
|
| 115 |
|
| 116 | return a.forward() == b.forward()
|
| 117 | && a.backward() == b.backward()
|
| 118 | && a.left() == b.left()
|
| 119 | && a.right() == b.right()
|
| 120 | && a.jump() == b.jump()
|
| 121 | && a.shift() == b.shift()
|
| 122 | && a.sprint() == b.sprint();
|
| 123 | }
|
| 124 |
|
| 125 | @Unique
|
| 126 | private static float combatant$impulse(boolean positive, boolean negative) {
|
| 127 | if (positive == negative) {
|
| 128 | return 0.0f;
|
| 129 | }
|
| 130 | return positive ? 1.0f : -1.0f;
|
| 131 | }
|
| 132 |
|
| 133 | @Unique
|
| 134 | private static float combatant$simulateBodyYaw(
|
| 135 | float yaw,
|
| 136 | float prevBodyYaw,
|
| 137 | double prevX,
|
| 138 | double prevZ,
|
| 139 | double currentX,
|
| 140 | double currentZ,
|
| 141 | float handSwingProgress
|
| 142 | ) {
|
| 143 | double motionX = currentX - prevX;
|
| 144 | double motionZ = currentZ - prevZ;
|
| 145 | float motionSquared = (float) (motionX * motionX + motionZ * motionZ);
|
| 146 | float bodyYaw = prevBodyYaw;
|
| 147 |
|
| 148 | if (motionSquared > 0.0025000002F) {
|
| 149 | float movementYaw = (float) Mth.atan2(motionZ, motionX) * Mth.RAD_TO_DEG - 90.0F;
|
| 150 | float yawDiff = Math.abs(Mth.wrapDegrees(yaw) - movementYaw);
|
| 151 | bodyYaw = (yawDiff > 95.0F && yawDiff < 265.0F) ? movementYaw - 180.0F : movementYaw;
|
| 152 | }
|
| 153 |
|
| 154 | if (handSwingProgress - 0.2F > 0.0F) {
|
| 155 | bodyYaw = yaw;
|
| 156 | }
|
| 157 |
|
| 158 | float deltaYaw = Mth.wrapDegrees(bodyYaw - prevBodyYaw);
|
| 159 | bodyYaw = prevBodyYaw + deltaYaw * 0.3F;
|
| 160 |
|
| 161 | float yawOffsetDiff = Mth.wrapDegrees(yaw - bodyYaw);
|
| 162 | float maxHeadRotation = 52.0F;
|
| 163 | if (Math.abs(yawOffsetDiff) > maxHeadRotation) {
|
| 164 | bodyYaw += yawOffsetDiff - Math.signum(yawOffsetDiff) * maxHeadRotation;
|
| 165 | }
|
| 166 |
|
| 167 | return bodyYaw;
|
| 168 | }
|
| 169 |
|
| 170 | @Inject(method = "tick", at = @At("HEAD"))
|
| 171 | private void combatant$cacheLastRotations(CallbackInfo ci) {
|
| 172 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 173 | combatant$lastYaw = self.getYRot();
|
| 174 | combatant$lastPitch = self.getXRot();
|
| 175 | RotationManager.INSTANCE.runTickLifecycle();
|
| 176 | if (!combatant$rotationBodyYawInitialized) {
|
| 177 | combatant$rotationPrevX = self.getX();
|
| 178 | combatant$rotationPrevZ = self.getZ();
|
| 179 | combatant$rotationPrevBodyYaw = self.getVisualRotationYInDegrees();
|
| 180 | combatant$rotationBodyYawInitialized = true;
|
| 181 | }
|
| 182 | }
|
| 183 |
|
| 184 | @Inject(method = "handlePortalTransitionEffect", at = @At("HEAD"), cancellable = true)
|
| 185 | private void combatant$disablePortalNausea(boolean inPortal, CallbackInfo ci) {
|
| 186 | if (RuntimeGate.isPanic()) return;
|
| 187 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 188 | PortalProcessor portalManager = null;
|
| 189 | if (self instanceof EntityAccessor accessor) {
|
| 190 | portalManager = accessor.combatant$getPortalManager();
|
| 191 | }
|
| 192 | if (portalManager != null && portalManager.isInsidePortalThisTick()) {
|
| 193 | if (self instanceof LocalPlayerAccessor accessor) {
|
| 194 | accessor.combatant$setNauseaIntensity(0.0f);
|
| 195 | accessor.combatant$setLastNauseaIntensity(0.0f);
|
| 196 | }
|
| 197 | ci.cancel();
|
| 198 | }
|
| 199 | }
|
| 200 |
|
| 201 | @Override
|
| 202 | public float combatant$getLastYaw() {
|
| 203 | return combatant$lastYaw;
|
| 204 | }
|
| 205 |
|
| 206 | @Override
|
| 207 | public float combatant$getLastPitch() {
|
| 208 | return combatant$lastPitch;
|
| 209 | }
|
| 210 |
|
| 211 | @Override
|
| 212 | public void combatant$setLastYaw(float yaw) {
|
| 213 | this.combatant$lastYaw = yaw;
|
| 214 | }
|
| 215 |
|
| 216 | @Override
|
| 217 | public void combatant$setLastPitch(float pitch) {
|
| 218 | this.combatant$lastPitch = pitch;
|
| 219 | }
|
| 220 |
|
| 221 | @ModifyExpressionValue(
|
| 222 | method = "aiStep",
|
| 223 | at = @At(
|
| 224 | value = "INVOKE",
|
| 225 | target = "Lnet/minecraft/client/player/LocalPlayer;canStartSprinting()Z"
|
| 226 | )
|
| 227 | )
|
| 228 | private boolean combatant$sprintMovementStart(boolean original) {
|
| 229 | return combatant$postSprintControl(original, SprintControlEvent.Source.MOVEMENT_TICK);
|
| 230 | }
|
| 231 |
|
| 232 | @ModifyExpressionValue(
|
| 233 | method = "aiStep",
|
| 234 | at = @At(
|
| 235 | value = "INVOKE",
|
| 236 | target = "Lnet/minecraft/world/entity/player/Input;sprint()Z"
|
| 237 | )
|
| 238 | )
|
| 239 | private boolean combatant$sprintMovementInput(boolean original) {
|
| 240 | return combatant$postSprintControl(original, SprintControlEvent.Source.MOVEMENT_TICK);
|
| 241 | }
|
| 242 |
|
| 243 | @ModifyExpressionValue(
|
| 244 | method = "sendIsSprintingIfNeeded",
|
| 245 | at = @At(
|
| 246 | value = "INVOKE",
|
| 247 | target = "Lnet/minecraft/client/player/LocalPlayer;isSprinting()Z"
|
| 248 | )
|
| 249 | )
|
| 250 | private boolean combatant$sprintNetwork(boolean original) {
|
| 251 | if (SprintController.INSTANCE.isSprintBlocked()) {
|
| 252 | return false;
|
| 253 | }
|
| 254 |
|
| 255 | return original;
|
| 256 | }
|
| 257 |
|
| 258 | @Unique
|
| 259 | private boolean combatant$postSprintControl(boolean original, SprintControlEvent.Source source) {
|
| 260 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 261 |
|
| 262 | if (self.input == null) {
|
| 263 | return original;
|
| 264 | }
|
| 265 |
|
| 266 | if (!Events.BUS.hasListeners(SprintControlEvent.class)) {
|
| 267 | return original;
|
| 268 | }
|
| 269 |
|
| 270 | Vec2 movement = self.input.getMoveVector();
|
| 271 | SprintControlEvent event = new SprintControlEvent(
|
| 272 | movement.y,
|
| 273 | movement.x,
|
| 274 | original,
|
| 275 | source
|
| 276 | );
|
| 277 | Events.BUS.post(event);
|
| 278 | return event.shouldSprint();
|
| 279 | }
|
| 280 |
|
| 281 | @Inject(method = "modifyInput", at = @At("RETURN"), cancellable = true)
|
| 282 | private void boostWhenUsing(Vec2 input, CallbackInfoReturnable<Vec2> cir) {
|
| 283 | NoStun ns = Modules.get(NoStun.class);
|
| 284 | if (ns == null || !ns.isEnabled()) return;
|
| 285 | if (!ns.isFunctionEnabled(NoStun.fnUseSpeed())) return;
|
| 286 |
|
| 287 | LocalPlayer player = (LocalPlayer) (Object) this;
|
| 288 | if (player.isUsingItem() && !player.isPassenger()) {
|
| 289 | Vec2 base = cir.getReturnValue();
|
| 290 |
|
| 291 | // 0.0 -> vanilla (no change), 1.0 -> normal walking speed.
|
| 292 | // Vanilla item-use slowdown is typically ~0.2x; lerp 1..5 approximates reciprocal compensation.
|
| 293 | float t = ns.getEatSpeed01();
|
| 294 | float mult = 1.0f + t * 4.0f;
|
| 295 |
|
| 296 | if (mult > 1.001f) {
|
| 297 | cir.setReturnValue(base.scale(mult));
|
| 298 | }
|
| 299 | }
|
| 300 | }
|
| 301 |
|
| 302 | @Inject(method = "aiStep", at = @At("HEAD"))
|
| 303 | private void combatant$elytraFlyVanilla(CallbackInfo ci) {
|
| 304 | LocalPlayer player = (LocalPlayer) (Object) this;
|
| 305 | ElytraFly elytraFly = Modules.get(ElytraFly.class);
|
| 306 | if (elytraFly == null || !elytraFly.shouldApplyVanillaHook(player)) {
|
| 307 | return;
|
| 308 | }
|
| 309 |
|
| 310 | Vec3 velocity = player.getDeltaMovement();
|
| 311 | Vec3 look = player.getViewVector(1.0f);
|
| 312 | float pitch = player.getXRot();
|
| 313 |
|
| 314 | velocity = velocity.scale(elytraFly.getVanillaDragFactor());
|
| 315 | velocity = velocity.add(look.scale(elytraFly.getVanillaForwardBoostFactor()));
|
| 316 |
|
| 317 | double lift = -Math.sin(Math.toRadians(pitch)) * elytraFly.getVanillaPitchLiftFactor();
|
| 318 | player.setDeltaMovement(velocity.add(0.0, lift, 0.0));
|
| 319 | }
|
| 320 |
|
| 321 | @Shadow
|
| 322 | protected abstract void sendPosition();
|
| 323 |
|
| 324 | @Inject(method = "applyInput", at = @At("HEAD"), cancellable = true)
|
| 325 | private void freecam$blockWASD(CallbackInfo ci) {
|
| 326 | Freecam fc = Modules.get(Freecam.class);
|
| 327 | if (fc != null && fc.isEnabled() && fc.isCameraInput()) {
|
| 328 | ci.cancel();
|
| 329 | }
|
| 330 | }
|
| 331 |
|
| 332 | @Inject(
|
| 333 | method = "aiStep",
|
| 334 | at = @At(
|
| 335 | value = "INVOKE",
|
| 336 | target = "Lnet/minecraft/client/player/ClientInput;tick()V",
|
| 337 | shift = At.Shift.AFTER
|
| 338 | )
|
| 339 | )
|
| 340 | private void freecam$afterInputTick(CallbackInfo ci) {
|
| 341 | Freecam fc = Modules.get(Freecam.class);
|
| 342 | if (fc == null || !fc.isEnabled() || !fc.isCameraInput()) return;
|
| 343 |
|
| 344 | ((InputAccessor) this.input).setMovementVector(Vec2.ZERO);
|
| 345 |
|
| 346 | boolean sneak = false;
|
| 347 | boolean sprint = this.input.keyPresses.sprint();
|
| 348 |
|
| 349 | this.input.keyPresses = new Input(
|
| 350 | false, false, false, false,
|
| 351 | false,
|
| 352 | sneak,
|
| 353 | sprint
|
| 354 | );
|
| 355 | }
|
| 356 |
|
| 357 | @Inject(
|
| 358 | method = "aiStep",
|
| 359 | at = @At(
|
| 360 | value = "INVOKE",
|
| 361 | target = "Lnet/minecraft/client/player/ClientInput;tick()V",
|
| 362 | shift = At.Shift.AFTER
|
| 363 | )
|
| 364 | )
|
| 365 | private void combatant$afterInputTickSprint(CallbackInfo ci) {
|
| 366 | if (this.input == null) return;
|
| 367 |
|
| 368 | Input original = this.input.keyPresses;
|
| 369 | if (original == null) return;
|
| 370 |
|
| 371 | Input input = original;
|
| 372 |
|
| 373 | if (Events.BUS.hasListeners(MovementInputEvent.class)) {
|
| 374 | MovementInputEvent event = new MovementInputEvent(input);
|
| 375 | Events.BUS.post(event);
|
| 376 |
|
| 377 | Input eventInput = event.toPlayerInput();
|
| 378 | if (!combatant$sameInput(input, eventInput)) {
|
| 379 | input = eventInput;
|
| 380 | }
|
| 381 | }
|
| 382 |
|
| 383 | Input transformedInput = combatant$transformDirection(input);
|
| 384 | if (!combatant$sameInput(input, transformedInput)) {
|
| 385 | input = transformedInput;
|
| 386 | }
|
| 387 |
|
| 388 | if (Events.BUS.hasListeners(SprintControlEvent.class)) {
|
| 389 | float forward = combatant$impulse(input.forward(), input.backward());
|
| 390 | float sideways = combatant$impulse(input.left(), input.right());
|
| 391 |
|
| 392 | SprintControlEvent event = new SprintControlEvent(
|
| 393 | forward,
|
| 394 | sideways,
|
| 395 | input.sprint(),
|
| 396 | SprintControlEvent.Source.INPUT
|
| 397 | );
|
| 398 | Events.BUS.post(event);
|
| 399 |
|
| 400 | if (event.shouldSprint() != input.sprint()) {
|
| 401 | input = new Input(
|
| 402 | input.forward(),
|
| 403 | input.backward(),
|
| 404 | input.left(),
|
| 405 | input.right(),
|
| 406 | input.jump(),
|
| 407 | input.shift(),
|
| 408 | event.shouldSprint()
|
| 409 | );
|
| 410 | }
|
| 411 | }
|
| 412 |
|
| 413 | if (!combatant$sameInput(original, input)) {
|
| 414 | combatant$applyPlayerInput(input);
|
| 415 | }
|
| 416 | }
|
| 417 |
|
| 418 | @Unique
|
| 419 | private void combatant$applyPlayerInput(Input input) {
|
| 420 | if (this.input == null || input == null) {
|
| 421 | return;
|
| 422 | }
|
| 423 |
|
| 424 | InputAccessor accessor = (InputAccessor) this.input;
|
| 425 | accessor.setPlayerInput(input);
|
| 426 |
|
| 427 | float forward = combatant$impulse(input.forward(), input.backward());
|
| 428 | float sideways = combatant$impulse(input.left(), input.right());
|
| 429 |
|
| 430 | accessor.setMovementVector(new Vec2(sideways, forward).normalized());
|
| 431 | }
|
| 432 |
|
| 433 | @Unique
|
| 434 | private Input combatant$transformDirection(Input input) {
|
| 435 | // Post-input hook remains inert to avoid double-transforming movement input.
|
| 436 | return input;
|
| 437 | }
|
| 438 |
|
| 439 | @Redirect(
|
| 440 | method = "aiStep",
|
| 441 | at = @At(
|
| 442 | value = "INVOKE",
|
| 443 | target = "Lnet/minecraft/world/entity/player/Input;shift()Z",
|
| 444 | ordinal = 0
|
| 445 | )
|
| 446 | )
|
| 447 | private boolean freecam$noFlyDown0(Input in) {
|
| 448 | Freecam fc = Modules.get(Freecam.class);
|
| 449 | if (fc != null && fc.isEnabled() && fc.isCameraInput()) {
|
| 450 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 451 | if (self.getAbilities().flying) return false;
|
| 452 | }
|
| 453 | return in.shift();
|
| 454 | }
|
| 455 |
|
| 456 | @Redirect(
|
| 457 | method = "aiStep",
|
| 458 | at = @At(
|
| 459 | value = "INVOKE",
|
| 460 | target = "Lnet/minecraft/world/entity/player/Input;shift()Z",
|
| 461 | ordinal = 1
|
| 462 | ),
|
| 463 | require = 0
|
| 464 | )
|
| 465 | private boolean freecam$noFlyDown1(Input in) {
|
| 466 | Freecam fc = Modules.get(Freecam.class);
|
| 467 | if (fc != null && fc.isEnabled() && fc.isCameraInput()) {
|
| 468 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 469 | if (self.getAbilities().flying) return false;
|
| 470 | }
|
| 471 | return in.shift();
|
| 472 | }
|
| 473 |
|
| 474 | @Inject(method = "hurtTo", at = @At("HEAD"))
|
| 475 | private void freecam$onUpdateHealth(float newHealth, CallbackInfo ci) {
|
| 476 | Freecam fc = Modules.get(Freecam.class);
|
| 477 |
|
| 478 | if (fc == null || !fc.isEnabled() || !fc.disableOnDamage()) {
|
| 479 | freecam$lastHealth = newHealth;
|
| 480 | return;
|
| 481 | }
|
| 482 |
|
| 483 | if (!Float.isNaN(freecam$lastHealth) && newHealth < freecam$lastHealth) {
|
| 484 | fc.toggle();
|
| 485 | }
|
| 486 |
|
| 487 | freecam$lastHealth = newHealth;
|
| 488 | }
|
| 489 |
|
| 490 | @Unique
|
| 491 | private boolean shouldFreezeNow() {
|
| 492 | boolean freezeModule = Modules.enabled(Freeze.class);
|
| 493 | Freecam freecam = Modules.get(Freecam.class);
|
| 494 | boolean freecamFreeze = freecam != null && freecam.freezePlayer() && freecam.isCameraInput();
|
| 495 | return freezeModule || freecamFreeze;
|
| 496 | }
|
| 497 |
|
| 498 | @Inject(method = "sendPosition", at = @At("HEAD"), cancellable = true)
|
| 499 | private void combatant$eventSync(CallbackInfo ci) {
|
| 500 | if (!Events.BUS.hasListeners(EventSync.class)) return;
|
| 501 | combatant$eventPostAction = null;
|
| 502 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 503 | EventSync event = new EventSync(self.getYRot(), self.getXRot());
|
| 504 | Events.BUS.post(event);
|
| 505 | combatant$activeSyncEvent = event;
|
| 506 | combatant$eventPostAction = event.getPostAction();
|
| 507 | if (event.isCancelled()) {
|
| 508 | combatant$activeSyncEvent = null;
|
| 509 | combatant$eventPostAction = null;
|
| 510 | ci.cancel();
|
| 511 | }
|
| 512 | }
|
| 513 |
|
| 514 | @Inject(method = "sendPosition", at = @At("RETURN"))
|
| 515 | private void combatant$eventPostSync(CallbackInfo ci) {
|
| 516 | if (Events.BUS.hasListeners(EventPostSync.class)) {
|
| 517 | Events.BUS.post(new EventPostSync());
|
| 518 | }
|
| 519 | if (combatant$eventPostAction != null) {
|
| 520 | combatant$eventPostAction.run();
|
| 521 | combatant$eventPostAction = null;
|
| 522 | }
|
| 523 | combatant$activeSyncEvent = null;
|
| 524 | }
|
| 525 |
|
| 526 | @ModifyExpressionValue(
|
| 527 | method = "sendPosition",
|
| 528 | at = @At(
|
| 529 | value = "INVOKE",
|
| 530 | target = "Lnet/minecraft/client/player/LocalPlayer;getYRot()F"
|
| 531 | )
|
| 532 | )
|
| 533 | private float combatant$eventSyncYaw(float original) {
|
| 534 | combatant$updateVisualBodyYaw();
|
| 535 |
|
| 536 | EventSync event = combatant$activeSyncEvent;
|
| 537 | if (event != null && event.hasRotationOverride()) return event.getYaw();
|
| 538 |
|
| 539 | Rotation rotation = RotationManager.INSTANCE.getCurrentRotation();
|
| 540 | return rotation != null ? rotation.yaw() : original;
|
| 541 | }
|
| 542 |
|
| 543 | @ModifyExpressionValue(
|
| 544 | method = "sendPosition",
|
| 545 | at = @At(
|
| 546 | value = "INVOKE",
|
| 547 | target = "Lnet/minecraft/client/player/LocalPlayer;getXRot()F"
|
| 548 | )
|
| 549 | )
|
| 550 | private float combatant$eventSyncPitch(float original) {
|
| 551 | EventSync event = combatant$activeSyncEvent;
|
| 552 | if (event != null && event.hasRotationOverride()) return Mth.clamp(event.getPitch(), -90.0f, 90.0f);
|
| 553 |
|
| 554 | Rotation rotation = RotationManager.INSTANCE.getCurrentRotation();
|
| 555 | return rotation != null ? Mth.clamp(rotation.pitch(), -90.0f, 90.0f) : original;
|
| 556 | }
|
| 557 |
|
| 558 | @ModifyExpressionValue(
|
| 559 | method = "tick",
|
| 560 | at = @At(
|
| 561 | value = "INVOKE",
|
| 562 | target = "Lnet/minecraft/client/player/LocalPlayer;getYRot()F"
|
| 563 | )
|
| 564 | )
|
| 565 | private float combatant$visualTickYaw(float original) {
|
| 566 | combatant$updateVisualBodyYaw();
|
| 567 |
|
| 568 | Rotation rotation = RotationManager.INSTANCE.getCurrentRotation();
|
| 569 | return rotation != null ? rotation.yaw() : original;
|
| 570 | }
|
| 571 |
|
| 572 | @ModifyExpressionValue(
|
| 573 | method = "tick",
|
| 574 | at = @At(
|
| 575 | value = "INVOKE",
|
| 576 | target = "Lnet/minecraft/client/player/LocalPlayer;getXRot()F"
|
| 577 | )
|
| 578 | )
|
| 579 | private float combatant$visualTickPitch(float original) {
|
| 580 | Rotation rotation = RotationManager.INSTANCE.getCurrentRotation();
|
| 581 | return rotation != null ? Mth.clamp(rotation.pitch(), -90.0f, 90.0f) : original;
|
| 582 | }
|
| 583 |
|
| 584 | @Inject(
|
| 585 | method = "tick",
|
| 586 | at = @At(
|
| 587 | value = "INVOKE",
|
| 588 | target = "Lnet/minecraft/client/player/LocalPlayer;sendPosition()V",
|
| 589 | ordinal = 0,
|
| 590 | shift = At.Shift.AFTER
|
| 591 | ),
|
| 592 | cancellable = true
|
| 593 | )
|
| 594 | private void combatant$postPlayerUpdate(CallbackInfo ci) {
|
| 595 | if (!Events.BUS.hasListeners(PostPlayerUpdateEvent.class)) return;
|
| 596 | if (combatant$postUpdateLock) return;
|
| 597 |
|
| 598 | PostPlayerUpdateEvent event = new PostPlayerUpdateEvent();
|
| 599 | Events.BUS.post(event);
|
| 600 |
|
| 601 | if (!event.isCancelled()) return;
|
| 602 |
|
| 603 | ci.cancel();
|
| 604 |
|
| 605 | int iterations = event.getIterations();
|
| 606 | if (iterations <= 0) return;
|
| 607 |
|
| 608 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 609 | for (int i = 0; i < iterations; i++) {
|
| 610 | combatant$postUpdateLock = true;
|
| 611 | self.tick();
|
| 612 | combatant$postUpdateLock = false;
|
| 613 | sendPosition();
|
| 614 | }
|
| 615 | }
|
| 616 |
|
| 617 | @Inject(method = "sendPosition", at = @At("HEAD"), cancellable = true)
|
| 618 | private void cancelPackets(CallbackInfo ci) {
|
| 619 | if (Modules.enabled(Freeze.class)) {
|
| 620 | ci.cancel();
|
| 621 | }
|
| 622 | }
|
| 623 |
|
| 624 | @Inject(method = "aiStep", at = @At("HEAD"), cancellable = true)
|
| 625 | private void combatant$freezeTickMovement(CallbackInfo ci) {
|
| 626 | LocalPlayer p = (LocalPlayer) (Object) this;
|
| 627 |
|
| 628 | if (!shouldFreezeNow()) {
|
| 629 | if (frozen) {
|
| 630 | p.setDeltaMovement(savedVelocity);
|
| 631 | frozen = false;
|
| 632 | }
|
| 633 | return;
|
| 634 | }
|
| 635 |
|
| 636 | if (!frozen) {
|
| 637 | frozen = true;
|
| 638 | savedX = p.getX();
|
| 639 | savedY = p.getY();
|
| 640 | savedZ = p.getZ();
|
| 641 | savedVelocity = p.getDeltaMovement();
|
| 642 |
|
| 643 | if (Modules.get(Freecam.class) == null || !Modules.get(Freecam.class).isEnabled()) {
|
| 644 | savedBodyYaw = p.yBodyRot;
|
| 645 | savedHeadYaw = p.yHeadRot;
|
| 646 | }
|
| 647 | }
|
| 648 |
|
| 649 | p.setDeltaMovement(Vec3.ZERO);
|
| 650 | p.absSnapTo(savedX, savedY, savedZ);
|
| 651 |
|
| 652 | if (Modules.get(Freecam.class) == null || !Modules.get(Freecam.class).isEnabled()) {
|
| 653 | p.yBodyRot = savedBodyYaw;
|
| 654 | p.yHeadRot = savedHeadYaw;
|
| 655 | }
|
| 656 |
|
| 657 | ci.cancel();
|
| 658 | }
|
| 659 |
|
| 660 | @Inject(method = "aiStep", at = @At("HEAD"))
|
| 661 | private void combatant$noStunTickMovement(CallbackInfo ci) {
|
| 662 | NoStun ns = Modules.get(NoStun.class);
|
| 663 | if (ns == null || !ns.isEnabled()) return;
|
| 664 |
|
| 665 | Freecam fc = Modules.get(Freecam.class);
|
| 666 | if (fc != null && fc.isEnabled() && fc.isCameraInput()) {
|
| 667 | return;
|
| 668 | }
|
| 669 |
|
| 670 | LocalPlayer player = (LocalPlayer) (Object) this;
|
| 671 | if (ns.isFunctionEnabled(NoStun.fnNoHurtStun())) {
|
| 672 | if (player.hurtTime == 0) {
|
| 673 | lastInput = player.input.keyPresses;
|
| 674 | } else if (lastInput != null) {
|
| 675 | player.input.keyPresses = lastInput;
|
| 676 | }
|
| 677 | }
|
| 678 |
|
| 679 | }
|
| 680 |
|
| 681 | @Unique
|
| 682 | private void combatant$updateVisualBodyYaw() {
|
| 683 | LocalPlayer self = (LocalPlayer) (Object) this;
|
| 684 | Rotation rotation = RotationManager.INSTANCE.getCurrentRotation();
|
| 685 | if (rotation == null) {
|
| 686 | combatant$rotationPrevX = self.getX();
|
| 687 | combatant$rotationPrevZ = self.getZ();
|
| 688 | combatant$rotationPrevBodyYaw = self.getVisualRotationYInDegrees();
|
| 689 | return;
|
| 690 | }
|
| 691 |
|
| 692 | float newBodyYaw = combatant$simulateBodyYaw(
|
| 693 | rotation.yaw(),
|
| 694 | combatant$rotationPrevBodyYaw,
|
| 695 | combatant$rotationPrevX,
|
| 696 | combatant$rotationPrevZ,
|
| 697 | self.getX(),
|
| 698 | self.getZ(),
|
| 699 | self.attackAnim
|
| 700 | );
|
| 701 |
|
| 702 | self.setYBodyRot(newBodyYaw);
|
| 703 | combatant$rotationPrevBodyYaw = newBodyYaw;
|
| 704 | combatant$rotationPrevX = self.getX();
|
| 705 | combatant$rotationPrevZ = self.getZ();
|
| 706 | }
|
| 707 |
|
| 708 | @Inject(method = "tick", at = @At("HEAD"))
|
| 709 | private void detectPearlImpact(CallbackInfo ci) {
|
| 710 | NoPush noPush = Modules.get(NoPush.class);
|
| 711 | if (noPush == null || !noPush.off("pearl_phase"))
|
| 712 | return;
|
| 713 |
|
| 714 | LocalPlayer p = (LocalPlayer) (Object) this;
|
| 715 |
|
| 716 | List<ThrownEnderpearl> pearls = new ArrayList<>();
|
| 717 | p.level().getEntities(
|
| 718 | EntityTypeTest.forClass(ThrownEnderpearl.class),
|
| 719 | p.getBoundingBox().inflate(1.5),
|
| 720 | e -> true,
|
| 721 | pearls
|
| 722 | );
|
| 723 |
|
| 724 | // перл соприкасается → сейчас будет телепорт → готовим спуф
|
| 725 | if (!pearls.isEmpty()) {
|
| 726 | pendingSpoof = true;
|
| 727 | }
|
| 728 | }
|
| 729 |
|
| 730 | @Inject(method = "sendPosition", at = @At("HEAD"))
|
| 731 | private void sendSpoofAfterPearl(CallbackInfo ci) {
|
| 732 | NoPush noPush = Modules.get(NoPush.class);
|
| 733 | if (noPush == null || !noPush.off("pearl_phase"))
|
| 734 | return;
|
| 735 |
|
| 736 | if (!pendingSpoof) return;
|
| 737 | LocalPlayer p = (LocalPlayer) (Object) this;
|
| 738 | // Avoid spoof on ceiling-only collision; it can freeze upward movement.
|
| 739 | if (p.verticalCollision && !p.horizontalCollision) {
|
| 740 | pendingSpoof = false;
|
| 741 | return;
|
| 742 | }
|
| 743 | pendingSpoof = false;
|
| 744 |
|
| 745 | Vec3 pos = p.position();
|
| 746 |
|
| 747 | p.connection.send(new ServerboundMovePlayerPacket.Pos(
|
| 748 | pos.x,
|
| 749 | pos.y + 0.0313, // легитная фаза
|
| 750 | pos.z,
|
| 751 | p.onGround(),
|
| 752 | false // horizontalCollision
|
| 753 | ));
|
| 754 | }
|
| 755 |
|
| 756 | @Inject(method = "aiStep", at = @At("TAIL"))
|
| 757 | private void onCollideBoost(CallbackInfo ci) {
|
| 758 |
|
| 759 | Speed speed = Modules.get(Speed.class);
|
| 760 | if (speed == null || !speed.enabled("entity_boost"))
|
| 761 | return;
|
| 762 |
|
| 763 | LocalPlayer p = (LocalPlayer) (Object) this;
|
| 764 |
|
| 765 | if (boostTicks > 0) {
|
| 766 | boostTicks--;
|
| 767 |
|
| 768 | Vec3 vel = p.getDeltaMovement();
|
| 769 | double vx = vel.x + boostX;
|
| 770 | double vz = vel.z + boostZ;
|
| 771 |
|
| 772 | double max = 0.48;
|
| 773 | double h = Math.hypot(vx, vz);
|
| 774 | if (h > max) {
|
| 775 | double s = max / h;
|
| 776 | vx *= s;
|
| 777 | vz *= s;
|
| 778 | }
|
| 779 |
|
| 780 | p.setDeltaMovement(vx, vel.y, vz);
|
| 781 | return;
|
| 782 | }
|
| 783 |
|
| 784 | List<Entity> nearby = p.level().getEntities(p, p.getBoundingBox().inflate(0.15), e -> e instanceof LivingEntity);
|
| 785 | if (nearby.isEmpty()) return;
|
| 786 |
|
| 787 | Vec3 vel = p.getDeltaMovement();
|
| 788 | double dirX = vel.x;
|
| 789 | double dirZ = vel.z;
|
| 790 |
|
| 791 | if (dirX == 0 && dirZ == 0) return;
|
| 792 |
|
| 793 | double len = Math.sqrt(dirX * dirX + dirZ * dirZ);
|
| 794 | if (len < 1e-5) return;
|
| 795 |
|
| 796 | dirX /= len;
|
| 797 | dirZ /= len;
|
| 798 |
|
| 799 | double boost = speed.entityBoostStrength.get();
|
| 800 |
|
| 801 | boostX = (dirX * boost) / 3.0;
|
| 802 | boostZ = (dirZ * boost) / 3.0;
|
| 803 | boostTicks = 3;
|
| 804 | }
|
| 805 |
|
| 806 | @Inject(method = "aiStep", at = @At("TAIL"))
|
| 807 | private void omniLongJump(CallbackInfo ci) {
|
| 808 | Speed speed = Modules.get(Speed.class);
|
| 809 | if (speed == null || !speed.enabled("jump_boost")) return;
|
| 810 | LocalPlayer p = (LocalPlayer) (Object) this;
|
| 811 |
|
| 812 | boolean onGround = p.onGround();
|
| 813 |
|
| 814 | if (p.isFallFlying()) {
|
| 815 | wasGround = onGround;
|
| 816 | return;
|
| 817 | }
|
| 818 |
|
| 819 | if (wasGround && !onGround && p.isSprinting() && !p.isInWater()) {
|
| 820 |
|
| 821 | Vec2 move = p.input.getMoveVector();
|
| 822 | float mx = move.x;
|
| 823 | float mz = move.y;
|
| 824 |
|
| 825 | if (mx == 0 && mz == 0) {
|
| 826 | wasGround = onGround;
|
| 827 | return;
|
| 828 | }
|
| 829 |
|
| 830 | float norm = Mth.sqrt(mx * mx + mz * mz);
|
| 831 | mx /= norm;
|
| 832 | mz /= norm;
|
| 833 |
|
| 834 | float yaw = p.getYRot();
|
| 835 | float rad = (float) Math.toRadians(yaw);
|
| 836 |
|
| 837 | double dirX = mz * -Mth.sin(rad) + mx * Mth.cos(rad);
|
| 838 | double dirZ = mz * Mth.cos(rad) + mx * Mth.sin(rad);
|
| 839 |
|
| 840 | Vec3 vel = p.getDeltaMovement();
|
| 841 | double ui = speed.jumpAcceleration.get();
|
| 842 | double internal = ui * 0.832;
|
| 843 | double strength = 0.33 * internal;
|
| 844 |
|
| 845 | double vx = dirX * strength;
|
| 846 | double vz = dirZ * strength;
|
| 847 | double max = 0.42;
|
| 848 | double h = Math.hypot(vx, vz);
|
| 849 |
|
| 850 | if (h > max) {
|
| 851 | double scale = max / h;
|
| 852 | vx *= scale;
|
| 853 | vz *= scale;
|
| 854 | }
|
| 855 |
|
| 856 | p.setDeltaMovement(vx, vel.y, vz);
|
| 857 | }
|
| 858 |
|
| 859 | wasGround = onGround;
|
| 860 | }
|
| 861 |
|
| 862 | @Inject(method = "modifyInput", at = @At("RETURN"), cancellable = true)
|
| 863 | private void applyLegitSpeed(Vec2 input, CallbackInfoReturnable<Vec2> cir) {
|
| 864 | Speed speed = Modules.get(Speed.class);
|
| 865 | if (speed == null || !speed.isEnabled()) return;
|
| 866 | if (!speed.enabled("legit_speed")) return;
|
| 867 | Vec2 base = cir.getReturnValue();
|
| 868 | float mult = speed.legitMultiplier.get();
|
| 869 | cir.setReturnValue(base.scale(mult));
|
| 870 | }
|
| 871 |
|
| 872 | @Inject(method = "closeContainer", at = @At("HEAD"), cancellable = true)
|
| 873 | private void combatant$inventoryMove$deferCloseHandledScreen(CallbackInfo ci) {
|
| 874 | InventoryMove module = Modules.get(InventoryMove.class);
|
| 875 | if (module == null || !module.isEnabled()) return;
|
| 876 | if (module.shouldCancelCloseHandledScreen()) {
|
| 877 | ci.cancel();
|
| 878 | }
|
| 879 | }
|
| 880 |
|
| 881 | @Inject(method = "closeContainer", at = @At("HEAD"), cancellable = true)
|
| 882 | private void combatant$keepInventoryOpen(CallbackInfo ci) {
|
| 883 | if (!Modules.enabled(XCarry.class)) return;
|
| 884 |
|
| 885 | // Cancel only when closing own inventory screen (PlayerScreenHandler) to retain crafting/cursor items
|
| 886 | var screen = ClientScreen.current(net.minecraft.client.Minecraft.getInstance());
|
| 887 | if (screen instanceof net.minecraft.client.gui.screens.inventory.AbstractContainerScreen<?> handled
|
| 888 | && handled.getMenu() instanceof InventoryMenu) {
|
| 889 | ((LocalPlayer) (Object) this).clientSideCloseContainer(); // client-side close without sending packet
|
| 890 | ci.cancel(); // skip packet CloseHandledScreen
|
| 891 | }
|
| 892 | }
|
| 893 |
|
| 894 | @Inject(method = "moveTowardsClosestSpace", at = @At("HEAD"), cancellable = true)
|
| 895 | private void combatant$noPushOutOfBlocks(double x, double z, CallbackInfo ci) {
|
| 896 | if (!Events.BUS.hasListeners(EventPushOutOfBlocks.class)) return;
|
| 897 | EventPushOutOfBlocks event = new EventPushOutOfBlocks(x, z);
|
| 898 | Events.BUS.post(event);
|
| 899 | if (event.isCancelled()) {
|
| 900 | ci.cancel();
|
| 901 | }
|
| 902 | }
|
| 903 | }
|
| 904 |
|