DataFixTypes .java

net.minecraft.util.datafix.DataFixTypes (enum, 98 lines): members: LEVEL, LEVEL_SUMMARY, PLAYER, CHUNK, HOTBAR, OPTIONS, STRUCTURE, STATS, ADVANCEMENTS.

net.minecraft.util.datafixenum98 linescommon4.1 KB

API Surface (7)

<A> Codec<A> wrapCodec(final Codec<A> codec, final DataFixer dataFixer, final int defaultVersion)
<T> DataResult<T> encode(final A input, final DynamicOps<T> ops, final T prefix)
<T> DataResult<Pair<A, T>> decode(final DynamicOps<T> ops, final T input)
<T> Dynamic<T> update(final DataFixer fixerUpper, final Dynamic<T> input, final int fromVersion, final int toVersion)
<T> Dynamic<T> updateToCurrentVersion(final DataFixer fixerUpper, final Dynamic<T> input, final int dataVersion)
CompoundTag update(final DataFixer fixer, final CompoundTag tag, final int fromVersion, final int toVersion)
CompoundTag updateToCurrentVersion(final DataFixer fixer, final CompoundTag tag, final int fromVersion)

Fields & Constants (2)

TYPES_FOR_LEVEL_LIST
type

String literals (1)

"DataVersion"

Code Graph: Dependencies (5)

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

Full Source

DataFixTypes.java98 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix;
2
3
import com.mojang.datafixers.DataFixer;
4
import com.mojang.datafixers.DSL.TypeReference;
5
import com.mojang.datafixers.util.Pair;
6
import com.mojang.serialization.Codec;
7
import com.mojang.serialization.DataResult;
8
import com.mojang.serialization.Dynamic;
9
import com.mojang.serialization.DynamicOps;
10
import java.util.Set;
11
import net.minecraft.SharedConstants;
12
import net.minecraft.nbt.CompoundTag;
13
import net.minecraft.nbt.NbtOps;
14
import net.minecraft.util.datafix.fixes.References;
15
16
public enum DataFixTypes {
17
	LEVEL(References.LEVEL),
18
	LEVEL_SUMMARY(References.LIGHTWEIGHT_LEVEL),
19
	PLAYER(References.PLAYER),
20
	CHUNK(References.CHUNK),
21
	HOTBAR(References.HOTBAR),
22
	OPTIONS(References.OPTIONS),
23
	STRUCTURE(References.STRUCTURE),
24
	STATS(References.STATS),
25
	SAVED_DATA_COMMAND_STORAGE(References.SAVED_DATA_COMMAND_STORAGE),
26
	SAVED_DATA_CUSTOM_BOSS_EVENTS(References.SAVED_DATA_CUSTOM_BOSS_EVENTS),
27
	SAVED_DATA_ENDER_DRAGON_FIGHT(References.SAVED_DATA_ENDER_DRAGON_FIGHT),
28
	SAVED_DATA_GAME_RULES(References.SAVED_DATA_GAME_RULES),
29
	SAVED_DATA_FORCED_CHUNKS(References.SAVED_DATA_TICKETS),
30
	SAVED_DATA_MAP_DATA(References.SAVED_DATA_MAP_DATA),
31
	SAVED_DATA_MAP_INDEX(References.SAVED_DATA_MAP_INDEX),
32
	SAVED_DATA_RAIDS(References.SAVED_DATA_RAIDS),
33
	SAVED_DATA_RANDOM_SEQUENCES(References.SAVED_DATA_RANDOM_SEQUENCES),
34
	SAVED_DATA_SCHEDULED_EVENTS(References.SAVED_DATA_SCHEDULED_EVENTS),
35
	SAVED_DATA_SCOREBOARD(References.SAVED_DATA_SCOREBOARD),
36
	SAVED_DATA_STOPWATCHES(References.SAVED_DATA_STOPWATCHES),
37
	SAVED_DATA_STRUCTURE_FEATURE_INDICES(References.SAVED_DATA_STRUCTURE_FEATURE_INDICES),
38
	SAVED_DATA_WANDERING_TRADER(References.SAVED_DATA_WANDERING_TRADER),
39
	SAVED_DATA_WEATHER(References.SAVED_DATA_WEATHER),
40
	SAVED_DATA_WORLD_BORDER(References.SAVED_DATA_WORLD_BORDER),
41
	SAVED_DATA_WORLD_CLOCKS(References.SAVED_DATA_WORLD_CLOCKS),
42
	SAVED_DATA_WORLD_GEN_SETTINGS(References.SAVED_DATA_WORLD_GEN_SETTINGS),
43
	ADVANCEMENTS(References.ADVANCEMENTS),
44
	POI_CHUNK(References.POI_CHUNK),
45
	WORLD_GEN_SETTINGS(References.WORLD_GEN_SETTINGS),
46
	ENTITY_CHUNK(References.ENTITY_CHUNK),
47
	DEBUG_PROFILE(References.DEBUG_PROFILE);
48
49
	public static final Set<TypeReference> TYPES_FOR_LEVEL_LIST;
50
	private final TypeReference type;
51
52
	DataFixTypes(final TypeReference type) {
53
		this.type = type;
54
	}
55
56
	private static int currentVersion() {
57
		return SharedConstants.getCurrentVersion().dataVersion().version();
58
	}
59
60
	public <A> Codec<A> wrapCodec(final Codec<A> codec, final DataFixer dataFixer, final int defaultVersion) {
61
		return new Codec<A>() {
62
			@Override
63
			public <T> DataResult<T> encode(final A input, final DynamicOps<T> ops, final T prefix) {
64
				return codec.encode(input, ops, prefix)
65
					.flatMap(data -> ops.mergeToMap((T)data, ops.createString("DataVersion"), ops.createInt(DataFixTypes.currentVersion())));
66
			}
67
68
			@Override
69
			public <T> DataResult<Pair<A, T>> decode(final DynamicOps<T> ops, final T input) {
70
				int fromVersion = ops.get(input, "DataVersion").flatMap(ops::getNumberValue).map(Number::intValue).result().orElse(defaultVersion);
71
				Dynamic<T> dataWithoutVersion = new Dynamic<>(ops, ops.remove(input, "DataVersion"));
72
				Dynamic<T> fixedData = DataFixTypes.this.updateToCurrentVersion(dataFixer, dataWithoutVersion, fromVersion);
73
				return codec.decode(fixedData);
74
			}
75
		};
76
	}
77
78
	public <T> Dynamic<T> update(final DataFixer fixerUpper, final Dynamic<T> input, final int fromVersion, final int toVersion) {
79
		return fixerUpper.update(this.type, input, fromVersion, toVersion);
80
	}
81
82
	public <T> Dynamic<T> updateToCurrentVersion(final DataFixer fixerUpper, final Dynamic<T> input, final int dataVersion) {
83
		return this.update(fixerUpper, input, dataVersion, currentVersion());
84
	}
85
86
	public CompoundTag update(final DataFixer fixer, final CompoundTag tag, final int fromVersion, final int toVersion) {
87
		return (CompoundTag)this.update(fixer, new Dynamic<>(NbtOps.INSTANCE, tag), fromVersion, toVersion).getValue();
88
	}
89
90
	public CompoundTag updateToCurrentVersion(final DataFixer fixer, final CompoundTag tag, final int fromVersion) {
91
		return this.update(fixer, tag, fromVersion, currentVersion());
92
	}
93
94
	static {
95
		TYPES_FOR_LEVEL_LIST = Set.of(LEVEL_SUMMARY.type);
96
	}
97
}
98

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