Search in sources :

Example 1 with GenerationContext

use of org.spongepowered.common.event.tracking.phase.generation.GenerationContext in project SpongeCommon by SpongePowered.

the class MixinMinecraftServer method prepareSpawnArea.

@Override
public void prepareSpawnArea(WorldServer worldServer) {
    if (!((WorldProperties) worldServer.getWorldInfo()).doesGenerateSpawnOnLoad()) {
        return;
    }
    IMixinChunkProviderServer chunkProviderServer = (IMixinChunkProviderServer) worldServer.getChunkProvider();
    chunkProviderServer.setForceChunkRequests(true);
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    try (GenerationContext context = GenerationPhase.State.TERRAIN_GENERATION.createPhaseContext().source(worldServer).world(worldServer).buildAndSwitch()) {
        int i = 0;
        this.setUserMessage("menu.generatingTerrain");
        LOGGER.info("Preparing start region for level {} ({})", ((IMixinWorldServer) worldServer).getDimensionId(), ((World) worldServer).getName());
        BlockPos blockpos = worldServer.getSpawnPoint();
        long j = MinecraftServer.getCurrentTimeMillis();
        for (int k = -192; k <= 192 && this.isServerRunning(); k += 16) {
            for (int l = -192; l <= 192 && this.isServerRunning(); l += 16) {
                long i1 = MinecraftServer.getCurrentTimeMillis();
                if (i1 - j > 1000L) {
                    this.outputPercentRemaining("Preparing spawn area", i * 100 / 625);
                    j = i1;
                }
                ++i;
                worldServer.getChunkProvider().provideChunk(blockpos.getX() + k >> 4, blockpos.getZ() + l >> 4);
            }
        }
        this.clearCurrentTask();
    }
    chunkProviderServer.setForceChunkRequests(false);
}
Also used : GenerationContext(org.spongepowered.common.event.tracking.phase.generation.GenerationContext) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockPos(net.minecraft.util.math.BlockPos) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)1 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)1 GenerationContext (org.spongepowered.common.event.tracking.phase.generation.GenerationContext)1 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)1