UpgradeStatusTranslator.java

net.minecraft.util.worldupdate.UpgradeStatusTranslator

信息

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

    TODO

字段/常量

  • FAILED

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

      TODO

  • COUNTING

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

      TODO

  • UPGRADING

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

      TODO

内部类/嵌套类型

  • net.minecraft.util.worldupdate.UpgradeStatusTranslator.Messages
    • 类型: record
    • 修饰符: public
    • 源码定位: L36
    • 说明:

      TODO

构造器

方法

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

public Component translate(UpgradeProgress upgradeProgress) @ L19

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

参数:

  • upgradeProgress: UpgradeProgress

说明:

TODO

代码

public class UpgradeStatusTranslator {
    private final Map<DataFixTypes, UpgradeStatusTranslator.Messages> messages = Util.make(new EnumMap<>(DataFixTypes.class), map -> {
        map.put(DataFixTypes.CHUNK, UpgradeStatusTranslator.Messages.create("chunks"));
        map.put(DataFixTypes.ENTITY_CHUNK, UpgradeStatusTranslator.Messages.create("entities"));
        map.put(DataFixTypes.POI_CHUNK, UpgradeStatusTranslator.Messages.create("poi"));
    });
    private static final Component FAILED = Component.translatable("optimizeWorld.stage.failed");
    private static final Component COUNTING = Component.translatable("optimizeWorld.stage.counting");
    private static final Component UPGRADING = Component.translatable("optimizeWorld.stage.upgrading");
 
    public Component translate(UpgradeProgress upgradeProgress) {
        UpgradeProgress.Status status = upgradeProgress.getStatus();
        if (status == UpgradeProgress.Status.FAILED) {
            return FAILED;
        } else if (status == UpgradeProgress.Status.COUNTING) {
            return COUNTING;
        } else {
            DataFixTypes dataFixType = upgradeProgress.getDataFixType();
            if (dataFixType == null) {
                return COUNTING;
            } else {
                UpgradeStatusTranslator.Messages typeMessages = this.messages.get(dataFixType);
                return typeMessages == null ? UPGRADING : typeMessages.forStatus(status);
            }
        }
    }
 
    public record Messages(Component upgrading, Component finished) {
        public static UpgradeStatusTranslator.Messages create(String type) {
            return new UpgradeStatusTranslator.Messages(
                Component.translatable("optimizeWorld.stage.upgrading." + type), Component.translatable("optimizeWorld.stage.finished." + type)
            );
        }
 
        public Component forStatus(UpgradeProgress.Status status) {
            return switch (status) {
                case UPGRADING -> this.upgrading;
                case FINISHED -> this.finished;
                default -> throw new IllegalStateException("Invalid Status received: " + status);
            };
        }
    }
}

引用的其他类

  • Component

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

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

    • 引用位置: 参数