55 lines
1.4 KiB
Java
55 lines
1.4 KiB
Java
package net.minecraft.world;
|
|
|
|
import java.util.function.IntFunction;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.util.ByIdMap;
|
|
import net.minecraft.util.StringRepresentable;
|
|
import net.minecraft.util.ByIdMap.OutOfBoundsStrategy;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public enum Difficulty implements StringRepresentable {
|
|
PEACEFUL(0, "peaceful"),
|
|
EASY(1, "easy"),
|
|
NORMAL(2, "normal"),
|
|
HARD(3, "hard");
|
|
|
|
public static final StringRepresentable.EnumCodec<Difficulty> CODEC = StringRepresentable.fromEnum(Difficulty::values);
|
|
private static final IntFunction<Difficulty> BY_ID = ByIdMap.continuous(Difficulty::getId, values(), OutOfBoundsStrategy.WRAP);
|
|
private final int id;
|
|
private final String key;
|
|
|
|
private Difficulty(final int id, final String key) {
|
|
this.id = id;
|
|
this.key = key;
|
|
}
|
|
|
|
public int getId() {
|
|
return this.id;
|
|
}
|
|
|
|
public Component getDisplayName() {
|
|
return Component.translatable("options.difficulty." + this.key);
|
|
}
|
|
|
|
public Component getInfo() {
|
|
return Component.translatable("options.difficulty." + this.key + ".info");
|
|
}
|
|
|
|
public static Difficulty byId(int id) {
|
|
return (Difficulty)BY_ID.apply(id);
|
|
}
|
|
|
|
@Nullable
|
|
public static Difficulty byName(String name) {
|
|
return (Difficulty)CODEC.byName(name);
|
|
}
|
|
|
|
public String getKey() {
|
|
return this.key;
|
|
}
|
|
|
|
@Override
|
|
public String getSerializedName() {
|
|
return this.key;
|
|
}
|
|
}
|