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));
});
}
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;
}
Aggregations