Skip to content

Commit e9b5f65

Browse files
committed
Finish 2D Camera
1 parent 8ce388d commit e9b5f65

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

src/main/java/com/cyao/mixin/CameraMixin.java

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.minecraft.client.render.Camera;
44
import org.spongepowered.asm.mixin.Mixin;
55
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.ModifyArg;
67
import org.spongepowered.asm.mixin.injection.ModifyVariable;
78

89
@Mixin(Camera.class)
@@ -12,8 +13,25 @@ public class CameraMixin {
1213
private float setYaw(float yaw) {
1314
return 0;
1415
}
16+
1517
@ModifyVariable(method = "setRotation(FF)V", at = @At("HEAD"), ordinal = 1, argsOnly = true)
1618
private float setPitch(float pitch) {
1719
return 0;
1820
}
21+
22+
// We set third person view to default so the player gets rendered
23+
@ModifyVariable(method = "update(Lnet/minecraft/world/BlockView;Lnet/minecraft/entity/Entity;ZZF)V", at = @At("HEAD"), ordinal = 0, argsOnly = true)
24+
protected boolean thirdPerson(boolean value) {
25+
return true;
26+
}
27+
28+
// Offset the camera a bit more
29+
@ModifyArg(
30+
method = "update(Lnet/minecraft/world/BlockView;Lnet/minecraft/entity/Entity;ZZF)V",
31+
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;moveBy(FFF)V"),
32+
index = 0
33+
)
34+
protected float offsetCamera(float x) {
35+
return x - 4.0f;
36+
}
1937
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.cyao.mixin;
2+
3+
import net.minecraft.client.option.GameOptions;
4+
import net.minecraft.client.option.Perspective;
5+
import org.objectweb.asm.Opcodes;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
9+
import org.spongepowered.asm.mixin.injection.Redirect;
10+
11+
@Mixin(GameOptions.class)
12+
public class GameOptionsMixin {
13+
@ModifyVariable(method = "setPerspective", at = @At("HEAD"), ordinal = 0, argsOnly = true)
14+
protected Perspective thirdPerson(Perspective value) {
15+
return Perspective.THIRD_PERSON_BACK;
16+
}
17+
18+
@Redirect(method = "getPerspective", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;perspective:Lnet/minecraft/client/option/Perspective;", opcode = Opcodes.GETFIELD))
19+
private Perspective injected(GameOptions instance) {
20+
return Perspective.THIRD_PERSON_BACK;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.cyao.mixin;
2+
3+
import net.minecraft.client.gui.hud.InGameHud;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
6+
@Mixin(InGameHud.class)
7+
public class HUDMixin {
8+
}

src/main/resources/2d-minecraft.mixins.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"package": "com.cyao.mixin",
44
"compatibilityLevel": "JAVA_21",
55
"mixins": [
6-
"CameraMixin"
6+
"CameraMixin",
7+
"GameOptionsMixin",
8+
"HUDMixin"
79
],
810
"injectors": {
911
"defaultRequire": 1

0 commit comments

Comments
 (0)