/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.forge.data;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.WorldData;
import net.minecraftforge.fml.WorldPersistenceHooks;

public final class SpongeLevelDataPersistence implements WorldPersistenceHooks.WorldPersistenceHook {

    public static final SpongeLevelDataPersistence INSTANCE = new SpongeLevelDataPersistence();

    /**
     * This is actually the tag name, no idea why they call this modid...
     * @return The tag name
     */
    @Override
    public String getModId() {
        return "SpongeData";
    }

    @Override
    public CompoundTag getDataForWriting(LevelStorageSource.LevelStorageAccess arg, WorldData arg2) {
        return new CompoundTag();
    }

    @Override
    public void readData(LevelStorageSource.LevelStorageAccess arg, WorldData arg2, CompoundTag arg3) {
    }
}

@@ -1280,16 +1280,139 @@
 .data;%0A%0A
+import com.mojang.serialization.Dynamic;%0Aimport com.mojang.serialization.DynamicOps;%0Aimport net.minecraft.nbt.CompoundTag;%0A
 import n
@@ -1424,32 +1424,24 @@
 necraft.nbt.
-Compound
 Tag;%0Aimport 
@@ -1494,16 +1494,75 @@
 Source;%0A
+import net.minecraft.world.level.storage.PrimaryLevelData;%0A
 import n
@@ -1657,16 +1657,207 @@
 ceHooks;
+%0Aimport org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge;%0Aimport org.spongepowered.common.server.BootstrapProperties;%0Aimport org.spongepowered.common.util.Constants;
 %0A%0Apublic
@@ -2232,20 +2232,44 @@
 urn 
-%22
+Constants.
 Sponge
+.
 Data
-%22
+.V2.SPONGE_DATA
 ;%0A  
@@ -2408,23 +2408,67 @@
 urn 
-new CompoundTag
+((PrimaryLevelDataBridge) arg2).bridge$writeSpongeLevelData
 ();%0A
@@ -2588,20 +2588,169 @@
 Tag arg3) %7B%0A
+        ((PrimaryLevelDataBridge) arg2).bridge$readSpongeLevelData(new Dynamic%3C%3E((DynamicOps%3CTag%3E) BootstrapProperties.worldSettingsAdapter, arg3));%0A
     %7D%0A%7D%0A

fix SpongeForge not loading/saving level data