ItemLoreFix .java

net.minecraft.util.datafix.fixes.ItemLoreFix (class): members: makeRule. strings: "Item Lore componentize", "Lore", "display". imports: OpticFinder, Type.

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

API Surface (1)

TypeRewriteRule makeRule()

String literals (3)

"display"
"Lore"
"Item Lore componentize"

Code Graph: Dependencies (1)

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

Full Source

ItemLoreFix.java40 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 ItemLoreFix extends DataFix {
13
	public ItemLoreFix(final Schema outputSchema) {
14
		super(outputSchema, false);
15
	}
16
17
	@Override
18
	protected 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<?> loreFinder = displayFinder.type().findField("Lore");
24
		OpticFinder<Pair<String, String>> textComponentFinder = DSL.typeFinder(textComponentType);
25
		return this.fixTypeEverywhereTyped(
26
			"Item Lore componentize",
27
			itemStackType,
28
			itemStack -> itemStack.updateTyped(
29
				tagFinder,
30
				tag -> tag.updateTyped(
31
					displayFinder,
32
					display -> display.updateTyped(
33
						loreFinder, lore -> lore.update(textComponentFinder, textComponent -> textComponent.mapSecond(LegacyComponentDataFixUtils::createTextComponentJson))
34
					)
35
				)
36
			)
37
		);
38
	}
39
}
40

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