ResourceLoadStateTracker.java

net.minecraft.client.ResourceLoadStateTracker

信息

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

    TODO

字段/常量

  • LOGGER

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

      TODO

  • reloadState

    • 类型: ResourceLoadStateTracker.ReloadState
    • 修饰符: private
    • 源码定位: L19
    • 说明:

      TODO

  • reloadCount

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.ResourceLoadStateTracker.RecoveryInfo

    • 类型: class
    • 修饰符: private static
    • 源码定位: L59
    • 说明:

      TODO

  • net.minecraft.client.ResourceLoadStateTracker.ReloadReason

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L77
    • 说明:

      TODO

  • net.minecraft.client.ResourceLoadStateTracker.ReloadState

    • 类型: class
    • 修饰符: private static
    • 源码定位: L90
    • 说明:

      TODO

构造器

方法

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

public void startReload(ResourceLoadStateTracker.ReloadReason reloadReason, List<PackResources> packs) @ L22

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

参数:

  • reloadReason: ResourceLoadStateTracker.ReloadReason
  • packs: List

说明:

TODO

public void startRecovery(Throwable reason) @ L33

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

参数:

  • reason: Throwable

说明:

TODO

public void finishReload() @ L42

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

参数:

说明:

TODO

public void fillCrashReport(CrashReport report) @ L50

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

参数:

  • report: CrashReport

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ResourceLoadStateTracker {
    private static final Logger LOGGER = LogUtils.getLogger();
    private ResourceLoadStateTracker.@Nullable ReloadState reloadState;
    private int reloadCount;
 
    public void startReload(ResourceLoadStateTracker.ReloadReason reloadReason, List<PackResources> packs) {
        this.reloadCount++;
        if (this.reloadState != null && !this.reloadState.finished) {
            LOGGER.warn("Reload already ongoing, replacing");
        }
 
        this.reloadState = new ResourceLoadStateTracker.ReloadState(
            reloadReason, packs.stream().map(PackResources::packId).collect(ImmutableList.toImmutableList())
        );
    }
 
    public void startRecovery(Throwable reason) {
        if (this.reloadState == null) {
            LOGGER.warn("Trying to signal reload recovery, but nothing was started");
            this.reloadState = new ResourceLoadStateTracker.ReloadState(ResourceLoadStateTracker.ReloadReason.UNKNOWN, ImmutableList.of());
        }
 
        this.reloadState.recoveryReloadInfo = new ResourceLoadStateTracker.RecoveryInfo(reason);
    }
 
    public void finishReload() {
        if (this.reloadState == null) {
            LOGGER.warn("Trying to finish reload, but nothing was started");
        } else {
            this.reloadState.finished = true;
        }
    }
 
    public void fillCrashReport(CrashReport report) {
        CrashReportCategory category = report.addCategory("Last reload");
        category.setDetail("Reload number", this.reloadCount);
        if (this.reloadState != null) {
            this.reloadState.fillCrashInfo(category);
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private static class RecoveryInfo {
        private final Throwable error;
 
        private RecoveryInfo(Throwable error) {
            this.error = error;
        }
 
        public void fillCrashInfo(CrashReportCategory category) {
            category.setDetail("Recovery", "Yes");
            category.setDetail("Recovery reason", () -> {
                StringWriter writer = new StringWriter();
                this.error.printStackTrace(new PrintWriter(writer));
                return writer.toString();
            });
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum ReloadReason {
        INITIAL("initial"),
        MANUAL("manual"),
        UNKNOWN("unknown");
 
        private final String name;
 
        private ReloadReason(String name) {
            this.name = name;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    private static class ReloadState {
        private final ResourceLoadStateTracker.ReloadReason reloadReason;
        private final List<String> packs;
        private ResourceLoadStateTracker.@Nullable RecoveryInfo recoveryReloadInfo;
        private boolean finished;
 
        private ReloadState(ResourceLoadStateTracker.ReloadReason reloadReason, List<String> packs) {
            this.reloadReason = reloadReason;
            this.packs = packs;
        }
 
        public void fillCrashInfo(CrashReportCategory category) {
            category.setDetail("Reload reason", this.reloadReason.name);
            category.setDetail("Finished", this.finished ? "Yes" : "No");
            category.setDetail("Packs", () -> String.join(", ", this.packs));
            if (this.recoveryReloadInfo != null) {
                this.recoveryReloadInfo.fillCrashInfo(category);
            }
        }
    }
}

引用的其他类