From a33acee11776898f1bf5339d8c2aa347bcc753c7 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Mon, 5 Jan 2026 16:49:48 +0200 Subject: [PATCH] Added Animation task consumers (much better than animation events) --- .../npcs/controllers/data/Animation.java | 44 ++++++++++++++++++- .../npcs/controllers/data/AnimationData.java | 3 ++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/controllers/data/Animation.java b/src/main/java/noppes/npcs/controllers/data/Animation.java index b60f9ad4d..c74a163b2 100644 --- a/src/main/java/noppes/npcs/controllers/data/Animation.java +++ b/src/main/java/noppes/npcs/controllers/data/Animation.java @@ -12,7 +12,8 @@ import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.controllers.AnimationController; import java.util.ArrayList; - +import java.util.function.BiConsumer; +import java.util.function.Consumer; public class Animation implements IAnimation { public AnimationData parent; //Client-sided only @@ -34,6 +35,10 @@ public class Animation implements IAnimation { //Client-sided public boolean paused; + public Consumer onAnimationStart; + public BiConsumer onAnimationFrame; + public Consumer onAnimationEnd; + public Animation() { } @@ -254,8 +259,10 @@ public class Animation implements IAnimation { if (this.currentFrame() != null) { EventHooks.onAnimationFrameEntered(this, this.currentFrame()); + fireFrameTask(this.currentFrame); } else { EventHooks.onAnimationEnded(this); + fireEndTask(); } if (nextFrame != null) { @@ -294,4 +301,39 @@ public class Animation implements IAnimation { } } } + + public IAnimation onStart(Consumer task) { + this.onAnimationStart = task; + return this; + } + + public IAnimation onFrame(BiConsumer task) { + this.onAnimationFrame = task; + return this; + } + + public IAnimation onEnd(Consumer task) { + this.onAnimationEnd = task; + return this; + } + + protected void fireStartTask() { + if (this.onAnimationStart != null) { + this.onAnimationStart.accept(this); + } + } + + protected void fireFrameTask(int frame) { + if (this.onAnimationFrame != null) { + this.onAnimationFrame.accept(frame, this); + } + } + + protected void fireEndTask() { + if (this.onAnimationEnd != null) { + this.onAnimationEnd.accept(this); + } + } + + } diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index c537d94e1..ca1e25900 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -98,15 +98,18 @@ public class AnimationData implements IAnimationData { this.isClientAnimating = this.allowAnimation && this.animation != null; if (prevIsClientAnimating && (!this.isClientAnimating || this.animation != this.currentClientAnimation)) { EventHooks.onAnimationEnded(this.currentClientAnimation); + this.currentClientAnimation.fireEndTask(); } if (this.isClientAnimating) { this.currentClientAnimation = this.animation; } if (this.animation != null && this.allowAnimation) { + this.animation.fireStartTask(); if (EventHooks.onAnimationStarted(this.animation)) return; EventHooks.onAnimationFrameEntered(this.animation, this.animation.currentFrame()); + this.animation.fireFrameTask(this.animation.currentFrame); } List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(