LegacyDimensionIdFix .java

net.minecraft.util.datafix.fixes.LegacyDimensionIdFix (class, 48 lines): members: makeRule. strings: "PlayerLegacyDimensionFix", "MapLegacyDimensionFix".

net.minecraft.util.datafix.fixesclass48 linescommonextends DataFix1.7 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (7)

"PlayerLegacyDimensionFix"
"MapLegacyDimensionFix"
"dimension"
"Dimension"
"minecraft:the_nether"
"minecraft:the_end"
"minecraft:overworld"

Full Source

LegacyDimensionIdFix.java48 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.DataFix;
5
import com.mojang.datafixers.DataFixUtils;
6
import com.mojang.datafixers.OpticFinder;
7
import com.mojang.datafixers.TypeRewriteRule;
8
import com.mojang.datafixers.schemas.Schema;
9
import com.mojang.datafixers.types.Type;
10
import com.mojang.serialization.Dynamic;
11
12
public class LegacyDimensionIdFix extends DataFix {
13
	public LegacyDimensionIdFix(final Schema outputSchema) {
14
		super(outputSchema, false);
15
	}
16
17
	@Override
18
	public TypeRewriteRule makeRule() {
19
		TypeRewriteRule playerRule = this.fixTypeEverywhereTyped(
20
			"PlayerLegacyDimensionFix", this.getInputSchema().getType(References.PLAYER), input -> input.update(DSL.remainderFinder(), this::fixPlayer)
21
		);
22
		Type<?> dataType = this.getInputSchema().getType(References.SAVED_DATA_MAP_DATA);
23
		OpticFinder<?> mapDataF = dataType.findField("data");
24
		TypeRewriteRule mapRule = this.fixTypeEverywhereTyped(
25
			"MapLegacyDimensionFix", dataType, input -> input.updateTyped(mapDataF, data -> data.update(DSL.remainderFinder(), this::fixMap))
26
		);
27
		return TypeRewriteRule.seq(playerRule, mapRule);
28
	}
29
30
	private <T> Dynamic<T> fixMap(final Dynamic<T> remainder) {
31
		return remainder.update("dimension", this::fixDimensionId);
32
	}
33
34
	private <T> Dynamic<T> fixPlayer(final Dynamic<T> remainder) {
35
		return remainder.update("Dimension", this::fixDimensionId);
36
	}
37
38
	private <T> Dynamic<T> fixDimensionId(final Dynamic<T> id) {
39
		return DataFixUtils.orElse(id.asNumber().result().map(legacyId -> {
40
			return switch (legacyId.intValue()) {
41
				case -1 -> id.createString("minecraft:the_nether");
42
				case 1 -> id.createString("minecraft:the_end");
43
				default -> id.createString("minecraft:overworld");
44
			};
45
		}), id);
46
	}
47
}
48

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