Skip to content

Commit

Permalink
Fix NPC's target trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Sep 8, 2022
1 parent 658b598 commit 404b365
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/mchorse/mappet/entities/EntityNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 404b365

Please sign in to comment.