LevelLoadProgressTracker.java

net.minecraft.server.level.progress.LevelLoadProgressTracker

信息

  • 全限定名:net.minecraft.server.level.progress.LevelLoadProgressTracker
  • 类型:public class
  • 包:net.minecraft.server.level.progress
  • 源码路径:src/main/java/net/minecraft/server/level/progress/LevelLoadProgressTracker.java
  • 起始行号:L8
  • 实现:LevelLoadListener
  • 职责:

    TODO

字段/常量

  • PREPARE_SERVER_WEIGHT

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

      TODO

  • EXPECTED_PLAYER_CHUNKS

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

      TODO

  • includePlayerChunks

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L11
    • 说明:

      TODO

  • totalWeight

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

      TODO

  • finalizedWeight

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

      TODO

  • segmentWeight

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

      TODO

  • segmentFraction

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

      TODO

  • progress

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

      TODO

内部类/嵌套类型

构造器

public LevelLoadProgressTracker(boolean includePlayerChunks) @ L18

  • 构造器名:LevelLoadProgressTracker
  • 源码定位:L18
  • 修饰符:public

参数:

  • includePlayerChunks: boolean

说明:

TODO

方法

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

public void start(LevelLoadListener.Stage stage, int totalChunks) @ L22

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

参数:

  • stage: LevelLoadListener.Stage
  • totalChunks: int

说明:

TODO

private void beginSegment(int weight) @ L39

  • 方法名:beginSegment
  • 源码定位:L39
  • 返回类型:void
  • 修饰符:private

参数:

  • weight: int

说明:

TODO

public void update(LevelLoadListener.Stage stage, int currentChunks, int totalChunks) @ L45

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

参数:

  • stage: LevelLoadListener.Stage
  • currentChunks: int
  • totalChunks: int

说明:

TODO

public void finish(LevelLoadListener.Stage stage) @ L53

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

参数:

  • stage: LevelLoadListener.Stage

说明:

TODO

private void finishSegment() @ L60

  • 方法名:finishSegment
  • 源码定位:L60
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

private boolean tracksStage(LevelLoadListener.Stage stage) @ L66

  • 方法名:tracksStage
  • 源码定位:L66
  • 返回类型:boolean
  • 修饰符:private

参数:

  • stage: LevelLoadListener.Stage

说明:

TODO

private void updateProgress() @ L74

  • 方法名:updateProgress
  • 源码定位:L74
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public float get() @ L83

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

参数:

说明:

TODO

public void updateFocus(ResourceKey<Level> dimension, ChunkPos chunkPos) @ L87

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

参数:

  • dimension: ResourceKey
  • chunkPos: ChunkPos

说明:

TODO

代码

public class LevelLoadProgressTracker implements LevelLoadListener {
    private static final int PREPARE_SERVER_WEIGHT = 10;
    private static final int EXPECTED_PLAYER_CHUNKS = Mth.square(7);
    private final boolean includePlayerChunks;
    private int totalWeight;
    private int finalizedWeight;
    private int segmentWeight;
    private float segmentFraction;
    private volatile float progress;
 
    public LevelLoadProgressTracker(boolean includePlayerChunks) {
        this.includePlayerChunks = includePlayerChunks;
    }
 
    @Override
    public void start(LevelLoadListener.Stage stage, int totalChunks) {
        if (this.tracksStage(stage)) {
            switch (stage) {
                case LOAD_INITIAL_CHUNKS:
                    int playerChunksWeight = this.includePlayerChunks ? EXPECTED_PLAYER_CHUNKS : 0;
                    this.totalWeight = 10 + totalChunks + playerChunksWeight;
                    this.beginSegment(10);
                    this.finishSegment();
                    this.beginSegment(totalChunks);
                    break;
                case LOAD_PLAYER_CHUNKS:
                    this.beginSegment(EXPECTED_PLAYER_CHUNKS);
            }
        }
    }
 
    private void beginSegment(int weight) {
        this.segmentWeight = weight;
        this.segmentFraction = 0.0F;
        this.updateProgress();
    }
 
    @Override
    public void update(LevelLoadListener.Stage stage, int currentChunks, int totalChunks) {
        if (this.tracksStage(stage)) {
            this.segmentFraction = totalChunks == 0 ? 0.0F : (float)currentChunks / totalChunks;
            this.updateProgress();
        }
    }
 
    @Override
    public void finish(LevelLoadListener.Stage stage) {
        if (this.tracksStage(stage)) {
            this.finishSegment();
        }
    }
 
    private void finishSegment() {
        this.finalizedWeight = this.finalizedWeight + this.segmentWeight;
        this.segmentWeight = 0;
        this.updateProgress();
    }
 
    private boolean tracksStage(LevelLoadListener.Stage stage) {
        return switch (stage) {
            case LOAD_INITIAL_CHUNKS -> true;
            case LOAD_PLAYER_CHUNKS -> this.includePlayerChunks;
            default -> false;
        };
    }
 
    private void updateProgress() {
        if (this.totalWeight == 0) {
            this.progress = 0.0F;
        } else {
            float currentWeight = this.finalizedWeight + this.segmentFraction * this.segmentWeight;
            this.progress = currentWeight / this.totalWeight;
        }
    }
 
    public float get() {
        return this.progress;
    }
 
    @Override
    public void updateFocus(ResourceKey<Level> dimension, ChunkPos chunkPos) {
    }
}

引用的其他类