Search in sources :

Example 1 with WorldServerBridge

use of org.spongepowered.common.bridge.world.WorldServerBridge in project SpongeVanilla by SpongePowered.

the class MinecraftServerMixin_Vanilla method updateTimeLightAndEntities.

/**
 * @author Zidane
 * @reason Handles ticking the additional worlds loaded by Sponge.
 */
@Overwrite
public void updateTimeLightAndEntities() {
    this.profiler.startSection("jobs");
    synchronized (this.futureTaskQueue) {
        while (!this.futureTaskQueue.isEmpty()) {
            Util.runTask(this.futureTaskQueue.poll(), LOGGER);
        }
    }
    this.profiler.endStartSection("levels");
    // Sponge: Tick chunk loader
    chunkIO$tickChunkLoader();
    // Sponge start - Iterate over all our dimensions
    for (final ObjectIterator<Int2ObjectMap.Entry<WorldServer>> it = WorldManager.worldsIterator(); it.hasNext(); ) {
        Int2ObjectMap.Entry<WorldServer> entry = it.next();
        final WorldServer worldServer = entry.getValue();
        // Sponge end
        long i = System.nanoTime();
        if (entry.getIntKey() == 0 || this.getAllowNether()) {
            // Sponge start - copy from SpongeCommon MinecraftServerMixin_Vanilla
            WorldServerBridge spongeWorld = (WorldServerBridge) worldServer;
            if (spongeWorld.bridge$getChunkGCTickInterval() > 0) {
                spongeWorld.bridge$doChunkGC();
            }
            // Sponge end
            this.profiler.startSection(worldServer.getWorldInfo().getWorldName());
            if (this.tickCounter % 20 == 0) {
                this.profiler.startSection("timeSync");
                this.playerList.sendPacketToAllPlayersInDimension(new SPacketTimeUpdate(worldServer.getTotalWorldTime(), worldServer.getWorldTime(), worldServer.getGameRules().getBoolean("doDaylightCycle")), ((WorldServerBridge) worldServer).bridge$getDimensionId());
                this.profiler.endSection();
            }
            this.profiler.startSection("tick");
            try {
                worldServer.tick();
            } catch (Throwable throwable1) {
                CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception ticking world");
                worldServer.addWorldInfoToCrashReport(crashreport);
                throw new ReportedException(crashreport);
            }
            try {
                worldServer.updateEntities();
            } catch (Throwable throwable) {
                CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, "Exception ticking world entities");
                worldServer.addWorldInfoToCrashReport(crashreport1);
                throw new ReportedException(crashreport1);
            }
            this.profiler.endSection();
            this.profiler.startSection("tracker");
            // Sponge start - copy from SpongeCommon MinecraftServerMixin_Vanilla
            if (spongeWorld.bridge$getChunkGCTickInterval() > 0) {
                worldServer.getChunkProvider().tick();
            }
            // Sponge end
            worldServer.getEntityTracker().tick();
            this.profiler.endSection();
            this.profiler.endSection();
        }
        // Sponge start - Write tick times to our custom map
        this.vanilla$worldTickTimes.get(entry.getIntKey())[this.tickCounter % 100] = System.nanoTime() - i;
    // Sponge end
    }
    // Sponge start - Unload requested worlds
    this.profiler.endStartSection("dim_unloading");
    WorldManager.unloadQueuedWorlds();
    // Sponge end
    this.profiler.endStartSection("connection");
    this.getNetworkSystem().networkTick();
    this.profiler.endStartSection("players");
    this.playerList.onTick();
    this.profiler.endStartSection("tickables");
    for (int k = 0; k < this.tickables.size(); ++k) {
        this.tickables.get(k).update();
    }
    this.profiler.endSection();
}
Also used : SPacketTimeUpdate(net.minecraft.network.play.server.SPacketTimeUpdate) CrashReport(net.minecraft.crash.CrashReport) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) WorldServer(net.minecraft.world.WorldServer) WorldServerBridge(org.spongepowered.common.bridge.world.WorldServerBridge) ReportedException(net.minecraft.util.ReportedException) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 CrashReport (net.minecraft.crash.CrashReport)1 SPacketTimeUpdate (net.minecraft.network.play.server.SPacketTimeUpdate)1 ReportedException (net.minecraft.util.ReportedException)1 WorldServer (net.minecraft.world.WorldServer)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 WorldServerBridge (org.spongepowered.common.bridge.world.WorldServerBridge)1