package net.minecraft.data.structures;

import org.apache.logging.log4j.LogManager;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.util.datafix.DataFixTypes;
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.nbt.CompoundTag;
import org.apache.logging.log4j.Logger;

public class StructureUpdater implements SnbtToNbt.Filter {
    private static final Logger LOGGER;
    
    @Override
    public CompoundTag apply(final String string, final CompoundTag le) {
        if (string.startsWith("data/minecraft/structures/")) {
            return updateStructure(string, patchVersion(le));
        }
        return le;
    }
    
    private static CompoundTag patchVersion(final CompoundTag le) {
        if (!le.contains("DataVersion", 99)) {
            le.putInt("DataVersion", 500);
        }
        return le;
    }
    
    private static CompoundTag updateStructure(final String string, final CompoundTag le) {
        final StructureTemplate cve3 = new StructureTemplate();
        final int integer4 = le.getInt("DataVersion");
        final int integer5 = 2532;
        if (integer4 < 2532) {
            StructureUpdater.LOGGER.warn("SNBT Too old, do not forget to update: " + integer4 + " < " + 2532 + ": " + string);
        }
        final CompoundTag le2 = NbtUtils.update(DataFixers.getDataFixer(), DataFixTypes.STRUCTURE, le, integer4);
        cve3.load(le2);
        return cve3.save(new CompoundTag());
    }
    
    static {
        LOGGER = LogManager.getLogger();
    }
}
