AnimationState .java

net.minecraft.world.entity.AnimationState (class): members: getTimeInMillis, startIfStopped, animateWhen, fastForward, ifStarted, STOPPED, isStarted, stop.

net.minecraft.world.entityclass56 linescommon1.2 KB

API Surface (9)

void start(final int tickCount)
void startIfStopped(final int tickCount)
void animateWhen(final boolean condition, final int tickCount)
void stop()
void ifStarted(final Consumer<AnimationState> timer)
void fastForward(final int ticks, final float timeScale)
long getTimeInMillis(final float ageInTicks)
boolean isStarted()
void copyFrom(final AnimationState state)

Fields & Constants (2)

STOPPED
startTick

Full Source

AnimationState.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import java.util.function.Consumer;
4
5
public class AnimationState {
6
	private static final int STOPPED = Integer.MIN_VALUE;
7
	private int startTick = Integer.MIN_VALUE;
8
9
	public void start(final int tickCount) {
10
		this.startTick = tickCount;
11
	}
12
13
	public void startIfStopped(final int tickCount) {
14
		if (!this.isStarted()) {
15
			this.start(tickCount);
16
		}
17
	}
18
19
	public void animateWhen(final boolean condition, final int tickCount) {
20
		if (condition) {
21
			this.startIfStopped(tickCount);
22
		} else {
23
			this.stop();
24
		}
25
	}
26
27
	public void stop() {
28
		this.startTick = Integer.MIN_VALUE;
29
	}
30
31
	public void ifStarted(final Consumer<AnimationState> timer) {
32
		if (this.isStarted()) {
33
			timer.accept(this);
34
		}
35
	}
36
37
	public void fastForward(final int ticks, final float timeScale) {
38
		if (this.isStarted()) {
39
			this.startTick -= (int)(ticks * timeScale);
40
		}
41
	}
42
43
	public long getTimeInMillis(final float ageInTicks) {
44
		float timeInTicks = ageInTicks - this.startTick;
45
		return (long)(timeInTicks * 50.0F);
46
	}
47
48
	public boolean isStarted() {
49
		return this.startTick != Integer.MIN_VALUE;
50
	}
51
52
	public void copyFrom(final AnimationState state) {
53
		this.startTick = state.startTick;
54
	}
55
}
56

Decompiled Minecraft 26.3 source of AnimationState (net/minecraft/world/entity/AnimationState.java) with Mojang official mappings, stored verbatim on the site.