RunningTrimmedMean .java

net.minecraft.client.renderer.RunningTrimmedMean (class, 42 lines): members: registerValueAndGetMean, cursor, values, count. imports: EnvType.

net.minecraft.client.rendererclass42 linesclient943 B

API Surface (1)

long registerValueAndGetMean(final long value)

Fields & Constants (3)

values
count
cursor

Full Source

RunningTrimmedMean.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
6
@Environment(EnvType.CLIENT)
7
public class RunningTrimmedMean {
8
	private final long[] values;
9
	private int count;
10
	private int cursor;
11
12
	public RunningTrimmedMean(final int maxCount) {
13
		this.values = new long[maxCount];
14
	}
15
16
	public long registerValueAndGetMean(final long value) {
17
		if (this.count < this.values.length) {
18
			this.count++;
19
		}
20
21
		this.values[this.cursor] = value;
22
		this.cursor = (this.cursor + 1) % this.values.length;
23
		long min = Long.MAX_VALUE;
24
		long max = Long.MIN_VALUE;
25
		long total = 0L;
26
27
		for (int i = 0; i < this.count; i++) {
28
			long current = this.values[i];
29
			total += current;
30
			min = Math.min(min, current);
31
			max = Math.max(max, current);
32
		}
33
34
		if (this.count > 2) {
35
			total -= min + max;
36
			return total / (this.count - 2);
37
		} else {
38
			return total > 0L ? this.count / total : 0L;
39
		}
40
	}
41
}
42

Decompiled Minecraft 26.3 source of RunningTrimmedMean (net/minecraft/client/renderer/RunningTrimmedMean.java) with Mojang official mappings, stored verbatim on the site.