BedItemColorFix .java

net.minecraft.util.datafix.fixes.BedItemColorFix (class): members: makeRule. strings: "Damage", "minecraft:bed". imports: NamespacedSchema, OpticFinder.

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

API Surface (1)

TypeRewriteRule makeRule()

String literals (2)

"minecraft:bed"
"Damage"

Code Graph: Dependencies (1)

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

Full Source

BedItemColorFix.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.OpticFinder;
6
import com.mojang.datafixers.TypeRewriteRule;
7
import com.mojang.datafixers.schemas.Schema;
8
import com.mojang.datafixers.util.Pair;
9
import com.mojang.serialization.Dynamic;
10
import java.util.Objects;
11
import java.util.Optional;
12
import net.minecraft.util.datafix.schemas.NamespacedSchema;
13
14
public class BedItemColorFix extends DataFix {
15
	public BedItemColorFix(final Schema outputSchema, final boolean changesType) {
16
		super(outputSchema, changesType);
17
	}
18
19
	@Override
20
	public TypeRewriteRule makeRule() {
21
		OpticFinder<Pair<String, String>> idF = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
22
		return this.fixTypeEverywhereTyped("BedItemColorFix", this.getInputSchema().getType(References.ITEM_STACK), input -> {
23
			Optional<Pair<String, String>> idOpt = input.getOptional(idF);
24
			if (idOpt.isPresent() && Objects.equals(idOpt.get().getSecond(), "minecraft:bed")) {
25
				Dynamic<?> tag = input.get(DSL.remainderFinder());
26
				if (tag.get("Damage").asInt(0) == 0) {
27
					return input.set(DSL.remainderFinder(), tag.set("Damage", tag.createShort((short)14)));
28
				}
29
			}
30
31
			return input;
32
		});
33
	}
34
}
35

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