| 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 jump rotation correction are adapted from LiquidBounce
|
| 18 | * (https://github.com/CCBlueX/LiquidBounce).
|
| 19 | * Original copyright (c) CCBlueX.
|
| 20 | */
|
| 21 |
|
| 22 | import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
| 23 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 24 | import net.minecraft.client.Minecraft;
|
| 25 | import net.minecraft.client.player.LocalPlayer;
|
| 26 | import net.minecraft.core.BlockPos;
|
| 27 | import net.minecraft.core.Holder;
|
| 28 | import net.minecraft.util.Mth;
|
| 29 | import net.minecraft.world.damagesource.DamageSource;
|
| 30 | import net.minecraft.world.effect.MobEffect;
|
| 31 | import net.minecraft.world.effect.MobEffectInstance;
|
| 32 | import net.minecraft.world.effect.MobEffects;
|
| 33 | import net.minecraft.world.entity.LivingEntity;
|
| 34 | import net.minecraft.world.entity.ai.attributes.Attribute;
|
| 35 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 36 | import net.minecraft.world.entity.player.Player;
|
| 37 | import net.minecraft.world.item.Item;
|
| 38 | import net.minecraft.world.item.ItemStack;
|
| 39 | import net.minecraft.world.level.Level;
|
| 40 | import net.minecraft.world.level.block.Blocks;
|
| 41 | import net.minecraft.world.level.block.state.BlockState;
|
| 42 | import net.minecraft.world.phys.AABB;
|
| 43 | import net.minecraft.world.phys.Vec3;
|
| 44 | import org.spongepowered.asm.mixin.Mixin;
|
| 45 | import org.spongepowered.asm.mixin.Shadow;
|
| 46 | import org.spongepowered.asm.mixin.Unique;
|
| 47 | import org.spongepowered.asm.mixin.injection.At;
|
| 48 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 49 | import org.spongepowered.asm.mixin.injection.Redirect;
|
| 50 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 51 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 52 | import combatant.client.config.values.ItemCooldownRulesValue;
|
| 53 | import combatant.client.events.Events;
|
| 54 | import combatant.client.events.impl.PlayerJumpEvent;
|
| 55 | import combatant.client.features.module.Modules;
|
| 56 | import combatant.client.features.module.modules.combat.PvpCooldowns;
|
| 57 | import combatant.client.features.module.modules.combat.TPSSync;
|
| 58 | import combatant.client.features.module.modules.movement.ElytraFly;
|
| 59 | import combatant.client.features.module.modules.movement.NoStun;
|
| 60 | import combatant.client.features.module.modules.movement.Timer;
|
| 61 | import combatant.client.features.module.modules.visuals.NoRender;
|
| 62 | import combatant.client.features.module.modules.visuals.WorldTweaks;
|
| 63 | import combatant.client.util.aiming.RotationManager;
|
| 64 | import combatant.client.util.aiming.data.Rotation;
|
| 65 | import combatant.client.util.aiming.features.MovementCorrection;
|
| 66 | import combatant.client.util.player.inventory.InventorySwap;
|
| 67 | import combatant.client.util.pvp.client.CooldownsState;
|
| 68 | import combatant.client.util.pvp.opponents.TotemPopCounter;
|
| 69 |
|
| 70 | @Mixin(LivingEntity.class)
|
| 71 | public abstract class LivingEntityMixin {
|
| 72 |
|
| 73 | @Unique
|
| 74 | private float combatant$itemUseRemainder = 0f;
|
| 75 |
|
| 76 | @Unique
|
| 77 | private float combatant$effectTickRemainder = 0f;
|
| 78 |
|
| 79 | @Shadow
|
| 80 | protected int useItemRemaining;
|
| 81 | @Unique
|
| 82 | private PlayerJumpEvent combatant$playerJumpEvent;
|
| 83 |
|
| 84 | @Shadow
|
| 85 | protected abstract float getJumpPower();
|
| 86 |
|
| 87 | @Inject(method = "getAttributeValue", at = @At("RETURN"))
|
| 88 | private void combatant$noStunSlownessMovementSpeed(Holder<Attribute> attribute, CallbackInfoReturnable<Double> cir) {
|
| 89 | if (!attribute.equals(Attributes.MOVEMENT_SPEED)) return;
|
| 90 | return;
|
| 91 |
|
| 92 | }
|
| 93 |
|
| 94 | @ModifyReturnValue(method = "getMainHandItem", at = @At("RETURN"))
|
| 95 | private ItemStack combatant$applyInventorySwapLeaseForMainHand(ItemStack original) {
|
| 96 | Minecraft mc = Minecraft.getInstance();
|
| 97 | if ((Object) this == mc.player) {
|
| 98 | InventorySwap.INSTANCE.isHotbarLeased();
|
| 99 | }
|
| 100 |
|
| 101 | return original;
|
| 102 | }
|
| 103 |
|
| 104 |
|
| 105 | /**
|
| 106 | * Optional local cooldown synthesis for servers that lock consumables without sending vanilla cooldown packets.
|
| 107 | * This never cancels item use; it only starts a visible local timer when explicitly configured.
|
| 108 | */
|
| 109 | @Inject(method = "updatingUsingItem", at = @At("HEAD"))
|
| 110 | private void combatant$onFinishEating(CallbackInfo ci) {
|
| 111 | LivingEntity self = (LivingEntity) (Object) this;
|
| 112 | Minecraft mc = Minecraft.getInstance();
|
| 113 | if (self != mc.player) return;
|
| 114 |
|
| 115 | ItemStack stack = self.getUseItem();
|
| 116 | if (stack == null || stack.isEmpty()) return;
|
| 117 | if (self.getUseItemRemainingTicks() != 1) return;
|
| 118 |
|
| 119 | PvpCooldowns cooldowns = Modules.get(PvpCooldowns.class);
|
| 120 | if (cooldowns == null) return;
|
| 121 |
|
| 122 | Item item = stack.getItem();
|
| 123 | cooldowns.tryStartLocalCooldown(item, ItemCooldownRulesValue.Trigger.CONSUME_FINISH);
|
| 124 | }
|
| 125 |
|
| 126 | @Inject(method = "updatingUsingItem", at = @At("HEAD"), cancellable = true)
|
| 127 | private void combatant$fixItemUseSpeed(CallbackInfo ci) {
|
| 128 | LivingEntity self = (LivingEntity) (Object) this;
|
| 129 | if (!(self instanceof Player player)) {
|
| 130 | combatant$itemUseRemainder = 0f;
|
| 131 | return;
|
| 132 | }
|
| 133 |
|
| 134 | if (!player.level().isClientSide()) return;
|
| 135 | if (!player.isUsingItem()) {
|
| 136 | combatant$itemUseRemainder = 0f;
|
| 137 | return;
|
| 138 | }
|
| 139 |
|
| 140 | float scale = combatant$clientTickScale();
|
| 141 | if (scale >= 0.999f) {
|
| 142 | combatant$itemUseRemainder = 0f;
|
| 143 | return;
|
| 144 | }
|
| 145 |
|
| 146 | combatant$itemUseRemainder += scale;
|
| 147 | if (combatant$itemUseRemainder < 1.0f) {
|
| 148 | ci.cancel();
|
| 149 | return;
|
| 150 | }
|
| 151 |
|
| 152 | combatant$itemUseRemainder -= 1.0f;
|
| 153 | }
|
| 154 |
|
| 155 | @Redirect(
|
| 156 | method = "tickEffects",
|
| 157 | at = @At(
|
| 158 | value = "INVOKE",
|
| 159 | target = "Lnet/minecraft/world/effect/MobEffectInstance;tickClient()V"
|
| 160 | )
|
| 161 | )
|
| 162 | private void combatant$scaleClientEffects(MobEffectInstance instance) {
|
| 163 | LivingEntity self = (LivingEntity) (Object) this;
|
| 164 | if (!self.level().isClientSide()) {
|
| 165 | instance.tickClient();
|
| 166 | return;
|
| 167 | }
|
| 168 |
|
| 169 | Minecraft mc = Minecraft.getInstance();
|
| 170 | if (!(self instanceof Player player) || mc == null || player != mc.player) {
|
| 171 | instance.tickClient();
|
| 172 | return;
|
| 173 | }
|
| 174 |
|
| 175 | float scale = combatant$clientTickScale();
|
| 176 | if (scale >= 0.999f) {
|
| 177 | combatant$effectTickRemainder = 0f;
|
| 178 | instance.tickClient();
|
| 179 | return;
|
| 180 | }
|
| 181 |
|
| 182 | combatant$effectTickRemainder += scale;
|
| 183 | if (combatant$effectTickRemainder < 1.0f) {
|
| 184 | return;
|
| 185 | }
|
| 186 | combatant$effectTickRemainder -= 1.0f;
|
| 187 | instance.tickClient();
|
| 188 | }
|
| 189 |
|
| 190 | @Unique
|
| 191 | private float combatant$clientTickScale() {
|
| 192 | float mult = Timer.getTickTimer();
|
| 193 | if (mult <= 0.0001f) return 1.0f;
|
| 194 |
|
| 195 | float serverDelta = 1.0f;
|
| 196 | TPSSync tps = Modules.get(TPSSync.class);
|
| 197 | if (tps != null && tps.isEnabled()) {
|
| 198 | serverDelta = tps.getServerTickDelta();
|
| 199 | }
|
| 200 |
|
| 201 | float scale = serverDelta / mult;
|
| 202 | if (scale > 1.0f) return 1.0f;
|
| 203 | return Math.max(scale, 0.0f);
|
| 204 | }
|
| 205 |
|
| 206 | /**
|
| 207 | * Local totem cooldowns are handled from the confirmed entity-status packet when explicitly configured.
|
| 208 | */
|
| 209 | @Inject(method = "checkTotemDeathProtection", at = @At("RETURN"))
|
| 210 | private void combatant$onTotemUse(DamageSource source, CallbackInfoReturnable<Boolean> cir) {
|
| 211 | // no local use blocking or prediction here
|
| 212 | }
|
| 213 |
|
| 214 | /**
|
| 215 | * Сброс кулдаунов при смерти.
|
| 216 | */
|
| 217 | @Inject(method = "die", at = @At("HEAD"))
|
| 218 | private void combatant$onDeath(DamageSource source, CallbackInfo ci) {
|
| 219 | LivingEntity self = (LivingEntity) (Object) this;
|
| 220 | if (self instanceof Player player) {
|
| 221 | TotemPopCounter.onPlayerDeath(player.getUUID());
|
| 222 | }
|
| 223 |
|
| 224 | PvpCooldowns cooldowns = Modules.get(PvpCooldowns.class);
|
| 225 | if (cooldowns == null || cooldowns.isSystemEnabled()) {
|
| 226 | CooldownsState.MANAGER.clear();
|
| 227 | }
|
| 228 | }
|
| 229 |
|
| 230 | @Inject(
|
| 231 | method = "getBlockSpeedFactor",
|
| 232 | at = @At("HEAD"),
|
| 233 | cancellable = true
|
| 234 | )
|
| 235 | private void weathercontrol$dontDampRiptide(CallbackInfoReturnable<Float> cir) {
|
| 236 | LivingEntity self = (LivingEntity) (Object) this;
|
| 237 |
|
| 238 | if (!(self instanceof Player player)) return;
|
| 239 | if (!player.isAutoSpinAttack()) return;
|
| 240 |
|
| 241 | Level world = player.level();
|
| 242 | if (world == null) return;
|
| 243 |
|
| 244 | if (WorldTweaks.isServerRaining(world)) {
|
| 245 | cir.setReturnValue(1.0F);
|
| 246 | }
|
| 247 | }
|
| 248 |
|
| 249 | @Inject(method = "aiStep", at = @At("HEAD"))
|
| 250 | private void preventCrash(CallbackInfo ci) {
|
| 251 | LivingEntity self = (LivingEntity) (Object) this;
|
| 252 |
|
| 253 | if (!(self instanceof Player p)) return;
|
| 254 | ElytraFly elytraFly = Modules.get(ElytraFly.class);
|
| 255 | if (elytraFly == null || !elytraFly.isEnabled()) return;
|
| 256 | if (!elytraFly.noCrash.get()) return;
|
| 257 | if (!p.isFallFlying()) return;
|
| 258 |
|
| 259 | Vec3 vel = p.getDeltaMovement();
|
| 260 |
|
| 261 | if (vel.horizontalDistance() < 1) return;
|
| 262 | AABB next = p.getBoundingBox().move(vel);
|
| 263 |
|
| 264 | if (!p.level().noCollision(next)) {
|
| 265 | p.setDeltaMovement(0, 0, 0);
|
| 266 | }
|
| 267 | }
|
| 268 |
|
| 269 | @ModifyExpressionValue(
|
| 270 | method = "updateFallFlyingMovement",
|
| 271 | at = @At(
|
| 272 | value = "INVOKE",
|
| 273 | target = "Lnet/minecraft/world/entity/LivingEntity;getLookAngle()Lnet/minecraft/world/phys/Vec3;"
|
| 274 | )
|
| 275 | )
|
| 276 | private Vec3 combatant$modifyGlidingRotationVector(Vec3 original) {
|
| 277 | LivingEntity self = (LivingEntity) (Object) this;
|
| 278 | Minecraft mc = Minecraft.getInstance();
|
| 279 | if (!(self instanceof LocalPlayer player) || mc == null || player != mc.player) {
|
| 280 | return original;
|
| 281 | }
|
| 282 |
|
| 283 | Rotation rotation = RotationManager.INSTANCE.getMovementRotation();
|
| 284 | var rotationTarget = RotationManager.INSTANCE.getActiveRotationTarget();
|
| 285 | if (rotationTarget == null
|
| 286 | || rotationTarget.movementCorrection == MovementCorrection.OFF
|
| 287 | || rotationTarget.movementCorrection == MovementCorrection.STRICT) {
|
| 288 | return original;
|
| 289 | }
|
| 290 |
|
| 291 | return rotation.directionVector();
|
| 292 | }
|
| 293 |
|
| 294 | @ModifyExpressionValue(
|
| 295 | method = "updateFallFlyingMovement",
|
| 296 | at = @At(
|
| 297 | value = "INVOKE",
|
| 298 | target = "Lnet/minecraft/world/entity/LivingEntity;getXRot()F"
|
| 299 | )
|
| 300 | )
|
| 301 | private float combatant$modifyGlidingPitch(float original) {
|
| 302 | LivingEntity self = (LivingEntity) (Object) this;
|
| 303 | Minecraft mc = Minecraft.getInstance();
|
| 304 | if (!(self instanceof LocalPlayer player) || mc == null || player != mc.player) {
|
| 305 | return original;
|
| 306 | }
|
| 307 |
|
| 308 | Rotation rotation = RotationManager.INSTANCE.getMovementRotation();
|
| 309 | var rotationTarget = RotationManager.INSTANCE.getActiveRotationTarget();
|
| 310 | if (rotationTarget == null || rotationTarget.movementCorrection == MovementCorrection.OFF) {
|
| 311 | return original;
|
| 312 | }
|
| 313 |
|
| 314 | return rotation.pitch();
|
| 315 | }
|
| 316 |
|
| 317 | @Inject(method = "hasEffect", at = @At("HEAD"), cancellable = true)
|
| 318 | private void killHasEffect(Holder<MobEffect> effect,
|
| 319 | CallbackInfoReturnable<Boolean> cir) {
|
| 320 | NoRender noRender = Modules.get(NoRender.class);
|
| 321 | if (noRender == null || !noRender.off("bad_effects")) return;
|
| 322 |
|
| 323 | if (isBad(effect)) {
|
| 324 | cir.setReturnValue(false);
|
| 325 | }
|
| 326 | }
|
| 327 |
|
| 328 | @Inject(method = "getEffect", at = @At("HEAD"), cancellable = true)
|
| 329 | private void killGetEffect(Holder<MobEffect> effect,
|
| 330 | CallbackInfoReturnable<MobEffectInstance> cir) {
|
| 331 | NoRender noRender = Modules.get(NoRender.class);
|
| 332 | if (noRender == null || !noRender.off("bad_effects")) return;
|
| 333 |
|
| 334 | if (isBad(effect)) {
|
| 335 | cir.setReturnValue(null);
|
| 336 | }
|
| 337 | }
|
| 338 |
|
| 339 | @Inject(method = "jumpFromGround", at = @At("HEAD"), cancellable = true)
|
| 340 | private void combatant$onJumpHead(CallbackInfo ci) {
|
| 341 | LivingEntity self = (LivingEntity) (Object) this;
|
| 342 | if (!(self instanceof LocalPlayer player)) {
|
| 343 | combatant$playerJumpEvent = null;
|
| 344 | return;
|
| 345 | }
|
| 346 |
|
| 347 | Minecraft mc = Minecraft.getInstance();
|
| 348 | if (mc == null || player != mc.player) {
|
| 349 | combatant$playerJumpEvent = null;
|
| 350 | return;
|
| 351 | }
|
| 352 |
|
| 353 | PlayerJumpEvent event = new PlayerJumpEvent(self.getYRot(), getJumpPower());
|
| 354 | Events.BUS.post(event);
|
| 355 | if (event.isCancelled()) {
|
| 356 | combatant$playerJumpEvent = null;
|
| 357 | ci.cancel();
|
| 358 | return;
|
| 359 | }
|
| 360 |
|
| 361 | combatant$playerJumpEvent = event;
|
| 362 | }
|
| 363 |
|
| 364 | @ModifyExpressionValue(
|
| 365 | method = "jumpFromGround",
|
| 366 | at = @At(
|
| 367 | value = "INVOKE",
|
| 368 | target = "Lnet/minecraft/world/entity/LivingEntity;getJumpPower()F"
|
| 369 | )
|
| 370 | )
|
| 371 | private float combatant$modifyJumpMotion(float original) {
|
| 372 | return combatant$playerJumpEvent != null ? combatant$playerJumpEvent.getMotion() : original;
|
| 373 | }
|
| 374 |
|
| 375 | @ModifyExpressionValue(
|
| 376 | method = "jumpFromGround",
|
| 377 | at = @At(
|
| 378 | value = "NEW",
|
| 379 | target = "(DDD)Lnet/minecraft/world/phys/Vec3;"
|
| 380 | )
|
| 381 | )
|
| 382 | private Vec3 combatant$fixJumpRotation(Vec3 original) {
|
| 383 | LivingEntity self = (LivingEntity) (Object) this;
|
| 384 | Minecraft mc = Minecraft.getInstance();
|
| 385 | if (!(self instanceof LocalPlayer player) || mc == null || player != mc.player) {
|
| 386 | return original;
|
| 387 | }
|
| 388 |
|
| 389 | Rotation rotation = RotationManager.INSTANCE.getMovementRotation();
|
| 390 | var rotationTarget = RotationManager.INSTANCE.getActiveRotationTarget();
|
| 391 | if (rotationTarget == null || rotationTarget.movementCorrection == MovementCorrection.OFF) {
|
| 392 | return original;
|
| 393 | }
|
| 394 |
|
| 395 | float yaw = rotation.yaw() * Mth.DEG_TO_RAD;
|
| 396 | return new Vec3(-Mth.sin(yaw) * 0.2F, 0.0, Mth.cos(yaw) * 0.2F);
|
| 397 | }
|
| 398 |
|
| 399 | @Redirect(
|
| 400 | method = "jumpFromGround",
|
| 401 | at = @At(
|
| 402 | value = "INVOKE",
|
| 403 | target = "Lnet/minecraft/world/entity/LivingEntity;getYRot()F"
|
| 404 | )
|
| 405 | )
|
| 406 | private float combatant$omniSprintJumpYaw(LivingEntity instance) {
|
| 407 | return combatant$playerJumpEvent != null ? combatant$playerJumpEvent.getYaw() : instance.getYRot();
|
| 408 | }
|
| 409 |
|
| 410 | @Inject(method = "jumpFromGround", at = @At("RETURN"))
|
| 411 | private void combatant$onJumpReturn(CallbackInfo ci) {
|
| 412 | combatant$playerJumpEvent = null;
|
| 413 | }
|
| 414 |
|
| 415 | @Unique
|
| 416 | private boolean isBad(Holder<MobEffect> entry) {
|
| 417 | MobEffect eff = entry.value();
|
| 418 | return eff == MobEffects.BLINDNESS.value()
|
| 419 | || eff == MobEffects.DARKNESS.value()
|
| 420 | || eff == MobEffects.NAUSEA.value();
|
| 421 | }
|
| 422 |
|
| 423 | @Inject(
|
| 424 | method = "getBlockSpeedFactor",
|
| 425 | at = @At("RETURN"),
|
| 426 | cancellable = true
|
| 427 | )
|
| 428 | private void nostun$soulSandVelocity(CallbackInfoReturnable<Float> cir) {
|
| 429 | LivingEntity self = (LivingEntity) (Object) this;
|
| 430 | if (!(self instanceof Player player)) return;
|
| 431 | Minecraft client = Minecraft.getInstance();
|
| 432 | if (client == null || player != client.player) return;
|
| 433 |
|
| 434 | NoStun ns = Modules.get(NoStun.class);
|
| 435 | if (ns == null || !ns.isEnabled()) return;
|
| 436 | if (ns.isVulcan297()) {
|
| 437 | BlockPos pos = player.blockPosition();
|
| 438 | BlockState state = player.level().getBlockState(pos);
|
| 439 | if (state.is(Blocks.SOUL_SAND)) {
|
| 440 | cir.setReturnValue(ns.getSoulSandVelocityMultiplier(cir.getReturnValue()));
|
| 441 | }
|
| 442 | return;
|
| 443 | }
|
| 444 |
|
| 445 | // общий тумблер env
|
| 446 | if (!ns.isFunctionEnabled(NoStun.fnEnvBlocks())) return;
|
| 447 |
|
| 448 | // конкретный тумблер песка душ
|
| 449 | if (!ns.isEnvBlockEnabled(NoStun.envSoulSand())) return;
|
| 450 |
|
| 451 | BlockPos pos = player.blockPosition();
|
| 452 | BlockState state = player.level().getBlockState(pos);
|
| 453 |
|
| 454 | if (!state.is(Blocks.SOUL_SAND)) return;
|
| 455 |
|
| 456 | float vanilla = cir.getReturnValue();
|
| 457 |
|
| 458 | if (vanilla < 1.0F) {
|
| 459 | cir.setReturnValue(1.0F);
|
| 460 | }
|
| 461 | }
|
| 462 |
|
| 463 | }
|
| 464 |
|