AbstractArrowPickupFix .java

net.minecraft.util.datafix.fixes.AbstractArrowPickupFix (class, 44 lines): members: makeRule. strings: "pickup", "minecraft:trident", "minecraft:arrow".

net.minecraft.util.datafix.fixesclass44 linescommonextends DataFix1.7 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (5)

"minecraft:arrow"
"minecraft:spectral_arrow"
"minecraft:trident"
"pickup"
"player"

Full Source

AbstractArrowPickupFix.java44 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.TypeRewriteRule;
6
import com.mojang.datafixers.Typed;
7
import com.mojang.datafixers.schemas.Schema;
8
import com.mojang.datafixers.types.Type;
9
import com.mojang.serialization.Dynamic;
10
import java.util.function.Function;
11
12
public class AbstractArrowPickupFix extends DataFix {
13
	public AbstractArrowPickupFix(final Schema outputSchema) {
14
		super(outputSchema, false);
15
	}
16
17
	@Override
18
	protected TypeRewriteRule makeRule() {
19
		Schema inputSchema = this.getInputSchema();
20
		return this.fixTypeEverywhereTyped("AbstractArrowPickupFix", inputSchema.getType(References.ENTITY), this::updateProjectiles);
21
	}
22
23
	private Typed<?> updateProjectiles(Typed<?> input) {
24
		input = this.updateEntity(input, "minecraft:arrow", AbstractArrowPickupFix::updatePickup);
25
		input = this.updateEntity(input, "minecraft:spectral_arrow", AbstractArrowPickupFix::updatePickup);
26
		return this.updateEntity(input, "minecraft:trident", AbstractArrowPickupFix::updatePickup);
27
	}
28
29
	private static Dynamic<?> updatePickup(final Dynamic<?> tag) {
30
		if (tag.get("pickup").result().isPresent()) {
31
			return tag;
32
		}
33
34
		boolean fromPlayer = tag.get("player").asBoolean(true);
35
		return tag.set("pickup", tag.createByte((byte)(fromPlayer ? 1 : 0))).remove("player");
36
	}
37
38
	private Typed<?> updateEntity(final Typed<?> input, final String name, final Function<Dynamic<?>, Dynamic<?>> function) {
39
		Type<?> oldType = this.getInputSchema().getChoiceType(References.ENTITY, name);
40
		Type<?> newType = this.getOutputSchema().getChoiceType(References.ENTITY, name);
41
		return input.updateTyped(DSL.namedChoice(name, oldType), newType, entity -> entity.update(DSL.remainderFinder(), function));
42
	}
43
}
44

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