package net.minecraft.world.level.saveddata; import com.mojang.logging.LogUtils; import java.io.File; import java.io.IOException; import java.util.function.BiFunction; import java.util.function.Supplier; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtUtils; import net.minecraft.util.datafix.DataFixTypes; import org.slf4j.Logger; public abstract class SavedData { private static final Logger LOGGER = LogUtils.getLogger(); private boolean dirty; public abstract CompoundTag save(CompoundTag tag, HolderLookup.Provider registries); /** * Marks this {@code SavedData} dirty, to be saved to disk when the level next saves. */ public void setDirty() { this.setDirty(true); } /** * Sets the dirty state of this {@code SavedData}, whether it needs saving to disk. */ public void setDirty(boolean dirty) { this.dirty = dirty; } /** * Whether this {@code SavedData} needs saving to disk. */ public boolean isDirty() { return this.dirty; } public void save(File file, HolderLookup.Provider registries) { if (this.isDirty()) { CompoundTag compoundTag = new CompoundTag(); compoundTag.put("data", this.save(new CompoundTag(), registries)); NbtUtils.addCurrentDataVersion(compoundTag); try { NbtIo.writeCompressed(compoundTag, file.toPath()); } catch (IOException var5) { LOGGER.error("Could not save data {}", this, var5); } this.setDirty(false); } } public record Factory(Supplier constructor, BiFunction deserializer, DataFixTypes type) { } }