63 lines
1.6 KiB
Java
63 lines
1.6 KiB
Java
package com.thebrokenrail.gestus.emote;
|
|
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.EulerAngle;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
|
|
public class EmoteLayer {
|
|
private int frame = 0;
|
|
private Identifier current;
|
|
private final boolean loop;
|
|
|
|
private boolean leftHanded = false;
|
|
|
|
public EmoteLayer(Identifier start, boolean loop) {
|
|
current = start;
|
|
this.loop = loop;
|
|
}
|
|
|
|
public Identifier getCurrent() {
|
|
return current;
|
|
}
|
|
|
|
public void play(Identifier current, boolean leftHanded) {
|
|
if (!Objects.equals(this.current, current) || this.leftHanded != leftHanded) {
|
|
this.current = current;
|
|
this.leftHanded = leftHanded;
|
|
frame = 0;
|
|
}
|
|
}
|
|
|
|
public boolean isPlaying() {
|
|
return current != null;
|
|
}
|
|
|
|
public boolean isLeftHanded() {
|
|
return leftHanded;
|
|
}
|
|
|
|
public Map<EmotePart, EulerAngle> next() {
|
|
if (current != null) {
|
|
Emote emote = EmoteRegistry.get(current);
|
|
if (emote != null) {
|
|
EmoteFrame result = emote.frames[frame];
|
|
frame++;
|
|
if (frame >= emote.frames.length) {
|
|
if (loop) {
|
|
frame = frame % emote.frames.length;
|
|
} else {
|
|
frame = 0;
|
|
current = null;
|
|
}
|
|
}
|
|
return leftHanded ? result.leftHanded : result.rightHanded;
|
|
}
|
|
}
|
|
frame = 0;
|
|
return new HashMap<>();
|
|
}
|
|
}
|