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);
}
}
}
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);
}
Aggregations