BlendingDataFix .java

net.minecraft.util.datafix.fixes.BlendingDataFix (class, 70 lines): extends DataFix. members: STATUSES_TO_SKIP_BLENDING, makeRule, name. imports: Type.

net.minecraft.util.datafix.fixesclass70 linescommonextends DataFix2.7 KB

API Surface (1)

TypeRewriteRule makeRule()

Fields & Constants (2)

STATUSES_TO_SKIP_BLENDING
name

String literals (15)

"minecraft:empty"
"minecraft:structure_starts"
"minecraft:structure_references"
"minecraft:biomes"
"Blending Data Fix v"
"__context"
"blending_data"
"minecraft:overworld"
"dimension"
"Status"
"empty"
"below_zero_retrogen"
"target_status"
"min_section"
"max_section"

Code Graph: Dependencies (2)

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

Full Source

BlendingDataFix.java70 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
import com.mojang.serialization.OptionalDynamic;
10
import java.util.Map;
11
import java.util.Optional;
12
import java.util.Set;
13
import net.minecraft.core.SectionPos;
14
import net.minecraft.util.datafix.schemas.NamespacedSchema;
15
16
public class BlendingDataFix extends DataFix {
17
	private final String name;
18
	private static final Set<String> STATUSES_TO_SKIP_BLENDING = Set.of(
19
		"minecraft:empty", "minecraft:structure_starts", "minecraft:structure_references", "minecraft:biomes"
20
	);
21
22
	public BlendingDataFix(final Schema outputSchema) {
23
		super(outputSchema, false);
24
		this.name = "Blending Data Fix v" + outputSchema.getVersionKey();
25
	}
26
27
	@Override
28
	protected TypeRewriteRule makeRule() {
29
		Type<?> chunkType = this.getOutputSchema().getType(References.CHUNK);
30
		return this.fixTypeEverywhereTyped(
31
			this.name, chunkType, chunk -> chunk.update(DSL.remainderFinder(), chunkTag -> updateChunkTag(chunkTag, chunkTag.get("__context")))
32
		);
33
	}
34
35
	private static Dynamic<?> updateChunkTag(Dynamic<?> chunkTag, final OptionalDynamic<?> contextTag) {
36
		chunkTag = chunkTag.remove("blending_data");
37
		boolean isOverworld = "minecraft:overworld".equals(contextTag.get("dimension").asString().result().orElse(""));
38
		Optional<? extends Dynamic<?>> statusOpt = chunkTag.get("Status").result();
39
		if (isOverworld && statusOpt.isPresent()) {
40
			String status = NamespacedSchema.ensureNamespaced(statusOpt.get().asString("empty"));
41
			Optional<? extends Dynamic<?>> belowZeroRetrogenOpt = chunkTag.get("below_zero_retrogen").result();
42
			if (!STATUSES_TO_SKIP_BLENDING.contains(status)) {
43
				chunkTag = updateBlendingData(chunkTag, 384, -64);
44
			} else if (belowZeroRetrogenOpt.isPresent()) {
45
				Dynamic<?> belowZeroRetrogen = (Dynamic<?>)belowZeroRetrogenOpt.get();
46
				String targetStatus = NamespacedSchema.ensureNamespaced(belowZeroRetrogen.get("target_status").asString("empty"));
47
				if (!STATUSES_TO_SKIP_BLENDING.contains(targetStatus)) {
48
					chunkTag = updateBlendingData(chunkTag, 256, 0);
49
				}
50
			}
51
		}
52
53
		return chunkTag;
54
	}
55
56
	private static Dynamic<?> updateBlendingData(final Dynamic<?> chunkTag, final int height, final int minY) {
57
		return chunkTag.set(
58
			"blending_data",
59
			chunkTag.createMap(
60
				Map.of(
61
					chunkTag.createString("min_section"),
62
					chunkTag.createInt(SectionPos.blockToSectionCoord(minY)),
63
					chunkTag.createString("max_section"),
64
					chunkTag.createInt(SectionPos.blockToSectionCoord(minY + height))
65
				)
66
			)
67
		);
68
	}
69
}
70

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