Skip to content

Commit 2e48516

Browse files
committed
fix: sun bouncing around after time change
1 parent 84fc4db commit 2e48516

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/main/java/dev/hugeblank/asahi/client/InterpolatedTickProperty.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,25 @@ public void tick() {
3232
}
3333

3434
public void update(long serverValue) {
35-
int localDiff = (int) (serverValue - getProperty.get());
36-
float minMoveFactor = 1f / TPS; // MIN_MOVE_FACTOR
37-
points.add((double) (localDiff + TPS) / TPS);
38-
double avg = 0, weights = 0; // weighted average
39-
int size = points.size();
40-
for (int i = 0; i < size; i++) {
41-
double weight = size - i + 1;
42-
weight *= weight;
43-
weights += weight;
44-
avg += points.get(i) * weight;
45-
}
46-
avg /= weights;
47-
double factor = avg < 0 ? Math.min(avg, -minMoveFactor) : Math.max(avg, minMoveFactor);
4835

4936
// If the next value would take more than 60 seconds at the current TPS to reach, just skip to the position.
5037
if (Math.abs(serverValue-getProperty.get()) >= 60 * TPS) {
5138
this.factor = 1;
5239
setProperty.accept(serverValue);
5340
} else {
54-
this.factor = factor;
41+
int localDiff = (int) (serverValue - getProperty.get());
42+
float minMoveFactor = 1f / TPS; // MIN_MOVE_FACTOR
43+
points.add((double) (localDiff + TPS) / TPS);
44+
double avg = 0, weights = 0; // weighted average
45+
int size = points.size();
46+
for (int i = 0; i < size; i++) {
47+
double weight = size - i + 1;
48+
weight *= weight;
49+
weights += weight;
50+
avg += points.get(i) * weight;
51+
}
52+
avg /= weights;
53+
this.factor = avg < 0 ? Math.min(avg, -minMoveFactor) : Math.max(avg, minMoveFactor);
5554
if (FabricLoader.getInstance().isDevelopmentEnvironment())
5655
System.out.format("%s: %s server by %d ticks. Speed: %f\n", prefix, (localDiff < 0 ? "ahead of" : "behind"), Math.abs(localDiff), avg);
5756
}

0 commit comments

Comments
 (0)