OptionsAddTextBackgroundFix .java

net.minecraft.util.datafix.fixes.OptionsAddTextBackgroundFix (class): members: makeRule. strings: "textBackgroundOpacity", "chatOpacity". imports: DataFix.

net.minecraft.util.datafix.fixesclass35 linescommonextends DataFix1.1 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (2)

"chatOpacity"
"textBackgroundOpacity"

Full Source

OptionsAddTextBackgroundFix.java35 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.DataFixUtils;
6
import com.mojang.datafixers.TypeRewriteRule;
7
import com.mojang.datafixers.schemas.Schema;
8
9
public class OptionsAddTextBackgroundFix extends DataFix {
10
	public OptionsAddTextBackgroundFix(final Schema outputSchema, final boolean changesType) {
11
		super(outputSchema, changesType);
12
	}
13
14
	@Override
15
	public TypeRewriteRule makeRule() {
16
		return this.fixTypeEverywhereTyped(
17
			"OptionsAddTextBackgroundFix",
18
			this.getInputSchema().getType(References.OPTIONS),
19
			input -> input.update(DSL.remainderFinder(), tag -> DataFixUtils.orElse(tag.get("chatOpacity").asString().map(value -> {
20
				double opacity = this.calculateBackground(value);
21
				return tag.set("textBackgroundOpacity", tag.createString(String.valueOf(opacity)));
22
			}).result(), tag))
23
		);
24
	}
25
26
	private double calculateBackground(final String textOpacity) {
27
		try {
28
			double textAlpha = 0.9 * Double.parseDouble(textOpacity) + 0.1;
29
			return textAlpha / 2.0;
30
		} catch (NumberFormatException e) {
31
			return 0.5;
32
		}
33
	}
34
}
35

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