New event hooks and animation event class

This commit is contained in:
Luis C.M. committed 2025-01-22 15:49:27 -06:00
1 parent 0bb5dee58f
commit 990419a411
3 files changed
+163 -4

No files matched your search

+49 -3
View File
@@ -15,11 +15,12 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.world.WorldEvent;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.entity.IProjectile;
import noppes.npcs.api.entity.*;
import noppes.npcs.api.event.IAnimationEvent;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.api.item.IItemCustom;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
@@ -803,4 +804,49 @@ public class EventHooks {
handler.callScript(EnumScriptType.PARTY_DISBAND, event);
NpcAPI.EVENT_BUS.post(event);
}
private static boolean postAnimationEvent(IAnimationEvent event) {
IScriptHandler handler;
IAnimatable animatable = event.getAnimation().getParent().getEntity();
if (animatable instanceof ICustomNpc<?>) {
EntityNPCInterface npc = (EntityNPCInterface) ((ICustomNpc<?>) animatable).getMCEntity();
handler = npc.script;
} else {
handler = ScriptController.Instance.playerScripts;
}
if (handler.isClient())
return false;
handler.callScript(event.getHookName(), (Event) event);
return NpcAPI.EVENT_BUS.post((Event) event);
}
public static boolean onAnimationStarted(IAnimation animation) {
if (animation.getParent() == null || animation.getParent().getEntity() == null) {
return false;
}
return postAnimationEvent(new AnimationEvent.Started(animation));
}
public static void onAnimationEnded(IAnimation animation) {
if (animation.getParent() == null || animation.getParent().getEntity() == null) {
return;
}
postAnimationEvent(new AnimationEvent.Ended(animation));
}
public static void onAnimationFrameEntered(IAnimation animation, IFrame frame) {
if (frame == null || animation.getParent() == null || animation.getParent().getEntity() == null) {
return;
}
postAnimationEvent(new AnimationEvent.FrameEvent.Entered(animation, frame));
}
public static void onAnimationFrameExited(IAnimation animation, IFrame frame) {
if (frame == null || animation.getParent() == null || animation.getParent().getEntity() == null) {
return;
}
postAnimationEvent(new AnimationEvent.FrameEvent.Exited(animation, frame));
}
}