Started by
__SK__
on
Topic category: Help with Minecraft modding (Java Edition)
Recently I shared a tutorial which implements Geckolib entity animations to MCreator. It added 4 basic options ... walking, idle, death, and attack. Now I am trying to add a random statement to the attack animation. But when using cases or random the animations will flicker (meaning, sort of starts but will not complete the assigned random animation). Here is the topic with the full code.
https://mcreator.net/forum/91171/tutorial-how-add-geckolib-animated-ent…
Partial code ...
private <E extends IAnimatable> PlayState movementPredicate(AnimationEvent<E> event) {
if (event.isMoving()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("walk", true));
return PlayState.CONTINUE;
}
if (!event.isMoving()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("idle", true));
return PlayState.CONTINUE;
}
if (this.isDeadOrDying()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("death", false));
return PlayState.CONTINUE;
}
if (this.isAggressive()) {
event.getController().setAnimation(new AnimationBuilder().addAnimation("attack", false));
return PlayState.CONTINUE;
}
return PlayState.CONTINUE;
}
Any pointers will be greatly appreciated.
Edited by __SK__ on Sat, 10/15/2022 - 03:33
One of many solutions ...
REMOVE - isAggressive statement from the movementPredicate
Create an new int
Let's name it attackingMarker with a value of 1
In this attackPredicate, when swinging add a simple 1 ... 0 sequence (not random - it will be 1...0...1...0...etc, but works as intended alternating animations)
What happened?
Now it will start with initial value of 1 (playing attack1 animation, not looping), after animation1 is played it will change the value to 0, and finally execute in else statement (playing attack2 animation, not looping) ... in which attackingMarker ends with a value of 1. Then the next attack will start with the value of 1.
And you are done!
Have fun
===================================================================
If it is useful, feel free to add/use it for your modding and/or future plugin templates.
===================================================================
isAgressive was useless to begin with, unless you want to do something like a skeleton's arm lifting animation when it shoots at you, by having a looping animation.
Yes, it took me a while to see the difference (still in the learning phase). Your Geckolib plugin is great, thanks for your contribution.