侧边栏壁纸
  • 累计撰写 781 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索
MC

run

Dettan
2021-07-10 / 0 评论 / 0 点赞 / 104 阅读 / 12,732 字
温馨提示:
本文最后更新于 2022-04-30,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
/ MC / run
"Client thread@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  在 org.lwjgl.opengl.WindowsContextImplementation.nSwapBuffers(WindowsContextImplementation.java:-1)
	  在 org.lwjgl.opengl.WindowsContextImplementation.swapBuffers(WindowsContextImplementation.java:70)
	  - 锁 <0x411c> (a org.lwjgl.opengl.ContextGL)
	  在 org.lwjgl.opengl.ContextGL.swapBuffers(ContextGL.java:175)
	  在 org.lwjgl.opengl.DrawableGL.swapBuffers(DrawableGL.java:90)
	  在 org.lwjgl.opengl.Display.swapBuffers(Display.java:618)
	  - 锁 <0x411d> (a java.lang.Object)
	  在 org.lwjgl.opengl.Display.update(Display.java:646)
	  在 org.lwjgl.opengl.Display.update(Display.java:628)
	  在 net.minecraft.client.Minecraft.updateDisplay(Minecraft.java:1295)
	  在 net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1243)
	  在 net.minecraft.client.Minecraft.run(Minecraft.java:442)
	  在 net.minecraft.client.main.Main.main(Main.java:118)
	  在 sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	  在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	  在 java.lang.reflect.Method.invoke(Method.java:498)
	  在 net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	  在 net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	  在 sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	  在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	  在 java.lang.reflect.Method.invoke(Method.java:498)
	  在 net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	  在 GradleStart.main(GradleStart.java:25)

"Server thread@16580" prio=5 tid=0x42 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  在 net.minecraft.nbt.NBTTagCompound.writeEntry(NBTTagCompound.java:577)
	  在 net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:39)
	  在 net.minecraft.nbt.NBTTagCompound.writeEntry(NBTTagCompound.java:582)
	  在 net.minecraft.nbt.NBTTagCompound.write(NBTTagCompound.java:39)
	  在 net.minecraft.nbt.CompressedStreamTools.writeTag(CompressedStreamTools.java:124)
	  在 net.minecraft.nbt.CompressedStreamTools.write(CompressedStreamTools.java:114)
	  在 net.minecraft.nbt.CompressedStreamTools.writeCompressed(CompressedStreamTools.java:53)
	  在 net.minecraft.world.storage.SaveHandler.saveWorldInfoWithPlayer(SaveHandler.java:170)
	  在 net.minecraft.world.chunk.storage.AnvilSaveHandler.saveWorldInfoWithPlayer(AnvilSaveHandler.java:46)
	  在 net.minecraft.world.WorldServer.saveLevel(WorldServer.java:1111)
	  在 net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:1054)
	  在 net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:468)
	  在 net.minecraft.server.integrated.IntegratedServer.saveAllWorlds(IntegratedServer.java:274)
	  在 net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:766)
	  在 net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	  在 net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
	  在 java.lang.Thread.run(Thread.java:748)

MinecraftServer 里的run
public void run()
    {
        try
        {
            if (this.init())
            {
                net.minecraftforge.fml.common.FMLCommonHandler.instance().handleServerStarted();
                this.currentTime = getCurrentTimeMillis();
                long i = 0L;
                this.statusResponse.setServerDescription(new TextComponentString(this.motd));
                this.statusResponse.setVersion(new ServerStatusResponse.Version("1.12.2", 340));
                this.applyServerIconToResponse(this.statusResponse);
            while (this.serverRunning)
            {
                long k = getCurrentTimeMillis();
                long j = k - this.currentTime;

                if (j &gt; 2000L && this.currentTime - this.timeOfLastWarning &gt;= 15000L)
                {
                    LOGGER.warn(&quot;Can't keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)&quot;, Long.valueOf(j), Long.valueOf(j / 50L));
                    j = 2000L;
                    this.timeOfLastWarning = this.currentTime;
                }

                if (j &lt; 0L)
                {
                    LOGGER.warn(&quot;Time ran backwards! Did the system time change?&quot;);
                    j = 0L;
                }

                i += j;
                this.currentTime = k;

                if (this.worlds[0].areAllPlayersAsleep())
                {
                    this.tick();
                    i = 0L;
                }
                else
                {
                    while (i &gt; 50L)
                    {
                        i -= 50L;
                        this.tick();
                    }
                }

                Thread.sleep(Math.max(1L, 50L - i));
                this.serverIsRunning = true;
            }
            net.minecraftforge.fml.common.FMLCommonHandler.instance().handleServerStopping();
            net.minecraftforge.fml.common.FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
        }
        else
        {
            net.minecraftforge.fml.common.FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
            this.finalTick((CrashReport)null);
        }
    }
    catch (net.minecraftforge.fml.common.StartupQuery.AbortedException e)
    {
        // ignore silently
        net.minecraftforge.fml.common.FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
    }
    catch (Throwable throwable1)
    {
        LOGGER.error(&quot;Encountered an unexpected exception&quot;, throwable1);
        CrashReport crashreport = null;

        if (throwable1 instanceof ReportedException)
        {
            crashreport = this.addServerInfoToCrashReport(((ReportedException)throwable1).getCrashReport());
        }
        else
        {
            crashreport = this.addServerInfoToCrashReport(new CrashReport(&quot;Exception in server tick loop&quot;, throwable1));
        }

        File file1 = new File(new File(this.getDataDirectory(), &quot;crash-reports&quot;), &quot;crash-&quot; + (new SimpleDateFormat(&quot;yyyy-MM-dd_HH.mm.ss&quot;)).format(new Date()) + &quot;-server.txt&quot;);

        if (crashreport.saveToFile(file1))
        {
            LOGGER.error(&quot;This crash report has been saved to: {}&quot;, (Object)file1.getAbsolutePath());
        }
        else
        {
            LOGGER.error(&quot;We were unable to save this crash report to disk.&quot;);
        }

        net.minecraftforge.fml.common.FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
        this.finalTick(crashreport);
    }
    finally
    {
        try
        {
            this.stopServer();
        }
        catch (Throwable throwable)
        {
            LOGGER.error(&quot;Exception stopping the server&quot;, throwable);
        }
        finally
        {
            net.minecraftforge.fml.common.FMLCommonHandler.instance().handleServerStopped();
            this.serverStopped = true;
            this.systemExitNow();
        }
    }
}</code></pre></div>            <div style="width: 100%; max-width: 996px; margin-top: 2px;">
            <div style="color: inherit; fill: inherit;">
                <div style="display: flex;">


控制每秒20tick的逻辑
net.minecraft.server.MinecraftServer
while (this.serverRunning)
{
    long k = getCurrentTimeMillis();
		//新时间 - 老时间 = 经过的时间.
    long j = k - this.currentTime;
	//时间隔得太长.
if (j &gt; 2000L && this.currentTime - this.timeOfLastWarning &gt;= 15000L)
{
    LOGGER.warn(&quot;Can't keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)&quot;, Long.valueOf(j), Long.valueOf(j / 50L));
    j = 2000L;
    this.timeOfLastWarning = this.currentTime;
}
	
	//时间为负
if (j &lt; 0L)
{
    LOGGER.warn(&quot;Time ran backwards! Did the system time change?&quot;);
    j = 0L;
}

	//i 初始化为0,每次累加.
i += j;
	
this.currentTime = k;
	//判断是不是所有的玩家都躺床上了.
if (this.worlds[0].areAllPlayersAsleep())
{   //立即执行
    this.tick();
    i = 0L;
}
else
{   //50ms运行一次,这里是看有几个50ms
    while (i &gt; 50L)
    {
        i -= 50L;
        this.tick();
    }
}
	//休眠到该下一次tick的时候.
Thread.sleep(Math.max(1L, 50L - i));
this.serverIsRunning = true;

}




net.minecraft.server.integrated.IntegratedServer 集成服务端 的 代码
public void tick()
{
    boolean flag = this.isGamePaused;
    this.isGamePaused = Minecraft.getMinecraft().getConnection() != null && Minecraft.getMinecraft().isGamePaused();
		//判断是不是刚暂停
    if (!flag && this.isGamePaused)
    {
        LOGGER.info("Saving and pausing game...");
        this.getPlayerList().saveAllPlayerData();
        this.saveAllWorlds(false);
    }
if (this.isGamePaused)
{   //把所有任务都处理完
    synchronized (this.futureTaskQueue)
    {
        while (!this.futureTaskQueue.isEmpty())
        {
            Util.runTask(this.futureTaskQueue.poll(), LOGGER);
        }
    }
}
else
{
    super.tick();

    if (this.mc.gameSettings.renderDistanceChunks != this.getPlayerList().getViewDistance())
    {
        LOGGER.info(&quot;Changing view distance to {}, from {}&quot;, Integer.valueOf(this.mc.gameSettings.renderDistanceChunks), Integer.valueOf(this.getPlayerList().getViewDistance()));
        this.getPlayerList().setViewDistance(this.mc.gameSettings.renderDistanceChunks);
    }

    if (this.mc.world != null)
    {
        WorldInfo worldinfo1 = this.worlds[0].getWorldInfo();
        WorldInfo worldinfo = this.mc.world.getWorldInfo();

        if (!worldinfo1.isDifficultyLocked() && worldinfo.getDifficulty() != worldinfo1.getDifficulty())
        {
            LOGGER.info(&quot;Changing difficulty to {}, from {}&quot;, worldinfo.getDifficulty(), worldinfo1.getDifficulty());
            this.setDifficultyForAllWorlds(worldinfo.getDifficulty());
        }
        else if (worldinfo.isDifficultyLocked() && !worldinfo1.isDifficultyLocked())
        {
            LOGGER.info(&quot;Locking difficulty to {}&quot;, (Object)worldinfo.getDifficulty());

            for (WorldServer worldserver : this.worlds)
            {
                if (worldserver != null)
                {
                    worldserver.getWorldInfo().setDifficultyLocked(true);
                }
            }
        }
    }
}

}




net.minecraft.server.MinecraftServer 父类
public void tick()
    {
        long i = System.nanoTime();
        net.minecraftforge.fml.common.FMLCommonHandler.instance().onPreServerTick();
        ++this.tickCounter;
    if (this.startProfiling)
    {
        this.startProfiling = false;
        this.profiler.profilingEnabled = true;
        this.profiler.clearProfiling();
    }

    this.profiler.startSection(&quot;root&quot;);
			//主要方法   核心  核心  核心
    this.updateTimeLightAndEntities();

    if (i - this.nanoTimeSinceStatusRefresh &gt;= 5000000000L)
    {
        this.nanoTimeSinceStatusRefresh = i;
        this.statusResponse.setPlayers(new ServerStatusResponse.Players(this.getMaxPlayers(), this.getCurrentPlayerCount()));
        GameProfile[] agameprofile = new GameProfile[Math.min(this.getCurrentPlayerCount(), 12)];
        int j = MathHelper.getInt(this.random, 0, this.getCurrentPlayerCount() - agameprofile.length);

        for (int k = 0; k &lt; agameprofile.length; ++k)
        {
            agameprofile[k] = ((EntityPlayerMP)this.playerList.getPlayers().get(j + k)).getGameProfile();
        }

        Collections.shuffle(Arrays.asList(agameprofile));
        this.statusResponse.getPlayers().setPlayers(agameprofile);
        this.statusResponse.invalidateJson();
    }
			//45s保存一次?
    if (this.tickCounter % 900 == 0)
    {
        this.profiler.startSection(&quot;save&quot;);
        this.playerList.saveAllPlayerData();
        this.saveAllWorlds(true);
        this.profiler.endSection();
    }

    this.profiler.startSection(&quot;tallying&quot;);
    this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - i;
    this.profiler.endSection();
    this.profiler.startSection(&quot;snooper&quot;);

    if (!this.usageSnooper.isSnooperRunning() && this.tickCounter &gt; 100)
    {
        this.usageSnooper.startSnooper();
    }

    if (this.tickCounter % 6000 == 0)
    {
        this.usageSnooper.addMemoryStatsToSnooper();
    }

    this.profiler.endSection();
    this.profiler.endSection();
    net.minecraftforge.fml.common.FMLCommonHandler.instance().onPostServerTick();
}</code></pre></div>            <div style="width: 100%; max-width: 996px; margin-top: 2px;">
            <div style="color: inherit; fill: inherit;">
                <div style="display: flex;">

net.minecraft.server.MinecraftServer 主要方法
public void updateTimeLightAndEntities()
{
    this.profiler.startSection("jobs");
		//运行任务,把任务运行完.可能会导致这一tick时间超标.
    synchronized (this.futureTaskQueue)
    {
        while (!this.futureTaskQueue.isEmpty())
        {
            Util.runTask(this.futureTaskQueue.poll(), LOGGER);
        }
    }
this.profiler.endStartSection(&quot;levels&quot;);
net.minecraftforge.common.chunkio.ChunkIOExecutor.tick();
	//获取所有世界id
Integer[] ids = net.minecraftforge.common.DimensionManager.getIDs(this.tickCounter % 200 == 0);
	//遍历所有世界
for (int x = 0; x &lt; ids.length; x++)
{
    int id = ids[x];
    long i = System.nanoTime();

    if (id == 0 || this.getAllowNether())
    {   //根据id 获取世界
        WorldServer worldserver = net.minecraftforge.common.DimensionManager.getWorld(id);
        this.profiler.func_194340_a(() -&gt;
        {
            return worldserver.getWorldInfo().getWorldName();
        });

        if (this.tickCounter % 20 == 0)
        {
            this.profiler.startSection(&quot;timeSync&quot;);
							//发送给此世界所有玩家:时间更新, 玩家客户端以此更新各种东西.
            this.playerList.sendPacketToAllPlayersInDimension(new SPacketTimeUpdate(worldserver.getTotalWorldTime(), worldserver.getWorldTime(), worldserver.getGameRules().getBoolean(&quot;doDaylightCycle&quot;)), worldserver.provider.getDimension());
            this.profiler.endSection();
        }

        this.profiler.startSection(&quot;tick&quot;);
        net.minecraftforge.fml.common.FMLCommonHandler.instance().onPreWorldTick(worldserver);

        try
        {
							//世界 的 tick
            worldserver.tick();
        }
        catch (Throwable throwable1)
        {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable1, &quot;Exception ticking world&quot;);
            worldserver.addWorldInfoToCrashReport(crashreport);
            throw new ReportedException(crashreport);
        }

        try
        {
							//更新 实体
            worldserver.updateEntities();
        }
        catch (Throwable throwable)
        {
            CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, &quot;Exception ticking world entities&quot;);
            worldserver.addWorldInfoToCrashReport(crashreport1);
            throw new ReportedException(crashreport1);
        }

        net.minecraftforge.fml.common.FMLCommonHandler.instance().onPostWorldTick(worldserver);
        this.profiler.endSection();
        this.profiler.startSection(&quot;tracker&quot;);
					//好像是更新 entity位置,根据速度.
        worldserver.getEntityTracker().tick();
        this.profiler.endSection();
        this.profiler.endSection();
    }

    worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - i;
}</code></pre></div></div>
0

评论区