Search in sources :

Example 1 with GameObjectSpawned

use of net.runelite.api.events.GameObjectSpawned 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)

Example 2 with GameObjectSpawned

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

the class RegionTileManager method simulateObjectSpawns.

/**
 * Simulate object spawns for EventBus subscriber
 * @param subscriber EventBus subscriber
 */
public void simulateObjectSpawns(Object subscriber) {
    eventBus.register(subscriber);
    forEachTile((tile) -> {
        Optional.ofNullable(tile.getWallObject()).ifPresent(object -> {
            final WallObjectSpawned objectSpawned = new WallObjectSpawned();
            objectSpawned.setTile(tile);
            objectSpawned.setWallObject(object);
            eventBus.post(objectSpawned);
        });
        Optional.ofNullable(tile.getDecorativeObject()).ifPresent(object -> {
            final DecorativeObjectSpawned objectSpawned = new DecorativeObjectSpawned();
            objectSpawned.setTile(tile);
            objectSpawned.setDecorativeObject(object);
            eventBus.post(objectSpawned);
        });
        Optional.ofNullable(tile.getGroundObject()).ifPresent(object -> {
            final GroundObjectSpawned objectSpawned = new GroundObjectSpawned();
            objectSpawned.setTile(tile);
            objectSpawned.setGroundObject(object);
            eventBus.post(objectSpawned);
        });
        Arrays.stream(tile.getGameObjects()).filter(Objects::nonNull).forEach(object -> {
            final GameObjectSpawned objectSpawned = new GameObjectSpawned();
            objectSpawned.setTile(tile);
            objectSpawned.setGameObject(object);
            eventBus.post(objectSpawned);
        });
    });
    eventBus.unregister(subscriber);
}
Also used : GroundObjectSpawned(net.runelite.api.events.GroundObjectSpawned) GameObjectSpawned(net.runelite.api.events.GameObjectSpawned) DecorativeObjectSpawned(net.runelite.api.events.DecorativeObjectSpawned) WallObjectSpawned(net.runelite.api.events.WallObjectSpawned)

Aggregations

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