diff --git a/src/main/java/thut/api/entity/IAnimated.java b/src/main/java/thut/api/entity/IAnimated.java index 9504789fc6..f99ecfa4ef 100644 --- a/src/main/java/thut/api/entity/IAnimated.java +++ b/src/main/java/thut/api/entity/IAnimated.java @@ -1,6 +1,7 @@ package thut.api.entity; import java.util.List; +import java.util.Map; import javax.annotation.Nonnull; @@ -37,19 +38,19 @@ public static class HeadInfo /** This is the current ticksExisted for the object being rendered.. */ public int currentTick = 0; /** - * This is the ticksExisted before this render tick for the object - * being rendered + * This is the ticksExisted before this render tick for the object being + * rendered */ - public int lastTick = 0; + public int lastTick = 0; - public float yawCapMax = 180; - public float yawCapMin = -180; + public float yawCapMax = 180; + public float yawCapMin = -180; public float pitchCapMax = 40; public float pitchCapMin = -40; - public int yawAxis = 1; - public int pitchAxis = 0; - public int yawDirection = 1; + public int yawAxis = 1; + public int pitchAxis = 0; + public int yawDirection = 1; public int pitchDirection = 1; public boolean fixed = false; @@ -90,8 +91,8 @@ public static interface IAnimationHolder void setPendingAnimations(final List list, final String name); /** - * Sets the last tick this animation was run. Can set to 0 to count - * this animation as cleared. + * Sets the last tick this animation was run. Can set to 0 to count this + * animation as cleared. * * @param animation * @param step @@ -119,5 +120,7 @@ public static interface IAnimationHolder @Nonnull HeadInfo getHeadInfo(); + + void initAnimations(Map> map, String _default); } } diff --git a/src/main/java/thut/api/entity/animation/CapabilityAnimation.java b/src/main/java/thut/api/entity/animation/CapabilityAnimation.java index 54d1356f2a..e7eaf9b513 100644 --- a/src/main/java/thut/api/entity/animation/CapabilityAnimation.java +++ b/src/main/java/thut/api/entity/animation/CapabilityAnimation.java @@ -35,19 +35,23 @@ public static class DefaultImpl implements IAnimationHolder, ICapabilitySerializ List keys = Lists.newArrayList(); - String pending = ""; - String playing = ""; + public String _default = "idle"; + + String pending = _default; + String playing = _default; boolean fixed = false; HeadInfo head = new HeadInfo(); + boolean init = false; + @Override public void clean() { - this.pending = ""; - this.playing = ""; - this.playingList = DefaultImpl.EMPTY; + this.pending = _default; + this.playing = _default; + this.playingList = this.anims.getOrDefault(this.pending, DefaultImpl.EMPTY); } @Override @@ -62,6 +66,15 @@ public String getPendingAnimations() return this.pending; } + @Override + public void initAnimations(Map> map, String _default) + { + if (init) return; + map.forEach((s, l) -> anims.computeIfAbsent(s, s2 -> Lists.newArrayList(l))); + this._default = _default; + init = true; + } + @Override public List getPlaying() { diff --git a/src/main/java/thut/core/client/render/model/IModelRenderer.java b/src/main/java/thut/core/client/render/model/IModelRenderer.java index de937a59c6..b7b767e781 100644 --- a/src/main/java/thut/core/client/render/model/IModelRenderer.java +++ b/src/main/java/thut/core/client/render/model/IModelRenderer.java @@ -23,7 +23,7 @@ public interface IModelRenderer public static class Vector5 { public Vector4 rotations; - public int time; + public int time; public Vector5() { @@ -91,8 +91,12 @@ default void setAnimation(final Entity entity, final float partialTick) { final IAnimationHolder holder = this.getAnimationHolder(); final String phase = this.getAnimation(entity); - final List anim = this.getAnimations(entity, phase); - if (holder != null && anim != null && !anim.isEmpty()) holder.setPendingAnimations(anim, phase); + if (holder != null) + { + final List anim = this.getAnimations(entity, phase); + if (getAnimations() != null) holder.initAnimations(getAnimations(), IModelRenderer.DEFAULTPHASE); + if (anim != null && !anim.isEmpty()) holder.setPendingAnimations(anim, phase); + } } default List getAnimations(final Entity entity, final String phase)