2020import com .lambda .interaction .request .rotation .RotationManager ;
2121import com .lambda .module .modules .player .Freecam ;
2222import com .lambda .module .modules .render .CameraTweaks ;
23+ import com .lambda .module .modules .render .FreeLook ;
2324import net .minecraft .client .render .Camera ;
2425import net .minecraft .entity .Entity ;
2526import net .minecraft .world .BlockView ;
2829import org .spongepowered .asm .mixin .injection .At ;
2930import org .spongepowered .asm .mixin .injection .Inject ;
3031import org .spongepowered .asm .mixin .injection .ModifyArg ;
32+ import org .spongepowered .asm .mixin .injection .ModifyArgs ;
3133import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
3234import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
35+ import org .spongepowered .asm .mixin .injection .invoke .arg .Args ;
3336
3437@ Mixin (Camera .class )
3538public abstract class CameraMixin {
@@ -74,6 +77,8 @@ private void injectQuickPerspectiveSwap(BlockView area, Entity focusedEntity, bo
7477 private void onClipToSpace (float desiredCameraDistance , CallbackInfoReturnable <Float > info ) {
7578 if (CameraTweaks .INSTANCE .isEnabled () && CameraTweaks .getNoClipCam ()) {
7679 info .setReturnValue (desiredCameraDistance );
80+ } else if (FreeLook .INSTANCE .isEnabled ()) {
81+ info .setReturnValue (desiredCameraDistance );
7782 }
7883 }
7984
@@ -93,8 +98,51 @@ private void onClipToSpace(float desiredCameraDistance, CallbackInfoReturnable<F
9398 private float onDistanceUpdate (float desiredCameraDistance ) {
9499 if (CameraTweaks .INSTANCE .isEnabled ()) {
95100 return CameraTweaks .getCamDistance ();
101+ } else if (FreeLook .INSTANCE .isEnabled ()) {
102+ return 4.0F ;
96103 }
97104
98105 return desiredCameraDistance ;
99106 }
107+
108+ /**
109+ * Modifies the arguments for setting the camera rotation.
110+ * Mixes into 4 arguments:
111+ * <p>Experimental Minecart Controller:</p>
112+ * <pre>
113+ * if (experimentalMinecartController.hasCurrentLerpSteps()) {
114+ * 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));
115+ * this.setRotation(focusedEntity.getYaw(tickProgress), focusedEntity.getPitch(tickProgress));
116+ * this.setPos(experimentalMinecartController.getLerpedPosition(tickProgress).add(vec3d));
117+ * break label39;
118+ * }
119+ * </pre>
120+ * <p>Default Camera:</p>
121+ * <pre>
122+ * this.setRotation(focusedEntity.getYaw(tickProgress), focusedEntity.getPitch(tickProgress));
123+ * 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()));
124+ * </pre>
125+ * <p>Third person camera:</p>
126+ * <pre>
127+ * if (thirdPerson) {
128+ * if (inverseView) {
129+ * this.setRotation(this.yaw + 180.0F, -this.pitch);
130+ * }
131+ * // ...
132+ * }
133+ * </pre>
134+ * <p>When the player is focused on another Living Entity:</p>
135+ * <pre>
136+ * Direction direction = ((LivingEntity)focusedEntity).getSleepingDirection();
137+ * this.setRotation(direction != null ? direction.getPositiveHorizontalDegrees() - 180.0F : 0.0F, 0.0F);
138+ * this.moveBy(0.0F, 0.3F, 0.0F);
139+ * </pre>
140+ */
141+ @ ModifyArgs (method = "update" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V" ))
142+ private void onUpdateSetRotationArgs (Args args ) {
143+ if (FreeLook .INSTANCE .isEnabled ()) {
144+ args .set (0 , FreeLook .INSTANCE .getCamera ().getYawF ());
145+ args .set (1 , FreeLook .INSTANCE .getCamera ().getPitchF ());
146+ }
147+ }
100148}
0 commit comments