WrittenBookPagesStrictJsonFix .java

net.minecraft.util.datafix.fixes.WrittenBookPagesStrictJsonFix (class, 26 lines): members: fixItemStackTag. strings: "minecraft:written_book", "pages".

net.minecraft.util.datafix.fixesclass26 linescommonextends ItemStackTagFix1.2 KB

API Surface (1)

Typed<?> fixItemStackTag(final Typed<?> tag)

String literals (2)

"minecraft:written_book"
"pages"

Code Graph: Dependencies (2)

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

Full Source

WrittenBookPagesStrictJsonFix.java26 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.mojang.datafixers.DSL;
4
import com.mojang.datafixers.OpticFinder;
5
import com.mojang.datafixers.Typed;
6
import com.mojang.datafixers.schemas.Schema;
7
import com.mojang.datafixers.types.Type;
8
import com.mojang.datafixers.util.Pair;
9
import net.minecraft.util.datafix.LegacyComponentDataFixUtils;
10
11
public class WrittenBookPagesStrictJsonFix extends ItemStackTagFix {
12
	public WrittenBookPagesStrictJsonFix(final Schema outputSchema) {
13
		super(outputSchema, "WrittenBookPagesStrictJsonFix", id -> id.equals("minecraft:written_book"));
14
	}
15
16
	@Override
17
	protected Typed<?> fixItemStackTag(final Typed<?> tag) {
18
		Type<Pair<String, String>> textComponentType = (Type<Pair<String, String>>)this.getInputSchema().getType(References.TEXT_COMPONENT);
19
		Type<?> itemStackType = this.getInputSchema().getType(References.ITEM_STACK);
20
		OpticFinder<?> tagF = itemStackType.findField("tag");
21
		OpticFinder<?> pagesF = tagF.type().findField("pages");
22
		OpticFinder<Pair<String, String>> pageF = DSL.typeFinder(textComponentType);
23
		return tag.updateTyped(pagesF, pages -> pages.update(pageF, page -> page.mapSecond(LegacyComponentDataFixUtils::rewriteFromLenient)));
24
	}
25
}
26

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