From 404b365ef0dd2d725d4f64f0ca84e8b0723e7e53 Mon Sep 17 00:00:00 2001 From: McHorse Date: Thu, 8 Sep 2022 12:11:05 +0100 Subject: [PATCH] Fix NPC's target trigger --- CHANGELOG.md | 1 + src/main/java/mchorse/mappet/entities/EntityNpc.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 117e6d21..ac46132f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This quick patch update patches and updates. * Fixed an error with quest node in a dialogue not loading when quest isn't accepted * Fixed respawn options can't be edited by `/mp npc edit` command * Fixed a couple of misspellings in documentation +* Fixed NPC's target trigger ## Version 0.2.1 diff --git a/src/main/java/mchorse/mappet/entities/EntityNpc.java b/src/main/java/mchorse/mappet/entities/EntityNpc.java index 6e336c06..1b049dbf 100644 --- a/src/main/java/mchorse/mappet/entities/EntityNpc.java +++ b/src/main/java/mchorse/mappet/entities/EntityNpc.java @@ -16,10 +16,10 @@ import mchorse.mappet.entities.ai.EntityAIHurtByTargetNpc; import mchorse.mappet.entities.ai.EntityAIPatrol; import mchorse.mappet.entities.ai.EntityAIReturnToPost; +import mchorse.mappet.entities.utils.MappetNpcRespawnManager; import mchorse.mappet.entities.utils.NpcDamageSource; import mchorse.mappet.network.Dispatcher; import mchorse.mappet.network.common.npc.PacketNpcMorph; -import mchorse.mappet.entities.utils.MappetNpcRespawnManager; import mchorse.mclib.utils.Interpolations; import mchorse.mclib.utils.MathUtils; import mchorse.metamorph.api.Morph; @@ -67,6 +67,8 @@ public class EntityNpc extends EntityCreature implements IEntityAdditionalSpawnD public float smoothBodyYawHead; public float prevSmoothBodyYawHead; + private Entity lastTarget; + /** * Needs to fix a clone issue, when npc dies and you quick reload world */ @@ -345,6 +347,13 @@ public void setMaxHealth(double value) @Override public void onUpdate() { + if (this.lastTarget != this.getAttackTarget()) + { + this.lastTarget = this.getAttackTarget(); + + this.state.triggerTarget.trigger(new DataContext(this, this.lastTarget)); + } + this.healthFailsafe(); this.updateAttackTarget();