| 1 | package com.jellypudding.offlineclient.mixin;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.OfflineClient;
|
| 4 | import com.jellypudding.offlineclient.event.events.AirStrafingSpeedEvent;
|
| 5 | import com.jellypudding.offlineclient.event.events.KnockbackEvent;
|
| 6 | import com.jellypudding.offlineclient.event.events.PostMotionEvent;
|
| 7 | import com.jellypudding.offlineclient.event.events.PreMotionEvent;
|
| 8 | import com.jellypudding.offlineclient.event.events.TickEvent;
|
| 9 | import com.jellypudding.offlineclient.modules.combat.BowAimbot;
|
| 10 | import com.jellypudding.offlineclient.modules.movement.AntiPush;
|
| 11 | import com.jellypudding.offlineclient.modules.movement.Flight;
|
| 12 | import com.jellypudding.offlineclient.modules.movement.HighJump;
|
| 13 | import com.jellypudding.offlineclient.modules.movement.HoleSnap;
|
| 14 | import com.jellypudding.offlineclient.modules.movement.NoKnockback;
|
| 15 | import com.jellypudding.offlineclient.modules.movement.LongJump;
|
| 16 | import com.jellypudding.offlineclient.modules.movement.NoSlowdown;
|
| 17 | import com.jellypudding.offlineclient.modules.movement.EdgeGuard;
|
| 18 | import com.jellypudding.offlineclient.modules.movement.Sprint;
|
| 19 | import com.jellypudding.offlineclient.modules.movement.Step;
|
| 20 | import com.jellypudding.offlineclient.modules.movement.VehicleFly;
|
| 21 | import com.jellypudding.offlineclient.modules.player.AutoDrop;
|
| 22 | import com.jellypudding.offlineclient.modules.player.AutoEat;
|
| 23 | import com.jellypudding.offlineclient.modules.player.AutoGap;
|
| 24 | import com.jellypudding.offlineclient.modules.player.FastBreak;
|
| 25 | import com.jellypudding.offlineclient.modules.player.PortalMenus;
|
| 26 | import com.jellypudding.offlineclient.modules.player.Reach;
|
| 27 | import com.jellypudding.offlineclient.modules.render.AntiBlind;
|
| 28 | import com.jellypudding.offlineclient.modules.world.AirPlace;
|
| 29 | import com.jellypudding.offlineclient.util.Modules;
|
| 30 | import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
| 31 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
| 32 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
| 33 | import com.mojang.authlib.GameProfile;
|
| 34 | import net.minecraft.client.gui.screens.Screen;
|
| 35 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 36 | import net.minecraft.client.player.AbstractClientPlayer;
|
| 37 | import net.minecraft.client.player.LocalPlayer;
|
| 38 | import net.minecraft.core.BlockPos;
|
| 39 | import net.minecraft.core.Holder;
|
| 40 | import net.minecraft.world.effect.MobEffect;
|
| 41 | import net.minecraft.world.effect.MobEffectInstance;
|
| 42 | import net.minecraft.world.effect.MobEffects;
|
| 43 | import net.minecraft.world.entity.PlayerRideableJumping;
|
| 44 | import net.minecraft.world.entity.player.Abilities;
|
| 45 | import net.minecraft.world.level.block.state.BlockState;
|
| 46 | import net.minecraft.world.phys.Vec3;
|
| 47 | import org.spongepowered.asm.mixin.Mixin;
|
| 48 | import org.spongepowered.asm.mixin.Shadow;
|
| 49 | import org.spongepowered.asm.mixin.Unique;
|
| 50 | import org.spongepowered.asm.mixin.injection.At;
|
| 51 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 52 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 53 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 54 |
|
| 55 | @Mixin(LocalPlayer.class)
|
| 56 | public abstract class LocalPlayerMixin extends AbstractClientPlayer {
|
| 57 |
|
| 58 | // The throw key never gives away an item AutoDrop is guarding.
|
| 59 | @Inject(method = "drop(Z)Z", at = @At("HEAD"), cancellable = true)
|
| 60 | private void onDrop(boolean whole, CallbackInfoReturnable<Boolean> cir) {
|
| 61 | AutoDrop autoDrop = Modules.get(AutoDrop.class);
|
| 62 | if (autoDrop != null && autoDrop.guards(OfflineClient.MC.player.getMainHandItem())) {
|
| 63 | cir.setReturnValue(false);
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | @Shadow
|
| 68 | public float portalEffectIntensity;
|
| 69 |
|
| 70 | @Shadow
|
| 71 | public float oPortalEffectIntensity;
|
| 72 |
|
| 73 | // Never called. The compiler only wants a constructor for the parent.
|
| 74 | private LocalPlayerMixin(ClientLevel level, GameProfile profile) {
|
| 75 | super(level, profile);
|
| 76 | }
|
| 77 |
|
| 78 | @Inject(method = "tick()V",
|
| 79 | at = @At(value = "INVOKE",
|
| 80 | target = "Lnet/minecraft/client/player/AbstractClientPlayer;tick()V",
|
| 81 | ordinal = 0))
|
| 82 | private void onTick(CallbackInfo ci) {
|
| 83 | OfflineClient.INSTANCE.getEventBus().post(TickEvent.INSTANCE);
|
| 84 | }
|
| 85 |
|
| 86 | // A mounted player never reaches sendPosition in this method.
|
| 87 | // Posting here on both sides of that branch keeps an aura working on a horse.
|
| 88 | @Inject(method = "tick()V",
|
| 89 | at = @At(value = "INVOKE",
|
| 90 | target = "Lnet/minecraft/client/player/LocalPlayer;isPassenger()Z"))
|
| 91 | private void onPreMotion(CallbackInfo ci) {
|
| 92 | OfflineClient.INSTANCE.getEventBus().post(PreMotionEvent.INSTANCE);
|
| 93 | }
|
| 94 |
|
| 95 | @Inject(method = "tick()V", at = @At("TAIL"))
|
| 96 | private void onPostMotion(CallbackInfo ci) {
|
| 97 | OfflineClient.INSTANCE.getEventBus().post(PostMotionEvent.INSTANCE);
|
| 98 | }
|
| 99 |
|
| 100 | // Vanilla closes any screen the moment the portal effect starts. With no
|
| 101 | // screen in sight that branch never runs.
|
| 102 | @ModifyExpressionValue(method = "handlePortalTransitionEffect(Z)V",
|
| 103 | at = @At(value = "INVOKE",
|
| 104 | target = "Lnet/minecraft/client/gui/Gui;screen()Lnet/minecraft/client/gui/screens/Screen;",
|
| 105 | ordinal = 0))
|
| 106 | private Screen hideScreenFromPortal(Screen original) {
|
| 107 | return Modules.active(PortalMenus.class) == null ? original : null;
|
| 108 | }
|
| 109 |
|
| 110 | @WrapOperation(method = "aiStep()V",
|
| 111 | at = @At(value = "INVOKE",
|
| 112 | target = "Lnet/minecraft/client/player/LocalPlayer;isSlowDueToUsingItem()Z",
|
| 113 | ordinal = 0))
|
| 114 | private boolean wrapAiStepItemUse(LocalPlayer instance, Operation<Boolean> original) {
|
| 115 | if (offlineclient$noSlowdown()) {
|
| 116 | return false;
|
| 117 | }
|
| 118 | return original.call(instance);
|
| 119 | }
|
| 120 |
|
| 121 | @WrapOperation(
|
| 122 | method = "modifyInput(Lnet/minecraft/world/phys/Vec2;)Lnet/minecraft/world/phys/Vec2;",
|
| 123 | at = @At(value = "INVOKE",
|
| 124 | target = "Lnet/minecraft/client/player/LocalPlayer;isUsingItem()Z",
|
| 125 | ordinal = 0))
|
| 126 | private boolean wrapModifyInputItemUse(LocalPlayer instance, Operation<Boolean> original) {
|
| 127 | if (offlineclient$noSlowdown()) {
|
| 128 | return false;
|
| 129 | }
|
| 130 | return original.call(instance);
|
| 131 | }
|
| 132 |
|
| 133 | @Unique
|
| 134 | private static boolean offlineclient$noSlowdown() {
|
| 135 | NoSlowdown noSlowdown = Modules.get(NoSlowdown.class);
|
| 136 | if (noSlowdown != null && noSlowdown.skipsItems()) {
|
| 137 | return true;
|
| 138 | }
|
| 139 | BowAimbot bowAimbot = Modules.get(BowAimbot.class);
|
| 140 | if (bowAimbot != null && bowAimbot.suppressesSlowdown()) {
|
| 141 | return true;
|
| 142 | }
|
| 143 | AutoEat autoEat = Modules.get(AutoEat.class);
|
| 144 | if (autoEat != null && autoEat.suppressesSlowdown()) {
|
| 145 | return true;
|
| 146 | }
|
| 147 | AutoGap autoGap = Modules.get(AutoGap.class);
|
| 148 | return autoGap != null && autoGap.suppressesSlowdown();
|
| 149 | }
|
| 150 |
|
| 151 | @Override
|
| 152 | protected float getFlyingSpeed() {
|
| 153 | AirStrafingSpeedEvent event = new AirStrafingSpeedEvent(super.getFlyingSpeed());
|
| 154 | OfflineClient.INSTANCE.getEventBus().post(event);
|
| 155 | return event.getSpeed();
|
| 156 | }
|
| 157 |
|
| 158 | @Override
|
| 159 | public void lerpMotion(Vec3 vec) {
|
| 160 | KnockbackEvent event = new KnockbackEvent(vec.x, vec.y, vec.z);
|
| 161 | OfflineClient.INSTANCE.getEventBus().post(event);
|
| 162 | super.lerpMotion(new Vec3(event.getX(), event.getY(), event.getZ()));
|
| 163 | }
|
| 164 |
|
| 165 | @Override
|
| 166 | protected float getJumpPower() {
|
| 167 | HighJump highJump = Modules.get(HighJump.class);
|
| 168 | return super.getJumpPower() + (highJump == null ? 0f : highJump.getAdditionalJumpMotion());
|
| 169 | }
|
| 170 |
|
| 171 | @Override
|
| 172 | public void jumpFromGround() {
|
| 173 | HoleSnap holeSnap = Modules.get(HoleSnap.class);
|
| 174 | if (holeSnap != null && holeSnap.cancelsJump()) {
|
| 175 | return;
|
| 176 | }
|
| 177 | super.jumpFromGround();
|
| 178 | LongJump longJump = Modules.get(LongJump.class);
|
| 179 | if (longJump != null) {
|
| 180 | longJump.onJump();
|
| 181 | }
|
| 182 | HighJump highJump = Modules.get(HighJump.class);
|
| 183 | if (highJump != null) {
|
| 184 | highJump.onJump();
|
| 185 | }
|
| 186 | }
|
| 187 |
|
| 188 | // Rage sprint answers the three vanilla sprint rules itself. Anything that
|
| 189 | // would normally refuse a sprint such as a wall or an item in use is ignored.
|
| 190 | @Inject(method = "canStartSprinting()Z", at = @At("HEAD"), cancellable = true)
|
| 191 | private void onCanStartSprinting(CallbackInfoReturnable<Boolean> cir) {
|
| 192 | Sprint sprint = Modules.get(Sprint.class);
|
| 193 | if (sprint != null && sprint.rage()) {
|
| 194 | cir.setReturnValue(!isSprinting() && sprint.rageWantsSprint((LocalPlayer) (Object) this));
|
| 195 | }
|
| 196 | }
|
| 197 |
|
| 198 | @Inject(method = "shouldStopRunSprinting()Z", at = @At("HEAD"), cancellable = true)
|
| 199 | private void onShouldStopRunSprinting(CallbackInfoReturnable<Boolean> cir) {
|
| 200 | Sprint sprint = Modules.get(Sprint.class);
|
| 201 | if (sprint != null && sprint.rage()) {
|
| 202 | cir.setReturnValue(!sprint.rageWantsSprint((LocalPlayer) (Object) this));
|
| 203 | }
|
| 204 | }
|
| 205 |
|
| 206 | @Inject(method = "shouldStopSwimSprinting()Z", at = @At("HEAD"), cancellable = true)
|
| 207 | private void onShouldStopSwimSprinting(CallbackInfoReturnable<Boolean> cir) {
|
| 208 | Sprint sprint = Modules.get(Sprint.class);
|
| 209 | if (sprint != null && sprint.rage()) {
|
| 210 | cir.setReturnValue(!sprint.rageWantsSprint((LocalPlayer) (Object) this));
|
| 211 | }
|
| 212 | }
|
| 213 |
|
| 214 | // The one place creative flight reads the fly speed for its push up
|
| 215 | // and down. Flight hands over its own vertical speed instead of scaling it.
|
| 216 | @WrapOperation(method = "aiStep()V",
|
| 217 | at = @At(value = "INVOKE",
|
| 218 | target = "Lnet/minecraft/world/entity/player/Abilities;getFlyingSpeed()F"))
|
| 219 | private float wrapVerticalFlySpeed(Abilities abilities, Operation<Float> original) {
|
| 220 | Flight flight = Modules.active(Flight.class);
|
| 221 | return flight == null ? original.call(abilities) : flight.verticalFlySpeed();
|
| 222 | }
|
| 223 |
|
| 224 | // Crowd pushing checks this on both sides of a collision. False here
|
| 225 | // blocks incoming pushes and leaves outgoing ones alone.
|
| 226 | @Override
|
| 227 | public boolean isPushable() {
|
| 228 | AntiPush antiPush = Modules.get(AntiPush.class);
|
| 229 | if (antiPush != null && antiPush.blocksEntities()) {
|
| 230 | return false;
|
| 231 | }
|
| 232 | return super.isPushable();
|
| 233 | }
|
| 234 |
|
| 235 | @Override
|
| 236 | public boolean isPushedByFluid() {
|
| 237 | AntiPush antiPush = Modules.get(AntiPush.class);
|
| 238 | if (antiPush != null && antiPush.blocksCurrents()) {
|
| 239 | return false;
|
| 240 | }
|
| 241 | return super.isPushedByFluid();
|
| 242 | }
|
| 243 |
|
| 244 | @Override
|
| 245 | public void onAboveBubbleColumn(boolean downwards, BlockPos pos) {
|
| 246 | AntiPush antiPush = Modules.get(AntiPush.class);
|
| 247 | if (antiPush != null && antiPush.blocksBubbleColumns()) {
|
| 248 | return;
|
| 249 | }
|
| 250 | super.onAboveBubbleColumn(downwards, pos);
|
| 251 | }
|
| 252 |
|
| 253 | @Override
|
| 254 | public void onInsideBubbleColumn(boolean downwards) {
|
| 255 | AntiPush antiPush = Modules.get(AntiPush.class);
|
| 256 | if (antiPush != null && antiPush.blocksBubbleColumns()) {
|
| 257 | return;
|
| 258 | }
|
| 259 | super.onInsideBubbleColumn(downwards);
|
| 260 | }
|
| 261 |
|
| 262 | // The client predicts mining five times slower in the air. FastBreak
|
| 263 | // fixes the server side by rewriting packets and can raise the rate outright.
|
| 264 | @Override
|
| 265 | public float getDestroySpeed(BlockState state) {
|
| 266 | float speed = super.getDestroySpeed(state);
|
| 267 | FastBreak fastBreak = Modules.get(FastBreak.class);
|
| 268 | return fastBreak == null ? speed : fastBreak.adjustSpeed(state, speed);
|
| 269 | }
|
| 270 |
|
| 271 | // Honey and soul sand slow through this factor alone.
|
| 272 | @Override
|
| 273 | protected float getBlockSpeedFactor() {
|
| 274 | float factor = super.getBlockSpeedFactor();
|
| 275 | NoSlowdown noSlowdown = Modules.get(NoSlowdown.class);
|
| 276 | if (factor >= 1 || noSlowdown == null) {
|
| 277 | return factor;
|
| 278 | }
|
| 279 | boolean skipped = noSlowdown.skipsBlockFriction(level().getBlockState(blockPosition()).getBlock())
|
| 280 | || noSlowdown.skipsBlockFriction(
|
| 281 | level().getBlockState(getBlockPosBelowThatAffectsMyMovement()).getBlock());
|
| 282 | return skipped ? 1 : factor;
|
| 283 | }
|
| 284 |
|
| 285 | // The sneak slowdown hangs off this. Crawling keeps its own pace.
|
| 286 | @Inject(method = "isMovingSlowly()Z", at = @At("HEAD"), cancellable = true)
|
| 287 | private void onIsMovingSlowly(CallbackInfoReturnable<Boolean> cir) {
|
| 288 | NoSlowdown noSlowdown = Modules.get(NoSlowdown.class);
|
| 289 | if (noSlowdown != null && noSlowdown.skipsSneaking()) {
|
| 290 | cir.setReturnValue(isVisuallyCrawling());
|
| 291 | }
|
| 292 | }
|
| 293 |
|
| 294 | @Override
|
| 295 | public float getSpeed() {
|
| 296 | float speed = super.getSpeed();
|
| 297 | MobEffectInstance slowness = getEffect(MobEffects.SLOWNESS);
|
| 298 | NoSlowdown noSlowdown = Modules.get(NoSlowdown.class);
|
| 299 | if (slowness == null || noSlowdown == null) {
|
| 300 | return speed;
|
| 301 | }
|
| 302 | return noSlowdown.withoutSlowness(speed, slowness.getAmplifier());
|
| 303 | }
|
| 304 |
|
| 305 | // A jumping mount takes the jump key to charge its leap. VehicleFly wants it to lift.
|
| 306 | @Inject(method = "jumpableVehicle()Lnet/minecraft/world/entity/PlayerRideableJumping;",
|
| 307 | at = @At("HEAD"), cancellable = true)
|
| 308 | private void onJumpableVehicle(CallbackInfoReturnable<PlayerRideableJumping> cir) {
|
| 309 | VehicleFly vehicleFly = Modules.get(VehicleFly.class);
|
| 310 | if (vehicleFly != null && vehicleFly.takesJumpKey()) {
|
| 311 | cir.setReturnValue(null);
|
| 312 | }
|
| 313 | }
|
| 314 |
|
| 315 | // The charge of a horse jump. One is a full power leap.
|
| 316 | @Inject(method = "getJumpRidingScale()F", at = @At("HEAD"), cancellable = true)
|
| 317 | private void onGetJumpRidingScale(CallbackInfoReturnable<Float> cir) {
|
| 318 | VehicleFly vehicleFly = Modules.get(VehicleFly.class);
|
| 319 | if (vehicleFly != null && vehicleFly.maxesJump()) {
|
| 320 | cir.setReturnValue(1f);
|
| 321 | }
|
| 322 | }
|
| 323 |
|
| 324 | // Vanilla shoves the player out of any block they stand inside.
|
| 325 | @Inject(method = "moveTowardsClosestSpace(DD)V", at = @At("HEAD"), cancellable = true)
|
| 326 | private void onMoveTowardsClosestSpace(double x, double z, CallbackInfo ci) {
|
| 327 | NoKnockback noKnockback = Modules.get(NoKnockback.class);
|
| 328 | if (noKnockback != null && noKnockback.blocksBlockPush()) {
|
| 329 | ci.cancel();
|
| 330 | }
|
| 331 | }
|
| 332 |
|
| 333 | @Override
|
| 334 | public float maxUpStep() {
|
| 335 | float vanilla = super.maxUpStep();
|
| 336 | Step step = Modules.get(Step.class);
|
| 337 | return step == null ? vanilla : step.adjustStepHeight(vanilla);
|
| 338 | }
|
| 339 |
|
| 340 | @Override
|
| 341 | protected boolean isStayingOnGroundSurface() {
|
| 342 | if (super.isStayingOnGroundSurface()) {
|
| 343 | return true;
|
| 344 | }
|
| 345 | EdgeGuard edgeGuard = Modules.get(EdgeGuard.class);
|
| 346 | return edgeGuard != null && edgeGuard.shouldGuard();
|
| 347 | }
|
| 348 |
|
| 349 | @Override
|
| 350 | public double blockInteractionRange() {
|
| 351 | double range = super.blockInteractionRange();
|
| 352 | Reach reach = Modules.get(Reach.class);
|
| 353 | if (reach != null) {
|
| 354 | range = reach.adjustBlockRange(range);
|
| 355 | }
|
| 356 | // A block placed in the air has to be reachable to build onto.
|
| 357 | AirPlace airPlace = Modules.active(AirPlace.class);
|
| 358 | return airPlace == null ? range : Math.max(range, airPlace.getRange());
|
| 359 | }
|
| 360 |
|
| 361 | @Override
|
| 362 | public double entityInteractionRange() {
|
| 363 | double vanilla = super.entityInteractionRange();
|
| 364 | Reach reach = Modules.get(Reach.class);
|
| 365 | return reach == null ? vanilla : reach.adjustEntityRange(vanilla);
|
| 366 | }
|
| 367 |
|
| 368 | @Override
|
| 369 | public boolean hasEffect(Holder<MobEffect> effect) {
|
| 370 | if (blocked(effect)) {
|
| 371 | return false;
|
| 372 | }
|
| 373 | return super.hasEffect(effect);
|
| 374 | }
|
| 375 |
|
| 376 | // The pulsing darkness dimming and the nausea spin read this instead of hasEffect.
|
| 377 | @Override
|
| 378 | public float getEffectBlendFactor(Holder<MobEffect> effect, float partialTicks) {
|
| 379 | if (blocked(effect)) {
|
| 380 | return 0;
|
| 381 | }
|
| 382 | return super.getEffectBlendFactor(effect, partialTicks);
|
| 383 | }
|
| 384 |
|
| 385 | @Unique
|
| 386 | private static boolean blocked(Holder<MobEffect> effect) {
|
| 387 | AntiBlind antiBlind = Modules.active(AntiBlind.class);
|
| 388 | if (antiBlind == null) {
|
| 389 | return false;
|
| 390 | }
|
| 391 | if (effect == MobEffects.BLINDNESS) {
|
| 392 | return antiBlind.blocksBlindness();
|
| 393 | }
|
| 394 | if (effect == MobEffects.DARKNESS) {
|
| 395 | return antiBlind.blocksDarkness();
|
| 396 | }
|
| 397 | return effect == MobEffects.NAUSEA && antiBlind.blocksNausea();
|
| 398 | }
|
| 399 |
|
| 400 | // The renderer reads the intensity a tick behind. Clearing it here is enough.
|
| 401 | @Inject(method = "tick()V", at = @At("TAIL"))
|
| 402 | private void onTickEnd(CallbackInfo ci) {
|
| 403 | AntiBlind antiBlind = Modules.active(AntiBlind.class);
|
| 404 | if (antiBlind != null && antiBlind.blocksPortal()) {
|
| 405 | portalEffectIntensity = 0;
|
| 406 | oPortalEffectIntensity = 0;
|
| 407 | }
|
| 408 | }
|
| 409 | }
|
| 410 |
|