UpgradeProgress.java

net.minecraft.util.worldupdate.UpgradeProgress

信息

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

    TODO

字段/常量

  • LOGGER

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

      TODO

  • finished

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

      TODO

  • totalFileFixStats

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

      TODO

  • typeFileFixStats

    • 类型: UpgradeProgress.FileFixStats
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • runningFileFixerStats

    • 类型: UpgradeProgress.FileFixStats
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • totalProgress

    • 类型: float
    • 修饰符: private volatile
    • 源码定位: L25
    • 说明:

      TODO

  • totalChunks

    • 类型: AtomicInteger
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • converted

    • 类型: AtomicInteger
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

  • skipped

    • 类型: AtomicInteger
    • 修饰符: private final
    • 源码定位: L28
    • 说明:

      TODO

  • progressMap

    • 类型: Reference2FloatMap<ResourceKey<Level>>
    • 修饰符: private final
    • 源码定位: L29
    • 说明:

      TODO

  • canceled

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

      TODO

  • dataFixType

    • 类型: DataFixTypes
    • 修饰符: private volatile
    • 源码定位: L31
    • 说明:

      TODO

  • status

    • 类型: UpgradeProgress.Status
    • 修饰符: private volatile
    • 源码定位: L32
    • 说明:

      TODO

  • type

    • 类型: UpgradeProgress.Type
    • 修饰符: private volatile
    • 源码定位: L33
    • 说明:

      TODO

  • lastLoggedProgressTime

    • 类型: AtomicLong
    • 修饰符: private
    • 源码定位: L34
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.util.worldupdate.UpgradeProgress.FileFixStats

    • 类型: class
    • 修饰符: public static
    • 源码定位: L166
    • 说明:

      TODO

  • net.minecraft.util.worldupdate.UpgradeProgress.Noop

    • 类型: class
    • 修饰符: public static
    • 源码定位: L188
    • 说明:

      TODO

  • net.minecraft.util.worldupdate.UpgradeProgress.Status

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

      TODO

  • net.minecraft.util.worldupdate.UpgradeProgress.Type

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

      TODO

构造器

方法

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

public boolean isFinished() @ L36

  • 方法名:isFinished
  • 源码定位:L36
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public void setFinished(boolean finished) @ L40

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

参数:

  • finished: boolean

说明:

TODO

public UpgradeProgress.FileFixStats getTotalFileFixStats() @ L44

  • 方法名:getTotalFileFixStats
  • 源码定位:L44
  • 返回类型:UpgradeProgress.FileFixStats
  • 修饰符:public

参数:

说明:

TODO

public UpgradeProgress.FileFixStats getTypeFileFixStats() @ L48

  • 方法名:getTypeFileFixStats
  • 源码定位:L48
  • 返回类型:UpgradeProgress.FileFixStats
  • 修饰符:public

参数:

说明:

TODO

public UpgradeProgress.FileFixStats getRunningFileFixerStats() @ L52

  • 方法名:getRunningFileFixerStats
  • 源码定位:L52
  • 返回类型:UpgradeProgress.FileFixStats
  • 修饰符:public

参数:

说明:

TODO

public void addTotalFileFixOperations(int additionalFileFixOperations) @ L56

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

参数:

  • additionalFileFixOperations: int

说明:

TODO

public float getTotalProgress() @ L61

  • 方法名:getTotalProgress
  • 源码定位:L61
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public void setTotalProgress(float totalProgress) @ L65

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

参数:

  • totalProgress: float

说明:

TODO

public int getTotalChunks() @ L69

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

参数:

说明:

TODO

public void addTotalChunks(int additionalTotalChunks) @ L73

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

参数:

  • additionalTotalChunks: int

说明:

TODO

public int getConverted() @ L77

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

参数:

说明:

TODO

public void setDimensionProgress(ResourceKey<Level> dimensionKey, float currentProgress) @ L81

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

参数:

  • dimensionKey: ResourceKey
  • currentProgress: float

说明:

TODO

public float getDimensionProgress(ResourceKey<Level> dimensionKey) @ L85

  • 方法名:getDimensionProgress
  • 源码定位:L85
  • 返回类型:float
  • 修饰符:public

参数:

  • dimensionKey: ResourceKey

说明:

TODO

public void incrementConverted() @ L89

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

参数:

说明:

TODO

public int getSkipped() @ L93

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

参数:

说明:

TODO

public void incrementSkipped() @ L97

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

参数:

说明:

TODO

public void incrementFinishedOperations() @ L101

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

参数:

说明:

TODO

public void incrementFinishedOperationsBy(int count) @ L105

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

参数:

  • count: int

说明:

TODO

public void setCanceled() @ L111

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

参数:

说明:

TODO

public boolean isCanceled() @ L115

  • 方法名:isCanceled
  • 源码定位:L115
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

public UpgradeProgress.Status getStatus() @ L119

  • 方法名:getStatus
  • 源码定位:L119
  • 返回类型:UpgradeProgress.Status
  • 修饰符:public

参数:

说明:

TODO

public void setStatus(UpgradeProgress.Status status) @ L123

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

参数:

  • status: UpgradeProgress.Status

说明:

TODO

public DataFixTypes getDataFixType() @ L127

  • 方法名:getDataFixType
  • 源码定位:L127
  • 返回类型:DataFixTypes
  • 修饰符:public

参数:

说明:

TODO

public void setType(UpgradeProgress.Type type) @ L131

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

参数:

  • type: UpgradeProgress.Type

说明:

TODO

public UpgradeProgress.Type getType() @ L136

  • 方法名:getType
  • 源码定位:L136
  • 返回类型:UpgradeProgress.Type
  • 修饰符:public

参数:

说明:

TODO

public void setApplicableFixerAmount(int amount) @ L140

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

参数:

  • amount: int

说明:

TODO

public void incrementRunningFileFixer() @ L144

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

参数:

说明:

TODO

public void reset(DataFixTypes dataFixType) @ L148

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

参数:

  • dataFixType: DataFixTypes

说明:

TODO

public void logProgress() @ L157

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

参数:

说明:

TODO

代码

public class UpgradeProgress {
    private static final Logger LOGGER = LogUtils.getLogger();
    private volatile boolean finished;
    private final UpgradeProgress.FileFixStats totalFileFixStats = new UpgradeProgress.FileFixStats();
    private final UpgradeProgress.FileFixStats typeFileFixStats = new UpgradeProgress.FileFixStats();
    private final UpgradeProgress.FileFixStats runningFileFixerStats = new UpgradeProgress.FileFixStats();
    private volatile float totalProgress;
    private final AtomicInteger totalChunks = new AtomicInteger();
    private final AtomicInteger converted = new AtomicInteger();
    private final AtomicInteger skipped = new AtomicInteger();
    private final Reference2FloatMap<ResourceKey<Level>> progressMap = Reference2FloatMaps.synchronize(new Reference2FloatOpenHashMap<>());
    private volatile boolean canceled = false;
    private volatile @Nullable DataFixTypes dataFixType;
    private volatile UpgradeProgress.Status status = UpgradeProgress.Status.COUNTING;
    private volatile UpgradeProgress.@Nullable Type type;
    private AtomicLong lastLoggedProgressTime = new AtomicLong();
 
    public boolean isFinished() {
        return this.finished;
    }
 
    public void setFinished(boolean finished) {
        this.finished = finished;
    }
 
    public UpgradeProgress.FileFixStats getTotalFileFixStats() {
        return this.totalFileFixStats;
    }
 
    public UpgradeProgress.FileFixStats getTypeFileFixStats() {
        return this.typeFileFixStats;
    }
 
    public UpgradeProgress.FileFixStats getRunningFileFixerStats() {
        return this.runningFileFixerStats;
    }
 
    public void addTotalFileFixOperations(int additionalFileFixOperations) {
        this.totalFileFixStats.totalOperations.addAndGet(additionalFileFixOperations);
        this.typeFileFixStats.totalOperations.addAndGet(additionalFileFixOperations);
    }
 
    public float getTotalProgress() {
        return this.totalProgress;
    }
 
    public void setTotalProgress(float totalProgress) {
        this.totalProgress = totalProgress;
    }
 
    public int getTotalChunks() {
        return this.totalChunks.get();
    }
 
    public void addTotalChunks(int additionalTotalChunks) {
        this.totalChunks.addAndGet(additionalTotalChunks);
    }
 
    public int getConverted() {
        return this.converted.get();
    }
 
    public void setDimensionProgress(ResourceKey<Level> dimensionKey, float currentProgress) {
        this.progressMap.put(dimensionKey, currentProgress);
    }
 
    public float getDimensionProgress(ResourceKey<Level> dimensionKey) {
        return this.progressMap.getFloat(dimensionKey);
    }
 
    public void incrementConverted() {
        this.converted.incrementAndGet();
    }
 
    public int getSkipped() {
        return this.skipped.get();
    }
 
    public void incrementSkipped() {
        this.skipped.incrementAndGet();
    }
 
    public void incrementFinishedOperations() {
        this.incrementFinishedOperationsBy(1);
    }
 
    public void incrementFinishedOperationsBy(int count) {
        this.totalFileFixStats.finishedOperations.addAndGet(count);
        this.typeFileFixStats.finishedOperations.addAndGet(count);
        this.logProgress();
    }
 
    public void setCanceled() {
        this.canceled = true;
    }
 
    public boolean isCanceled() {
        return this.canceled;
    }
 
    public UpgradeProgress.Status getStatus() {
        return this.status;
    }
 
    public void setStatus(UpgradeProgress.Status status) {
        this.status = status;
    }
 
    public @Nullable DataFixTypes getDataFixType() {
        return this.dataFixType;
    }
 
    public void setType(UpgradeProgress.Type type) {
        this.type = type;
        this.typeFileFixStats.reset();
    }
 
    public UpgradeProgress.@Nullable Type getType() {
        return this.type;
    }
 
    public void setApplicableFixerAmount(int amount) {
        this.runningFileFixerStats.totalOperations.set(amount);
    }
 
    public void incrementRunningFileFixer() {
        this.runningFileFixerStats.finishedOperations.incrementAndGet();
    }
 
    public void reset(DataFixTypes dataFixType) {
        this.totalFileFixStats.reset();
        this.typeFileFixStats.reset();
        this.totalChunks.set(0);
        this.converted.set(0);
        this.skipped.set(0);
        this.dataFixType = dataFixType;
    }
 
    public void logProgress() {
        long now = Util.getMillis();
        if (now >= this.lastLoggedProgressTime.get() + 1000L) {
            float progress = (float)this.totalFileFixStats.finishedOperations() / this.totalFileFixStats.totalOperations();
            this.lastLoggedProgressTime.set(now);
            LOGGER.info("Upgrading progress: {}%", (int)(progress * 100.0F));
        }
    }
 
    public static class FileFixStats {
        private final AtomicInteger finishedOperations = new AtomicInteger();
        private final AtomicInteger totalOperations = new AtomicInteger();
 
        public int finishedOperations() {
            return this.finishedOperations.get();
        }
 
        public int totalOperations() {
            return this.totalOperations.get();
        }
 
        public void reset() {
            this.finishedOperations.set(0);
            this.totalOperations.set(0);
        }
 
        public float getProgress() {
            return this.totalOperations() == 0 ? 0.0F : Mth.clamp((float)this.finishedOperations() / this.totalOperations(), 0.0F, 1.0F);
        }
    }
 
    public static class Noop extends UpgradeProgress {
        @Override
        public void setFinished(boolean finished) {
        }
 
        @Override
        public void addTotalFileFixOperations(int additionalFileFixOperations) {
        }
 
        @Override
        public void setTotalProgress(float totalProgress) {
        }
 
        @Override
        public void addTotalChunks(int additionalTotalChunks) {
        }
 
        @Override
        public void setDimensionProgress(ResourceKey<Level> dimensionKey, float currentProgress) {
        }
 
        @Override
        public void incrementConverted() {
        }
 
        @Override
        public void incrementSkipped() {
        }
 
        @Override
        public void incrementFinishedOperations() {
        }
 
        @Override
        public void incrementFinishedOperationsBy(int count) {
        }
 
        @Override
        public void setCanceled() {
        }
 
        @Override
        public void setStatus(UpgradeProgress.Status status) {
        }
 
        @Override
        public void setApplicableFixerAmount(int amount) {
        }
 
        @Override
        public void incrementRunningFileFixer() {
        }
 
        @Override
        public void reset(DataFixTypes dataFixType) {
        }
    }
 
    public static enum Status {
        COUNTING,
        FAILED,
        FINISHED,
        UPGRADING;
    }
 
    public static enum Type implements StringRepresentable {
        FILES("files"),
        LEGACY_STRUCTURES("legacy_structures"),
        REGIONS("regions");
 
        private final String id;
        private final Component label;
 
        private Type(String id) {
            this.id = id;
            this.label = Component.translatable("upgradeWorld.progress.type." + this.getSerializedName());
        }
 
        @Override
        public String getSerializedName() {
            return this.id;
        }
 
        public Component label() {
            return this.label;
        }
    }
}

引用的其他类

  • Component

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

    • 引用位置: 参数/字段
  • Mth

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

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

    • 引用位置: 参数/字段/返回值
  • Level

    • 引用位置: 参数/字段