PlayerEquipmentFix .java

net.minecraft.util.datafix.fixes.PlayerEquipmentFix (class): members: SLOT_TRANSLATIONS, makeRule. strings: "Player Equipment Fix", "Slot", "legs", "feet".

net.minecraft.util.datafix.fixesclass37 linescommonextends DataFix1.4 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (1)

SLOT_TRANSLATIONS

String literals (9)

"feet"
"legs"
"chest"
"head"
"offhand"
"Player Equipment Fix"
"Inventory"
"Slot"
"equipment"

Full Source

PlayerEquipmentFix.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DataFix;
4
import com.mojang.datafixers.TypeRewriteRule;
5
import com.mojang.datafixers.schemas.Schema;
6
import com.mojang.datafixers.types.Type;
7
import com.mojang.serialization.Dynamic;
8
import java.util.HashMap;
9
import java.util.Map;
10
11
public class PlayerEquipmentFix extends DataFix {
12
	private static final Map<Integer, String> SLOT_TRANSLATIONS = Map.of(100, "feet", 101, "legs", 102, "chest", 103, "head", -106, "offhand");
13
14
	public PlayerEquipmentFix(final Schema outputSchema) {
15
		super(outputSchema, true);
16
	}
17
18
	@Override
19
	protected TypeRewriteRule makeRule() {
20
		Type<?> oldPlayerType = this.getInputSchema().getTypeRaw(References.PLAYER);
21
		Type<?> newPlayerType = this.getOutputSchema().getTypeRaw(References.PLAYER);
22
		return this.writeFixAndRead("Player Equipment Fix", oldPlayerType, newPlayerType, tag -> {
23
			Map<Dynamic<?>, Dynamic<?>> equipment = new HashMap<>();
24
			tag = tag.update("Inventory", inventory -> inventory.createList(inventory.asStream().filter(item -> {
25
				int inventorySlot = item.get("Slot").asInt(-1);
26
				String equipmentSlot = SLOT_TRANSLATIONS.get(inventorySlot);
27
				if (equipmentSlot != null) {
28
					equipment.put(inventory.createString(equipmentSlot), item.remove("Slot"));
29
				}
30
31
				return equipmentSlot == null;
32
			})));
33
			return tag.set("equipment", tag.createMap(equipment));
34
		});
35
	}
36
}
37

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