-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCameraMixin.java
More file actions
155 lines (144 loc) · 6.66 KB
/
CameraMixin.java
File metadata and controls
155 lines (144 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lambda.mixin.render;
import com.lambda.interaction.managers.rotating.RotationManager;
import com.lambda.module.modules.player.Freecam;
import com.lambda.module.modules.render.CameraTweaks;
import com.lambda.module.modules.render.FreeLook;
import com.lambda.module.modules.render.NoRender;
import net.minecraft.block.enums.CameraSubmersionType;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
@Mixin(Camera.class)
public abstract class CameraMixin {
@Shadow
public abstract void setRotation(float yaw, float pitch);
@Inject(method = "update", at = @At("TAIL"))
private void onUpdate(
BlockView area,
Entity focusedEntity,
boolean thirdPerson,
boolean inverseView,
float tickDelta,
CallbackInfo ci
) {
if (!Freecam.INSTANCE.isEnabled()) return;
Freecam.updateCam();
}
/**
* Sets the lock rotation to the active rotation
* <pre>{@code
* this.setPos(
* MathHelper.lerp((double)tickDelta, focusedEntity.prevX, focusedEntity.getX()),
* MathHelper.lerp((double)tickDelta, focusedEntity.prevY, focusedEntity.getY()) + (double)MathHelper.lerp(tickDelta, this.lastCameraY, this.cameraY),
* MathHelper.lerp((double)tickDelta, focusedEntity.prevZ, focusedEntity.getZ())
* );
* }</pre>
*/
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V", shift = At.Shift.AFTER))
private void injectQuickPerspectiveSwap(BlockView area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) {
var rot = RotationManager.getLockRotation();
if (rot == null) return;
setRotation(rot.getYawF(), rot.getPitchF());
}
/**
* Allows camera to clip through blocks in third person
*/
@Inject(method = "clipToSpace", at = @At("HEAD"), cancellable = true)
private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable<Float> info) {
if (CameraTweaks.INSTANCE.isEnabled() && CameraTweaks.getNoClipCam()) {
info.setReturnValue(desiredCameraDistance);
} else if (FreeLook.INSTANCE.isEnabled()) {
info.setReturnValue(desiredCameraDistance);
}
}
/**
* Modifies the third person camera distance
* <pre>{@code
* if (thirdPerson) {
* if (inverseView) {
* this.setRotation(this.yaw + 180.0F, -this.pitch);
* }
*
* this.moveBy(-this.clipToSpace(4.0), 0.0, 0.0);
* }
* }</pre>
*/
@ModifyArg(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;clipToSpace(F)F"))
private float onDistanceUpdate(float desiredCameraDistance) {
if (CameraTweaks.INSTANCE.isEnabled()) {
return CameraTweaks.getCamDistance();
} else if (FreeLook.INSTANCE.isEnabled()) {
return 4.0F;
}
return desiredCameraDistance;
}
/**
* Modifies the arguments for setting the camera rotation.
* Mixes into 4 arguments:
* <p>Experimental Minecart Controller:</p>
* <pre>
* if (experimentalMinecartController.hasCurrentLerpSteps()) {
* Vec3d vec3d = minecartEntity.getPassengerRidingPos(focusedEntity).subtract(minecartEntity.getPos()).subtract(focusedEntity.getVehicleAttachmentPos(minecartEntity)).add(new Vec3d(0.0, (double)MathHelper.lerp(tickProgress, this.lastCameraY, this.cameraY), 0.0));
* this.setRotation(focusedEntity.getYaw(tickProgress), focusedEntity.getPitch(tickProgress));
* this.setPos(experimentalMinecartController.getLerpedPosition(tickProgress).add(vec3d));
* break label39;
* }
* </pre>
* <p>Default Camera:</p>
* <pre>
* this.setRotation(focusedEntity.getYaw(tickProgress), focusedEntity.getPitch(tickProgress));
* this.setPos(MathHelper.lerp((double)tickProgress, focusedEntity.lastX, focusedEntity.getX()), MathHelper.lerp((double)tickProgress, focusedEntity.lastY, focusedEntity.getY()) + (double)MathHelper.lerp(tickProgress, this.lastCameraY, this.cameraY), MathHelper.lerp((double)tickProgress, focusedEntity.lastZ, focusedEntity.getZ()));
* </pre>
* <p>Third person camera:</p>
* <pre>
* if (thirdPerson) {
* if (inverseView) {
* this.setRotation(this.yaw + 180.0F, -this.pitch);
* }
* // ...
* }
* </pre>
* <p>When the player is focused on another Living Entity:</p>
* <pre>
* Direction direction = ((LivingEntity)focusedEntity).getSleepingDirection();
* this.setRotation(direction != null ? direction.getPositiveHorizontalDegrees() - 180.0F : 0.0F, 0.0F);
* this.moveBy(0.0F, 0.3F, 0.0F);
* </pre>
*/
@ModifyArgs(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V"))
private void onUpdateSetRotationArgs(Args args) {
if (FreeLook.INSTANCE.isEnabled()) {
args.set(0, FreeLook.INSTANCE.getCamera().getYawF());
args.set(1, FreeLook.INSTANCE.getCamera().getPitchF());
}
}
@Inject(method = "getSubmersionType", at = @At("HEAD"), cancellable = true)
private void injectGetSubmersionType(CallbackInfoReturnable<CameraSubmersionType> cir) {
if (NoRender.INSTANCE.isEnabled() && NoRender.getNoFluidOverlay()) cir.setReturnValue(CameraSubmersionType.NONE);
}
}