Search in sources :

Example 1 with PrimaryLevelDataBridge

use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.

the class LevelChunkMixin method impl$getValidatedUUID.

private Optional<UUID> impl$getValidatedUUID(final int key, final int ownerIndex) {
    final PrimaryLevelDataBridge worldInfo = (PrimaryLevelDataBridge) this.level.getLevelData();
    final UUID uuid = worldInfo.bridge$getUniqueIdForIndex(ownerIndex).orElse(null);
    if (uuid != null) {
        // Verify id is valid and not invalid
        if (SpongeConfigs.getCommon().get().world.invalidLookupUuids.contains(uuid)) {
            if (key <= Short.MAX_VALUE) {
                this.impl$trackedShortBlockPositions.remove((short) key);
            }
            this.impl$trackedIntBlockPositions.remove(key);
            return Optional.empty();
        }
        // player is not online, get or create user from storage
        return Optional.of(uuid);
    }
    return Optional.empty();
}
Also used : UUID(java.util.UUID) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)

Example 2 with PrimaryLevelDataBridge

use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.

the class LevelStemMixin method bridge$populateFromLevelData.

@Override
public void bridge$populateFromLevelData(final PrimaryLevelData levelData) {
    final PrimaryLevelDataBridge levelDataBridge = (PrimaryLevelDataBridge) levelData;
    this.impl$gameMode = (ResourceLocation) (Object) RegistryTypes.GAME_MODE.get().valueKey((GameMode) (Object) levelData.getGameType());
    this.impl$difficulty = (ResourceLocation) (Object) RegistryTypes.DIFFICULTY.get().valueKey((Difficulty) (Object) levelData.getDifficulty());
    this.impl$serializationBehavior = levelDataBridge.bridge$serializationBehavior().orElse(null);
    this.impl$displayName = levelDataBridge.bridge$displayName().orElse(null);
    this.impl$viewDistance = levelDataBridge.bridge$viewDistance().orElse(null);
    this.impl$spawnPosition = new Vector3i(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn());
    this.impl$loadOnStartup = levelDataBridge.bridge$loadOnStartup();
    this.impl$performsSpawnLogic = levelDataBridge.bridge$performsSpawnLogic();
    this.impl$hardcore = levelData.isHardcore();
    this.impl$commands = levelData.getAllowCommands();
    this.impl$pvp = levelDataBridge.bridge$pvp().orElse(null);
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) Vector3i(org.spongepowered.math.vector.Vector3i) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)

Example 3 with PrimaryLevelDataBridge

use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.

the class LevelStorageSourceMixin_Vanilla method impl$readSpongeLevelData.

@Redirect(method = "lambda$getLevelData$4", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelSettings;parse(Lcom/mojang/serialization/Dynamic;Lnet/minecraft/world/level/DataPackConfig;)Lnet/minecraft/world/level/LevelSettings;"), to = @At(value = "RETURN")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;parse(Lcom/mojang/serialization/Dynamic;Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/storage/LevelVersion;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/world/level/storage/PrimaryLevelData;"))
private static PrimaryLevelData impl$readSpongeLevelData(final Dynamic<Tag> p_237369_0_, final DataFixer p_237369_1_, final int p_237369_2_, final CompoundTag p_237369_3_, final LevelSettings p_237369_4_, final LevelVersion p_237369_5_, final WorldGenSettings p_237369_6_, final Lifecycle p_237369_7_) {
    final PrimaryLevelData levelData = PrimaryLevelData.parse(p_237369_0_, p_237369_1_, p_237369_2_, p_237369_3_, p_237369_4_, p_237369_5_, p_237369_6_, p_237369_7_);
    ((PrimaryLevelDataBridge) levelData).bridge$readSpongeLevelData(LevelStorageSourceMixin_Vanilla.impl$spongeLevelData);
    LevelStorageSourceMixin_Vanilla.impl$spongeLevelData = null;
    return levelData;
}
Also used : PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with PrimaryLevelDataBridge

use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge 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 5 with PrimaryLevelDataBridge

use of org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge in project SpongeCommon by SpongePowered.

the class SpongeWorldManager method prepareWorld.

private ServerLevel prepareWorld(final ServerLevel world, final boolean isDebugGeneration) {
    final boolean isDefaultWorld = Level.OVERWORLD.equals(world.dimension());
    final PrimaryLevelData levelData = (PrimaryLevelData) world.getLevelData();
    if (isDefaultWorld) {
        // Initialize scoreboard data. This will hook to the ServerScoreboard, needs to be made multi-world aware
        ((MinecraftServerAccessor) this.server).accessor$readScoreboard(world.getDataStorage());
        ((MinecraftServerAccessor) this.server).accessor$commandStorage(new CommandStorage(world.getDataStorage()));
    }
    final boolean isInitialized = levelData.isInitialized();
    SpongeCommon.post(SpongeEventFactory.createLoadWorldEvent(PhaseTracker.getCauseStackManager().currentCause(), (org.spongepowered.api.world.server.ServerWorld) world, isInitialized));
    PlatformHooks.INSTANCE.getWorldHooks().postLoadWorld(world);
    // Set the view distance back on it's self to trigger the logic
    ((PrimaryLevelDataBridge) world.getLevelData()).bridge$viewDistance().ifPresent(v -> ((PrimaryLevelDataBridge) world.getLevelData()).bridge$setViewDistance(v));
    world.getWorldBorder().applySettings(levelData.getWorldBorder());
    if (!isInitialized) {
        try {
            final boolean hasSpawnAlready = ((PrimaryLevelDataBridge) world.getLevelData()).bridge$customSpawnPosition();
            if (!hasSpawnAlready) {
                if (isDefaultWorld || ((ServerWorldProperties) world.getLevelData()).performsSpawnLogic()) {
                    MinecraftServerAccessor.invoker$setInitialSpawn(world, levelData, levelData.worldGenSettings().generateBonusChest(), isDebugGeneration, !isDebugGeneration);
                } else if (Level.END.equals(world.dimension())) {
                    ((PrimaryLevelData) world.getLevelData()).setSpawn(ServerLevel.END_SPAWN_POINT, 0);
                }
            } else {
                Features.BONUS_CHEST.place(world, world.getChunkSource().getGenerator(), world.random, new BlockPos(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn()));
            }
            levelData.setInitialized(true);
            if (isDebugGeneration) {
                ((MinecraftServerAccessor) this.server).invoker$setupDebugLevel(levelData);
            }
        } catch (final Throwable throwable) {
            final CrashReport crashReport = CrashReport.forThrowable(throwable, "Exception initializing world '" + world.dimension().location() + "'");
            try {
                world.fillReportDetails(crashReport);
            } catch (final Throwable ignore) {
            }
            throw new ReportedException(crashReport);
        }
        levelData.setInitialized(true);
    }
    // Initialize PlayerData in PlayerList, add WorldBorder listener. We change the method in PlayerList to handle per-world border
    this.server.getPlayerList().setLevel(world);
    if (levelData.getCustomBossEvents() != null) {
        ((ServerLevelBridge) world).bridge$getBossBarManager().load(levelData.getCustomBossEvents());
    }
    return world;
}
Also used : PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) MinecraftServerAccessor(org.spongepowered.common.accessor.server.MinecraftServerAccessor) CrashReport(net.minecraft.CrashReport) CommandStorage(net.minecraft.world.level.storage.CommandStorage) BlockPos(net.minecraft.core.BlockPos) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) ReportedException(net.minecraft.ReportedException)

Aggregations

PrimaryLevelDataBridge (org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)15 PrimaryLevelData (net.minecraft.world.level.storage.PrimaryLevelData)7 WorldConfig (org.spongepowered.common.config.inheritable.WorldConfig)6 ServerLevel (net.minecraft.server.level.ServerLevel)5 JsonObject (com.google.gson.JsonObject)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Level (net.minecraft.world.level.Level)4 LevelSettings (net.minecraft.world.level.LevelSettings)4 LevelStem (net.minecraft.world.level.dimension.LevelStem)4 LevelStorageSource (net.minecraft.world.level.storage.LevelStorageSource)4 WorldType (org.spongepowered.api.world.WorldType)4 MinecraftServerAccessor (org.spongepowered.common.accessor.server.MinecraftServerAccessor)4 PrimaryLevelDataAccessor (org.spongepowered.common.accessor.world.level.storage.PrimaryLevelDataAccessor)4 DynamicOps (com.mojang.serialization.DynamicOps)3 Map (java.util.Map)3 Tag (net.minecraft.nbt.Tag)3 ChunkProgressListener (net.minecraft.server.level.progress.ChunkProgressListener)3 Difficulty (net.minecraft.world.Difficulty)3 VillageSiege (net.minecraft.world.entity.ai.village.VillageSiege)3