TextComponentStringifiedFlagsFix .java

net.minecraft.util.datafix.fixes.TextComponentStringifiedFlagsFix (class, 47 lines): extends DataFix. members: makeRule. strings: "strikethrough", "bold".

net.minecraft.util.datafix.fixesclass47 linescommonextends DataFix1.7 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (6)

"TextComponentStringyFlagsFix"
"bold"
"italic"
"underlined"
"strikethrough"
"obfuscated"

Full Source

TextComponentStringifiedFlagsFix.java47 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.datafixers.util.Either;
8
import com.mojang.datafixers.util.Pair;
9
import com.mojang.serialization.Dynamic;
10
import java.util.Optional;
11
12
public class TextComponentStringifiedFlagsFix extends DataFix {
13
	public TextComponentStringifiedFlagsFix(final Schema outputSchema) {
14
		super(outputSchema, false);
15
	}
16
17
	@Override
18
	protected TypeRewriteRule makeRule() {
19
		Type<Pair<String, Either<?, Pair<?, Pair<?, Pair<?, Dynamic<?>>>>>>> textComponentType = (Type<Pair<String, Either<?, Pair<?, Pair<?, Pair<?, Dynamic<?>>>>>>>)this.getInputSchema()
20
			.getType(References.TEXT_COMPONENT);
21
		return this.fixTypeEverywhere(
22
			"TextComponentStringyFlagsFix",
23
			textComponentType,
24
			ops -> named -> named.mapSecond(
25
				e1 -> e1.mapRight(
26
					p2 -> p2.mapSecond(
27
						p3 -> p3.mapSecond(
28
							p4 -> p4.mapSecond(
29
								remainder -> remainder.update("bold", TextComponentStringifiedFlagsFix::stringToBool)
30
									.update("italic", TextComponentStringifiedFlagsFix::stringToBool)
31
									.update("underlined", TextComponentStringifiedFlagsFix::stringToBool)
32
									.update("strikethrough", TextComponentStringifiedFlagsFix::stringToBool)
33
									.update("obfuscated", TextComponentStringifiedFlagsFix::stringToBool)
34
							)
35
						)
36
					)
37
				)
38
			)
39
		);
40
	}
41
42
	private static <T> Dynamic<T> stringToBool(final Dynamic<T> input) {
43
		Optional<String> string = input.asString().result();
44
		return string.isPresent() ? input.createBoolean(Boolean.parseBoolean(string.get())) : input;
45
	}
46
}
47

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