ReorganizePoi .java

net.minecraft.util.datafix.fixes.ReorganizePoi (class, 48 lines): extends DataFix. members: makeRule. strings: "POI reorganization", "Records", "Sections".

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

API Surface (1)

TypeRewriteRule makeRule()

String literals (4)

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

Full Source

ReorganizePoi.java48 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.google.common.collect.ImmutableMap;
4
import com.google.common.collect.Maps;
5
import com.mojang.datafixers.DSL;
6
import com.mojang.datafixers.DataFix;
7
import com.mojang.datafixers.TypeRewriteRule;
8
import com.mojang.datafixers.schemas.Schema;
9
import com.mojang.datafixers.types.Type;
10
import com.mojang.datafixers.util.Pair;
11
import com.mojang.serialization.Dynamic;
12
import java.util.Map;
13
import java.util.Objects;
14
import java.util.Optional;
15
16
public class ReorganizePoi extends DataFix {
17
	public ReorganizePoi(final Schema outputSchema, final boolean changesType) {
18
		super(outputSchema, changesType);
19
	}
20
21
	@Override
22
	protected TypeRewriteRule makeRule() {
23
		Type<Pair<String, Dynamic<?>>> poiChunkType = DSL.named(References.POI_CHUNK.typeName(), DSL.remainderType());
24
		if (!Objects.equals(poiChunkType, this.getInputSchema().getType(References.POI_CHUNK))) {
25
			throw new IllegalStateException("Poi type is not what was expected.");
26
		} else {
27
			return this.fixTypeEverywhere("POI reorganization", poiChunkType, ops -> input -> input.mapSecond(ReorganizePoi::cap));
28
		}
29
	}
30
31
	private static <T> Dynamic<T> cap(Dynamic<T> input) {
32
		Map<Dynamic<T>, Dynamic<T>> sections = Maps.newHashMap();
33
34
		for (int i = 0; i < 16; i++) {
35
			String key = String.valueOf(i);
36
			Optional<Dynamic<T>> section = input.get(key).result();
37
			if (section.isPresent()) {
38
				Dynamic<T> sectionRecords = section.get();
39
				Dynamic<T> newSection = input.createMap(ImmutableMap.of(input.createString("Records"), sectionRecords));
40
				sections.put(input.createString(Integer.toString(i)), newSection);
41
				input = input.remove(key);
42
			}
43
		}
44
45
		return input.set("Sections", input.createMap(sections));
46
	}
47
}
48

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