VillagerTradeFix .java

net.minecraft.util.datafix.fixes.VillagerTradeFix (class): members: makeRule. strings: "Villager trade fix", "minecraft:carved_pumpkin", "sell", "buyB".

net.minecraft.util.datafix.fixesclass39 linescommonextends DataFix1.6 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (5)

"buyB"
"sell"
"Villager trade fix"
"minecraft:carved_pumpkin"
"minecraft:pumpkin"

Code Graph: Dependencies (1)

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

Full Source

VillagerTradeFix.java39 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.Typed;
8
import com.mojang.datafixers.schemas.Schema;
9
import com.mojang.datafixers.types.Type;
10
import com.mojang.datafixers.util.Pair;
11
import java.util.Objects;
12
import java.util.function.Function;
13
import net.minecraft.util.datafix.schemas.NamespacedSchema;
14
15
public class VillagerTradeFix extends DataFix {
16
	public VillagerTradeFix(final Schema outputSchema) {
17
		super(outputSchema, false);
18
	}
19
20
	@Override
21
	protected TypeRewriteRule makeRule() {
22
		Type<?> recipeType = this.getInputSchema().getType(References.VILLAGER_TRADE);
23
		OpticFinder<?> buyFinder = recipeType.findField("buy");
24
		OpticFinder<?> buyBFinder = recipeType.findField("buyB");
25
		OpticFinder<?> sellFinder = recipeType.findField("sell");
26
		OpticFinder<Pair<String, String>> idF = DSL.fieldFinder("id", DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString()));
27
		Function<Typed<?>, Typed<?>> itemStackUpdater = itemStack -> this.updateItemStack(idF, itemStack);
28
		return this.fixTypeEverywhereTyped(
29
			"Villager trade fix",
30
			recipeType,
31
			recipe -> recipe.updateTyped(buyFinder, itemStackUpdater).updateTyped(buyBFinder, itemStackUpdater).updateTyped(sellFinder, itemStackUpdater)
32
		);
33
	}
34
35
	private Typed<?> updateItemStack(final OpticFinder<Pair<String, String>> idF, final Typed<?> itemStack) {
36
		return itemStack.update(idF, pair -> pair.mapSecond(name -> Objects.equals(name, "minecraft:carved_pumpkin") ? "minecraft:pumpkin" : name));
37
	}
38
}
39

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