3
3
import com .xtracr .realcamera .api .VirtualRenderer ;
4
4
import com .xtracr .realcamera .compat .PehkuiCompat ;
5
5
import com .xtracr .realcamera .compat .PhysicsModCompat ;
6
+ import com .xtracr .realcamera .config .BindingTarget ;
6
7
import com .xtracr .realcamera .config .ConfigFile ;
7
8
import com .xtracr .realcamera .config .ModConfig ;
8
9
import com .xtracr .realcamera .mixin .PlayerEntityRendererAccessor ;
25
26
import net .minecraft .util .math .Vec3d ;
26
27
import org .joml .Matrix3f ;
27
28
import org .joml .Matrix4f ;
28
- import org .joml .Vector3f ;
29
29
import org .joml .Vector4f ;
30
30
31
31
import java .util .ArrayList ;
32
32
import java .util .Collection ;
33
33
import java .util .List ;
34
- import java .util .function .BiPredicate ;
34
+ import java .util .function .BiFunction ;
35
35
36
36
public class RealCameraCore {
37
- private static final ModConfig config = ConfigFile .modConfig ;
38
37
private static VertexRecorder recorder = new VertexRecorder ();
38
+ private static BindingTarget currentTarget = new BindingTarget ();
39
39
private static String status = "Successful" ;
40
40
private static boolean renderingPlayer = false ;
41
41
private static boolean active = false ;
@@ -55,40 +55,40 @@ public static void setRenderingPlayer(boolean value) {
55
55
}
56
56
57
57
public static float getPitch (float f ) {
58
- if (config . isRotationBound ()) return pitch ;
59
- else return f + config . getBindingPitch ();
58
+ if (currentTarget . bindRotation ()) return pitch ;
59
+ else return f + currentTarget . pitch ();
60
60
}
61
61
62
62
public static float getYaw (float f ) {
63
- if (config . isRotationBound ()) return yaw ;
64
- else return f - config . getBindingYaw ();
63
+ if (currentTarget . bindRotation ()) return yaw ;
64
+ else return f - currentTarget . yaw ();
65
65
}
66
66
67
67
public static float getRoll (float f ) {
68
- if (config .isClassic ()) return f + config .getClassicRoll ();
69
- else if (config . isRotationBound ()) return roll ;
70
- else return f + config . getBindingRoll ();
68
+ if (config () .isClassic ()) return f + config () .getClassicRoll ();
69
+ else if (currentTarget . bindRotation ()) return roll ;
70
+ else return f + currentTarget . roll ();
71
71
}
72
72
73
73
public static Vec3d getPos (Vec3d vec3d ) {
74
- return new Vec3d (config . isXBound () ? pos .getX () : vec3d .getX () + config . getBindingX (),
75
- config . isYBound () ? pos .getY () : vec3d .getY () + config . getBindingY (),
76
- config . isZBound () ? pos .getZ () : vec3d .getZ () + config . getBindingZ ());
74
+ return new Vec3d (currentTarget . bindX () ? pos .getX () : vec3d .getX () + currentTarget . offsetX (),
75
+ currentTarget . bindY () ? pos .getY () : vec3d .getY () + currentTarget . offsetY (),
76
+ currentTarget . bindZ () ? pos .getZ () : vec3d .getZ () + currentTarget . offsetZ ());
77
77
}
78
78
79
79
public static Vec3d getCameraPos (Vec3d vec3d ) {
80
- return new Vec3d (config . isXBound () ? cameraPos .getX () : vec3d .getX () + config . getBindingX (),
81
- config . isYBound () ? cameraPos .getY () : vec3d .getY () + config . getBindingY (),
82
- config . isZBound () ? cameraPos .getZ () : vec3d .getZ () + config . getBindingZ ());
80
+ return new Vec3d (currentTarget . bindX () ? cameraPos .getX () : vec3d .getX () + currentTarget . offsetX (),
81
+ currentTarget . bindY () ? cameraPos .getY () : vec3d .getY () + currentTarget . offsetY (),
82
+ currentTarget . bindZ () ? cameraPos .getZ () : vec3d .getZ () + currentTarget . offsetZ ());
83
83
}
84
84
85
85
public static void setCameraPos (Vec3d vec3d ) {
86
86
cameraPos = vec3d ;
87
87
}
88
88
89
89
public static void init (MinecraftClient client ) {
90
- active = config .isEnabled () && client .options .getPerspective ().isFirstPerson () && client .gameRenderer .getCamera () != null
91
- && client .player != null && !config .shouldDisableMod (client );
90
+ active = config () .isEnabled () && client .options .getPerspective ().isFirstPerson () && client .gameRenderer .getCamera () != null
91
+ && client .player != null && !config () .shouldDisableMod (client );
92
92
}
93
93
94
94
public static boolean isActive () {
@@ -103,20 +103,24 @@ public static void renderPlayer(VertexConsumerProvider vertexConsumers) {
103
103
Matrix4f positionMatrix = matrixStack .peek ().getPositionMatrix ().transpose ().invertAffine ()
104
104
.translate ((float ) -pos .getX (), (float ) -pos .getY (), (float ) -pos .getZ ());
105
105
Matrix3f normalMatrix = matrixStack .peek ().getNormalMatrix ().transpose ().invert ();
106
- BiPredicate <RenderLayer , VertexRecorder .Vertex []> biPredicate = (renderLayer , vertices ) -> {
107
- double depth = config .disable .depth , centerZ = 0 ;
108
- for (VertexRecorder .Vertex vertex : vertices ) {
109
- if (vertex .z () < -depth ) return true ;
106
+ BiFunction <RenderLayer , VertexRecorder .Vertex [], VertexRecorder .Vertex []> function = (renderLayer , vertices ) -> {
107
+ double depth = currentTarget .disablingDepth (), centerZ = 0 ;
108
+ int size = vertices .length ;
109
+ VertexRecorder .Vertex [] newQuad = new VertexRecorder .Vertex [size ];
110
+ for (int i = 0 ; i < size ; i ++) newQuad [i ] = vertices [i ].transform (positionMatrix , normalMatrix );
111
+ for (VertexRecorder .Vertex vertex : newQuad ) {
112
+ if (vertex .z () < -depth ) return newQuad ;
110
113
centerZ += vertex .z ();
111
114
}
112
- return centerZ < -depth * vertices .length ;
115
+ return centerZ < -depth * vertices .length ? newQuad : null ;
113
116
};
114
- recorder .drawByAnother (vertex -> vertex . transform ( positionMatrix , normalMatrix ), vertexConsumers , renderLayer -> true , biPredicate );
117
+ recorder .drawByAnother (vertexConsumers , renderLayer -> true , function );
115
118
}
116
119
117
120
public static void computeCamera (MinecraftClient client , float tickDelta ) {
118
- roll = config .getClassicRoll ();
119
- if (config .isClassic ()) return ;
121
+ roll = config ().getClassicRoll ();
122
+ currentTarget = new BindingTarget ();
123
+ if (config ().isClassic ()) return ;
120
124
121
125
// GameRenderer.renderWorld
122
126
MatrixStack matrixStack = new MatrixStack ();
@@ -125,48 +129,45 @@ public static void computeCamera(MinecraftClient client, float tickDelta) {
125
129
recorder .buildLastRecord ();
126
130
127
131
// ModelPart$Cuboid.renderCuboid
128
- Vector4f offset = matrixStack .peek ().getPositionMatrix ().transform (new Vector4f ((float ) (config .getBindingZ () * config .getScale ()),
129
- -(float ) (config .getBindingY () * config .getScale ()) - 0.125f ,
130
- -(float ) (config .getBindingX () * config .getScale ()) - 0.225f , 1.0F ));
132
+ Vector4f offset = matrixStack .peek ().getPositionMatrix ().transform (new Vector4f ((float ) (config () .getBindingZ () * config () .getScale ()),
133
+ -(float ) (config () .getBindingY () * config () .getScale ()) - 0.125f ,
134
+ -(float ) (config () .getBindingX () * config () .getScale ()) - 0.225f , 1.0f ));
131
135
pos = new Vec3d (offset .x (), offset .y (), offset .z ());
132
- Matrix3f normal = matrixStack .peek ().getNormalMatrix ().scale (1.0F , -1.0F , -1.0F );
133
- if (config .binding .experimental ) {
134
- List <ModConfig . Binding . Target > targetList = new ArrayList <>();
135
- if (config .binding .autoBind ) {
136
- Collection <ModConfig . Binding . Target > targetSet = config .binding .targetMap .values ();
136
+ Matrix3f normal = matrixStack .peek ().getNormalMatrix ().scale (1.0f , -1.0f , -1.0f );
137
+ if (config () .binding .experimental ) {
138
+ List <BindingTarget > targetList = new ArrayList <>();
139
+ if (config () .binding .autoBind ) {
140
+ Collection <BindingTarget > targetSet = config () .binding .targetMap .values ();
137
141
recorder .setCurrent (renderLayer -> targetSet .stream ().anyMatch (t -> renderLayer .toString ().contains (t .textureId ())));
138
142
String textureId = recorder .currentTextureId ();
139
143
if (textureId != null ) targetList .addAll (targetSet .stream ().filter (t -> textureId .contains (t .textureId ())).toList ());
140
144
}
141
- targetList .add (config .binding .targetMap .get (config .binding .nameOfList ));
142
- for (ModConfig . Binding . Target target : targetList ) {
145
+ targetList .add (config () .binding .targetMap .get (config () .binding .nameOfList ));
146
+ for (BindingTarget target : targetList ) {
143
147
try {
144
148
recorder .setCurrent (renderLayer -> renderLayer .toString ().contains (target .textureId ()));
145
149
if (recorder .quadCount () <= 0 ) throw new NullPointerException ("Vertices not found" );
146
- Vec3d front = recorder .getNormal (target .forwardU (), target .forwardV ());
147
- Vec3d up = recorder .getNormal (target .upwardU (), target .upwardV ());
148
- Vec3d center = recorder .getPos (target .posU (), target .posV ());
149
- if (!MathUtil .isFinite (front ) || !MathUtil .isFinite (up ) || !MathUtil .isFinite (center )) throw new ArithmeticException ();
150
- normal .set (up .crossProduct (front ).toVector3f (), up .toVector3f (), front .toVector3f ());
151
- Vector3f vec3f = normal .transform (new Vector3f ((float ) (config .getBindingZ () * config .getScale ()),
152
- (float ) (config .getBindingY () * config .getScale ()),
153
- (float ) (config .getBindingX () * config .getScale ())));
154
- pos = center .add (vec3f .x (), vec3f .y (), vec3f .z ());
150
+ pos = recorder .getTargetPosAndRot (target , normal );
151
+ currentTarget = target ;
155
152
break ;
156
153
} catch (Exception ignored ) {
157
154
}
158
155
}
159
156
}
160
157
161
- normal .rotateLocal ((float ) Math .toRadians (config . getBindingYaw ()), normal .m10 , normal .m11 , normal .m12 );
162
- normal .rotateLocal ((float ) Math .toRadians (config . getBindingPitch ()), normal .m00 , normal .m01 , normal .m02 );
163
- normal .rotateLocal ((float ) Math .toRadians (config . getBindingRoll ()), normal .m20 , normal .m21 , normal .m22 );
164
- Vec3d eulerAngle = MathUtil .getEulerAngleYXZ (normal ).multiply (180.0D / Math .PI );
158
+ normal .rotateLocal ((float ) Math .toRadians (currentTarget . yaw ()), normal .m10 , normal .m11 , normal .m12 );
159
+ normal .rotateLocal ((float ) Math .toRadians (currentTarget . pitch ()), normal .m00 , normal .m01 , normal .m02 );
160
+ normal .rotateLocal ((float ) Math .toRadians (currentTarget . roll ()), normal .m20 , normal .m21 , normal .m22 );
161
+ Vec3d eulerAngle = MathUtil .getEulerAngleYXZ (normal ).multiply (180.0d / Math .PI );
165
162
pitch = (float ) eulerAngle .getX ();
166
163
yaw = (float ) -eulerAngle .getY ();
167
164
roll = (float ) eulerAngle .getZ ();
168
165
}
169
166
167
+ private static ModConfig config () {
168
+ return ConfigFile .modConfig ;
169
+ }
170
+
170
171
private static void virtualRender (MinecraftClient client , float tickDelta , MatrixStack matrixStack , VertexConsumerProvider consumers ) {
171
172
ClientPlayerEntity player = client .player ;
172
173
// WorldRenderer.render
@@ -182,21 +183,21 @@ private static void virtualRender(MinecraftClient client, float tickDelta, Matri
182
183
matrixStack .push ();
183
184
EntityRenderDispatcher dispatcher = client .getEntityRenderDispatcher ();
184
185
dispatcher .configure (client .world , client .gameRenderer .getCamera (), player );
185
- if (config .binding .experimental ) dispatcher .render (player , renderOffset .getX (), renderOffset .getY (), renderOffset .getZ (),
186
+ if (config () .binding .experimental ) dispatcher .render (player , renderOffset .getX (), renderOffset .getY (), renderOffset .getZ (),
186
187
MathHelper .lerp (tickDelta , player .prevYaw , player .getYaw ()), tickDelta , matrixStack , consumers , dispatcher .getLight (player , tickDelta ));
187
188
matrixStack .pop ();
188
189
// EntityRenderDispatcher.render
189
- if (config .compatPhysicsMod ())
190
+ if (config () .compatPhysicsMod ())
190
191
PhysicsModCompat .renderStart (client .getEntityRenderDispatcher (), player , renderOffset .getX (), renderOffset .getY (),
191
192
renderOffset .getZ (), MathHelper .lerp (tickDelta , player .prevYaw , player .getYaw ()), tickDelta , matrixStack );
192
193
193
194
PlayerEntityRenderer playerRenderer = (PlayerEntityRenderer ) client .getEntityRenderDispatcher ().getRenderer (player );
194
195
renderOffset = renderOffset .add (playerRenderer .getPositionOffset (player , tickDelta ));
195
196
matrixStack .translate (renderOffset .getX (), renderOffset .getY (), renderOffset .getZ ());
196
197
197
- if (config .compatPehkui ()) PehkuiCompat .scaleMatrices (matrixStack , player , tickDelta );
198
+ if (config () .compatPehkui ()) PehkuiCompat .scaleMatrices (matrixStack , player , tickDelta );
198
199
199
- if (config .isUsingModModel ()) {
200
+ if (config () .isUsingModModel ()) {
200
201
status = "Successful" ;
201
202
try {
202
203
matrixStack .push ();
@@ -257,6 +258,6 @@ private static void virtualRender(MinecraftClient client, float tickDelta, Matri
257
258
playerModel .setAngles (player , o , n , l , k , m );
258
259
// AnimalModel.render
259
260
// ModelPart.render
260
- config .getVanillaModelPart ().get (playerRenderer .getModel ()).rotate (matrixStack );
261
+ config () .getVanillaModelPart ().get (playerRenderer .getModel ()).rotate (matrixStack );
261
262
}
262
263
}
0 commit comments