@@ -175,84 +175,65 @@ public void render(@NotNull T pEntity, float pEntityYaw, float pPartialTick, @No
175
175
@ Override
176
176
public void actuallyRender (@ NotNull IRenderContext <T > pContext ) {
177
177
if (pContext instanceof FullRenderContext <T > full ) {
178
- PoseStack pPoseStack = full .poseStack ();
178
+ PoseStack poseStack = full .poseStack ();
179
179
T animatable = full .animatable ();
180
180
VertexConsumer buffer = full .optionalBuffer ();
181
- boolean pIsReRender = full .isReRender ();
182
- float pPartialTick = full .partialTick ();
181
+ boolean isReRender = full .isReRender ();
182
+ float partialTick = full .partialTick ();
183
183
184
- pPoseStack .pushPose ();
184
+ poseStack .pushPose ();
185
185
186
- LivingEntity livingEntity = animatable instanceof LivingEntity entity ? entity : null ;
187
- boolean shouldSit = animatable .isPassenger () && (animatable .getVehicle () != null );
188
- float lerpBodyRot = livingEntity == null ? 0 : Mth .rotLerp (pPartialTick , livingEntity .yBodyRotO , livingEntity .yBodyRot );
189
- float lerpHeadRot = livingEntity == null ? 0 : Mth .rotLerp (pPartialTick , livingEntity .yHeadRotO , livingEntity .yHeadRot );
190
- float netHeadYaw = lerpHeadRot - lerpBodyRot ;
186
+ LivingEntity livingEntity = animatable instanceof LivingEntity e ? e : null ;
187
+ boolean shouldSit = animatable .isPassenger () && animatable .getVehicle () != null ;
191
188
192
- if ( shouldSit && animatable . getVehicle () instanceof LivingEntity livingentity ) {
193
- lerpBodyRot = Mth . rotLerp ( pPartialTick , livingentity . yBodyRotO , livingentity . yBodyRot );
194
- netHeadYaw = lerpHeadRot - lerpBodyRot ;
195
- float clampedHeadYaw = Mth . clamp ( Mth . wrapDegrees ( netHeadYaw ), - 85 , 85 ) ;
196
- lerpBodyRot = lerpHeadRot - clampedHeadYaw ;
189
+ float lerpBodyRot = EntityRenderUtils . getLerpBodyRot ( livingEntity , partialTick );
190
+ float lerpHeadRot = EntityRenderUtils . getLerpHeadRot ( livingEntity , partialTick );
191
+ float [] adjusted = EntityRenderUtils . adjustSittingRotations ( shouldSit , animatable , lerpHeadRot , lerpBodyRot , partialTick ) ;
192
+ lerpBodyRot = adjusted [ 0 ] ;
193
+ float netHeadYaw = adjusted [ 1 ] ;
197
194
198
- if (clampedHeadYaw * clampedHeadYaw > 2500f )
199
- lerpBodyRot += clampedHeadYaw * 0.2f ;
200
-
201
- netHeadYaw = lerpHeadRot - lerpBodyRot ;
202
- }
203
-
204
- if (animatable .getPose () == Pose .SLEEPING && livingEntity != null ) {
205
- Direction bedDirection = livingEntity .getBedOrientation ();
206
-
207
- if (bedDirection != null ) {
208
- float eyePosOffset = livingEntity .getEyeHeight (Pose .STANDING ) - 0.1F ;
209
- pPoseStack .translate (-bedDirection .getStepX () * eyePosOffset , 0 , -bedDirection .getStepZ () * eyePosOffset );
210
- }
211
- }
195
+ if (livingEntity != null )
196
+ EntityRenderUtils .applySleepingTranslation (poseStack , livingEntity );
212
197
213
198
float nativeScale = livingEntity != null ? livingEntity .getScale () : 1 ;
214
- float ageInTicks = animatable .tickCount + pPartialTick ;
215
- float limbSwingAmount = 0 ;
216
- float limbSwing = 0 ;
199
+ float ageInTicks = animatable .tickCount + partialTick ;
217
200
218
- pPoseStack .scale (nativeScale , nativeScale , nativeScale );
219
- applyRotations (animatable , pPoseStack , ageInTicks , lerpBodyRot , pPartialTick , nativeScale );
201
+ poseStack .scale (nativeScale , nativeScale , nativeScale );
202
+ applyRotations (animatable , poseStack , ageInTicks , lerpBodyRot , partialTick , nativeScale );
220
203
221
- if (!shouldSit && animatable .isAlive () && livingEntity != null ) {
222
- limbSwingAmount = livingEntity .walkAnimation .speed (pPartialTick );
223
- limbSwing = livingEntity .walkAnimation .position (pPartialTick );
204
+ float [] limbSwingData = livingEntity != null
205
+ ? EntityRenderUtils .computeLimbSwing (livingEntity , shouldSit , partialTick )
206
+ : new float [] { 0 , 0 };
207
+ float limbSwing = limbSwingData [0 ];
208
+ float limbSwingAmount = limbSwingData [1 ];
224
209
225
- if (livingEntity .isBaby ())
226
- limbSwing *= 3f ;
210
+ if (!isReRender ) {
211
+ float headPitch = Mth .lerp (partialTick , animatable .xRotO , animatable .getXRot ());
212
+ float motionThreshold = getMotionAnimThreshold (pContext );
227
213
228
- if ( limbSwingAmount > 1f )
229
- limbSwingAmount = 1f ;
230
- }
214
+ boolean moving = livingEntity != null
215
+ ? EntityRenderUtils . isEntityMoving ( livingEntity , motionThreshold , limbSwingAmount )
216
+ : ( Math . abs ( limbSwingAmount ) >= motionThreshold );
231
217
232
- if (!pIsReRender ) {
233
- float headPitch = Mth .lerp (pPartialTick , animatable .xRotO , animatable .getXRot ());
234
- float motionThreshold = getMotionAnimThreshold (pContext );
235
- Vec3 velocity = animatable .getDeltaMovement ();
236
- float avgVelocity = (float ) ((Math .abs (velocity .x ) + Math .abs (velocity .z )) / 2f );
237
- AnimationState <T > animationState = new AnimationState <>(animatable , limbSwing , limbSwingAmount , pPartialTick , avgVelocity >= motionThreshold && limbSwingAmount != 0 );
218
+ AnimationState <T > state = new AnimationState <>(animatable , limbSwing , limbSwingAmount , partialTick , moving );
238
219
long instanceId = getInstanceId (pContext );
239
- BlueModel <T > currentModel = getBlueModel ();
240
-
241
- animationState .setData (DataTickets .TICK , animatable .getTick (animatable ));
242
- animationState .setData (DataTickets .ENTITY , animatable );
243
- animationState .setData (DataTickets .ENTITY_MODEL_DATA , new EntityModelData (shouldSit , livingEntity != null && livingEntity .isBaby (), -netHeadYaw , -headPitch ));
244
- currentModel .addAdditionalStateData (animatable , instanceId , animationState ::setData );
245
- currentModel .handleAnimations (animatable , instanceId , animationState , pPartialTick );
220
+ BlueModel <T > model = getBlueModel ();
221
+
222
+ state .setData (DataTickets .TICK , animatable .getTick (animatable ));
223
+ state .setData (DataTickets .ENTITY , animatable );
224
+ state .setData (DataTickets .ENTITY_MODEL_DATA ,
225
+ new EntityModelData (shouldSit , livingEntity != null && livingEntity .isBaby (), -netHeadYaw , -headPitch ));
226
+ model .addAdditionalStateData (animatable , instanceId , state ::setData );
227
+ model .handleAnimations (animatable , instanceId , state , partialTick );
246
228
}
247
229
248
- pPoseStack .translate (0 , 0.01f , 0 );
249
-
250
- this .modelRenderTranslations = new Matrix4f (pPoseStack .last ().pose ());
230
+ poseStack .translate (0 , 0.01f , 0 );
231
+ this .modelRenderTranslations = new Matrix4f (poseStack .last ().pose ());
251
232
252
233
if (buffer != null )
253
234
BlueRenderer .super .actuallyRender (full );
254
235
255
- pPoseStack .popPose ();
236
+ poseStack .popPose ();
256
237
} else if (pContext instanceof BaseRenderContext <T > base ) {
257
238
handleBaseActuallyRenderContext (base , this );
258
239
}
0 commit comments