Search in sources :

Example 1 with CommandStorage

use of net.minecraft.world.level.storage.CommandStorage 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

CrashReport (net.minecraft.CrashReport)1 ReportedException (net.minecraft.ReportedException)1 BlockPos (net.minecraft.core.BlockPos)1 CommandStorage (net.minecraft.world.level.storage.CommandStorage)1 PrimaryLevelData (net.minecraft.world.level.storage.PrimaryLevelData)1 MinecraftServerAccessor (org.spongepowered.common.accessor.server.MinecraftServerAccessor)1 PrimaryLevelDataBridge (org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)1