FixWolfHealth .java

net.minecraft.util.datafix.fixes.FixWolfHealth (class): members: WOLF_HEALTH, WOLF_ID, fix. strings: "minecraft:generic.max_health", "Attributes", "Base".

net.minecraft.util.datafix.fixesclass50 linescommonextends NamedEntityFix1.5 KB

API Surface (1)

Typed<?> fix(final Typed<?> entity)

Fields & Constants (2)

WOLF_ID
WOLF_HEALTH

String literals (5)

"minecraft:wolf"
"minecraft:generic.max_health"
"Attributes"
"Base"
"Health"

Code Graph: Dependencies (2)

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

Full Source

FixWolfHealth.java50 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 net.minecraft.util.datafix.schemas.NamespacedSchema;
7
import org.apache.commons.lang3.mutable.MutableBoolean;
8
9
public class FixWolfHealth extends NamedEntityFix {
10
	private static final String WOLF_ID = "minecraft:wolf";
11
	private static final String WOLF_HEALTH = "minecraft:generic.max_health";
12
13
	public FixWolfHealth(final Schema outputSchema) {
14
		super(outputSchema, false, "FixWolfHealth", References.ENTITY, "minecraft:wolf");
15
	}
16
17
	@Override
18
	protected Typed<?> fix(final Typed<?> entity) {
19
		return entity.update(
20
			DSL.remainderFinder(),
21
			dynamic -> {
22
				MutableBoolean healthAdjusted = new MutableBoolean(false);
23
				dynamic = dynamic.update(
24
					"Attributes",
25
					attributes -> attributes.createList(
26
						attributes.asStream()
27
							.map(
28
								attribute -> "minecraft:generic.max_health".equals(NamespacedSchema.ensureNamespaced(attribute.get("Name").asString("")))
29
									? attribute.update("Base", base -> {
30
										if (base.asDouble(0.0) == 20.0) {
31
											healthAdjusted.setTrue();
32
											return base.createDouble(40.0);
33
										} else {
34
											return base;
35
										}
36
									})
37
									: attribute
38
							)
39
					)
40
				);
41
				if (healthAdjusted.isTrue()) {
42
					dynamic = dynamic.update("Health", health -> health.createFloat(health.asFloat(0.0F) * 2.0F));
43
				}
44
45
				return dynamic;
46
			}
47
		);
48
	}
49
}
50

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