AbstractPoiSectionFix .java

net.minecraft.util.datafix.fixes.AbstractPoiSectionFix (class, 46 lines): members: processRecords, makeRule, name. strings: "Records", "Sections".

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

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (1)

name

String literals (3)

"Poi type is not what was expected."
"Sections"
"Records"

Full Source

AbstractPoiSectionFix.java46 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.DataFixUtils;
6
import com.mojang.datafixers.TypeRewriteRule;
7
import com.mojang.datafixers.schemas.Schema;
8
import com.mojang.datafixers.types.Type;
9
import com.mojang.datafixers.util.Pair;
10
import com.mojang.serialization.Dynamic;
11
import java.util.Objects;
12
import java.util.stream.Stream;
13
14
public abstract class AbstractPoiSectionFix extends DataFix {
15
	private final String name;
16
17
	public AbstractPoiSectionFix(final Schema outputSchema, final String name) {
18
		super(outputSchema, false);
19
		this.name = name;
20
	}
21
22
	@Override
23
	protected TypeRewriteRule makeRule() {
24
		Type<Pair<String, Dynamic<?>>> poiChunkType = DSL.named(References.POI_CHUNK.typeName(), DSL.remainderType());
25
		if (!Objects.equals(poiChunkType, this.getInputSchema().getType(References.POI_CHUNK))) {
26
			throw new IllegalStateException("Poi type is not what was expected.");
27
		} else {
28
			return this.fixTypeEverywhere(this.name, poiChunkType, ops -> input -> input.mapSecond(this::cap));
29
		}
30
	}
31
32
	private <T> Dynamic<T> cap(final Dynamic<T> input) {
33
		return input.update("Sections", sections -> sections.updateMapValues(entry -> entry.mapSecond(this::processSection)));
34
	}
35
36
	private Dynamic<?> processSection(final Dynamic<?> section) {
37
		return section.update("Records", this::processSectionRecords);
38
	}
39
40
	private <T> Dynamic<T> processSectionRecords(final Dynamic<T> input) {
41
		return DataFixUtils.orElse(input.asStreamOpt().result().map(stream -> input.createList(this.processRecords((Stream<Dynamic<T>>)stream))), input);
42
	}
43
44
	protected abstract <T> Stream<Dynamic<T>> processRecords(Stream<Dynamic<T>> records);
45
}
46

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