SavedDataNbt .java

net.minecraft.util.filefix.access.SavedDataNbt (class): members: targetVersion, read, write, type. imports: DataFixers, TypeReference, NbtUtils, Tag.

net.minecraft.util.filefix.accessclass37 linescommonextends CompressedNbt1.2 KB

API Surface (2)

Optional<Dynamic<Tag>> read()
<T> void write(final Dynamic<T> data)

Fields & Constants (2)

type
targetVersion

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SavedDataNbt.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.filefix.access;
2
3
import com.mojang.datafixers.DSL.TypeReference;
4
import com.mojang.serialization.Dynamic;
5
import java.io.IOException;
6
import java.nio.file.Path;
7
import java.util.Optional;
8
import net.minecraft.nbt.NbtUtils;
9
import net.minecraft.nbt.Tag;
10
import net.minecraft.util.datafix.DataFixers;
11
12
public class SavedDataNbt extends CompressedNbt {
13
	private final TypeReference type;
14
	private final int targetVersion;
15
16
	public SavedDataNbt(final TypeReference type, final Path path, final int targetVersion, final CompressedNbt.MissingSeverity missingSeverity) {
17
		super(path, missingSeverity);
18
		this.type = type;
19
		this.targetVersion = targetVersion;
20
	}
21
22
	@Override
23
	public Optional<Dynamic<Tag>> read() throws IOException {
24
		return this.readFile().map(readData -> {
25
			int version = NbtUtils.getDataVersion((Dynamic<?>)readData);
26
			return DataFixers.getDataFixer().update(this.type, (Dynamic<Tag>)readData, version, this.targetVersion).get("data").orElseEmptyMap();
27
		});
28
	}
29
30
	@Override
31
	public <T> void write(final Dynamic<T> data) {
32
		Dynamic<T> dataTag = data.emptyMap().set("data", data);
33
		Dynamic<T> wrappedAndWithDataVersion = NbtUtils.addDataVersion(dataTag, this.targetVersion);
34
		this.writeFile(wrappedAndWithDataVersion);
35
	}
36
}
37

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