runelite-api: add game object and wall object spawn/change/despawn events
This commit is contained in:
@@ -24,16 +24,24 @@
|
||||
*/
|
||||
package net.runelite.mixins;
|
||||
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.GameObject;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.WallObject;
|
||||
import net.runelite.api.events.GameObjectChanged;
|
||||
import net.runelite.api.events.GameObjectDespawned;
|
||||
import net.runelite.api.events.GameObjectSpawned;
|
||||
import net.runelite.api.events.WallObjectChanged;
|
||||
import net.runelite.api.events.WallObjectDespawned;
|
||||
import net.runelite.api.events.WallObjectSpawned;
|
||||
import net.runelite.api.mixins.FieldHook;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.api.mixins.Shadow;
|
||||
import net.runelite.api.events.GameObjectsChanged;
|
||||
import static net.runelite.client.callback.Hooks.eventBus;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
import net.runelite.rs.api.RSGameObject;
|
||||
import net.runelite.rs.api.RSTile;
|
||||
|
||||
@Mixin(RSTile.class)
|
||||
@@ -42,6 +50,12 @@ public abstract class RSTileMixin implements RSTile
|
||||
@Shadow("clientInstance")
|
||||
private static RSClient client;
|
||||
|
||||
@Inject
|
||||
private WallObject previousWallObject;
|
||||
|
||||
@Inject
|
||||
private GameObject[] previousGameObjects;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public Point getWorldLocation()
|
||||
@@ -65,18 +79,84 @@ public abstract class RSTileMixin implements RSTile
|
||||
return Perspective.regionToLocal(client, regionLocation);
|
||||
}
|
||||
|
||||
@FieldHook("wallObject")
|
||||
@Inject
|
||||
public void wallObjectChanged(int idx)
|
||||
{
|
||||
WallObject previous = previousWallObject;
|
||||
WallObject current = getWallObject();
|
||||
|
||||
previousWallObject = current;
|
||||
|
||||
if (current == null && previous != null)
|
||||
{
|
||||
WallObjectDespawned wallObjectDespawned = new WallObjectDespawned();
|
||||
wallObjectDespawned.setTile(this);
|
||||
wallObjectDespawned.setWallObject(previous);
|
||||
eventBus.post(wallObjectDespawned);
|
||||
}
|
||||
else if (current != null && previous == null)
|
||||
{
|
||||
WallObjectSpawned wallObjectSpawned = new WallObjectSpawned();
|
||||
wallObjectSpawned.setTile(this);
|
||||
wallObjectSpawned.setWallObject(current);
|
||||
eventBus.post(wallObjectSpawned);
|
||||
}
|
||||
else if (current != null && previous != null)
|
||||
{
|
||||
WallObjectChanged wallObjectChanged = new WallObjectChanged();
|
||||
wallObjectChanged.setTile(this);
|
||||
wallObjectChanged.setPrevious(previous);
|
||||
wallObjectChanged.setWallObject(current);
|
||||
eventBus.post(wallObjectChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@FieldHook("objects")
|
||||
@Inject
|
||||
public void animationChanged(int idx)
|
||||
public void gameObjectsChanged(int idx)
|
||||
{
|
||||
if (idx != -1) // this happens from the field assignment
|
||||
if (idx == -1) // this happens from the field assignment
|
||||
{
|
||||
// GameObject that was changed.
|
||||
GameObject go = getGameObjects()[idx];
|
||||
if (go != null)
|
||||
return;
|
||||
}
|
||||
|
||||
if (previousGameObjects == null)
|
||||
{
|
||||
previousGameObjects = new GameObject[5];
|
||||
}
|
||||
|
||||
// Previous game object
|
||||
GameObject previous = previousGameObjects[idx];
|
||||
// GameObject that was changed.
|
||||
RSGameObject current = (RSGameObject) getGameObjects()[idx];
|
||||
|
||||
// Update previous object to current
|
||||
previousGameObjects[idx] = current;
|
||||
|
||||
// Characters seem to generate a constant stream of new GameObjects
|
||||
if (current == null || !(current.getRenderable() instanceof Actor))
|
||||
{
|
||||
if (current == null && previous != null)
|
||||
{
|
||||
GameObjectsChanged gameObjectsChanged = new GameObjectsChanged();
|
||||
gameObjectsChanged.setGameObject(go);
|
||||
GameObjectDespawned gameObjectDespawned = new GameObjectDespawned();
|
||||
gameObjectDespawned.setTile(this);
|
||||
gameObjectDespawned.setGameObject(previous);
|
||||
eventBus.post(gameObjectDespawned);
|
||||
}
|
||||
else if (current != null && previous == null)
|
||||
{
|
||||
GameObjectSpawned gameObjectSpawned = new GameObjectSpawned();
|
||||
gameObjectSpawned.setTile(this);
|
||||
gameObjectSpawned.setGameObject(current);
|
||||
eventBus.post(gameObjectSpawned);
|
||||
}
|
||||
else if (current != null && previous != null)
|
||||
{
|
||||
GameObjectChanged gameObjectsChanged = new GameObjectChanged();
|
||||
gameObjectsChanged.setTile(this);
|
||||
gameObjectsChanged.setPrevious(previous);
|
||||
gameObjectsChanged.setGameObject(current);
|
||||
eventBus.post(gameObjectsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user