68 lines
2.1 KiB
Java
68 lines
2.1 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.stats;
|
|
|
|
import java.util.Objects;
|
|
import net.minecraft.core.registries.BuiltInRegistries;
|
|
import net.minecraft.core.registries.Registries;
|
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
|
import net.minecraft.network.codec.ByteBufCodecs;
|
|
import net.minecraft.network.codec.StreamCodec;
|
|
import net.minecraft.resources.Identifier;
|
|
import net.minecraft.stats.StatFormatter;
|
|
import net.minecraft.stats.StatType;
|
|
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class Stat<T>
|
|
extends ObjectiveCriteria {
|
|
public static final StreamCodec<RegistryFriendlyByteBuf, Stat<?>> STREAM_CODEC = ByteBufCodecs.registry(Registries.STAT_TYPE).dispatch(Stat::getType, StatType::streamCodec);
|
|
private final StatFormatter formatter;
|
|
private final T value;
|
|
private final StatType<T> type;
|
|
|
|
protected Stat(StatType<T> type, T value, StatFormatter formatter) {
|
|
super(Stat.buildName(type, value));
|
|
this.type = type;
|
|
this.formatter = formatter;
|
|
this.value = value;
|
|
}
|
|
|
|
public static <T> String buildName(StatType<T> type, T value) {
|
|
return Stat.locationToKey(BuiltInRegistries.STAT_TYPE.getKey(type)) + ":" + Stat.locationToKey(type.getRegistry().getKey(value));
|
|
}
|
|
|
|
private static String locationToKey(@Nullable Identifier location) {
|
|
return location.toString().replace(':', '.');
|
|
}
|
|
|
|
public StatType<T> getType() {
|
|
return this.type;
|
|
}
|
|
|
|
public T getValue() {
|
|
return this.value;
|
|
}
|
|
|
|
public String format(int value) {
|
|
return this.formatter.format(value);
|
|
}
|
|
|
|
public boolean equals(Object o) {
|
|
return this == o || o instanceof Stat && Objects.equals(this.getName(), ((Stat)o).getName());
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.getName().hashCode();
|
|
}
|
|
|
|
public String toString() {
|
|
return "Stat{name=" + this.getName() + ", formatter=" + String.valueOf(this.formatter) + "}";
|
|
}
|
|
}
|
|
|