| 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.ModifyExpressionValue;
|
| 9 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 10 | import com.llamalad7.mixinextras.sugar.Local;
|
| 11 | import meteordevelopment.meteorclient.MeteorClient;
|
| 12 | import meteordevelopment.meteorclient.events.render.GetFovEvent;
|
| 13 | import meteordevelopment.meteorclient.mixininterface.ICamera;
|
| 14 | import meteordevelopment.meteorclient.systems.modules.Modules;
|
| 15 | import meteordevelopment.meteorclient.systems.modules.render.CameraTweaks;
|
| 16 | import meteordevelopment.meteorclient.systems.modules.render.FreeLook;
|
| 17 | import meteordevelopment.meteorclient.systems.modules.render.Freecam;
|
| 18 | import meteordevelopment.meteorclient.systems.modules.render.NoRender;
|
| 19 | import meteordevelopment.meteorclient.systems.modules.world.HighwayBuilder;
|
| 20 | import net.minecraft.client.Camera;
|
| 21 | import net.minecraft.util.Mth;
|
| 22 | import net.minecraft.world.level.material.FogType;
|
| 23 | import org.spongepowered.asm.mixin.Mixin;
|
| 24 | import org.spongepowered.asm.mixin.Shadow;
|
| 25 | import org.spongepowered.asm.mixin.injection.At;
|
| 26 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 27 | import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
| 28 | import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
| 29 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 30 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 31 | import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
| 32 |
|
| 33 | @Mixin(Camera.class)
|
| 34 | public abstract class CameraMixin implements ICamera {
|
| 35 | @Shadow
|
| 36 | private boolean detached;
|
| 37 |
|
| 38 | @Shadow
|
| 39 | private float yRot;
|
| 40 | @Shadow
|
| 41 | private float xRot;
|
| 42 |
|
| 43 | @Shadow
|
| 44 | protected abstract void setRotation(float yRot, float xRot);
|
| 45 |
|
| 46 | @Inject(method = "getFluidInCamera", at = @At("HEAD"), cancellable = true)
|
| 47 | private void getSubmergedFluidState(CallbackInfoReturnable<FogType> cir) {
|
| 48 | if (Modules.get().get(NoRender.class).noLiquidOverlay()) cir.setReturnValue(FogType.NONE);
|
| 49 | }
|
| 50 |
|
| 51 | @ModifyVariable(method = "getMaxZoom", at = @At("HEAD"), argsOnly = true, name = "cameraDist")
|
| 52 | private float modifyGetMaxZoom(float cameraDist) {
|
| 53 | if (Modules.get().get(Freecam.class).isActive()) return 0;
|
| 54 |
|
| 55 | CameraTweaks cameraTweaks = Modules.get().get(CameraTweaks.class);
|
| 56 | return cameraTweaks.isActive() ? (float) cameraTweaks.distance : cameraDist;
|
| 57 | }
|
| 58 |
|
| 59 | @Inject(method = "getMaxZoom", at = @At("HEAD"), cancellable = true)
|
| 60 | private void onGetMaxZoom(float cameraDist, CallbackInfoReturnable<Float> cir) {
|
| 61 | if (Modules.get().get(CameraTweaks.class).clip()) {
|
| 62 | cir.setReturnValue(cameraDist);
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | @Inject(method = "alignWithEntity", at = @At("TAIL"))
|
| 67 | private void onAlignWithEntityTail(float partialTicks, CallbackInfo ci) {
|
| 68 | if (Modules.get().isActive(Freecam.class)) {
|
| 69 | this.detached = true;
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | @ModifyArgs(method = "alignWithEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setPosition(DDD)V"))
|
| 74 | private void onAlignSetPosArgs(Args args, @Local(argsOnly = true, name = "partialTicks") float partialTicks) {
|
| 75 | Freecam freecam = Modules.get().get(Freecam.class);
|
| 76 |
|
| 77 | if (freecam.isActive()) {
|
| 78 | args.set(0, freecam.getX(partialTicks));
|
| 79 | args.set(1, freecam.getY(partialTicks));
|
| 80 | args.set(2, freecam.getZ(partialTicks));
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | @ModifyArgs(method = "alignWithEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;setRotation(FF)V"))
|
| 85 | private void onAlignSetRotationArgs(Args args, @Local(argsOnly = true, name = "partialTicks") float partialTicks) {
|
| 86 | Freecam freecam = Modules.get().get(Freecam.class);
|
| 87 | FreeLook freeLook = Modules.get().get(FreeLook.class);
|
| 88 |
|
| 89 | if (freecam.isActive()) {
|
| 90 | args.set(0, (float) freecam.getYaw(partialTicks));
|
| 91 | args.set(1, (float) freecam.getPitch(partialTicks));
|
| 92 | } else if (Modules.get().isActive(HighwayBuilder.class)) {
|
| 93 | args.set(0, yRot);
|
| 94 | args.set(1, xRot);
|
| 95 | } else if (freeLook.isActive()) {
|
| 96 | args.set(0, freeLook.cameraYaw);
|
| 97 | args.set(1, freeLook.cameraPitch);
|
| 98 | }
|
| 99 | }
|
| 100 |
|
| 101 | /**
|
| 102 | * Set as spectator to disable smart culling
|
| 103 | */
|
| 104 | @ModifyExpressionValue(method = "extractRenderState", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;isSpectator()Z"))
|
| 105 | private boolean hookFreeCamDisableSmartCullInBlocks(boolean original) {
|
| 106 | return original || Modules.get().get(Freecam.class).isActive();
|
| 107 | }
|
| 108 |
|
| 109 | @ModifyReturnValue(method = "calculateFov", at = @At("RETURN"))
|
| 110 | private float modifyFov(float original) {
|
| 111 | return MeteorClient.EVENT_BUS.post(GetFovEvent.get(original)).fov;
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | public void meteor$setRot(double yaw, double pitch) {
|
| 116 | setRotation((float) yaw, (float) Mth.clamp(pitch, -90, 90));
|
| 117 | }
|
| 118 | }
|
| 119 |
|