Difficulty.java

net.minecraft.world.Difficulty

信息

  • 全限定名:net.minecraft.world.Difficulty
  • 类型:public enum
  • 包:net.minecraft.world
  • 源码路径:src/main/java/net/minecraft/world/Difficulty.java
  • 起始行号:L12
  • 实现:StringRepresentable
  • 职责:

    TODO

字段/常量

  • PEACEFUL, EASY, NORMAL, HARD

    • 类型: Difficulty
    • 修饰符: package-private
    • 源码定位: L13
    • 说明:

      TODO

  • CODEC

    • 类型: StringRepresentable.EnumCodec<Difficulty>
    • 修饰符: public static final
    • 源码定位: L18
    • 说明:

      TODO

  • BY_ID

    • 类型: IntFunction<Difficulty>
    • 修饰符: private static final
    • 源码定位: L19
    • 说明:

      TODO

  • STREAM_CODEC

    • 类型: StreamCodec<ByteBuf,Difficulty>
    • 修饰符: public static final
    • 源码定位: L20
    • 说明:

      TODO

  • id

    • 类型: int
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • key

    • 类型: String
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

内部类/嵌套类型

构造器

private Difficulty(int id, String key) @ L24

  • 构造器名:Difficulty
  • 源码定位:L24
  • 修饰符:private

参数:

  • id: int
  • key: String

说明:

TODO

方法

下面的方法块按源码顺序生成。

public int getId() @ L29

  • 方法名:getId
  • 源码定位:L29
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public Component getDisplayName() @ L33

  • 方法名:getDisplayName
  • 源码定位:L33
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

public Component getInfo() @ L37

  • 方法名:getInfo
  • 源码定位:L37
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

public static Difficulty byId(int id) @ L41

  • 方法名:byId
  • 源码定位:L41
  • 返回类型:Difficulty
  • 修饰符:public static

参数:

  • id: int

说明:

TODO

public static Difficulty byName(String name) @ L46

  • 方法名:byName
  • 源码定位:L46
  • 返回类型:Difficulty
  • 修饰符:public static

参数:

  • name: String

说明:

TODO

public String getSerializedName() @ L50

  • 方法名:getSerializedName
  • 源码定位:L50
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

代码

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(), ByIdMap.OutOfBoundsStrategy.WRAP);
    public static final StreamCodec<ByteBuf, Difficulty> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Difficulty::getId);
    private final int id;
    private final String key;
 
    private Difficulty(int id, 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");
    }
 
    @Deprecated
    public static Difficulty byId(int id) {
        return BY_ID.apply(id);
    }
 
    public static @Nullable Difficulty byName(String name) {
        return CODEC.byName(name);
    }
 
    @Override
    public String getSerializedName() {
        return this.key;
    }
}

引用的其他类

  • Component

    • 引用位置: 方法调用/返回值
    • 关联成员: Component.translatable()
  • ByteBufCodecs

    • 引用位置: 方法调用
    • 关联成员: ByteBufCodecs.idMapper()
  • StreamCodec

    • 引用位置: 字段
  • ByIdMap

    • 引用位置: 方法调用
    • 关联成员: ByIdMap.continuous()
  • StringRepresentable

    • 引用位置: 字段/实现/方法调用
    • 关联成员: StringRepresentable.fromEnum()