@@ -39,7 +39,7 @@ public void physicsTick(final double partialPhysicsTick, final double timeStep,
3939 this .containers .clear ();
4040 this .containers .add (this .sublevelContainer );
4141
42- for (final KinematicContraption contraption : this .subLevel .getPlot ().getContraptions ()) {
42+ for (final KinematicContraption contraption : this .subLevel .getPlot ().getContraptions ()) {
4343 final FloatingClusterContainer container = contraption .sable$getFloatingClusterContainer ();
4444
4545 final Vector3dc lastPosition = new Vector3d (contraption .sable$getPosition (partialPhysicsTick - 1.0f ));
@@ -64,7 +64,7 @@ public void physicsTick(final double partialPhysicsTick, final double timeStep,
6464
6565 localGravity .set (DimensionPhysicsData .getGravity (this .subLevel .getLevel (), this .subLevel .logicalPose ().position ()));
6666 this .subLevel .logicalPose ().orientation ().transformInverse (localGravity );
67- if (!this .needsTicking ())
67+ if (!this .needsTicking ())
6868 return ;
6969
7070 this .subLevel .logicalPose ().orientation ().transformInverse (linearVelocity , localLinearVelocity );
@@ -82,10 +82,10 @@ public void physicsTick(final double partialPhysicsTick, final double timeStep,
8282 if (cluster .getMaterial ().scaleWithPressure ())
8383 cluster .getBlockData ().computePressureScale (this .subLevel );
8484
85- this .applyFriction (container ,cluster , localGravity , localLinearVelocity , localAngularVelocity , clusterFrictionForce , clusterFrictionTorque );
85+ this .applyFriction (container , cluster , localGravity , localLinearVelocity , localAngularVelocity , clusterFrictionForce , clusterFrictionTorque );
8686
8787 final Vector3d recordedClusterFrictionForce = new Vector3d (clusterFrictionForce );
88- this .recordForce (container ,cluster , dragGroup , recordedClusterFrictionForce );
88+ this .recordForce (container , cluster , dragGroup , recordedClusterFrictionForce );
8989 recordedFrictionForces .add (recordedClusterFrictionForce );
9090
9191 frictionForce .add (clusterFrictionForce );
@@ -113,19 +113,18 @@ public void physicsTick(final double partialPhysicsTick, final double timeStep,
113113 for (final Vector3d force : recordedFrictionForces ) {
114114 force .mul (timeStep );//forceScale *
115115 }
116- if (localGravity .lengthSquared ()> 0 )
116+ if (localGravity .lengthSquared () > 0 )
117117 this .applyLift (localGravity , linearImpulse , angularImpulse , timeStep );
118118
119119 linearImpulse .fma (timeStep , frictionForce );
120120 angularImpulse .fma (timeStep , frictionTorque );
121121 }
122122
123- public boolean needsTicking ()
124- {
125- if (this .sublevelContainer .needsTicking ())
123+ public boolean needsTicking () {
124+ if (this .sublevelContainer .needsTicking ())
126125 return true ;
127126 for (final FloatingClusterContainer container : this .containers ) {
128- if (container .needsTicking ())
127+ if (container .needsTicking ())
129128 return true ;
130129 }
131130 return false ;
@@ -174,7 +173,7 @@ private void applyLift(final Vector3d localGravity, final Vector3d linearImpulse
174173 //unit: strength * weight
175174 final double weightedForce = clusterForce * cluster .getBlockData ().totalScale ;
176175
177- this .getTrueWeightedClusterPosition (container ,cluster ,weightedPositionTemp );
176+ this .getTrueWeightedClusterPosition (container , cluster , weightedPositionTemp );
178177
179178 if (material .preventSelfLift ()) {
180179 totalForce += weightedForce ;
@@ -186,7 +185,7 @@ private void applyLift(final Vector3d localGravity, final Vector3d linearImpulse
186185 if (this .subLevel .isTrackingIndividualQueuedForces ()) {
187186 final QueuedForceGroup levitationGroup = this .subLevel .getOrCreateQueuedForceGroup (ForceGroups .LEVITATION .get ());
188187
189- this .recordForce (container ,cluster , levitationGroup , new Vector3d (localGravity ).mul (-weightedForce * timeStep ));
188+ this .recordForce (container , cluster , levitationGroup , new Vector3d (localGravity ).mul (-weightedForce * timeStep ));
190189 }
191190
192191 localGravity .cross (weightedPositionTemp , torqueTemp );//torqueTemp unit: weight * position * gravity
@@ -226,7 +225,7 @@ private void applyLift(final Vector3d localGravity, final Vector3d linearImpulse
226225 final Vector3d force = new Vector3d (localGravity ).mul (timeStep * -cluster .getBlockData ().totalScale * material .liftStrength ());
227226 force .mul (scaleFactor );
228227
229- this .recordForce (container ,cluster , levitationGroup , force );
228+ this .recordForce (container , cluster , levitationGroup , force );
230229 }
231230 }
232231 }
@@ -237,13 +236,13 @@ private void applyLift(final Vector3d localGravity, final Vector3d linearImpulse
237236 angularImpulse .fma (timeStep , liftingTorque );
238237 }
239238
240- private void recordForce (final FloatingClusterContainer container ,final FloatingBlockCluster cluster , final QueuedForceGroup forceGroup , final Vector3d force ) {
241- forceGroup .recordPointForce (this .getTrueWeightedClusterPosition (container ,cluster ,new Vector3d ()).div (cluster .getBlockData ().totalScale ).add (this .subLevel .getMassTracker ().getCenterOfMass ()), force );
239+ private void recordForce (final FloatingClusterContainer container , final FloatingBlockCluster cluster , final QueuedForceGroup forceGroup , final Vector3d force ) {
240+ forceGroup .recordPointForce (this .getTrueWeightedClusterPosition (container , cluster , new Vector3d ()).div (cluster .getBlockData ().totalScale ).add (this .subLevel .getMassTracker ().getCenterOfMass ()), force );
242241 }
243- private Vector3d getTrueWeightedClusterPosition ( final FloatingClusterContainer container , final FloatingBlockCluster cluster , final Vector3d pos )
244- {
245- container .rotationOffset .transform (cluster .getBlockData ().weightedPosition ,pos );
246- return pos .fma (cluster .getBlockData ().totalScale ,container .positionOffset );
242+
243+ private Vector3d getTrueWeightedClusterPosition ( final FloatingClusterContainer container , final FloatingBlockCluster cluster , final Vector3d pos ) {
244+ container .rotationOffset .transform (cluster .getBlockData ().weightedPosition , pos );
245+ return pos .fma (cluster .getBlockData ().totalScale , container .positionOffset );
247246 }
248247
249248 private static final Matrix3d containerRotation = new Matrix3d ();
@@ -261,10 +260,10 @@ private Vector3d getTrueWeightedClusterPosition(final FloatingClusterContainer c
261260 private static final Vector3d shiftedCenter = new Vector3d ();
262261 private static final Vector3d linearSlowDrag = new Vector3d ();
263262
264- private void applyFriction (final FloatingClusterContainer container ,final FloatingBlockCluster cluster , final Vector3dc localGravity , final Vector3dc linearVelocity , final Vector3dc angularVelocity , final Vector3d frictionForce , final Vector3d frictionTorque ) {
263+ private void applyFriction (final FloatingClusterContainer container , final FloatingBlockCluster cluster , final Vector3dc localGravity , final Vector3dc linearVelocity , final Vector3dc angularVelocity , final Vector3d frictionForce , final Vector3d frictionTorque ) {
265264
266265 double frictionScale = 1 ;
267- if (cluster .getMaterial ().scaleWithGravity ())
266+ if (cluster .getMaterial ().scaleWithGravity ())
268267 frictionScale = localGravity .length ();
269268 if (cluster .getMaterial ().scaleWithPressure ())
270269 frictionScale *= cluster .getBlockData ().getPressureScale ();
@@ -274,7 +273,7 @@ private void applyFriction(final FloatingClusterContainer container,final Floati
274273 speedScale = 0 ;
275274
276275 totalAngularVelocity .set (angularVelocity ).add (container .angularVelocity );
277- this .getTrueWeightedClusterPosition (container ,cluster ,clusterCenter ).div (cluster .getBlockData ().totalScale );
276+ this .getTrueWeightedClusterPosition (container , cluster , clusterCenter ).div (cluster .getBlockData ().totalScale );
278277
279278 cluster .getBlockData ().outerProduct .scale (1 / cluster .getBlockData ().totalScale , averagePositionMatrix );
280279
@@ -291,8 +290,8 @@ private void applyFriction(final FloatingClusterContainer container,final Floati
291290
292291 //velocity of the center of lift in local space
293292 angularVelocity .cross (clusterCenter , meanVelocity );
294- container .rotationOffset .transform (cluster .getBlockData ().weightedPosition ,rotatedPos ).div (cluster .getBlockData ().totalScale );
295- final Vector3d extraContainerVelocity = container .angularVelocity .cross (rotatedPos ,rotatedPos );
293+ container .rotationOffset .transform (cluster .getBlockData ().weightedPosition , rotatedPos ).div (cluster .getBlockData ().totalScale );
294+ final Vector3d extraContainerVelocity = container .angularVelocity .cross (rotatedPos , rotatedPos );
296295 meanVelocity .add (linearVelocity ).add (container .velocity ).add (extraContainerVelocity );
297296
298297 //center of the shifted position distribution relative to clusterCenter, variance is shiftedPositionMatrix
@@ -343,7 +342,7 @@ private void matrixThingy(final Matrix3dc X, final Matrix3dc Y, final Matrix3d o
343342 }
344343
345344 private Matrix3d getGravityMatrix (final Vector3dc g , final double verticalDrag , final double horizontalDrag , final Matrix3d target ) {
346- if (g .lengthSquared () > 0.00001 )
345+ if (g .lengthSquared () > 0.00001 )
347346 SableMathUtils .setOuterProduct (g , g , (horizontalDrag - verticalDrag ) / g .dot (g ), target );
348347 else
349348 target .identity ();
@@ -365,31 +364,31 @@ private double getClampingFactor(final Vector3dc currentVelocity, final Vector3d
365364 return v * (1 - Math .exp (-k / v )) / k ;
366365 }
367366
368- private double getKineticClampingFactor (final Vector3dc currentLinearVelocity ,final Vector3dc currentAngularVelocity ,final Vector3d frictionForce ,final Vector3d frictionTorque ,final double timestep ) {
367+ private double getKineticClampingFactor (final Vector3dc currentLinearVelocity , final Vector3dc currentAngularVelocity , final Vector3d frictionForce , final Vector3d frictionTorque , final double timestep ) {
369368
370369 final double numerator = currentLinearVelocity .dot (frictionForce ) + currentAngularVelocity .dot (frictionTorque );
371- double denominator = frictionForce .dot (frictionForce )* this .subLevel .getMassTracker ().getInverseMass () +
372- SableMathUtils .multiplyInnerProduct (frictionTorque , this .subLevel .getMassTracker ().getInverseInertiaTensor (),frictionTorque );
373- denominator *= timestep ;
374- if (denominator < 1E-10 )
370+ double denominator = frictionForce .dot (frictionForce ) * this .subLevel .getMassTracker ().getInverseMass () +
371+ SableMathUtils .multiplyInnerProduct (frictionTorque , this .subLevel .getMassTracker ().getInverseInertiaTensor (), frictionTorque );
372+ denominator *= timestep ;
373+ if (denominator < 1E-10 )
375374 return 1 ;
376- final double t = -numerator / denominator ;
377- return Math .max (Math .min (t ,1 ),0 );
375+ final double t = -numerator / denominator ;
376+ return Math .max (Math .min (t , 1 ), 0 );
378377 }
379378
380379 public void addFloatingBlock (final BlockState state , final Vector3d pos ) {
381- this .sublevelContainer .addFloatingBlock (state ,pos );
380+ this .sublevelContainer .addFloatingBlock (state , pos );
382381 }
383382
384383 public void removeFloatingBlock (final BlockState state , final Vector3d pos ) {
385- this .sublevelContainer .removeFloatingBlock (state ,pos );
384+ this .sublevelContainer .removeFloatingBlock (state , pos );
386385 }
387386
388387 public void queueAddFloatingBlock (final BlockState state , final BlockPos pos ) {
389- this .sublevelContainer .queueAddFloatingBlock (state ,pos );
388+ this .sublevelContainer .queueAddFloatingBlock (state , pos );
390389 }
391390
392391 public void queueRemoveFloatingBlock (final BlockState state , final BlockPos pos ) {
393- this .sublevelContainer .queueRemoveFloatingBlock (state ,pos );
392+ this .sublevelContainer .queueRemoveFloatingBlock (state , pos );
394393 }
395394}
0 commit comments