EntityHorseSplitFix .java

net.minecraft.util.datafix.fixes.EntityHorseSplitFix (class, 37 lines): members: fix. strings: "SkeletonHorse", "ZombieHorse", "Donkey", "Horse", "Mule".

net.minecraft.util.datafix.fixesclass37 linescommonextends EntityRenameFix1.2 KB

API Surface (1)

Pair<String, Typed<?>> fix(final String name, final Typed<?> entity)

String literals (6)

"EntityHorse"
"Donkey"
"Mule"
"ZombieHorse"
"SkeletonHorse"
"Horse"

Code Graph: Dependencies (2)

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

Full Source

EntityHorseSplitFix.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.Typed;
5
import com.mojang.datafixers.schemas.Schema;
6
import com.mojang.datafixers.types.Type;
7
import com.mojang.datafixers.util.Pair;
8
import com.mojang.serialization.Dynamic;
9
import java.util.Objects;
10
import net.minecraft.util.Util;
11
12
public class EntityHorseSplitFix extends EntityRenameFix {
13
	public EntityHorseSplitFix(final Schema outputSchema, final boolean changesType) {
14
		super("EntityHorseSplitFix", outputSchema, changesType);
15
	}
16
17
	@Override
18
	protected Pair<String, Typed<?>> fix(final String name, final Typed<?> entity) {
19
		if (Objects.equals("EntityHorse", name)) {
20
			Dynamic<?> tag = entity.get(DSL.remainderFinder());
21
			int type = tag.get("Type").asInt(0);
22
23
			String newName = switch (type) {
24
				case 1 -> "Donkey";
25
				case 2 -> "Mule";
26
				case 3 -> "ZombieHorse";
27
				case 4 -> "SkeletonHorse";
28
				default -> "Horse";
29
			};
30
			Type<?> newType = this.getOutputSchema().findChoiceType(References.ENTITY).types().get(newName);
31
			return Pair.of(newName, Util.writeAndReadTypedOrThrow(entity, newType, dynamic -> dynamic.remove("Type")));
32
		} else {
33
			return Pair.of(name, entity);
34
		}
35
	}
36
}
37

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