ChunkBiomeFix .java

net.minecraft.util.datafix.fixes.ChunkBiomeFix (class): members: makeRule. strings: "Leaves fix", "Biomes", "Level". imports: OpticFinder, Type, DataFix.

net.minecraft.util.datafix.fixesclass52 linescommonextends DataFix1.5 KB

API Surface (1)

TypeRewriteRule makeRule()

String literals (3)

"Level"
"Leaves fix"
"Biomes"

Full Source

ChunkBiomeFix.java52 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.schemas.Schema;
8
import com.mojang.datafixers.types.Type;
9
import java.util.Arrays;
10
import java.util.Optional;
11
import java.util.stream.IntStream;
12
13
public class ChunkBiomeFix extends DataFix {
14
	public ChunkBiomeFix(final Schema outputSchema, final boolean changesType) {
15
		super(outputSchema, changesType);
16
	}
17
18
	@Override
19
	protected TypeRewriteRule makeRule() {
20
		Type<?> chunkType = this.getInputSchema().getType(References.CHUNK);
21
		OpticFinder<?> levelFinder = chunkType.findField("Level");
22
		return this.fixTypeEverywhereTyped("Leaves fix", chunkType, chunk -> chunk.updateTyped(levelFinder, level -> level.update(DSL.remainderFinder(), tag -> {
23
			Optional<IntStream> biomes = tag.get("Biomes").asIntStreamOpt().result();
24
			if (biomes.isEmpty()) {
25
				return tag;
26
			}
27
28
			int[] oldBiomes = biomes.get().toArray();
29
			if (oldBiomes.length != 256) {
30
				return tag;
31
			}
32
33
			int[] newBiomes = new int[1024];
34
35
			for (int z = 0; z < 4; z++) {
36
				for (int x = 0; x < 4; x++) {
37
					int oldX = (x << 2) + 2;
38
					int oldZ = (z << 2) + 2;
39
					int index = oldZ << 4 | oldX;
40
					newBiomes[z << 2 | x] = oldBiomes[index];
41
				}
42
			}
43
44
			for (int ySlice = 1; ySlice < 64; ySlice++) {
45
				System.arraycopy(newBiomes, 0, newBiomes, ySlice * 16, 16);
46
			}
47
48
			return tag.set("Biomes", tag.createIntList(Arrays.stream(newBiomes)));
49
		})));
50
	}
51
}
52

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