StructureUpdater .java

net.minecraft.data.structures.StructureUpdater (class, 35 lines): implements Filter. members: PREFIX, update, apply, LOGGER. imports: DataFixers, PackType.

net.minecraft.data.structuresclass35 linescommon1.4 KB

Implements

API Surface (2)

CompoundTag apply(final String name, final CompoundTag input)
CompoundTag update(final String name, final CompoundTag tag)

Fields & Constants (2)

LOGGER
PREFIX

String literals (1)

"/minecraft/structure/"

Code Graph: Dependencies (8)

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

Full Source

StructureUpdater.java35 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.structures;
2
3
import com.mojang.logging.LogUtils;
4
import net.minecraft.core.registries.BuiltInRegistries;
5
import net.minecraft.nbt.CompoundTag;
6
import net.minecraft.nbt.NbtUtils;
7
import net.minecraft.server.packs.PackType;
8
import net.minecraft.util.datafix.DataFixTypes;
9
import net.minecraft.util.datafix.DataFixers;
10
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
11
import org.slf4j.Logger;
12
13
public class StructureUpdater implements SnbtToNbt.Filter {
14
	private static final Logger LOGGER = LogUtils.getLogger();
15
	private static final String PREFIX = PackType.SERVER_DATA.getDirectory() + "/minecraft/structure/";
16
17
	@Override
18
	public CompoundTag apply(final String name, final CompoundTag input) {
19
		return name.startsWith(PREFIX) ? update(name, input) : input;
20
	}
21
22
	public static CompoundTag update(final String name, final CompoundTag tag) {
23
		StructureTemplate structureTemplate = new StructureTemplate();
24
		int fromVersion = NbtUtils.getDataVersion(tag, 500);
25
		int toVersion = 4997;
26
		if (fromVersion < 4997) {
27
			LOGGER.warn("SNBT Too old, do not forget to update: {} < {}: {}", fromVersion, 4997, name);
28
		}
29
30
		CompoundTag updated = DataFixTypes.STRUCTURE.updateToCurrentVersion(DataFixers.getDataFixer(), tag, fromVersion);
31
		structureTemplate.load(BuiltInRegistries.BLOCK, updated);
32
		return structureTemplate.save(new CompoundTag());
33
	}
34
}
35

Decompiled Minecraft 26.3 source of StructureUpdater (net/minecraft/data/structures/StructureUpdater.java) with Mojang official mappings, stored verbatim on the site.