mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 15:45:10 +00:00
Added Animation task consumers (much better than animation events)
This commit is contained in:
1 parent
c5c35a1113
commit
a33acee117
2 files changed
+46
-1
No files matched your search
@@ -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<Animation> onAnimationStart;
|
||||
public BiConsumer<Integer, Animation> onAnimationFrame;
|
||||
public Consumer<Animation> 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<Animation> task) {
|
||||
this.onAnimationStart = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation onFrame(BiConsumer<Integer, Animation> task) {
|
||||
this.onAnimationFrame = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IAnimation onEnd(Consumer<Animation> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<EntityPlayer> entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(
|
||||
|
||||
Reference in new issue
Block a user