WorldGenSettingsHeightAndBiomeFix .java

net.minecraft.util.datafix.fixes.WorldGenSettingsHeightAndBiomeFix (class): members: WAS_PREVIOUSLY_INCREASED_KEY, NAME, makeRule. strings: "large_biomes".

net.minecraft.util.datafix.fixesclass103 linescommonextends DataFix4.0 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (2)

NAME
WAS_PREVIOUSLY_INCREASED_KEY

String literals (17)

"has_increased_height_already"
"dimensions"
"minecraft:overworld"
"generator"
"minecraft:noise"
"biome_source"
"minecraft:vanilla_layered"
"minecraft:multi_noise"
"large_biomes"
"preset"
"settings"
"minecraft:large_biomes"
"minecraft:flat"
"layers"
"height"
"block"
"minecraft:air"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

WorldGenSettingsHeightAndBiomeFix.java103 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.datafix.fixes;
2
3
import com.google.common.collect.ImmutableMap;
4
import com.mojang.datafixers.DSL;
5
import com.mojang.datafixers.DataFix;
6
import com.mojang.datafixers.OpticFinder;
7
import com.mojang.datafixers.TypeRewriteRule;
8
import com.mojang.datafixers.schemas.Schema;
9
import com.mojang.datafixers.types.Type;
10
import com.mojang.serialization.Dynamic;
11
import com.mojang.serialization.OptionalDynamic;
12
import java.util.stream.Stream;
13
import net.minecraft.util.Util;
14
import org.apache.commons.lang3.mutable.MutableBoolean;
15
16
public class WorldGenSettingsHeightAndBiomeFix extends DataFix {
17
	private static final String NAME = "WorldGenSettingsHeightAndBiomeFix";
18
	public static final String WAS_PREVIOUSLY_INCREASED_KEY = "has_increased_height_already";
19
20
	public WorldGenSettingsHeightAndBiomeFix(final Schema outputSchema) {
21
		super(outputSchema, true);
22
	}
23
24
	@Override
25
	protected TypeRewriteRule makeRule() {
26
		Type<?> worldGenSettingsType = this.getInputSchema().getType(References.WORLD_GEN_SETTINGS);
27
		OpticFinder<?> dimensionsFinder = worldGenSettingsType.findField("dimensions");
28
		Type<?> worldGenSettingsTypeNew = this.getOutputSchema().getType(References.WORLD_GEN_SETTINGS);
29
		Type<?> dimensionsType = worldGenSettingsTypeNew.findFieldType("dimensions");
30
		return this.fixTypeEverywhereTyped(
31
			"WorldGenSettingsHeightAndBiomeFix",
32
			worldGenSettingsType,
33
			worldGenSettingsTypeNew,
34
			input -> {
35
				OptionalDynamic<?> wasIncreasedOpt = input.get(DSL.remainderFinder()).get("has_increased_height_already");
36
				boolean wasExpSnap = wasIncreasedOpt.result().isEmpty();
37
				boolean wasPreviouslyIncreased = wasIncreasedOpt.asBoolean(true);
38
				return input.update(DSL.remainderFinder(), tag -> tag.remove("has_increased_height_already"))
39
					.updateTyped(
40
						dimensionsFinder,
41
						dimensionsType,
42
						dimensions -> Util.writeAndReadTypedOrThrow(
43
							dimensions,
44
							dimensionsType,
45
							dimensionsTag -> dimensionsTag.update(
46
								"minecraft:overworld",
47
								overworldTag -> overworldTag.update(
48
									"generator",
49
									generator -> {
50
										String generatorType = generator.get("type").asString("");
51
										if ("minecraft:noise".equals(generatorType)) {
52
											MutableBoolean isLargeBiomes = new MutableBoolean();
53
											generator = generator.update(
54
												"biome_source",
55
												biomeSource -> {
56
													String type = biomeSource.get("type").asString("");
57
													if ("minecraft:vanilla_layered".equals(type) || wasExpSnap && "minecraft:multi_noise".equals(type)) {
58
														if (biomeSource.get("large_biomes").asBoolean(false)) {
59
															isLargeBiomes.setTrue();
60
														}
61
62
														return biomeSource.createMap(
63
															ImmutableMap.of(
64
																biomeSource.createString("preset"),
65
																biomeSource.createString("minecraft:overworld"),
66
																biomeSource.createString("type"),
67
																biomeSource.createString("minecraft:multi_noise")
68
															)
69
														);
70
													} else {
71
														return biomeSource;
72
													}
73
												}
74
											);
75
											return isLargeBiomes.booleanValue()
76
												? generator.update(
77
													"settings", settings -> "minecraft:overworld".equals(settings.asString("")) ? settings.createString("minecraft:large_biomes") : settings
78
												)
79
												: generator;
80
										} else if ("minecraft:flat".equals(generatorType)) {
81
											return wasPreviouslyIncreased
82
												? generator
83
												: generator.update("settings", settings -> settings.update("layers", WorldGenSettingsHeightAndBiomeFix::updateLayers));
84
										} else {
85
											return generator;
86
										}
87
									}
88
								)
89
							)
90
						)
91
					);
92
			}
93
		);
94
	}
95
96
	private static Dynamic<?> updateLayers(final Dynamic<?> layers) {
97
		Dynamic<?> airLayer = layers.createMap(
98
			ImmutableMap.of(layers.createString("height"), layers.createInt(64), layers.createString("block"), layers.createString("minecraft:air"))
99
		);
100
		return layers.createList(Stream.concat(Stream.of(airLayer), layers.asStream()));
101
	}
102
}
103

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