2025-11-24 22:52:51 +03:00

71 lines
1.8 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.world;
import net.minecraft.util.TimeUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
public class TickRateManager {
public static final float MIN_TICKRATE = 1.0f;
protected float tickrate = 20.0f;
protected long nanosecondsPerTick = TimeUtil.NANOSECONDS_PER_SECOND / 20L;
protected int frozenTicksToRun = 0;
protected boolean runGameElements = true;
protected boolean isFrozen = false;
public void setTickRate(float rate) {
this.tickrate = Math.max(rate, 1.0f);
this.nanosecondsPerTick = (long)((double)TimeUtil.NANOSECONDS_PER_SECOND / (double)this.tickrate);
}
public float tickrate() {
return this.tickrate;
}
public float millisecondsPerTick() {
return (float)this.nanosecondsPerTick / (float)TimeUtil.NANOSECONDS_PER_MILLISECOND;
}
public long nanosecondsPerTick() {
return this.nanosecondsPerTick;
}
public boolean runsNormally() {
return this.runGameElements;
}
public boolean isSteppingForward() {
return this.frozenTicksToRun > 0;
}
public void setFrozenTicksToRun(int timeout) {
this.frozenTicksToRun = timeout;
}
public int frozenTicksToRun() {
return this.frozenTicksToRun;
}
public void setFrozen(boolean state) {
this.isFrozen = state;
}
public boolean isFrozen() {
return this.isFrozen;
}
public void tick() {
boolean bl = this.runGameElements = !this.isFrozen || this.frozenTicksToRun > 0;
if (this.frozenTicksToRun > 0) {
--this.frozenTicksToRun;
}
}
public boolean isEntityFrozen(Entity entity) {
return !this.runsNormally() && !(entity instanceof Player) && entity.countPlayerPassengers() <= 0;
}
}