ItemCustomNameToComponentFix .java

net.minecraft.util.datafix.fixes.ItemCustomNameToComponentFix (class, 41 lines): members: makeRule. strings: "display". imports: OpticFinder, Type.

net.minecraft.util.datafix.fixesclass41 linescommonextends DataFix1.5 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (1)

"display"

Code Graph: Dependencies (1)

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

Full Source

ItemCustomNameToComponentFix.java41 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.DataFix;
5
import com.mojang.datafixers.OpticFinder;
6
import com.mojang.datafixers.TypeRewriteRule;
7
import com.mojang.datafixers.schemas.Schema;
8
import com.mojang.datafixers.types.Type;
9
import com.mojang.datafixers.util.Pair;
10
import net.minecraft.util.datafix.LegacyComponentDataFixUtils;
11
12
public class ItemCustomNameToComponentFix extends DataFix {
13
	public ItemCustomNameToComponentFix(final Schema outputSchema) {
14
		super(outputSchema, false);
15
	}
16
17
	@Override
18
	public TypeRewriteRule makeRule() {
19
		Type<?> itemStackType = this.getInputSchema().getType(References.ITEM_STACK);
20
		Type<Pair<String, String>> textComponentType = (Type<Pair<String, String>>)this.getInputSchema().getType(References.TEXT_COMPONENT);
21
		OpticFinder<?> tagFinder = itemStackType.findField("tag");
22
		OpticFinder<?> displayFinder = tagFinder.type().findField("display");
23
		OpticFinder<?> customNameFinder = displayFinder.type().findField("Name");
24
		OpticFinder<Pair<String, String>> textComponentFinder = DSL.typeFinder(textComponentType);
25
		return this.fixTypeEverywhereTyped(
26
			"ItemCustomNameToComponentFix",
27
			itemStackType,
28
			itemStack -> itemStack.updateTyped(
29
				tagFinder,
30
				tag -> tag.updateTyped(
31
					displayFinder,
32
					display -> display.updateTyped(
33
						customNameFinder,
34
						customName -> customName.update(textComponentFinder, textComponent -> textComponent.mapSecond(LegacyComponentDataFixUtils::createTextComponentJson))
35
					)
36
				)
37
			)
38
		);
39
	}
40
}
41

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