HorseBodyArmorItemFix .java

net.minecraft.util.datafix.fixes.HorseBodyArmorItemFix (class, 43 lines): members: previousBodyArmorTag, clearArmorItems, fix. strings: "ArmorDropChances".

net.minecraft.util.datafix.fixesclass43 linescommonextends NamedEntityWriteReadFix1.6 KB

API Surface (1)

<T> Dynamic<T> fix(final Dynamic<T> input)

Fields & Constants (2)

previousBodyArmorTag
clearArmorItems

String literals (5)

"Horse armor fix for "
"ArmorItems"
"ArmorDropChances"
"body_armor_item"
"body_armor_drop_chance"

Code Graph: Dependencies (1)

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

Full Source

HorseBodyArmorItemFix.java43 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.google.common.collect.Streams;
4
import com.mojang.datafixers.schemas.Schema;
5
import com.mojang.serialization.Dynamic;
6
import java.util.Optional;
7
8
public class HorseBodyArmorItemFix extends NamedEntityWriteReadFix {
9
	private final String previousBodyArmorTag;
10
	private final boolean clearArmorItems;
11
12
	public HorseBodyArmorItemFix(final Schema outputSchema, final String entityName, final String previousBodyArmorTag, final boolean clearArmorItems) {
13
		super(outputSchema, true, "Horse armor fix for " + entityName, References.ENTITY, entityName);
14
		this.previousBodyArmorTag = previousBodyArmorTag;
15
		this.clearArmorItems = clearArmorItems;
16
	}
17
18
	@Override
19
	protected <T> Dynamic<T> fix(final Dynamic<T> input) {
20
		Optional<? extends Dynamic<?>> previousBodyArmor = input.get(this.previousBodyArmorTag).result();
21
		if (previousBodyArmor.isPresent()) {
22
			Dynamic<?> bodyArmorItem = (Dynamic<?>)previousBodyArmor.get();
23
			Dynamic<T> output = input.remove(this.previousBodyArmorTag);
24
			if (this.clearArmorItems) {
25
				output = output.update(
26
					"ArmorItems", armorItems -> armorItems.createList(Streams.mapWithIndex(armorItems.asStream(), (entry, index) -> index == 2L ? entry.emptyMap() : entry))
27
				);
28
				output = output.update(
29
					"ArmorDropChances",
30
					armorDropChances -> armorDropChances.createList(
31
						Streams.mapWithIndex(armorDropChances.asStream(), (entry, index) -> index == 2L ? entry.createFloat(0.085F) : entry)
32
					)
33
				);
34
			}
35
36
			output = output.set("body_armor_item", bodyArmorItem);
37
			return output.set("body_armor_drop_chance", input.createFloat(2.0F));
38
		} else {
39
			return input;
40
		}
41
	}
42
}
43

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