Bootstrap.java

net.minecraft.server.Bootstrap

信息

  • 全限定名:net.minecraft.server.Bootstrap
  • 类型:public class
  • 包:net.minecraft.server
  • 源码路径:src/main/java/net/minecraft/server/Bootstrap.java
  • 起始行号:L36
  • 职责:

    TODO

字段/常量

  • STDOUT

    • 类型: PrintStream
    • 修饰符: public static final
    • 源码定位: L37
    • 说明:

      TODO

  • isBootstrapped

    • 类型: boolean
    • 修饰符: private static volatile
    • 源码定位: L38
    • 说明:

      TODO

  • LOGGER

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

      TODO

  • bootstrapDuration

    • 类型: AtomicLong
    • 修饰符: public static final
    • 源码定位: L40
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public static void bootStrap() @ L42

  • 方法名:bootStrap
  • 源码定位:L42
  • 返回类型:void
  • 修饰符:public static

参数:

说明:

TODO

private static <T> void checkTranslations(Iterable<T> registry, Function<T,String> descriptionGetter, Set<String> output) @ L66

  • 方法名:checkTranslations
  • 源码定位:L66
  • 返回类型: void
  • 修饰符:private static

参数:

  • registry: Iterable
  • descriptionGetter: Function<T,String>
  • output: Set

说明:

TODO

private static void checkGameruleTranslations(Set<String> missing) @ L76

  • 方法名:checkGameruleTranslations
  • 源码定位:L76
  • 返回类型:void
  • 修饰符:private static

参数:

  • missing: Set

说明:

TODO

public static Set<String> getMissingTranslations() @ L89

  • 方法名:getMissingTranslations
  • 源码定位:L89
  • 返回类型:Set
  • 修饰符:public static

参数:

说明:

TODO

public static void checkBootstrapCalled(Supplier<String> location) @ L101

  • 方法名:checkBootstrapCalled
  • 源码定位:L101
  • 返回类型:void
  • 修饰符:public static

参数:

  • location: Supplier

说明:

TODO

private static RuntimeException createBootstrapException(Supplier<String> location) @ L107

  • 方法名:createBootstrapException
  • 源码定位:L107
  • 返回类型:RuntimeException
  • 修饰符:private static

参数:

  • location: Supplier

说明:

TODO

public static void validate() @ L118

  • 方法名:validate
  • 源码定位:L118
  • 返回类型:void
  • 修饰符:public static

参数:

说明:

TODO

private static void wrapStreams() @ L128

  • 方法名:wrapStreams
  • 源码定位:L128
  • 返回类型:void
  • 修饰符:private static

参数:

说明:

TODO

public static void realStdoutPrintln(String string) @ L138

  • 方法名:realStdoutPrintln
  • 源码定位:L138
  • 返回类型:void
  • 修饰符:public static

参数:

  • string: String

说明:

TODO

public static void shutdownStdout() @ L142

  • 方法名:shutdownStdout
  • 源码定位:L142
  • 返回类型:void
  • 修饰符:public static

参数:

说明:

TODO

代码

@SuppressForbidden(reason = "System.out setup")
public class Bootstrap {
    public static final PrintStream STDOUT = System.out;
    private static volatile boolean isBootstrapped;
    private static final Logger LOGGER = LogUtils.getLogger();
    public static final AtomicLong bootstrapDuration = new AtomicLong(-1L);
 
    public static void bootStrap() {
        if (!isBootstrapped) {
            isBootstrapped = true;
            Instant start = Instant.now();
            if (BuiltInRegistries.REGISTRY.keySet().isEmpty()) {
                throw new IllegalStateException("Unable to load registries");
            } else {
                FireBlock.bootStrap();
                ComposterBlock.bootStrap();
                if (EntityType.getKey(EntityType.PLAYER) == null) {
                    throw new IllegalStateException("Failed loading EntityTypes");
                } else {
                    EntitySelectorOptions.bootStrap();
                    DispenseItemBehavior.bootStrap();
                    CauldronInteractions.bootStrap();
                    BuiltInRegistries.bootStrap();
                    CreativeModeTabs.validate();
                    wrapStreams();
                    bootstrapDuration.set(Duration.between(start, Instant.now()).toMillis());
                }
            }
        }
    }
 
    private static <T> void checkTranslations(Iterable<T> registry, Function<T, String> descriptionGetter, Set<String> output) {
        Language language = Language.getInstance();
        registry.forEach(t -> {
            String id = descriptionGetter.apply((T)t);
            if (!language.has(id)) {
                output.add(id);
            }
        });
    }
 
    private static void checkGameruleTranslations(Set<String> missing) {
        final Language language = Language.getInstance();
        GameRules rules = new GameRules(FeatureFlags.REGISTRY.allFlags());
        rules.visitGameRuleTypes(new GameRuleTypeVisitor() {
            @Override
            public <T> void visit(GameRule<T> gameRule) {
                if (!language.has(gameRule.getDescriptionId())) {
                    missing.add(gameRule.id());
                }
            }
        });
    }
 
    public static Set<String> getMissingTranslations() {
        Set<String> missing = new TreeSet<>();
        checkTranslations(BuiltInRegistries.ATTRIBUTE, Attribute::getDescriptionId, missing);
        checkTranslations(BuiltInRegistries.ENTITY_TYPE, EntityType::getDescriptionId, missing);
        checkTranslations(BuiltInRegistries.MOB_EFFECT, MobEffect::getDescriptionId, missing);
        checkTranslations(BuiltInRegistries.ITEM, Item::getDescriptionId, missing);
        checkTranslations(BuiltInRegistries.BLOCK, BlockBehaviour::getDescriptionId, missing);
        checkTranslations(BuiltInRegistries.CUSTOM_STAT, id -> "stat." + id.toString().replace(':', '.'), missing);
        checkGameruleTranslations(missing);
        return missing;
    }
 
    public static void checkBootstrapCalled(Supplier<String> location) {
        if (!isBootstrapped) {
            throw createBootstrapException(location);
        }
    }
 
    private static RuntimeException createBootstrapException(Supplier<String> location) {
        try {
            String resolvedLocation = location.get();
            return new IllegalArgumentException("Not bootstrapped (called from " + resolvedLocation + ")");
        } catch (Exception var3) {
            RuntimeException result = new IllegalArgumentException("Not bootstrapped (failed to resolve location)");
            result.addSuppressed(var3);
            return result;
        }
    }
 
    public static void validate() {
        checkBootstrapCalled(() -> "validate");
        if (SharedConstants.IS_RUNNING_IN_IDE) {
            getMissingTranslations().forEach(key -> LOGGER.error("Missing translations: {}", key));
            Commands.validate();
        }
 
        DefaultAttributes.validate();
    }
 
    private static void wrapStreams() {
        if (LOGGER.isDebugEnabled()) {
            System.setErr(new DebugLoggedPrintStream("STDERR", System.err));
            System.setOut(new DebugLoggedPrintStream("STDOUT", STDOUT));
        } else {
            System.setErr(new LoggedPrintStream("STDERR", System.err));
            System.setOut(new LoggedPrintStream("STDOUT", STDOUT));
        }
    }
 
    public static void realStdoutPrintln(String string) {
        STDOUT.println(string);
    }
 
    public static void shutdownStdout() {
        STDOUT.close();
    }
}

引用的其他类

  • LoggedChatMessage

    • 引用位置: 方法调用
    • 关联成员: System.setErr(), System.setOut()
  • Commands

    • 引用位置: 方法调用
    • 关联成员: Commands.validate()
  • EntitySelectorOptions

    • 引用位置: 方法调用
    • 关联成员: EntitySelectorOptions.bootStrap()
  • CauldronInteractions

    • 引用位置: 方法调用
    • 关联成员: CauldronInteractions.bootStrap()
  • DispenseItemBehavior

    • 引用位置: 方法调用
    • 关联成员: DispenseItemBehavior.bootStrap()
  • BuiltInRegistries

    • 引用位置: 方法调用
    • 关联成员: BuiltInRegistries.bootStrap()
  • Language

    • 引用位置: 方法调用
    • 关联成员: Language.getInstance()
  • DebugLoggedPrintStream

    • 引用位置: 构造调用
    • 关联成员: DebugLoggedPrintStream()
  • LoggedPrintStream

    • 引用位置: 构造调用
    • 关联成员: LoggedPrintStream()
  • EntityType

    • 引用位置: 方法调用
    • 关联成员: EntityType.getKey()
  • DefaultAttributes

    • 引用位置: 方法调用
    • 关联成员: DefaultAttributes.validate()
  • CreativeModeTabs

    • 引用位置: 方法调用
    • 关联成员: CreativeModeTabs.validate()
  • ComposterBlock

    • 引用位置: 方法调用
    • 关联成员: ComposterBlock.bootStrap()
  • FireBlock

    • 引用位置: 方法调用
    • 关联成员: FireBlock.bootStrap()
  • GameRuleTypeVisitor

    • 引用位置: 构造调用
    • 关联成员: GameRuleTypeVisitor()
  • GameRules

    • 引用位置: 构造调用
    • 关联成员: GameRules()