runelite-mixins: fire npc despawn event before composition is nulled

This commit is contained in:
Adam
2018-05-13 15:45:39 -04:00
parent 484d664a3c
commit e915070b4b
2 changed files with 13 additions and 14 deletions

View File

@@ -71,7 +71,6 @@ import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GrandExchangeOfferChanged;
import net.runelite.api.events.MapRegionChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.api.events.PlayerDespawned;
import net.runelite.api.events.PlayerMenuOptionsChanged;
@@ -126,9 +125,6 @@ public abstract class RSClientMixin implements RSClient
@Inject
private static RSPlayer[] oldPlayers = new RSPlayer[2048];
@Inject
private static RSNPC[] oldNpcs = new RSNPC[32768];
@Inject
private static int itemPressedDurationBuffer;
@@ -807,17 +803,7 @@ public abstract class RSClientMixin implements RSClient
if (npc != null)
{
npc.setIndex(idx);
}
RSNPC oldNpc = oldNpcs[idx];
oldNpcs[idx] = npc;
if (oldNpc != null)
{
eventBus.post(new NpcDespawned(oldNpc));
}
if (npc != null)
{
deferredEventBus.post(new NpcSpawned(npc));
}
}

View File

@@ -24,11 +24,14 @@
*/
package net.runelite.mixins;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.FieldHook;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.api.mixins.Shadow;
import static net.runelite.client.callback.Hooks.eventBus;
import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSModel;
import net.runelite.rs.api.RSNPC;
@@ -93,6 +96,16 @@ public abstract class RSNPCMixin implements RSNPC
npcIndex = id;
}
@FieldHook(value = "composition", before = true)
@Inject
public void onCompositionChanged(RSNPCComposition composition)
{
if (composition == null)
{
eventBus.post(new NpcDespawned(this));
}
}
@Copy("getModel")
public abstract RSModel rs$getModel();