This commit is contained in:
zeruth
2019-06-10 02:24:21 -04:00
parent a3c4144273
commit fb9709ab71

View File

@@ -24,12 +24,12 @@
*/ */
package net.runelite.mixins; package net.runelite.mixins;
import net.runelite.api.Actor; import java.util.ArrayList;
import java.util.List;
import net.runelite.api.CollisionData; import net.runelite.api.CollisionData;
import net.runelite.api.CollisionDataFlag; import net.runelite.api.CollisionDataFlag;
import net.runelite.api.Constants; import net.runelite.api.Constants;
import net.runelite.api.DecorativeObject; import net.runelite.api.DecorativeObject;
import net.runelite.api.GameObject;
import net.runelite.api.GroundObject; import net.runelite.api.GroundObject;
import net.runelite.api.Item; import net.runelite.api.Item;
import net.runelite.api.ItemLayer; import net.runelite.api.ItemLayer;
@@ -53,31 +53,31 @@ import net.runelite.api.events.ItemSpawned;
import net.runelite.api.events.WallObjectChanged; import net.runelite.api.events.WallObjectChanged;
import net.runelite.api.events.WallObjectDespawned; import net.runelite.api.events.WallObjectDespawned;
import net.runelite.api.events.WallObjectSpawned; import net.runelite.api.events.WallObjectSpawned;
import java.util.ArrayList;
import java.util.List;
import net.runelite.api.mixins.FieldHook; import net.runelite.api.mixins.FieldHook;
import net.runelite.api.mixins.Inject; import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin; import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Shadow; import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSActor;
import net.runelite.rs.api.RSClient; import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSDeque;
import net.runelite.rs.api.RSGameObject; import net.runelite.rs.api.RSGameObject;
import net.runelite.rs.api.RSGroundItem; import net.runelite.rs.api.RSGraphicsObject;
import net.runelite.rs.api.RSGroundItemPile; import net.runelite.rs.api.RSItem;
import net.runelite.rs.api.RSItemLayer;
import net.runelite.rs.api.RSNode; import net.runelite.rs.api.RSNode;
import net.runelite.rs.api.RSNodeDeque; import net.runelite.rs.api.RSProjectile;
import net.runelite.rs.api.RSRenderable;
import net.runelite.rs.api.RSTile; import net.runelite.rs.api.RSTile;
import org.slf4j.Logger;
@Mixin(RSTile.class) @Mixin(RSTile.class)
public abstract class RSTileMixin implements RSTile public abstract class RSTileMixin implements RSTile
{ {
@Shadow("client") @Shadow("clientInstance")
private static RSClient client; private static RSClient client;
@Inject @Inject
private static GameObject lastGameObject; private static RSDeque[][][] lastGroundItems = new RSDeque[Constants.MAX_Z][Constants.SCENE_SIZE][Constants.SCENE_SIZE];
@Inject
private static RSNodeDeque[][][] lastGroundItems = new RSNodeDeque[Constants.MAX_Z][Constants.SCENE_SIZE][Constants.SCENE_SIZE];
@Inject @Inject
private WallObject previousWallObject; private WallObject previousWallObject;
@@ -89,7 +89,7 @@ public abstract class RSTileMixin implements RSTile
private GroundObject previousGroundObject; private GroundObject previousGroundObject;
@Inject @Inject
private GameObject[] previousGameObjects; private RSGameObject[] previousGameObjects;
@Inject @Inject
@Override @Override
@@ -112,7 +112,7 @@ public abstract class RSTileMixin implements RSTile
return LocalPoint.fromScene(getX(), getY()); return LocalPoint.fromScene(getX(), getY());
} }
@FieldHook("boundaryObject") @FieldHook("wallObject")
@Inject @Inject
public void wallObjectChanged(int idx) public void wallObjectChanged(int idx)
{ {
@@ -135,7 +135,7 @@ public abstract class RSTileMixin implements RSTile
wallObjectSpawned.setWallObject(current); wallObjectSpawned.setWallObject(current);
client.getCallbacks().post(wallObjectSpawned); client.getCallbacks().post(wallObjectSpawned);
} }
else if (current != null) else if (current != null && previous != null)
{ {
WallObjectChanged wallObjectChanged = new WallObjectChanged(); WallObjectChanged wallObjectChanged = new WallObjectChanged();
wallObjectChanged.setTile(this); wallObjectChanged.setTile(this);
@@ -145,7 +145,7 @@ public abstract class RSTileMixin implements RSTile
} }
} }
@FieldHook("wallDecoration") @FieldHook("decorativeObject")
@Inject @Inject
public void decorativeObjectChanged(int idx) public void decorativeObjectChanged(int idx)
{ {
@@ -168,7 +168,7 @@ public abstract class RSTileMixin implements RSTile
decorativeObjectSpawned.setDecorativeObject(current); decorativeObjectSpawned.setDecorativeObject(current);
client.getCallbacks().post(decorativeObjectSpawned); client.getCallbacks().post(decorativeObjectSpawned);
} }
else if (current != null) else if (current != null && previous != null)
{ {
DecorativeObjectChanged decorativeObjectChanged = new DecorativeObjectChanged(); DecorativeObjectChanged decorativeObjectChanged = new DecorativeObjectChanged();
decorativeObjectChanged.setTile(this); decorativeObjectChanged.setTile(this);
@@ -178,7 +178,7 @@ public abstract class RSTileMixin implements RSTile
} }
} }
@FieldHook("floorDecoration") @FieldHook("groundObject")
@Inject @Inject
public void groundObjectChanged(int idx) public void groundObjectChanged(int idx)
{ {
@@ -201,7 +201,7 @@ public abstract class RSTileMixin implements RSTile
groundObjectSpawned.setGroundObject(current); groundObjectSpawned.setGroundObject(current);
client.getCallbacks().post(groundObjectSpawned); client.getCallbacks().post(groundObjectSpawned);
} }
else if (current != null) else if (current != null && previous != null)
{ {
GroundObjectChanged groundObjectChanged = new GroundObjectChanged(); GroundObjectChanged groundObjectChanged = new GroundObjectChanged();
groundObjectChanged.setTile(this); groundObjectChanged.setTile(this);
@@ -211,7 +211,7 @@ public abstract class RSTileMixin implements RSTile
} }
} }
@FieldHook("gameObjects") @FieldHook("objects")
@Inject @Inject
public void gameObjectsChanged(int idx) public void gameObjectsChanged(int idx)
{ {
@@ -222,69 +222,96 @@ public abstract class RSTileMixin implements RSTile
if (previousGameObjects == null) if (previousGameObjects == null)
{ {
previousGameObjects = new GameObject[5]; previousGameObjects = new RSGameObject[5];
} }
// Previous game object // Previous game object
GameObject previous = previousGameObjects[idx]; RSGameObject previous = previousGameObjects[idx];
// GameObject that was changed. // GameObject that was changed.
RSGameObject current = (RSGameObject) getGameObjects()[idx]; RSGameObject current = (RSGameObject) getGameObjects()[idx];
// Last game object
GameObject last = lastGameObject;
// Update last game object
lastGameObject = current;
// Update previous object to current // Update previous object to current
previousGameObjects[idx] = current; previousGameObjects[idx] = current;
// Duplicate event, return // Duplicate event, return
if (current != null && current.equals(last)) if (current == previous)
{ {
return; return;
} }
// Characters seem to generate a constant stream of new GameObjects // actors, projectiles, and graphics objects are added and removed from the scene each frame as GameObjects,
if (current == null || !(current.getRenderable() instanceof Actor)) // so ignore them.
boolean currentInvalid = false, prevInvalid = false;
if (current != null)
{ {
if (current == null && previous != null) RSRenderable renderable = current.getRenderable();
currentInvalid = renderable instanceof RSActor || renderable instanceof RSProjectile || renderable instanceof RSGraphicsObject;
}
if (previous != null)
{
RSRenderable renderable = previous.getRenderable();
prevInvalid = renderable instanceof RSActor || renderable instanceof RSProjectile || renderable instanceof RSGraphicsObject;
}
Logger logger = client.getLogger();
if (current == null)
{
if (prevInvalid)
{ {
GameObjectDespawned gameObjectDespawned = new GameObjectDespawned(); return;
gameObjectDespawned.setTile(this);
gameObjectDespawned.setGameObject(previous);
client.getCallbacks().post(gameObjectDespawned);
} }
else if (current != null && previous == null)
logger.trace("Game object despawn: {}", previous.getId());
GameObjectDespawned gameObjectDespawned = new GameObjectDespawned();
gameObjectDespawned.setTile(this);
gameObjectDespawned.setGameObject(previous);
client.getCallbacks().post(gameObjectDespawned);
}
else if (previous == null)
{
if (currentInvalid)
{ {
GameObjectSpawned gameObjectSpawned = new GameObjectSpawned(); return;
gameObjectSpawned.setTile(this);
gameObjectSpawned.setGameObject(current);
client.getCallbacks().post(gameObjectSpawned);
} }
else if (current != null)
logger.trace("Game object spawn: {}", current.getId());
GameObjectSpawned gameObjectSpawned = new GameObjectSpawned();
gameObjectSpawned.setTile(this);
gameObjectSpawned.setGameObject(current);
client.getCallbacks().post(gameObjectSpawned);
}
else
{
if (currentInvalid && prevInvalid)
{ {
GameObjectChanged gameObjectsChanged = new GameObjectChanged(); return;
gameObjectsChanged.setTile(this);
gameObjectsChanged.setPrevious(previous);
gameObjectsChanged.setGameObject(current);
client.getCallbacks().post(gameObjectsChanged);
} }
logger.trace("Game object change: {} -> {}", previous.getId(), current.getId());
GameObjectChanged gameObjectsChanged = new GameObjectChanged();
gameObjectsChanged.setTile(this);
gameObjectsChanged.setPrevious(previous);
gameObjectsChanged.setGameObject(current);
client.getCallbacks().post(gameObjectsChanged);
} }
} }
@FieldHook("groundItemPile") @FieldHook("itemLayer")
@Inject @Inject
public void itemLayerChanged(int idx) public void itemLayerChanged(int idx)
{ {
int x = getX(); int x = getX();
int y = getY(); int y = getY();
int z = client.getPlane(); int z = client.getPlane();
RSNodeDeque[][][] groundItemDeque = client.getGroundItemDeque(); RSDeque[][][] groundItemDeque = client.getGroundItemDeque();
RSNodeDeque oldQueue = lastGroundItems[z][x][y]; RSDeque oldQueue = lastGroundItems[z][x][y];
RSNodeDeque newQueue = groundItemDeque[z][x][y]; RSDeque newQueue = groundItemDeque[z][x][y];
if (oldQueue != newQueue) if (oldQueue != newQueue)
{ {
@@ -294,7 +321,7 @@ public abstract class RSTileMixin implements RSTile
RSNode head = oldQueue.getHead(); RSNode head = oldQueue.getHead();
for (RSNode cur = head.getNext(); cur != head; cur = cur.getNext()) for (RSNode cur = head.getNext(); cur != head; cur = cur.getNext())
{ {
RSGroundItem item = (RSGroundItem) cur; RSItem item = (RSItem) cur;
ItemDespawned itemDespawned = new ItemDespawned(this, item); ItemDespawned itemDespawned = new ItemDespawned(this, item);
client.getCallbacks().post(itemDespawned); client.getCallbacks().post(itemDespawned);
} }
@@ -302,13 +329,13 @@ public abstract class RSTileMixin implements RSTile
lastGroundItems[z][x][y] = newQueue; lastGroundItems[z][x][y] = newQueue;
} }
RSGroundItem lastUnlink = client.getLastItemDespawn(); RSItem lastUnlink = client.getLastItemDespawn();
if (lastUnlink != null) if (lastUnlink != null)
{ {
client.setLastItemDespawn(null); client.setLastItemDespawn(null);
} }
RSGroundItemPile itemLayer = (RSGroundItemPile) getItemLayer(); RSItemLayer itemLayer = (RSItemLayer) getItemLayer();
if (itemLayer == null) if (itemLayer == null)
{ {
if (lastUnlink != null) if (lastUnlink != null)
@@ -319,7 +346,7 @@ public abstract class RSTileMixin implements RSTile
return; return;
} }
RSNodeDeque itemDeque = newQueue; RSDeque itemDeque = newQueue;
if (itemDeque == null) if (itemDeque == null)
{ {
@@ -338,7 +365,7 @@ public abstract class RSTileMixin implements RSTile
boolean forward = false; boolean forward = false;
if (head != previous) if (head != previous)
{ {
RSGroundItem prev = (RSGroundItem) previous; RSItem prev = (RSItem) previous;
if (x != prev.getX() || y != prev.getY()) if (x != prev.getX() || y != prev.getY())
{ {
current = prev; current = prev;
@@ -348,7 +375,7 @@ public abstract class RSTileMixin implements RSTile
RSNode next = head.getNext(); RSNode next = head.getNext();
if (current == null && head != next) if (current == null && head != next)
{ {
RSGroundItem n = (RSGroundItem) next; RSItem n = (RSItem) next;
if (x != n.getX() || y != n.getY()) if (x != n.getX() || y != n.getY())
{ {
current = n; current = n;
@@ -369,7 +396,7 @@ public abstract class RSTileMixin implements RSTile
do do
{ {
RSGroundItem item = (RSGroundItem) current; RSItem item = (RSItem) current;
item.setX(x); item.setX(x);
item.setY(y); item.setY(y);
@@ -380,7 +407,7 @@ public abstract class RSTileMixin implements RSTile
// Send spawn events for anything on this tile which is at the wrong location, which happens // Send spawn events for anything on this tile which is at the wrong location, which happens
// when the scene base changes // when the scene base changes
} while (current != head && (((RSGroundItem) current).getX() != x || ((RSGroundItem) current).getY() != y)); } while (current != head && (((RSItem) current).getX() != x || ((RSItem) current).getY() != y));
} }
@Inject @Inject