StatsCounter .java

net.minecraft.stats.StatsCounter (class, 32 lines): members: increment, stats, setValue, getValue. imports: Object2IntMaps, Object2IntOpenHashMap, Player.

net.minecraft.statsclass32 linescommon981 B

API Surface (4)

void increment(final Player player, final Stat<?> stat, final int count)
void setValue(final Player player, final Stat<?> stat, final int count)
<T> int getValue(final StatType<T> type, final T key)
int getValue(final Stat<?> stat)

Fields & Constants (1)

stats

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

StatsCounter.java32 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.stats;
2
3
import it.unimi.dsi.fastutil.objects.Object2IntMap;
4
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
5
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
6
import net.minecraft.world.entity.player.Player;
7
8
public class StatsCounter {
9
	protected final Object2IntMap<Stat<?>> stats = Object2IntMaps.synchronize(new Object2IntOpenHashMap<>());
10
11
	public StatsCounter() {
12
		this.stats.defaultReturnValue(0);
13
	}
14
15
	public void increment(final Player player, final Stat<?> stat, final int count) {
16
		int result = (int)Math.min((long)this.getValue(stat) + count, 2147483647L);
17
		this.setValue(player, stat, result);
18
	}
19
20
	public void setValue(final Player player, final Stat<?> stat, final int count) {
21
		this.stats.put(stat, count);
22
	}
23
24
	public <T> int getValue(final StatType<T> type, final T key) {
25
		return type.contains(key) ? this.getValue(type.get(key)) : 0;
26
	}
27
28
	public int getValue(final Stat<?> stat) {
29
		return this.stats.getInt(stat);
30
	}
31
}
32

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