5
5
import com .xtracr .realcamera .compat .PhysicsModCompat ;
6
6
import com .xtracr .realcamera .config .ConfigFile ;
7
7
import com .xtracr .realcamera .config .ModConfig ;
8
- import com .xtracr .realcamera .mixins .CameraAccessor ;
9
8
import com .xtracr .realcamera .mixins .PlayerEntityRendererAccessor ;
10
9
import com .xtracr .realcamera .utils .MathUtils ;
11
10
import com .xtracr .realcamera .utils .Matrix3fc ;
12
11
import net .minecraft .client .MinecraftClient ;
13
12
import net .minecraft .client .network .AbstractClientPlayerEntity ;
14
13
import net .minecraft .client .network .ClientPlayerEntity ;
15
- import net .minecraft .client .render .Camera ;
16
14
import net .minecraft .client .render .entity .PlayerEntityRenderer ;
17
15
import net .minecraft .client .render .entity .model .PlayerEntityModel ;
18
16
import net .minecraft .client .util .math .MatrixStack ;
19
17
import net .minecraft .entity .EntityPose ;
20
18
import net .minecraft .entity .LivingEntity ;
21
- import net .minecraft .util .hit .HitResult ;
22
19
import net .minecraft .util .math .Direction ;
23
20
import net .minecraft .util .math .MathHelper ;
24
21
import net .minecraft .util .math .Vec3d ;
25
- import net .minecraft .util .math .Vec3f ;
26
22
import net .minecraft .util .math .Vector4f ;
27
- import net .minecraft .world .RaycastContext ;
28
23
29
24
public class RealCameraCore {
30
25
private static final ModConfig config = ConfigFile .modConfig ;
31
26
32
27
private static String status = "Successful" ;
33
- private static float cameraRoll = 0.0F ;
28
+ private static float pitch = 0.0F ;
29
+ private static float yaw = 0.0F ;
30
+ private static float roll = 0.0F ;
31
+ private static Vec3d pos = Vec3d .ZERO ;
32
+ private static Vec3d modelOffset = Vec3d .ZERO ;
34
33
35
34
public static String getStatus () {
36
35
return status ;
37
36
}
38
37
38
+ public static float getPitch () {
39
+ return pitch ;
40
+ }
41
+
42
+ public static float getYaw () {
43
+ return yaw ;
44
+ }
45
+
39
46
public static float getRoll () {
40
- return cameraRoll ;
47
+ return roll ;
41
48
}
42
49
43
- public static boolean isActive () {
44
- MinecraftClient client = MinecraftClient .getInstance ();
45
- return config .isEnabled () && client .options .getPerspective ().isFirstPerson () && client .gameRenderer .getCamera () != null
46
- && client .player != null && !config .disableModWhen (client );
50
+ public static Vec3d getPos () {
51
+ return pos ;
47
52
}
48
53
49
- public static void updateCamera (Camera camera , MinecraftClient client , float tickDelta ) {
50
- cameraRoll = 0.0F ;
54
+ public static Vec3d getModelOffset () {
55
+ return modelOffset ;
56
+ }
51
57
52
- if ( config . isRendering () && ! config . disableRenderingWhen ( client ) ) {
53
- (( CameraAccessor ) camera ). setThirdPerson ( true ) ;
54
- }
58
+ public static void setModelOffset ( Vec3d vec3d ) {
59
+ modelOffset = vec3d ;
60
+ }
55
61
56
- if (config .isClassic ()) {
57
- classicModeUpdate (camera , client , tickDelta );
58
- } else {
59
- // GameRenderer.render
60
- bindingModeUpdate (camera , client , tickDelta , new MatrixStack ());
61
- }
62
+ public static boolean isActive () {
63
+ MinecraftClient client = MinecraftClient .getInstance ();
64
+ return config .isEnabled () && client .options .getPerspective ().isFirstPerson () && client .gameRenderer .getCamera () != null
65
+ && client .player != null && !config .shouldDisableMod (client );
62
66
}
63
67
64
- private static void classicModeUpdate (Camera camera , MinecraftClient client , float tickDelta ) {
65
- ClientPlayerEntity player = client .player ;
68
+ public static void computeCamera (MinecraftClient client , float tickDelta ) {
69
+ modelOffset = Vec3d .ZERO ;
70
+ roll = config .getClassicRoll ();
71
+ if (config .isClassic ()) return ;
66
72
67
- float centerYaw = camera .getYaw ();
68
- float pitch = camera .getPitch () + config .getClassicPitch ();
69
- float yaw = centerYaw - config .getClassicYaw ();
70
- cameraRoll = config .getClassicRoll ();
71
- Vec3d offset = new Vec3d (config .getClassicX (), config .getClassicY (), config .getClassicZ ()).multiply (config .getScale ());
72
- Vec3d center = new Vec3d (config .getCenterX (), config .getCenterY (), config .getCenterZ ()).multiply (config .getScale ());
73
+ // GameRenderer.renderWorld
74
+ MatrixStack matrixStack = new MatrixStack ();
75
+ virtualRender (client , tickDelta , matrixStack );
73
76
74
- if (player .isSneaking ()) {
75
- center = center .add (0.0D , -0.021875D , 0.0D );
76
- }
77
- if (config .compatPehkui ()) {
78
- offset = PehkuiCompat .scaleVec3d (offset , player , tickDelta );
79
- center = PehkuiCompat .scaleVec3d (center , player , tickDelta );
80
- }
77
+ // ModelPart$Cuboid.renderCuboid
78
+ Vector4f offset = new Vector4f ((float )(config .getBindingZ () * config .getScale ()),
79
+ -(float )(config .getBindingY () * config .getScale ()),
80
+ -(float )(config .getBindingX () * config .getScale ()), 1.0F );
81
+ offset .transform (matrixStack .peek ().getPositionMatrix ());
82
+ pos = new Vec3d (offset .getX (), offset .getY (), offset .getZ ());
81
83
82
- ((CameraAccessor ) camera ).invokeSetRotation (centerYaw , 0.0F );
83
- ((CameraAccessor ) camera ).invokeMoveBy (center .getX (), center .getY (), center .getZ ());
84
- ((CameraAccessor ) camera ).invokeSetRotation (yaw , pitch );
85
- Vec3d referVec = camera .getPos ();
86
- ((CameraAccessor ) camera ).invokeMoveBy (offset .getX (), offset .getY (), offset .getZ ());
87
- clipCameraToSpace (camera , referVec );
84
+ Matrix3fc normal = new Matrix3fc (matrixStack .peek ().getNormalMatrix ()).scale (1.0F , -1.0F , -1.0F );
85
+ normal .rotateLocal ((float ) Math .toRadians (config .getBindingYaw ()), normal .m10 , normal .m11 , normal .m12 );
86
+ normal .rotateLocal ((float ) Math .toRadians (config .getBindingPitch ()), normal .m00 , normal .m01 , normal .m02 );
87
+ normal .rotateLocal ((float ) Math .toRadians (config .getBindingRoll ()), normal .m20 , normal .m21 , normal .m22 );
88
+ Vec3d eulerAngle = MathUtils .getEulerAngleYXZ (normal ).multiply (180.0D / Math .PI );
89
+ pitch = (float ) eulerAngle .getX ();
90
+ yaw = (float ) -eulerAngle .getY ();
91
+ roll = config .isRollingBound () ? (float ) eulerAngle .getZ () : config .getBindingRoll ();
88
92
}
89
93
90
- private static void bindingModeUpdate (Camera camera , MinecraftClient client , float tickDelta , MatrixStack matrixStack ) {
91
-
92
- // GameRenderer.renderWorld
93
- matrixStack .multiply (Vec3f .POSITIVE_X .getDegreesQuaternion (camera .getPitch ()));
94
- matrixStack .multiply (Vec3f .POSITIVE_Y .getDegreesQuaternion (camera .getYaw () + 180.0F ));
95
- matrixStack .peek ().getNormalMatrix ().loadIdentity ();
96
- // WorldRenderer.render
94
+ private static void virtualRender (MinecraftClient client , float tickDelta , MatrixStack matrixStack ) {
97
95
ClientPlayerEntity player = client .player ;
96
+ // WorldRenderer.render
98
97
if (player .age == 0 ) {
99
98
player .lastRenderX = player .getX ();
100
99
player .lastRenderY = player .getY ();
@@ -103,68 +102,18 @@ private static void bindingModeUpdate(Camera camera, MinecraftClient client, flo
103
102
// WorldRenderer.renderEntity
104
103
Vec3d renderOffset = new Vec3d (MathHelper .lerp (tickDelta , player .lastRenderX , player .getX ()),
105
104
MathHelper .lerp (tickDelta , player .lastRenderY , player .getY ()),
106
- MathHelper .lerp (tickDelta , player .lastRenderZ , player .getZ ()))
107
- .subtract (camera .getPos ());
105
+ MathHelper .lerp (tickDelta , player .lastRenderZ , player .getZ ()));
108
106
// EntityRenderDispatcher.render
109
107
if (config .compatPhysicsMod ())
110
- PhysicsModCompat .renderStart (client .getEntityRenderDispatcher (), player , renderOffset .getX (),
111
- renderOffset .getY (), renderOffset . getZ (), MathHelper .lerp (tickDelta , player .prevYaw , player .getYaw ()), tickDelta , matrixStack );
108
+ PhysicsModCompat .renderStart (client .getEntityRenderDispatcher (), player , renderOffset .getX (), renderOffset . getY (),
109
+ renderOffset .getZ (), MathHelper .lerp (tickDelta , player .prevYaw , player .getYaw ()), tickDelta , matrixStack );
112
110
113
111
PlayerEntityRenderer playerRenderer = (PlayerEntityRenderer ) client .getEntityRenderDispatcher ().getRenderer (player );
114
112
renderOffset = renderOffset .add (playerRenderer .getPositionOffset (player , tickDelta ));
115
113
matrixStack .translate (renderOffset .getX (), renderOffset .getY (), renderOffset .getZ ());
116
114
117
115
if (config .compatPehkui ()) PehkuiCompat .scaleMatrices (matrixStack , player , tickDelta );
118
116
119
- virtualRender (player , playerRenderer , tickDelta , matrixStack );
120
-
121
- // ModelPart$Cuboid.renderCuboid
122
- Vector4f offset = new Vector4f ((float )(config .getBindingZ () * config .getScale ()),
123
- -(float )(config .getBindingY () * config .getScale ()),
124
- -(float )(config .getBindingX () * config .getScale ()), 1.0F );
125
- offset .transform (matrixStack .peek ().getPositionMatrix ());
126
-
127
- Vec3d referVec = camera .getPos ();
128
- ((CameraAccessor ) camera ).invokeMoveBy (-offset .getZ (), offset .getY (), -offset .getX ());
129
- clipCameraToSpace (camera , referVec );
130
-
131
- Matrix3fc normal = new Matrix3fc (matrixStack .peek ().getNormalMatrix ()).scale (1.0F , -1.0F , -1.0F );
132
- normal .rotateLocal ((float ) Math .toRadians (config .getBindingYaw ()), normal .m10 , normal .m11 , normal .m12 );
133
- normal .rotateLocal ((float ) Math .toRadians (config .getBindingPitch ()), normal .m00 , normal .m01 , normal .m02 );
134
- normal .rotateLocal ((float ) Math .toRadians (config .getBindingRoll ()), normal .m20 , normal .m21 , normal .m22 );
135
- Vec3d eulerAngle = MathUtils .getEulerAngleYXZ (normal ).multiply (180.0D / Math .PI );
136
-
137
- float pitch = config .isPitchingBound () ? (float ) eulerAngle .getX () : camera .getPitch () + config .getBindingPitch ();
138
- float yaw = config .isYawingBound () ? (float ) eulerAngle .getY () : -camera .getYaw () + config .getBindingYaw ();
139
- cameraRoll = config .isRollingBound () ? (float ) eulerAngle .getZ () : config .getBindingRoll ();
140
- ((CameraAccessor ) camera ).invokeSetRotation (-yaw , pitch );
141
- }
142
-
143
- private static void clipCameraToSpace (Camera camera , Vec3d referVec ) {
144
- if (!config .doClipToSpace ()) return ;
145
- Vec3d offset = camera .getPos ().subtract (referVec );
146
- boolean hitted = false ;
147
- final float depth = 0.1F ;
148
- for (int i = 0 ; i < 8 ; ++i ) {
149
- float f = depth * ((i & 1 ) * 2 - 1 );
150
- float g = depth * ((i >> 1 & 1 ) * 2 - 1 );
151
- float h = depth * ((i >> 2 & 1 ) * 2 - 1 );
152
- Vec3d start = referVec .add (f , g , h );
153
- Vec3d end = referVec .add (offset ).add (f , g , h );
154
- HitResult hitResult = ((CameraAccessor ) camera ).getArea ().raycast (new RaycastContext (start , end ,
155
- RaycastContext .ShapeType .VISUAL , RaycastContext .FluidHandling .NONE , camera .getFocusedEntity ()));
156
- double l = hitResult .getPos ().distanceTo (start );
157
- if (hitResult .getType () == HitResult .Type .MISS || l >= offset .length ()) continue ;
158
- offset = offset .multiply (l / offset .length ());
159
- hitted = true ;
160
- }
161
- ((CameraAccessor ) camera ).invokeSetPos (referVec .add (offset ));
162
- if (hitted && offset .length () <= 0.8F ) ((CameraAccessor ) camera ).setThirdPerson (false );
163
- }
164
-
165
- private static void virtualRender (AbstractClientPlayerEntity player , PlayerEntityRenderer playerRenderer ,
166
- float tickDelta , MatrixStack matrixStack ) {
167
-
168
117
if (config .isUsingModModel ()) {
169
118
status = "Successful" ;
170
119
try {
0 commit comments