-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AnimationManager And AnimationData
- Loading branch information
1 parent
e80d1cc
commit 6d09912
Showing
4 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
.../java/com/mmodding/mmodding_lib/library/client/render/entity/animation/AnimationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mmodding.mmodding_lib.library.client.render.entity.animation; | ||
|
||
import net.minecraft.entity.AnimationState; | ||
import net.minecraft.entity.Entity; | ||
|
||
// will move that to a better package since it's not a client thing, but that will be in a next version | ||
public class AnimationData { | ||
|
||
public final AnimationState moving = new AnimationState(); | ||
public final AnimationState idle = new AnimationState(); | ||
public final AnimationState falling = new AnimationState(); | ||
public final AnimationState dodge = new AnimationState(); | ||
|
||
public int fallingAge; | ||
public int fallingCount; | ||
|
||
public AnimationData(Entity entity) { | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...va/com/mmodding/mmodding_lib/library/client/render/entity/animation/AnimationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.mmodding.mmodding_lib.library.client.render.entity.animation; | ||
|
||
import com.mmodding.mmodding_lib.library.client.utils.AnimationUtils; | ||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.render.animation.Animation; | ||
import net.minecraft.client.render.entity.model.SinglePartEntityModel; | ||
import net.minecraft.entity.AnimationState; | ||
|
||
public class AnimationManager { | ||
|
||
private final SinglePartEntityModel<?> model; | ||
|
||
private final Animation moving; | ||
private final Animation idle; | ||
private final Animation falling; | ||
private final Animation dodge; | ||
|
||
public AnimationManager(SinglePartEntityModel<?> model, Animation moving, Animation idle, Animation falling, Animation dodge) { | ||
this.model = model; | ||
this.moving = moving; | ||
this.idle = idle; | ||
this.falling = falling; | ||
this.dodge = dodge; | ||
} | ||
|
||
private void updateFall(AnimationData data, int age, GroundChecker groundChecker) { | ||
if (groundChecker.isInAir()) { | ||
if (data.fallingAge != age) { | ||
data.fallingAge = age; | ||
data.fallingCount++; | ||
} | ||
} | ||
else { | ||
data.fallingCount = 0; | ||
} | ||
} | ||
|
||
private void switchAnimation(Animation animation, AnimationState state, float animationProgress) { | ||
AnimationUtils.updateAnimation(this.model, animation, state, animationProgress); | ||
// data.transition = 20; | ||
} | ||
|
||
public void handle(AnimationData data, float animationProgress, int age, GroundChecker groundChecker, MovingChecker movingChecker) { | ||
this.model.getPart().traverse().forEach(ModelPart::resetTransform); | ||
if (data.dodge.isAnimating()) { | ||
this.switchAnimation(this.dodge, data.dodge, animationProgress); | ||
} | ||
else { | ||
this.updateFall(data, age, groundChecker); | ||
if (data.fallingCount <= 3) { | ||
if (movingChecker.isMoving()) { | ||
this.switchAnimation(this.moving, data.moving, animationProgress); | ||
} else { | ||
this.switchAnimation(this.idle, data.idle, animationProgress); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
public interface GroundChecker { | ||
|
||
boolean isOnGround(); | ||
|
||
default boolean isInAir() { | ||
return !this.isOnGround(); | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
public interface MovingChecker { | ||
|
||
boolean isMoving(); | ||
|
||
default boolean isStatic() { | ||
return !this.isMoving(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters