2323@ Mixin (World .class )
2424public abstract class ClientWorldMixin implements ExtendedBlockView , IWorld , AutoCloseable , TimeSmoother {
2525
26- @ Unique private final EvictingList <Double > points = new EvictingList <>(10 );
27- @ Unique private long lastPacketTimeOfDay = 0 ;
2826 @ Unique private boolean shouldTickDay = true ;
2927
3028 @ Unique private InterpolatedTickProperty timeProperty ;
@@ -39,16 +37,16 @@ protected ClientWorldMixin(
3937 @ Inject (at =@ At ("TAIL" ), method = "<init>" )
4038 private void init (LevelProperties levelProperties , DimensionType dimensionType , BiFunction biFunction , Profiler profiler , boolean bl , CallbackInfo ci ) {
4139 if (this .isClient ) {
42- this .timeProperty = new InterpolatedTickProperty (this ::setTime , this ::getTime );
43- this .dayTimeProperty = new InterpolatedTickProperty (this ::setTimeOfDay , this ::getTimeOfDay );
40+ this .timeProperty = new InterpolatedTickProperty ("time" , this ::setTime , this ::getTime );
41+ this .dayTimeProperty = new InterpolatedTickProperty ("timeOfDay" , this ::setTimeOfDay , this ::getTimeOfDay );
4442 }
4543 }
4644
4745 @ Inject (at =@ At ("HEAD" ), method = "tickTime" , cancellable = true )
4846 public void tickTime (CallbackInfo ci ) {
4947 if (this .isClient ) {
50- timeProperty .increment ();
51- if (shouldTickDay ) dayTimeProperty .increment ();
48+ timeProperty .tick ();
49+ if (shouldTickDay ) dayTimeProperty .tick ();
5250 ci .cancel ();
5351 }
5452 }
@@ -65,39 +63,9 @@ public void tickTime(CallbackInfo ci) {
6563
6664 @ Override
6765 public void asahi$updateTimes (WorldTimeUpdateS2CPacket packet ) {
68- if (lastPacketTimeOfDay == packet .getTimeOfDay ()) {
69- if (!shouldTickDay ) {
70- this .setTimeOfDay (packet .getTimeOfDay ());
71- }
72- shouldTickDay = false ;
73- } else {
74- shouldTickDay = true ;
75- }
76-
77- final int TPS = 20 ;
78- int localDiff = (int ) (packet .getTime () - this .getTime ());
79- if (Math .abs (localDiff ) >= 60 * TPS ) { // SKIP_DURATION
80- this .setTime (packet .getTime ());
81- if (shouldTickDay ) this .setTimeOfDay (packet .getTimeOfDay ());
82- } else {
83- float minMoveFactor = 1f / TPS ; // MIN_MOVE_FACTOR
84- points .add ((double ) (localDiff + TPS ) / TPS );
85- double avg = 0 , weights = 0 ; // weighted average
86- int size = points .size ();
87- for (int i = 0 ; i < size ; i ++) {
88- double weight = size - i + 1 ;
89- weight *= weight ;
90- weights += weight ;
91- avg += points .get (i )*weight ;
92- }
93- avg /= weights ;
94- double factor = avg < 0 ? Math .min (avg , -minMoveFactor ) : Math .max (avg , minMoveFactor );
95- timeProperty .setFactor (factor );
96- dayTimeProperty .setFactor (factor );
66+ shouldTickDay = packet .getTimeOfDay () > 0 ;
9767
98- if (FabricLoader .getInstance ().isDevelopmentEnvironment ())
99- System .out .format ("%s server by %d ticks. Speed: %f\n " , (localDiff < 0 ? "ahead of" : "behind" ), Math .abs (localDiff ), avg );
100- }
101- lastPacketTimeOfDay = packet .getTimeOfDay ();
68+ timeProperty .update (packet .getTime ());
69+ dayTimeProperty .update (shouldTickDay ? packet .getTimeOfDay () : packet .getTimeOfDay ()*-1 );
10270 }
10371}
0 commit comments