Search in sources :

Example 1 with WorldData

use of net.minecraft.world.level.storage.WorldData in project SpongeCommon by SpongePowered.

the class SpongeWorldManager method loadProperties.

@Override
public CompletableFuture<Optional<ServerWorldProperties>> loadProperties(final ResourceKey key) {
    final net.minecraft.resources.ResourceKey<Level> registryKey = SpongeWorldManager.createRegistryKey(Objects.requireNonNull(key, "key"));
    if (this.worlds.get(registryKey) != null) {
        return CompletableFuture.completedFuture(Optional.empty());
    }
    if (!this.worldExists(key)) {
        return CompletableFuture.completedFuture(Optional.empty());
    }
    final boolean isVanillaWorld = this.isVanillaWorld(key);
    final String directoryName = this.getDirectoryName(key);
    final LevelStorageSource.LevelStorageAccess storageSource;
    try {
        if (isVanillaWorld) {
            storageSource = LevelStorageSource.createDefault(this.defaultWorldDirectory).createAccess(directoryName);
        } else {
            storageSource = LevelStorageSource.createDefault(this.customWorldsDirectory).createAccess(key.namespace() + File.separator + key.value());
        }
    } catch (final IOException e) {
        return FutureUtil.completedWithException(e);
    }
    final WorldData levelData;
    try {
        final PrimaryLevelData defaultLevelData = (PrimaryLevelData) this.server.getWorldData();
        final LevelSettings defaultLevelSettings = ((PrimaryLevelDataAccessor) defaultLevelData).accessor$settings();
        try {
            levelData = storageSource.getDataTag((DynamicOps<Tag>) BootstrapProperties.worldSettingsAdapter, defaultLevelSettings.getDataPackConfig());
        } catch (final Exception ex) {
            return FutureUtil.completedWithException(ex);
        }
    } finally {
        try {
            storageSource.close();
        } catch (final IOException ex) {
            return FutureUtil.completedWithException(ex);
        }
    }
    return this.loadTemplate(key).thenCompose(r -> {
        r.ifPresent(template -> {
            final LevelStem scratch = ((SpongeWorldTemplate) template).asDimension();
            ((PrimaryLevelDataBridge) levelData).bridge$populateFromDimension(scratch);
        });
        return CompletableFuture.completedFuture(Optional.of((ServerWorldProperties) levelData));
    });
}
Also used : ServerWorldProperties(org.spongepowered.api.world.server.storage.ServerWorldProperties) LevelStorageSource(net.minecraft.world.level.storage.LevelStorageSource) IOException(java.io.IOException) WorldData(net.minecraft.world.level.storage.WorldData) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ReportedException(net.minecraft.ReportedException) PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) LevelStem(net.minecraft.world.level.dimension.LevelStem) Level(net.minecraft.world.level.Level) ServerLevel(net.minecraft.server.level.ServerLevel) LevelSettings(net.minecraft.world.level.LevelSettings) PrimaryLevelDataAccessor(org.spongepowered.common.accessor.world.level.storage.PrimaryLevelDataAccessor) DynamicOps(com.mojang.serialization.DynamicOps)

Example 2 with WorldData

use of net.minecraft.world.level.storage.WorldData in project SpongeCommon by SpongePowered.

the class MinecraftMixin method impl$serializeDelayedDataPackOnLoadAndSetBootstrapProperties.

@Redirect(method = "loadWorldData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getDataTag(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/world/level/DataPackConfig;)Lnet/minecraft/world/level/storage/WorldData;"))
private static WorldData impl$serializeDelayedDataPackOnLoadAndSetBootstrapProperties(final LevelStorageSource.LevelStorageAccess levelSave, final DynamicOps<Tag> p_237284_1_, final DataPackConfig p_237284_2_, final LevelStorageSource.LevelStorageAccess p_238181_0_, final RegistryAccess.RegistryHolder p_238181_1_) {
    SpongeDataPackManager.INSTANCE.serializeDelayedDataPack(DataPackTypes.WORLD);
    final WorldData saveData = levelSave.getDataTag(p_237284_1_, p_237284_2_);
    BootstrapProperties.init(saveData.worldGenSettings(), saveData.getGameType(), saveData.getDifficulty(), true, saveData.isHardcore(), saveData.getAllowCommands(), 10, p_238181_1_);
    return saveData;
}
Also used : WorldData(net.minecraft.world.level.storage.WorldData) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

WorldData (net.minecraft.world.level.storage.WorldData)2 DynamicOps (com.mojang.serialization.DynamicOps)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ReportedException (net.minecraft.ReportedException)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 Level (net.minecraft.world.level.Level)1 LevelSettings (net.minecraft.world.level.LevelSettings)1 LevelStem (net.minecraft.world.level.dimension.LevelStem)1 LevelStorageSource (net.minecraft.world.level.storage.LevelStorageSource)1 PrimaryLevelData (net.minecraft.world.level.storage.PrimaryLevelData)1 ServerWorldProperties (org.spongepowered.api.world.server.storage.ServerWorldProperties)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 PrimaryLevelDataAccessor (org.spongepowered.common.accessor.world.level.storage.PrimaryLevelDataAccessor)1 PrimaryLevelDataBridge (org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)1