minecraft-src/net/minecraft/world/entity/AnimationState.java
2025-07-04 01:41:11 +03:00

61 lines
1.3 KiB
Java

package net.minecraft.world.entity;
import java.util.function.Consumer;
import net.minecraft.util.Mth;
public class AnimationState {
private static final long STOPPED = Long.MAX_VALUE;
private long lastTime = Long.MAX_VALUE;
private long accumulatedTime;
public void start(int tickCount) {
this.lastTime = tickCount * 1000L / 20L;
this.accumulatedTime = 0L;
}
public void startIfStopped(int tickCount) {
if (!this.isStarted()) {
this.start(tickCount);
}
}
public void animateWhen(boolean condition, int tickCount) {
if (condition) {
this.startIfStopped(tickCount);
} else {
this.stop();
}
}
public void stop() {
this.lastTime = Long.MAX_VALUE;
}
public void ifStarted(Consumer<AnimationState> action) {
if (this.isStarted()) {
action.accept(this);
}
}
public void updateTime(float ageInTicks, float speed) {
if (this.isStarted()) {
long l = Mth.lfloor(ageInTicks * 1000.0F / 20.0F);
this.accumulatedTime = this.accumulatedTime + (long)((float)(l - this.lastTime) * speed);
this.lastTime = l;
}
}
public void fastForward(int duration, float speed) {
if (this.isStarted()) {
this.accumulatedTime += (long)(duration * 1000 * speed) / 20L;
}
}
public long getAccumulatedTime() {
return this.accumulatedTime;
}
public boolean isStarted() {
return this.lastTime != Long.MAX_VALUE;
}
}