Skip to content

Commit 61fab32

Browse files
committed
added perspective mod
1 parent 3d9e114 commit 61fab32

File tree

7 files changed

+139
-3
lines changed

7 files changed

+139
-3
lines changed

simpleclient-1.19.4/src/main/java/simpleclient/mixin/feature/perspective/MouseMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
@Mixin(MouseHandler.class)
1212
public class MouseMixin {
1313
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/tutorial/Tutorial;onMouse(DD)V"), method = "turnPlayer", locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
14-
private void onMouse(CallbackInfo ci, double d, double e, double k, double l, double f, double g, double h, int m) {
14+
private void onMouse(CallbackInfo ci, double d, double e, double yaw, double pitch, double f, double g, double h, int invertion) {
1515
if (Perspective.ACTIVE) {
16-
Perspective.YAW = (float) (Perspective.YAW + k / 8.0D);
17-
Perspective.PITCH = (float) Math.max(-90, Math.min(Perspective.PITCH + l * m / 8.0D, 90));
16+
Perspective.YAW = (float) (Perspective.YAW + yaw / 8.0D);
17+
Perspective.PITCH = (float) Math.max(-90, Math.min(Perspective.PITCH + pitch * invertion / 8.0D, 90));
1818
System.out.println(Perspective.YAW + " " + Perspective.PITCH);
1919
ci.cancel();
2020
}

simpleclient-1.8.9/src/main/java/simpleclient/feature/FeatureManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public void init() {
2121
addFeature(new Lowfire());
2222
addFeature(new Motionblur());
2323
addFeature(new OldAnimations());
24+
addFeature(new Perspective());
2425
addFeature(new Ping());
2526
addFeature(new PvPImprovements());
2627
addFeature(new Zoom());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package simpleclient.feature;
2+
3+
import net.legacyfabric.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
4+
import net.legacyfabric.fabric.api.client.keybinding.v1.KeyBindingHelper;
5+
import net.minecraft.client.option.KeyBinding;
6+
import org.lwjgl.input.Keyboard;
7+
8+
public class Perspective extends Feature {
9+
public static boolean ACTIVE = false;
10+
public static float YAW = 0;
11+
public static float PITCH = 0;
12+
private int previousPerspective;
13+
14+
public Perspective() {
15+
super(FeatureType.PERSPECTIVE);
16+
KeyBinding key = KeyBindingHelper.registerKeyBinding(new KeyBinding("simpleclient.perspective", Keyboard.KEY_LMENU, "simpleclient.category"));
17+
ClientTickEvents.END_CLIENT_TICK.register(minecraft -> {
18+
if (key.isPressed() && !ACTIVE) {
19+
ACTIVE = true;
20+
previousPerspective = minecraft.options.perspective;
21+
minecraft.options.perspective = 1;
22+
} else if (!key.isPressed() && ACTIVE) {
23+
ACTIVE = false;
24+
if (previousPerspective != -1) minecraft.options.perspective = previousPerspective;
25+
previousPerspective = -1;
26+
}
27+
});
28+
}
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package simpleclient.mixin.feature.perspective;
2+
3+
import net.minecraft.client.render.Camera;
4+
import net.minecraft.entity.player.PlayerEntity;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Redirect;
8+
import simpleclient.feature.Perspective;
9+
10+
@Mixin(Camera.class)
11+
public class CameraMixin {
12+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;yaw:F"), method = "update")
13+
private static float yaw(PlayerEntity entity) {
14+
return Perspective.ACTIVE ? Perspective.YAW : entity.yaw;
15+
}
16+
17+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;pitch:F"), method = "update")
18+
private static float pitch(PlayerEntity entity) {
19+
return Perspective.ACTIVE ? Perspective.PITCH : entity.pitch;
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package simpleclient.mixin.feature.perspective;
2+
3+
import net.minecraft.client.render.entity.EntityRenderDispatcher;
4+
import net.minecraft.entity.Entity;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Redirect;
8+
import simpleclient.feature.Perspective;
9+
10+
@Mixin(EntityRenderDispatcher.class)
11+
public abstract class EntityRenderDispatcherMixin {
12+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;yaw:F"), method = "updateCamera(Lnet/minecraft/world/World;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity;Lnet/minecraft/client/option/GameOptions;F)V")
13+
public float yaw(Entity entity) {
14+
return Perspective.ACTIVE ? Perspective.YAW : entity.yaw;
15+
}
16+
17+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;prevYaw:F"), method = "updateCamera(Lnet/minecraft/world/World;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity;Lnet/minecraft/client/option/GameOptions;F)V")
18+
public float prevYaw(Entity entity) {
19+
return Perspective.ACTIVE ? Perspective.YAW : entity.prevYaw;
20+
}
21+
22+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;pitch:F"), method = "updateCamera(Lnet/minecraft/world/World;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity;Lnet/minecraft/client/option/GameOptions;F)V")
23+
public float pitch(Entity entity) {
24+
return Perspective.ACTIVE ? Perspective.PITCH : entity.pitch;
25+
}
26+
27+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;prevPitch:F"), method = "updateCamera(Lnet/minecraft/world/World;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity;Lnet/minecraft/client/option/GameOptions;F)V")
28+
public float prevPitch(Entity entity) {
29+
return Perspective.ACTIVE ? Perspective.PITCH : entity.prevPitch;
30+
}
31+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package simpleclient.mixin.feature.perspective;
2+
3+
import net.minecraft.client.MinecraftClient;
4+
import net.minecraft.client.render.GameRenderer;
5+
import net.minecraft.entity.Entity;
6+
import net.minecraft.entity.player.ClientPlayerEntity;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Redirect;
11+
import simpleclient.feature.Perspective;
12+
13+
@Mixin(GameRenderer.class)
14+
public class GameRendererMixin {
15+
@Shadow private MinecraftClient client;
16+
17+
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ClientPlayerEntity;increaseTransforms(FF)V"), method = "render")
18+
private void increaseTransforms(ClientPlayerEntity entity, float yaw, float pitch) {
19+
if (Perspective.ACTIVE) {
20+
if (Float.isNaN(Perspective.YAW)) {
21+
Perspective.YAW = entity.yaw;
22+
Perspective.PITCH = entity.pitch;
23+
}
24+
Perspective.YAW = (float) (Perspective.YAW + yaw / 8.0D);
25+
Perspective.PITCH = (float) Math.max(-90, Math.min(Perspective.PITCH + pitch / 8.0D, 90));
26+
} else {
27+
if (!Float.isNaN(Perspective.YAW)) Perspective.YAW = Float.NaN;
28+
client.player.increaseTransforms(yaw, pitch);
29+
}
30+
}
31+
32+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;yaw:F"), method = "transformCamera")
33+
public float yaw(Entity entity) {
34+
return Perspective.ACTIVE ? Perspective.YAW : entity.yaw;
35+
}
36+
37+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;prevYaw:F"), method = "transformCamera")
38+
public float prevYaw(Entity entity) {
39+
return Perspective.ACTIVE ? Perspective.YAW : entity.prevYaw;
40+
}
41+
42+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;pitch:F"), method = "transformCamera")
43+
public float pitch(Entity entity) {
44+
return Perspective.ACTIVE ? Perspective.PITCH : entity.pitch;
45+
}
46+
47+
@Redirect(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;prevPitch:F"), method = "transformCamera")
48+
public float prevPitch(Entity entity) {
49+
return Perspective.ACTIVE ? Perspective.PITCH : entity.prevPitch;
50+
}
51+
}

simpleclient-1.8.9/src/main/resources/simpleclient.mixins.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"feature.old_animations.BiPedModelMixin",
1717
"feature.old_animations.HeldItemRendererMixin",
1818
"feature.old_animations.ItemFeatureRendererMixin",
19+
"feature.perspective.CameraMixin",
20+
"feature.perspective.EntityRenderDispatcherMixin",
21+
"feature.perspective.GameRendererMixin",
1922
"feature.pvp_improvements.LivingEntityMixin",
2023
"feature.pvp_improvements.MinecraftClientMixin",
2124
"feature.zoom.GameRendererMixin"

0 commit comments

Comments
 (0)