ScoreboardDisplayNameFix .java

net.minecraft.util.datafix.fixes.ScoreboardDisplayNameFix (class): members: makeRule, name, type. strings: "DisplayName". imports: TypeReference, Type.

net.minecraft.util.datafix.fixesclass38 linescommonextends DataFix1.3 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (2)

name
type

String literals (1)

"DisplayName"

Code Graph: Dependencies (1)

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

Full Source

ScoreboardDisplayNameFix.java38 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.DSL.TypeReference;
8
import com.mojang.datafixers.schemas.Schema;
9
import com.mojang.datafixers.types.Type;
10
import com.mojang.datafixers.util.Pair;
11
import net.minecraft.util.datafix.LegacyComponentDataFixUtils;
12
13
public class ScoreboardDisplayNameFix extends DataFix {
14
	private final String name;
15
	private final TypeReference type;
16
17
	public ScoreboardDisplayNameFix(final Schema outputSchema, final String name, final TypeReference type) {
18
		super(outputSchema, false);
19
		this.name = name;
20
		this.type = type;
21
	}
22
23
	@Override
24
	protected TypeRewriteRule makeRule() {
25
		Type<?> inputType = this.getInputSchema().getType(this.type);
26
		OpticFinder<?> displayNameF = inputType.findField("DisplayName");
27
		OpticFinder<Pair<String, String>> textComponentF = DSL.typeFinder((Type<Pair<String, String>>)this.getInputSchema().getType(References.TEXT_COMPONENT));
28
		return this.fixTypeEverywhereTyped(
29
			this.name,
30
			inputType,
31
			team -> team.updateTyped(
32
				displayNameF,
33
				displayName -> displayName.update(textComponentF, textComponent -> textComponent.mapSecond(LegacyComponentDataFixUtils::createTextComponentJson))
34
			)
35
		);
36
	}
37
}
38

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