ProjectileStoredWeaponFix .java

net.minecraft.util.datafix.fixes.ProjectileStoredWeaponFix (class, 47 lines): extends DataFix. members: inputEntityChoiceType, makeRule. imports: Typed.

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

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (1)

inputEntityChoiceType

String literals (3)

"Fix Arrow stored weapon"
"minecraft:arrow"
"minecraft:spectral_arrow"

Code Graph: Dependencies (2)

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

Full Source

ProjectileStoredWeaponFix.java47 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 java.util.function.Function;
11
import java.util.function.UnaryOperator;
12
import net.minecraft.util.Util;
13
import net.minecraft.util.datafix.ExtraDataFixUtils;
14
15
public class ProjectileStoredWeaponFix extends DataFix {
16
	public ProjectileStoredWeaponFix(final Schema outputSchema) {
17
		super(outputSchema, true);
18
	}
19
20
	@Override
21
	protected TypeRewriteRule makeRule() {
22
		Type<?> inputEntityType = this.getInputSchema().getType(References.ENTITY);
23
		Type<?> outputEntityType = this.getOutputSchema().getType(References.ENTITY);
24
		return this.fixTypeEverywhereTyped(
25
			"Fix Arrow stored weapon",
26
			inputEntityType,
27
			outputEntityType,
28
			ExtraDataFixUtils.chainAllFilters(this.fixChoice("minecraft:arrow"), this.fixChoice("minecraft:spectral_arrow"))
29
		);
30
	}
31
32
	private Function<Typed<?>, Typed<?>> fixChoice(final String entityName) {
33
		Type<?> inputEntityChoiceType = this.getInputSchema().getChoiceType(References.ENTITY, entityName);
34
		Type<?> outputEntityChoiceType = this.getOutputSchema().getChoiceType(References.ENTITY, entityName);
35
		return fixChoiceCap(entityName, inputEntityChoiceType, outputEntityChoiceType);
36
	}
37
38
	private static <T> Function<Typed<?>, Typed<?>> fixChoiceCap(
39
		final String entityName, final Type<?> inputEntityChoiceType, final Type<T> outputEntityChoiceType
40
	) {
41
		OpticFinder<?> entityF = DSL.namedChoice(entityName, inputEntityChoiceType);
42
		return input -> input.updateTyped(
43
			entityF, outputEntityChoiceType, typed -> Util.writeAndReadTypedOrThrow(typed, outputEntityChoiceType, UnaryOperator.identity())
44
		);
45
	}
46
}
47

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