ServerTickRateManager.java
net.minecraft.server.ServerTickRateManager
信息
- 全限定名:net.minecraft.server.ServerTickRateManager
- 类型:public class
- 包:net.minecraft.server
- 源码路径:src/main/java/net/minecraft/server/ServerTickRateManager.java
- 起始行号:L11
- 继承:TickRateManager
- 职责:
TODO
字段/常量
-
remainingSprintTicks- 类型:
long - 修饰符:
private - 源码定位:
L12 - 说明:
TODO
- 类型:
-
sprintTickStartTime- 类型:
long - 修饰符:
private - 源码定位:
L13 - 说明:
TODO
- 类型:
-
sprintTimeSpend- 类型:
long - 修饰符:
private - 源码定位:
L14 - 说明:
TODO
- 类型:
-
scheduledCurrentSprintTicks- 类型:
long - 修饰符:
private - 源码定位:
L15 - 说明:
TODO
- 类型:
-
previousIsFrozen- 类型:
boolean - 修饰符:
private - 源码定位:
L16 - 说明:
TODO
- 类型:
-
server- 类型:
MinecraftServer - 修饰符:
private final - 源码定位:
L17 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ServerTickRateManager(MinecraftServer server) @ L19
- 构造器名:ServerTickRateManager
- 源码定位:L19
- 修饰符:public
参数:
- server: MinecraftServer
说明:
TODO
方法
下面的方法块按源码顺序生成。
public boolean isSprinting() @ L23
- 方法名:isSprinting
- 源码定位:L23
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void setFrozen(boolean frozen) @ L27
- 方法名:setFrozen
- 源码定位:L27
- 返回类型:void
- 修饰符:public
参数:
- frozen: boolean
说明:
TODO
private void updateStateToClients() @ L33
- 方法名:updateStateToClients
- 源码定位:L33
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void updateStepTicks() @ L37
- 方法名:updateStepTicks
- 源码定位:L37
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public boolean stepGameIfPaused(int ticks) @ L41
- 方法名:stepGameIfPaused
- 源码定位:L41
- 返回类型:boolean
- 修饰符:public
参数:
- ticks: int
说明:
TODO
public boolean stopStepping() @ L51
- 方法名:stopStepping
- 源码定位:L51
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean stopSprinting() @ L61
- 方法名:stopSprinting
- 源码定位:L61
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean requestGameToSprint(int time) @ L70
- 方法名:requestGameToSprint
- 源码定位:L70
- 返回类型:boolean
- 修饰符:public
参数:
- time: int
说明:
TODO
private void finishTickSprint() @ L80
- 方法名:finishTickSprint
- 源码定位:L80
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
public boolean checkShouldSprintThisTick() @ L97
- 方法名:checkShouldSprintThisTick
- 源码定位:L97
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public void endTickWork() @ L110
- 方法名:endTickWork
- 源码定位:L110
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void setTickRate(float rate) @ L114
- 方法名:setTickRate
- 源码定位:L114
- 返回类型:void
- 修饰符:public
参数:
- rate: float
说明:
TODO
public void updateJoiningPlayer(ServerPlayer player) @ L121
- 方法名:updateJoiningPlayer
- 源码定位:L121
- 返回类型:void
- 修饰符:public
参数:
- player: ServerPlayer
说明:
TODO
代码
public class ServerTickRateManager extends TickRateManager {
private long remainingSprintTicks = 0L;
private long sprintTickStartTime = 0L;
private long sprintTimeSpend = 0L;
private long scheduledCurrentSprintTicks = 0L;
private boolean previousIsFrozen = false;
private final MinecraftServer server;
public ServerTickRateManager(MinecraftServer server) {
this.server = server;
}
public boolean isSprinting() {
return this.scheduledCurrentSprintTicks > 0L;
}
@Override
public void setFrozen(boolean frozen) {
super.setFrozen(frozen);
this.updateStateToClients();
}
private void updateStateToClients() {
this.server.getPlayerList().broadcastAll(ClientboundTickingStatePacket.from(this));
}
private void updateStepTicks() {
this.server.getPlayerList().broadcastAll(ClientboundTickingStepPacket.from(this));
}
public boolean stepGameIfPaused(int ticks) {
if (!this.isFrozen()) {
return false;
} else {
this.frozenTicksToRun = ticks;
this.updateStepTicks();
return true;
}
}
public boolean stopStepping() {
if (this.frozenTicksToRun > 0) {
this.frozenTicksToRun = 0;
this.updateStepTicks();
return true;
} else {
return false;
}
}
public boolean stopSprinting() {
if (this.remainingSprintTicks > 0L) {
this.finishTickSprint();
return true;
} else {
return false;
}
}
public boolean requestGameToSprint(int time) {
boolean interrupted = this.remainingSprintTicks > 0L;
this.sprintTimeSpend = 0L;
this.scheduledCurrentSprintTicks = time;
this.remainingSprintTicks = time;
this.previousIsFrozen = this.isFrozen();
this.setFrozen(false);
return interrupted;
}
private void finishTickSprint() {
long completedTicks = this.scheduledCurrentSprintTicks - this.remainingSprintTicks;
double millisecondsToComplete = Math.max(1.0, (double)this.sprintTimeSpend) / TimeUtil.NANOSECONDS_PER_MILLISECOND;
int ticksPerSecond = (int)(TimeUtil.MILLISECONDS_PER_SECOND * completedTicks / millisecondsToComplete);
String millisecondsPerTick = String.format(
Locale.ROOT, "%.2f", completedTicks == 0L ? this.millisecondsPerTick() : millisecondsToComplete / completedTicks
);
this.scheduledCurrentSprintTicks = 0L;
this.sprintTimeSpend = 0L;
this.server
.createCommandSourceStack()
.sendSuccess(() -> Component.translatable("commands.tick.sprint.report", ticksPerSecond, millisecondsPerTick), true);
this.remainingSprintTicks = 0L;
this.setFrozen(this.previousIsFrozen);
this.server.onTickRateChanged();
}
public boolean checkShouldSprintThisTick() {
if (!this.runGameElements) {
return false;
} else if (this.remainingSprintTicks > 0L) {
this.sprintTickStartTime = System.nanoTime();
this.remainingSprintTicks--;
return true;
} else {
this.finishTickSprint();
return false;
}
}
public void endTickWork() {
this.sprintTimeSpend = this.sprintTimeSpend + (System.nanoTime() - this.sprintTickStartTime);
}
@Override
public void setTickRate(float rate) {
super.setTickRate(rate);
this.server.onTickRateChanged();
this.updateStateToClients();
}
public void updateJoiningPlayer(ServerPlayer player) {
player.connection.send(ClientboundTickingStatePacket.from(this));
player.connection.send(ClientboundTickingStepPacket.from(this));
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
System.nanoTime()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ClientboundTickingStatePacket.from()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ClientboundTickingStepPacket.from()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置: