minecraft-src/net/minecraft/data/structures/StructureUpdater.java
2025-07-04 01:41:11 +03:00

34 lines
1.4 KiB
Java

package net.minecraft.data.structures;
import com.mojang.logging.LogUtils;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.datafix.DataFixTypes;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import org.slf4j.Logger;
public class StructureUpdater implements SnbtToNbt.Filter {
private static final Logger LOGGER = LogUtils.getLogger();
private static final String PREFIX = PackType.SERVER_DATA.getDirectory() + "/minecraft/structure/";
@Override
public CompoundTag apply(String string, CompoundTag compoundTag) {
return string.startsWith(PREFIX) ? update(string, compoundTag) : compoundTag;
}
public static CompoundTag update(String structureLocationPath, CompoundTag tag) {
StructureTemplate structureTemplate = new StructureTemplate();
int i = NbtUtils.getDataVersion(tag, 500);
int j = 3937;
if (i < 3937) {
LOGGER.warn("SNBT Too old, do not forget to update: {} < {}: {}", i, 3937, structureLocationPath);
}
CompoundTag compoundTag = DataFixTypes.STRUCTURE.updateToCurrentVersion(DataFixers.getDataFixer(), tag, i);
structureTemplate.load(BuiltInRegistries.BLOCK.asLookup(), compoundTag);
return structureTemplate.save(new CompoundTag());
}
}