Search in sources :

Example 1 with GameObjectChanged

use of net.runelite.api.events.GameObjectChanged in project runelite by runelite.

the class RSTileMixin method gameObjectsChanged.

@FieldHook("objects")
@Inject
public void gameObjectsChanged(int idx) {
    if (// this happens from the field assignment
    idx == -1) {
        return;
    }
    if (previousGameObjects == null) {
        previousGameObjects = new GameObject[5];
    }
    // Previous game object
    GameObject previous = previousGameObjects[idx];
    // GameObject that was changed.
    RSGameObject current = (RSGameObject) getGameObjects()[idx];
    // Last game object
    GameObject last = lastGameObject;
    // Update last game object
    lastGameObject = current;
    // Update previous object to current
    previousGameObjects[idx] = current;
    // Duplicate event, return
    if (current != null && current.equals(last)) {
        return;
    }
    // Characters seem to generate a constant stream of new GameObjects
    if (current == null || !(current.getRenderable() instanceof Actor)) {
        if (current == null && previous != null) {
            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);
        }
    }
}
Also used : GameObjectSpawned(net.runelite.api.events.GameObjectSpawned) RSGameObject(net.runelite.rs.api.RSGameObject) GameObject(net.runelite.api.GameObject) RSGameObject(net.runelite.rs.api.RSGameObject) Actor(net.runelite.api.Actor) GameObjectDespawned(net.runelite.api.events.GameObjectDespawned) GameObjectChanged(net.runelite.api.events.GameObjectChanged) Inject(net.runelite.api.mixins.Inject) FieldHook(net.runelite.api.mixins.FieldHook)

Aggregations

Actor (net.runelite.api.Actor)1 GameObject (net.runelite.api.GameObject)1 GameObjectChanged (net.runelite.api.events.GameObjectChanged)1 GameObjectDespawned (net.runelite.api.events.GameObjectDespawned)1 GameObjectSpawned (net.runelite.api.events.GameObjectSpawned)1 FieldHook (net.runelite.api.mixins.FieldHook)1 Inject (net.runelite.api.mixins.Inject)1 RSGameObject (net.runelite.rs.api.RSGameObject)1