package net.minecraft.world.level.saveddata; import java.util.function.BiFunction; import java.util.function.Supplier; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.util.datafix.DataFixTypes; public abstract class SavedData { 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 CompoundTag save(HolderLookup.Provider provider) { CompoundTag compoundTag = new CompoundTag(); compoundTag.put("data", this.save(new CompoundTag(), provider)); NbtUtils.addCurrentDataVersion(compoundTag); this.setDirty(false); return compoundTag; } public record Factory(Supplier constructor, BiFunction deserializer, DataFixTypes type) { } }