EntityZombieSplitFix .java

net.minecraft.util.datafix.fixes.EntityZombieSplitFix (class, 57 lines): members: zombieVillagerType, fix. strings: "Profession", "ZombieType", "Husk".

net.minecraft.util.datafix.fixesclass57 linescommonextends EntityRenameFix1.7 KB

API Surface (1)

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

Fields & Constants (1)

zombieVillagerType

String literals (5)

"ZombieVillager"
"Zombie"
"ZombieType"
"Husk"
"Profession"

Code Graph: Dependencies (2)

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

Full Source

EntityZombieSplitFix.java57 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.google.common.base.Suppliers;
4
import com.mojang.datafixers.DSL;
5
import com.mojang.datafixers.Typed;
6
import com.mojang.datafixers.schemas.Schema;
7
import com.mojang.datafixers.types.Type;
8
import com.mojang.datafixers.util.Pair;
9
import com.mojang.serialization.Dynamic;
10
import java.util.function.Supplier;
11
import net.minecraft.util.Util;
12
13
public class EntityZombieSplitFix extends EntityRenameFix {
14
	private final Supplier<Type<?>> zombieVillagerType = Suppliers.memoize(() -> this.getOutputSchema().getChoiceType(References.ENTITY, "ZombieVillager"));
15
16
	public EntityZombieSplitFix(final Schema outputSchema) {
17
		super("EntityZombieSplitFix", outputSchema, true);
18
	}
19
20
	@Override
21
	protected Pair<String, Typed<?>> fix(final String name, final Typed<?> entity) {
22
		if (!name.equals("Zombie")) {
23
			return Pair.of(name, entity);
24
		}
25
26
		Dynamic<?> tag = entity.getOptional(DSL.remainderFinder()).orElseThrow();
27
		int type = tag.get("ZombieType").asInt(0);
28
		String newName;
29
		Typed<?> newEntity;
30
		switch (type) {
31
			case 1:
32
			case 2:
33
			case 3:
34
			case 4:
35
			case 5:
36
				newName = "ZombieVillager";
37
				newEntity = this.changeSchemaToZombieVillager(entity, type - 1);
38
				break;
39
			case 6:
40
				newName = "Husk";
41
				newEntity = entity;
42
				break;
43
			default:
44
				newName = "Zombie";
45
				newEntity = entity;
46
		}
47
48
		return Pair.of(newName, newEntity.update(DSL.remainderFinder(), e -> e.remove("ZombieType")));
49
	}
50
51
	private Typed<?> changeSchemaToZombieVillager(final Typed<?> entity, final int profession) {
52
		return Util.writeAndReadTypedOrThrow(
53
			entity, this.zombieVillagerType.get(), serializedEntity -> serializedEntity.set("Profession", serializedEntity.createInt(profession))
54
		);
55
	}
56
}
57

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