Skip to content
是封面

[1. 14. 4+] TPS检测

8月6日在wiki发现的,B站,planetminecraft和modrinth搜了下发现没有人做过,于是记录一下。

原理[1]

Java版1.3.1(12w27a)加入的/debug stop命令通过/execute store result ...获取的输出是整个分析过程中的平均TPS。

/debug start会开始新的刻分析器会话,会话可以通过/debug stop命令结束

因此我们可以借助/schedule[2]/execute store result ... run debug stop创建一个每20tick执行一次的计划来检测TPS

经测试,上述间隔低于15tick就会检测不出(误差很大),20tick可以兼顾速度和准确性

版本限制

权限等级

为什么是1.14.4+呢?因为1.14.4-pre4才在server.properties中加入了function-permission-level,用于控制函数拥有的权限等级。[3]

/debug命令需要的权限等级为3,函数默认的权限等级为2[4],导致低于1.14.4-pre4的版本无法通过函数运行/debug

schedule

1.15(19w38a)/schedule加入了replace参数[5],在这之前的版本计划的函数如果不覆盖的话不知道会不会有问题。

写到这才发现replace是默认的,不知道在这之前的版本是不是也是默认。

tick

1.20.3(23w43a)添加了/tick[6],在数据包运行的时候可以用/execute store result ...获取/tick query的输出获取目标TPS[7],如果服务器更改目标TPS的话可以检测。

单复数

1.21(24w21a)functions重命名为function[8]

示例数据包

这里是示例TPS检测数据包,会以title的形式显示当前TPS和目标TPS,支持1.14.4+

代码

这是1.21+的代码

mcfunction
# load.mcfunction

scoreboard objectives add tps_detection dummy

#1.20.3+
execute store result score target_tps tps_detection run tick query
#1.20.3-
#scoreboard players set target_tps tps_detection 20

#1.15+
schedule function tps-detection:update_tps 20 replace
#1.15- 1.14.4+
#schedule function tps-detection:update_tps 20

debug start
mcfunction
# update_tps.mcfunction

#1.15+
schedule function tps-detection:update_tps 20 replace
#1.15- 1.14.4+
#schedule function tps-detection:update_tps 20

execute store result score tps tps_detection run debug stop

#display
title @a title ["TPS:",{"score":{"name":"tps","objective":"tps_detection"}},"/",{"score":{"name":"target_tps","objective":"tps_detection"}}]


debug start

演示

1.14.4

1.14.4

1.21.8

1.21.8

实战

实战

写在后面

数据包检测TPS这个想法是1.20.3添加/tick的时候有的。当时以为能直接通过/tick query的输出获取TPS,甚至还想获取mspt,结果它的输出是目标TPS...

当时还想着从命令方块的输出获取,但是/tick需要的权限等级为3,完全不行。

之后想了个办法,/schedule等待的时间有s这个单位,以为是现实时间,但是游戏会将其转换为tick

发现/debug后以为有数据包的版本就能检测TPS,但是因为上面说的权限等级所以不行。

但是玩家还是能手动执行获取TPS的(如下图)

1.13


  1. 参见命令/debug - 中文 Minecraft Wiki ↩︎

  2. 参见命令/schedule - 中文 Minecraft Wiki ↩︎

  3. 参见Java版1.14.4-pre4 - 中文 Minecraft Wiki ↩︎

  4. 参见权限等级 - 中文 Minecraft Wiki ↩︎

  5. 参见19w38a - 中文 Minecraft Wiki ↩︎

  6. 参见23w43a - 中文 Minecraft Wiki ↩︎

  7. 参见命令/tick - 中文 Minecraft Wiki ↩︎

  8. 参见24w21a - 中文 Minecraft Wiki ↩︎

Powered by Vitepress and Github Pages