EnchantmentNames.java

net.minecraft.client.gui.screens.inventory.EnchantmentNames

信息

  • 全限定名:net.minecraft.client.gui.screens.inventory.EnchantmentNames
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.inventory
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/inventory/EnchantmentNames.java
  • 起始行号:L15
  • 职责:

    TODO

字段/常量

  • ALT_FONT

    • 类型: FontDescription
    • 修饰符: private static final
    • 源码定位: L16
    • 说明:

      TODO

  • ROOT_STYLE

    • 类型: Style
    • 修饰符: private static final
    • 源码定位: L17
    • 说明:

      TODO

  • INSTANCE

    • 类型: EnchantmentNames
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

  • random

    • 类型: RandomSource
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • words

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

      TODO

内部类/嵌套类型

构造器

private EnchantmentNames() @ L85

  • 构造器名:EnchantmentNames
  • 源码定位:L85
  • 修饰符:private

参数:

说明:

TODO

方法

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

public static EnchantmentNames getInstance() @ L88

  • 方法名:getInstance
  • 源码定位:L88
  • 返回类型:EnchantmentNames
  • 修饰符:public static

参数:

说明:

TODO

public FormattedText getRandomName(Font font, int maxWidth) @ L92

  • 方法名:getRandomName
  • 源码定位:L92
  • 返回类型:FormattedText
  • 修饰符:public

参数:

  • font: Font
  • maxWidth: int

说明:

TODO

public void initSeed(long seed) @ L107

  • 方法名:initSeed
  • 源码定位:L107
  • 返回类型:void
  • 修饰符:public

参数:

  • seed: long

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class EnchantmentNames {
    private static final FontDescription ALT_FONT = new FontDescription.Resource(Identifier.withDefaultNamespace("alt"));
    private static final Style ROOT_STYLE = Style.EMPTY.withFont(ALT_FONT);
    private static final EnchantmentNames INSTANCE = new EnchantmentNames();
    private final RandomSource random = RandomSource.create();
    private final String[] words = new String[]{
        "the",
        "elder",
        "scrolls",
        "klaatu",
        "berata",
        "niktu",
        "xyzzy",
        "bless",
        "curse",
        "light",
        "darkness",
        "fire",
        "air",
        "earth",
        "water",
        "hot",
        "dry",
        "cold",
        "wet",
        "ignite",
        "snuff",
        "embiggen",
        "twist",
        "shorten",
        "stretch",
        "fiddle",
        "destroy",
        "imbue",
        "galvanize",
        "enchant",
        "free",
        "limited",
        "range",
        "of",
        "towards",
        "inside",
        "sphere",
        "cube",
        "self",
        "other",
        "ball",
        "mental",
        "physical",
        "grow",
        "shrink",
        "demon",
        "elemental",
        "spirit",
        "animal",
        "creature",
        "beast",
        "humanoid",
        "undead",
        "fresh",
        "stale",
        "phnglui",
        "mglwnafh",
        "cthulhu",
        "rlyeh",
        "wgahnagl",
        "fhtagn",
        "baguette"
    };
 
    private EnchantmentNames() {
    }
 
    public static EnchantmentNames getInstance() {
        return INSTANCE;
    }
 
    public FormattedText getRandomName(Font font, int maxWidth) {
        StringBuilder result = new StringBuilder();
        int wordCount = this.random.nextInt(2) + 3;
 
        for (int i = 0; i < wordCount; i++) {
            if (i != 0) {
                result.append(" ");
            }
 
            result.append(Util.getRandom(this.words, this.random));
        }
 
        return font.getSplitter().headByWidth(Component.literal(result.toString()).withStyle(ROOT_STYLE), maxWidth, Style.EMPTY);
    }
 
    public void initSeed(long seed) {
        this.random.setSeed(seed);
    }
}

引用的其他类

  • Font

    • 引用位置: 参数
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.literal()
  • FontDescription

    • 引用位置: 字段/方法调用/构造调用
    • 关联成员: FontDescription.Resource(), Resource()
  • FormattedText

    • 引用位置: 返回值
  • Style

    • 引用位置: 字段
  • Identifier

    • 引用位置: 方法调用
    • 关联成员: Identifier.withDefaultNamespace()
  • RandomSource

    • 引用位置: 字段/方法调用
    • 关联成员: RandomSource.create()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.getRandom()