| 1 | package com.jellypudding.offlineclient.mixin;
|
| 2 |
|
| 3 | import com.jellypudding.offlineclient.modules.render.CameraTweaks;
|
| 4 | import com.jellypudding.offlineclient.modules.render.FreeLook;
|
| 5 | import com.jellypudding.offlineclient.modules.render.Freecam;
|
| 6 | import com.jellypudding.offlineclient.modules.render.NoRender;
|
| 7 | import com.jellypudding.offlineclient.modules.render.WallHack;
|
| 8 | import com.jellypudding.offlineclient.modules.render.XRay;
|
| 9 | import com.jellypudding.offlineclient.modules.render.Zoom;
|
| 10 | import com.jellypudding.offlineclient.util.Modules;
|
| 11 | import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
| 12 | import net.minecraft.client.Camera;
|
| 13 | import net.minecraft.client.DeltaTracker;
|
| 14 | import net.minecraft.client.renderer.state.level.CameraRenderState;
|
| 15 | import net.minecraft.world.phys.Vec3;
|
| 16 | import org.spongepowered.asm.mixin.Mixin;
|
| 17 | import org.spongepowered.asm.mixin.Shadow;
|
| 18 | import org.spongepowered.asm.mixin.injection.At;
|
| 19 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 20 | import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
| 21 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 22 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
| 23 |
|
| 24 | @Mixin(Camera.class)
|
| 25 | public abstract class CameraMixin {
|
| 26 |
|
| 27 | @Shadow
|
| 28 | private boolean detached;
|
| 29 |
|
| 30 | @Shadow
|
| 31 | protected abstract void setPosition(Vec3 pos);
|
| 32 |
|
| 33 | @Shadow
|
| 34 | protected abstract void setRotation(float yaw, float pitch);
|
| 35 |
|
| 36 | // The world and the hand each read the field of view. One ease a frame keeps them level.
|
| 37 | @Inject(method = "update(Lnet/minecraft/client/DeltaTracker;)V", at = @At("HEAD"))
|
| 38 | private void onCameraUpdate(DeltaTracker deltaTracker, CallbackInfo ci) {
|
| 39 | Zoom zoom = Modules.get(Zoom.class);
|
| 40 | if (zoom != null) {
|
| 41 | zoom.advance();
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | // FreeLook lends its look angles to the camera entity for the alignment call.
|
| 46 | @Inject(method = "update(Lnet/minecraft/client/DeltaTracker;)V",
|
| 47 | at = @At(value = "INVOKE",
|
| 48 | target = "Lnet/minecraft/client/Camera;alignWithEntity(F)V"))
|
| 49 | private void beforeAlignWithEntity(DeltaTracker deltaTracker, CallbackInfo ci) {
|
| 50 | FreeLook freeLook = Modules.get(FreeLook.class);
|
| 51 | if (freeLook != null) {
|
| 52 | freeLook.applyRotation();
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | @Inject(method = "update(Lnet/minecraft/client/DeltaTracker;)V",
|
| 57 | at = @At(value = "INVOKE",
|
| 58 | target = "Lnet/minecraft/client/Camera;alignWithEntity(F)V",
|
| 59 | shift = At.Shift.AFTER))
|
| 60 | private void afterAlignWithEntity(DeltaTracker deltaTracker, CallbackInfo ci) {
|
| 61 | FreeLook freeLook = Modules.get(FreeLook.class);
|
| 62 | if (freeLook != null) {
|
| 63 | freeLook.restoreRotation();
|
| 64 | }
|
| 65 | Freecam freecam = Modules.active(Freecam.class);
|
| 66 | if (freecam == null) {
|
| 67 | return;
|
| 68 | }
|
| 69 | detached = true;
|
| 70 | float partialTicks = deltaTracker.getGameTimeDeltaPartialTick(true);
|
| 71 | setPosition(freecam.getCamPos(partialTicks));
|
| 72 | setRotation(freecam.getCamYaw(), freecam.getCamPitch());
|
| 73 | }
|
| 74 |
|
| 75 | // Vanilla skips chunk sections that are boxed in by solid ground.
|
| 76 | @Inject(method = "extractRenderState(Lnet/minecraft/client/renderer/state/level/CameraRenderState;F)V",
|
| 77 | at = @At("RETURN"))
|
| 78 | private void onExtractRenderState(CameraRenderState state, float partialTicks, CallbackInfo ci) {
|
| 79 | XRay xray = XRay.get();
|
| 80 | WallHack wallHack = Modules.get(WallHack.class);
|
| 81 | NoRender noRender = Modules.get(NoRender.class);
|
| 82 | if ((xray != null && xray.isEnabled()) || (wallHack != null && wallHack.showsHiddenChunks())
|
| 83 | || (noRender != null && noRender.skipsCaveCulling())) {
|
| 84 | state.smartCull = false;
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 | @ModifyReturnValue(method = "calculateFov(F)F", at = @At("RETURN"))
|
| 89 | private float onCalculateFov(float original) {
|
| 90 | Zoom zoom = Modules.get(Zoom.class);
|
| 91 | return zoom == null ? original : zoom.applyZoom(original);
|
| 92 | }
|
| 93 |
|
| 94 | @ModifyReturnValue(method = "calculateHudFov(F)F", at = @At("RETURN"))
|
| 95 | private float onCalculateHudFov(float original) {
|
| 96 | Zoom zoom = Modules.get(Zoom.class);
|
| 97 | return zoom == null ? original : zoom.applyZoom(original);
|
| 98 | }
|
| 99 |
|
| 100 | // The distance vanilla wants before it walks the ray out and shortens it.
|
| 101 | @ModifyVariable(method = "getMaxZoom(F)F", at = @At("HEAD"), argsOnly = true)
|
| 102 | private float onWantedZoom(float wanted) {
|
| 103 | CameraTweaks tweaks = Modules.get(CameraTweaks.class);
|
| 104 | return tweaks == null ? wanted : tweaks.adjustDistance(wanted);
|
| 105 | }
|
| 106 |
|
| 107 | // No clip returns the wanted distance whole and skips the ray walk.
|
| 108 | @Inject(method = "getMaxZoom(F)F", at = @At("HEAD"), cancellable = true)
|
| 109 | private void onGetMaxZoom(float wanted, CallbackInfoReturnable<Float> cir) {
|
| 110 | CameraTweaks tweaks = Modules.get(CameraTweaks.class);
|
| 111 | if (tweaks != null && tweaks.passesThroughWalls()) {
|
| 112 | cir.setReturnValue(tweaks.adjustDistance(wanted));
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 |
|