EntityZombieVillagerTypeFix .java

net.minecraft.util.datafix.fixes.EntityZombieVillagerTypeFix (class): members: PROFESSION_MAX, fixTag, fix. strings: "VillagerProfession", "IsVillager".

net.minecraft.util.datafix.fixesclass42 linescommonextends NamedEntityFix1.3 KB

API Surface (2)

Dynamic<?> fixTag(Dynamic<?> input)
Typed<?> fix(final Typed<?> entity)

Fields & Constants (1)

PROFESSION_MAX

String literals (4)

"Zombie"
"IsVillager"
"ZombieType"
"VillagerProfession"

Code Graph: Dependencies (2)

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

Full Source

EntityZombieVillagerTypeFix.java42 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.serialization.Dynamic;
7
import net.minecraft.util.RandomSource;
8
9
public class EntityZombieVillagerTypeFix extends NamedEntityFix {
10
	private static final int PROFESSION_MAX = 6;
11
12
	public EntityZombieVillagerTypeFix(final Schema outputSchema, final boolean changesType) {
13
		super(outputSchema, changesType, "EntityZombieVillagerTypeFix", References.ENTITY, "Zombie");
14
	}
15
16
	public Dynamic<?> fixTag(Dynamic<?> input) {
17
		if (input.get("IsVillager").asBoolean(false)) {
18
			if (input.get("ZombieType").result().isEmpty()) {
19
				int type = this.getVillagerProfession(input.get("VillagerProfession").asInt(-1));
20
				if (type == -1) {
21
					type = this.getVillagerProfession(RandomSource.createThreadLocalInstance().nextInt(6));
22
				}
23
24
				input = input.set("ZombieType", input.createInt(type));
25
			}
26
27
			input = input.remove("IsVillager");
28
		}
29
30
		return input;
31
	}
32
33
	private int getVillagerProfession(final int profession) {
34
		return profession >= 0 && profession < 6 ? profession : -1;
35
	}
36
37
	@Override
38
	protected Typed<?> fix(final Typed<?> entity) {
39
		return entity.update(DSL.remainderFinder(), this::fixTag);
40
	}
41
}
42

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