IglooMetadataRemovalFix .java

net.minecraft.util.datafix.fixes.IglooMetadataRemovalFix (class, 34 lines): members: makeRule. strings: "Igloo", "Iglu", "Children". imports: Type.

net.minecraft.util.datafix.fixesclass34 linescommonextends DataFix1.4 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (3)

"Children"
"Igloo"
"Iglu"

Full Source

IglooMetadataRemovalFix.java34 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.schemas.Schema;
7
import com.mojang.datafixers.types.Type;
8
import com.mojang.serialization.Dynamic;
9
10
public class IglooMetadataRemovalFix extends DataFix {
11
	public IglooMetadataRemovalFix(final Schema outputSchema, final boolean changesType) {
12
		super(outputSchema, changesType);
13
	}
14
15
	@Override
16
	protected TypeRewriteRule makeRule() {
17
		Type<?> type = this.getInputSchema().getType(References.STRUCTURE_FEATURE);
18
		return this.fixTypeEverywhereTyped("IglooMetadataRemovalFix", type, typed -> typed.update(DSL.remainderFinder(), IglooMetadataRemovalFix::fixTag));
19
	}
20
21
	private static <T> Dynamic<T> fixTag(final Dynamic<T> input) {
22
		boolean isIglooOnly = input.get("Children").asStreamOpt().map(s -> s.allMatch(IglooMetadataRemovalFix::isIglooPiece)).result().orElse(false);
23
		return isIglooOnly ? input.set("id", input.createString("Igloo")).remove("Children") : input.update("Children", IglooMetadataRemovalFix::removeIglooPieces);
24
	}
25
26
	private static <T> Dynamic<T> removeIglooPieces(final Dynamic<T> children) {
27
		return children.asStreamOpt().map(s -> s.filter(v -> !isIglooPiece((Dynamic<?>)v))).map(children::createList).result().orElse(children);
28
	}
29
30
	private static boolean isIglooPiece(final Dynamic<?> tag) {
31
		return tag.get("id").asString("").equals("Iglu");
32
	}
33
}
34

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