ChunkNbt.java

net.minecraft.util.filefix.access.ChunkNbt

信息

  • 全限定名:net.minecraft.util.filefix.access.ChunkNbt
  • 类型:public class
  • 包:net.minecraft.util.filefix.access
  • 源码路径:src/main/java/net/minecraft/util/filefix/access/ChunkNbt.java
  • 起始行号:L14
  • 实现:AutoCloseable
  • 职责:

    TODO

字段/常量

  • storage

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

      TODO

  • targetVersion

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

      TODO

内部类/嵌套类型

构造器

public ChunkNbt(RegionStorageInfo info, Path path, DataFixTypes type, int targetVersion) @ L18

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

参数:

  • info: RegionStorageInfo
  • path: Path
  • type: DataFixTypes
  • targetVersion: int

说明:

TODO

方法

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

public void updateChunk(ChunkPos pos, CompoundTag dataFixContext, UnaryOperator<CompoundTag> fixer) @ L23

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

参数:

  • pos: ChunkPos
  • dataFixContext: CompoundTag
  • fixer: UnaryOperator

说明:

TODO

public void close() @ L31

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

参数:

说明:

TODO

代码

public class ChunkNbt implements AutoCloseable {
    private final SimpleRegionStorage storage;
    private final int targetVersion;
 
    public ChunkNbt(RegionStorageInfo info, Path path, DataFixTypes type, int targetVersion) {
        this.targetVersion = targetVersion;
        this.storage = new SimpleRegionStorage(info, path, DataFixers.getDataFixer(), false, type);
    }
 
    public void updateChunk(ChunkPos pos, CompoundTag dataFixContext, UnaryOperator<CompoundTag> fixer) {
        this.storage
            .read(pos)
            .thenApply(tag -> tag.<CompoundTag>map(tag1 -> this.storage.upgradeChunkTag(tag1, -1, dataFixContext, this.targetVersion)).map(fixer))
            .thenCompose(value -> value.<CompletableFuture<Void>>map(tag2 -> this.storage.write(pos, tag2)).orElse(CompletableFuture.completedFuture(null)))
            .join();
    }
 
    @Override
    public void close() throws IOException {
        this.storage.close();
    }
}

引用的其他类