StatsCounter.java
net.minecraft.stats.StatsCounter
信息
- 全限定名:net.minecraft.stats.StatsCounter
- 类型:public class
- 包:net.minecraft.stats
- 源码路径:src/main/java/net/minecraft/stats/StatsCounter.java
- 起始行号:L8
- 职责:
TODO
字段/常量
stats- 类型:
Object2IntMap<Stat<?>> - 修饰符:
protected final - 源码定位:
L9 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public StatsCounter() @ L11
- 构造器名:StatsCounter
- 源码定位:L11
- 修饰符:public
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void increment(Player player, Stat<?> stat, int count) @ L15
- 方法名:increment
- 源码定位:L15
- 返回类型:void
- 修饰符:public
参数:
- player: Player
- stat: Stat<?>
- count: int
说明:
TODO
public void setValue(Player player, Stat<?> stat, int count) @ L20
- 方法名:setValue
- 源码定位:L20
- 返回类型:void
- 修饰符:public
参数:
- player: Player
- stat: Stat<?>
- count: int
说明:
TODO
public <T> int getValue(StatType<T> type, T key) @ L24
- 方法名:getValue
- 源码定位:L24
- 返回类型:
int - 修饰符:public
参数:
- type: StatType
- key: T
说明:
TODO
public int getValue(Stat<?> stat) @ L28
- 方法名:getValue
- 源码定位:L28
- 返回类型:int
- 修饰符:public
参数:
- stat: Stat<?>
说明:
TODO
代码
public class StatsCounter {
protected final Object2IntMap<Stat<?>> stats = Object2IntMaps.synchronize(new Object2IntOpenHashMap<>());
public StatsCounter() {
this.stats.defaultReturnValue(0);
}
public void increment(Player player, Stat<?> stat, int count) {
int result = (int)Math.min((long)this.getValue(stat) + count, 2147483647L);
this.setValue(player, stat, result);
}
public void setValue(Player player, Stat<?> stat, int count) {
this.stats.put(stat, count);
}
public <T> int getValue(StatType<T> type, T key) {
return type.contains(key) ? this.getValue(type.get(key)) : 0;
}
public int getValue(Stat<?> stat) {
return this.stats.getInt(stat);
}
}