LevelUUIDFix .java

net.minecraft.util.datafix.fixes.LevelUUIDFix (class, 62 lines): extends AbstractUUIDFix. members: makeRule, LOGGER. strings: "DragonUUID", "Dragon".

net.minecraft.util.datafix.fixesclass62 linescommonextends AbstractUUIDFix2.2 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (1)

LOGGER

String literals (8)

"CustomBossEvents"
"WanderingTraderId"
"DimensionData"
"DragonFight"
"DragonUUID"
"Dragon"
"Players"
"CustomBossEvents contains invalid UUIDs."

Code Graph: Dependencies (1)

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

Full Source

LevelUUIDFix.java62 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.OpticFinder;
5
import com.mojang.datafixers.TypeRewriteRule;
6
import com.mojang.datafixers.schemas.Schema;
7
import com.mojang.datafixers.types.Type;
8
import com.mojang.logging.LogUtils;
9
import com.mojang.serialization.Dynamic;
10
import org.slf4j.Logger;
11
12
public class LevelUUIDFix extends AbstractUUIDFix {
13
	private static final Logger LOGGER = LogUtils.getLogger();
14
15
	public LevelUUIDFix(final Schema outputSchema) {
16
		super(outputSchema, References.LEVEL);
17
	}
18
19
	@Override
20
	protected TypeRewriteRule makeRule() {
21
		Type<?> type = this.getInputSchema().getType(this.typeReference);
22
		OpticFinder<?> customBossEventsF = type.findField("CustomBossEvents");
23
		OpticFinder<?> customBossEventF = DSL.typeFinder(
24
			DSL.and(DSL.optional(DSL.field("Name", this.getInputSchema().getTypeRaw(References.TEXT_COMPONENT))), DSL.remainderType())
25
		);
26
		return this.fixTypeEverywhereTyped(
27
			"LevelUUIDFix",
28
			type,
29
			input -> input.update(DSL.remainderFinder(), tag -> {
30
					tag = this.updateDragonFight(tag);
31
					return this.updateWanderingTrader(tag);
32
				})
33
				.updateTyped(
34
					customBossEventsF,
35
					customBossEvents -> customBossEvents.updateTyped(customBossEventF, event -> event.update(DSL.remainderFinder(), this::updateCustomBossEvent))
36
				)
37
		);
38
	}
39
40
	private Dynamic<?> updateWanderingTrader(final Dynamic<?> tag) {
41
		return replaceUUIDString(tag, "WanderingTraderId", "WanderingTraderId").orElse(tag);
42
	}
43
44
	private Dynamic<?> updateDragonFight(final Dynamic<?> tag) {
45
		return tag.update(
46
			"DimensionData",
47
			dimensionDataMap -> dimensionDataMap.updateMapValues(
48
				dimensionDataPair -> dimensionDataPair.mapSecond(
49
					dimensionData -> dimensionData.update("DragonFight", dragonfight -> replaceUUIDLeastMost(dragonfight, "DragonUUID", "Dragon").orElse(dragonfight))
50
				)
51
			)
52
		);
53
	}
54
55
	private Dynamic<?> updateCustomBossEvent(final Dynamic<?> tag) {
56
		return tag.update("Players", players -> tag.createList(players.asStream().map(player -> createUUIDFromML((Dynamic<?>)player).orElseGet(() -> {
57
			LOGGER.warn("CustomBossEvents contains invalid UUIDs.");
58
			return player;
59
		}))));
60
	}
61
}
62

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