| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.mixin;
|
| 7 |
|
| 8 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 9 | import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
|
| 10 | import meteordevelopment.meteorclient.MeteorClient;
|
| 11 | import meteordevelopment.meteorclient.events.entity.DropItemsEvent;
|
| 12 | import meteordevelopment.meteorclient.events.entity.player.ClipAtLedgeEvent;
|
| 13 | import meteordevelopment.meteorclient.systems.modules.Modules;
|
| 14 | import meteordevelopment.meteorclient.systems.modules.movement.Flight;
|
| 15 | import meteordevelopment.meteorclient.systems.modules.movement.NoSlow;
|
| 16 | import meteordevelopment.meteorclient.systems.modules.movement.Sprint;
|
| 17 | import meteordevelopment.meteorclient.systems.modules.player.Reach;
|
| 18 | import meteordevelopment.meteorclient.systems.modules.player.SpeedMine;
|
| 19 | import meteordevelopment.meteorclient.utils.world.BlockUtils;
|
| 20 | import net.minecraft.core.BlockPos;
|
| 21 | import net.minecraft.world.entity.EntityType;
|
| 22 | import net.minecraft.world.entity.LivingEntity;
|
| 23 | import net.minecraft.world.entity.item.ItemEntity;
|
| 24 | import net.minecraft.world.entity.player.Abilities;
|
| 25 | import net.minecraft.world.entity.player.Player;
|
| 26 | import net.minecraft.world.item.ItemStack;
|
| 27 | import net.minecraft.world.level.Level;
|
| 28 | import net.minecraft.world.level.block.state.BlockState;
|
| 29 | import net.minecraft.world.phys.BlockHitResult;
|
| 30 | import net.minecraft.world.phys.Vec3;
|
| 31 | import org.spongepowered.asm.mixin.Mixin;
|
| 32 | import org.spongepowered.asm.mixin.Shadow;
|
| 33 | import org.spongepowered.asm.mixin.injection.At;
|
| 34 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 35 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 36 |
|
| 37 | import static meteordevelopment.meteorclient.MeteorClient.mc;
|
| 38 |
|
| 39 | @Mixin(Player.class)
|
| 40 | public abstract class PlayerMixin extends LivingEntity {
|
| 41 | @Shadow
|
| 42 | public abstract Abilities getAbilities();
|
| 43 |
|
| 44 | protected PlayerMixin(EntityType<? extends LivingEntity> entityType, Level world) {
|
| 45 | super(entityType, world);
|
| 46 | }
|
| 47 |
|
| 48 | @Inject(method = "isStayingOnGroundSurface", at = @At("HEAD"), cancellable = true)
|
| 49 | protected void clipAtLedge(CallbackInfoReturnable<Boolean> cir) {
|
| 50 | if (!level().isClientSide()) return;
|
| 51 |
|
| 52 | ClipAtLedgeEvent event = MeteorClient.EVENT_BUS.post(ClipAtLedgeEvent.get());
|
| 53 | if (event.isSet()) cir.setReturnValue(event.isClip());
|
| 54 | }
|
| 55 |
|
| 56 | @Inject(method = "drop", at = @At("HEAD"), cancellable = true)
|
| 57 | private void onDropItem(ItemStack itemStack, boolean thrownFromHand, CallbackInfoReturnable<ItemEntity> cir) {
|
| 58 | if (level().isClientSide() && !itemStack.isEmpty()) {
|
| 59 | if (MeteorClient.EVENT_BUS.post(DropItemsEvent.get(itemStack)).isCancelled()) cir.setReturnValue(null);
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | @Inject(method = "isSpectator", at = @At("HEAD"), cancellable = true)
|
| 64 | private void onIsSpectator(CallbackInfoReturnable<Boolean> cir) {
|
| 65 | if (mc.getConnection() == null) cir.setReturnValue(false);
|
| 66 | }
|
| 67 |
|
| 68 | @Inject(method = "isCreative", at = @At("HEAD"), cancellable = true)
|
| 69 | private void onIsCreative(CallbackInfoReturnable<Boolean> cir) {
|
| 70 | if (mc.getConnection() == null) cir.setReturnValue(false);
|
| 71 | }
|
| 72 |
|
| 73 | @ModifyReturnValue(method = "getDestroySpeed", at = @At(value = "RETURN"))
|
| 74 | public float onGetBlockBreakingSpeed(float breakSpeed, BlockState state) {
|
| 75 | if (!level().isClientSide()) return breakSpeed;
|
| 76 |
|
| 77 | SpeedMine speedMine = Modules.get().get(SpeedMine.class);
|
| 78 | if (!speedMine.isActive() || speedMine.mode.get() != SpeedMine.Mode.Normal || !speedMine.filter(state.getBlock()))
|
| 79 | return breakSpeed;
|
| 80 |
|
| 81 | float breakSpeedMod = (float) (breakSpeed * speedMine.modifier.get());
|
| 82 |
|
| 83 | if (mc.hitResult instanceof BlockHitResult bhr) {
|
| 84 | BlockPos pos = bhr.getBlockPos();
|
| 85 | if (speedMine.modifier.get() < 1 || (BlockUtils.canInstaBreak(pos, breakSpeed) == BlockUtils.canInstaBreak(pos, breakSpeedMod))) {
|
| 86 | return breakSpeedMod;
|
| 87 | } else {
|
| 88 | return 0.9f / BlockUtils.calcBlockBreakingDelta2(pos, 1);
|
| 89 | }
|
| 90 | }
|
| 91 |
|
| 92 | return breakSpeed;
|
| 93 | }
|
| 94 |
|
| 95 | @ModifyReturnValue(method = "getSpeed", at = @At("RETURN"))
|
| 96 | private float onGetSpeed(float original) {
|
| 97 | if (!level().isClientSide()) return original;
|
| 98 | if (!Modules.get().get(NoSlow.class).slowness()) return original;
|
| 99 |
|
| 100 | float walkSpeed = getAbilities().getWalkingSpeed();
|
| 101 |
|
| 102 | if (original < walkSpeed) {
|
| 103 | if (isSprinting()) return (float) (walkSpeed * 1.30000001192092896);
|
| 104 | else return walkSpeed;
|
| 105 | }
|
| 106 |
|
| 107 | return original;
|
| 108 | }
|
| 109 |
|
| 110 | @Inject(method = "getFlyingSpeed", at = @At("HEAD"), cancellable = true)
|
| 111 | private void onGetFlyingSpeed(CallbackInfoReturnable<Float> cir) {
|
| 112 | if (!level().isClientSide()) return;
|
| 113 |
|
| 114 | float speed = Modules.get().get(Flight.class).getFlyingSpeed();
|
| 115 | if (speed != -1) cir.setReturnValue(speed);
|
| 116 | }
|
| 117 |
|
| 118 | @WrapWithCondition(method = "causeExtraKnockback", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;setDeltaMovement(Lnet/minecraft/world/phys/Vec3;)V"))
|
| 119 | private boolean keepSprint$setDeltaMovement(Player instance, Vec3 vec3d) {
|
| 120 | return Modules.get().get(Sprint.class).stopSprinting();
|
| 121 | }
|
| 122 |
|
| 123 | @WrapWithCondition(method = "causeExtraKnockback", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;setSprinting(Z)V"))
|
| 124 | private boolean keepSprint$setSprinting(Player instance, boolean b) {
|
| 125 | return Modules.get().get(Sprint.class).stopSprinting();
|
| 126 | }
|
| 127 |
|
| 128 | @ModifyReturnValue(method = "blockInteractionRange", at = @At("RETURN"))
|
| 129 | private double modifyBlockInteractionRange(double original) {
|
| 130 | return Math.max(0, original + Modules.get().get(Reach.class).blockReach());
|
| 131 | }
|
| 132 |
|
| 133 | @ModifyReturnValue(method = "entityInteractionRange", at = @At("RETURN"))
|
| 134 | private double modifyEntityInteractionRange(double original) {
|
| 135 | return Math.max(0, original + Modules.get().get(Reach.class).entityReach());
|
| 136 | }
|
| 137 | }
|
| 138 |
|