ChunkNbt .java

net.minecraft.util.filefix.access.ChunkNbt (class, 42 lines): members: updateChunk, targetVersion, storage, close. imports: SimpleRegionStorage, ChunkPos.

net.minecraft.util.filefix.accessclass42 linescommon1.5 KB

Implements

API Surface (2)

CompletableFuture<?> updateChunk(final ChunkPos pos, final CompoundTag dataFixContext, final UnaryOperator<CompoundTag> fixer)
void close()

Fields & Constants (2)

storage
targetVersion

Full Source

ChunkNbt.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.filefix.access;
2
3
import java.io.IOException;
4
import java.nio.file.Path;
5
import java.util.concurrent.CompletableFuture;
6
import java.util.function.UnaryOperator;
7
import net.minecraft.nbt.CompoundTag;
8
import net.minecraft.util.Util;
9
import net.minecraft.util.datafix.DataFixTypes;
10
import net.minecraft.util.datafix.DataFixers;
11
import net.minecraft.world.level.ChunkPos;
12
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
13
import net.minecraft.world.level.chunk.storage.SimpleRegionStorage;
14
15
public class ChunkNbt implements AutoCloseable {
16
	private final SimpleRegionStorage storage;
17
	private final int targetVersion;
18
19
	public ChunkNbt(final RegionStorageInfo info, final Path path, final DataFixTypes type, final int targetVersion) {
20
		this.targetVersion = targetVersion;
21
		this.storage = new SimpleRegionStorage(info, path, DataFixers.getDataFixer(), false, type);
22
	}
23
24
	public CompletableFuture<?> updateChunk(final ChunkPos pos, final CompoundTag dataFixContext, final UnaryOperator<CompoundTag> fixer) {
25
		return this.storage.read(pos).thenComposeAsync(maybeTag -> {
26
			if (maybeTag.isEmpty()) {
27
				return CompletableFuture.completedFuture(null);
28
			}
29
30
			CompoundTag tag = maybeTag.get();
31
			tag = this.storage.upgradeChunkTag(tag, -1, dataFixContext, this.targetVersion);
32
			tag = fixer.apply(tag);
33
			return this.storage.write(pos, tag);
34
		}, Util.backgroundExecutor());
35
	}
36
37
	@Override
38
	public void close() throws IOException {
39
		this.storage.close();
40
	}
41
}
42

Decompiled Minecraft 26.3 source of ChunkNbt (net/minecraft/util/filefix/access/ChunkNbt.java) with Mojang official mappings, stored verbatim on the site.