Skip to content

Commit

Permalink
fixes some momentary frames with no animation
Browse files Browse the repository at this point in the history
now it will cycle to the idle animation if no transition is found
  • Loading branch information
Thutmose committed Nov 2, 2022
1 parent af42fa6 commit f06cdd0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
23 changes: 13 additions & 10 deletions src/main/java/thut/api/entity/IAnimated.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package thut.api.entity;

import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -90,8 +91,8 @@ public static interface IAnimationHolder
void setPendingAnimations(final List<Animation> 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
Expand Down Expand Up @@ -119,5 +120,7 @@ public static interface IAnimationHolder

@Nonnull
HeadInfo getHeadInfo();

void initAnimations(Map<String, List<Animation>> map, String _default);
}
}
23 changes: 18 additions & 5 deletions src/main/java/thut/api/entity/animation/CapabilityAnimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ public static class DefaultImpl implements IAnimationHolder, ICapabilitySerializ

List<Animation> 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
Expand All @@ -62,6 +66,15 @@ public String getPendingAnimations()
return this.pending;
}

@Override
public void initAnimations(Map<String, List<Animation>> 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<Animation> getPlaying()
{
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/thut/core/client/render/model/IModelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IModelRenderer<T extends Entity>
public static class Vector5
{
public Vector4 rotations;
public int time;
public int time;

public Vector5()
{
Expand Down Expand Up @@ -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<Animation> anim = this.getAnimations(entity, phase);
if (holder != null && anim != null && !anim.isEmpty()) holder.setPendingAnimations(anim, phase);
if (holder != null)
{
final List<Animation> anim = this.getAnimations(entity, phase);
if (getAnimations() != null) holder.initAnimations(getAnimations(), IModelRenderer.DEFAULTPHASE);
if (anim != null && !anim.isEmpty()) holder.setPendingAnimations(anim, phase);
}
}

default List<Animation> getAnimations(final Entity entity, final String phase)
Expand Down

0 comments on commit f06cdd0

Please sign in to comment.