grounditems: try fix the broken stuff in open-osrs/plugins#316

This commit is contained in:
ThatGamerBlue
2020-06-18 19:36:58 +01:00
parent 1c68411ca9
commit 60300fb102
4 changed files with 90 additions and 34 deletions

View File

@@ -38,7 +38,6 @@ import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.HitsplatApplied;
import net.runelite.api.events.PlayerDeath;
import net.runelite.api.events.PlayerDeath;
import net.runelite.api.events.SpotAnimationChanged;
import net.runelite.api.events.InteractingChanged;
import net.runelite.api.events.OverheadTextChanged;

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* Copyright (c) 2020, ThatGamerBlue <thatgamerblue@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -82,6 +83,7 @@ import net.runelite.api.events.FriendsChatChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GrandExchangeOfferChanged;
import net.runelite.api.events.GrandExchangeSearched;
import net.runelite.api.events.ItemSpawned;
import net.runelite.api.events.Menu;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOpened;
@@ -120,11 +122,14 @@ import net.runelite.rs.api.RSFriendSystem;
import net.runelite.rs.api.RSIndexedSprite;
import net.runelite.rs.api.RSItemContainer;
import net.runelite.rs.api.RSNPC;
import net.runelite.rs.api.RSNode;
import net.runelite.rs.api.RSNodeDeque;
import net.runelite.rs.api.RSNodeHashTable;
import net.runelite.rs.api.RSPacketBuffer;
import net.runelite.rs.api.RSPlayer;
import net.runelite.rs.api.RSScene;
import net.runelite.rs.api.RSSprite;
import net.runelite.rs.api.RSTile;
import net.runelite.rs.api.RSTileItem;
import net.runelite.rs.api.RSUsername;
import net.runelite.rs.api.RSWidget;
@@ -826,7 +831,7 @@ public abstract class RSClientMixin implements RSClient
{
List<Projectile> projectiles = new ArrayList<Projectile>();
RSNodeDeque projectileDeque = this.getProjectilesDeque();
Node head = projectileDeque.getHead();
Node head = projectileDeque.getSentinel();
for (Node node = head.getNext(); node != head; node = node.getNext())
{
@@ -842,7 +847,7 @@ public abstract class RSClientMixin implements RSClient
{
List<GraphicsObject> graphicsObjects = new ArrayList<GraphicsObject>();
RSNodeDeque graphicsObjectDeque = this.getGraphicsObjectDeque();
Node head = graphicsObjectDeque.getHead();
Node head = graphicsObjectDeque.getSentinel();
for (Node node = head.getNext(); node != head; node = node.getNext())
{
@@ -1062,8 +1067,39 @@ public abstract class RSClientMixin implements RSClient
public static void gameStateChanged(int idx)
{
GameStateChanged gameStateChange = new GameStateChanged();
gameStateChange.setGameState(client.getGameState());
GameState gameState = client.getGameState();
gameStateChange.setGameState(gameState);
client.getCallbacks().post(GameStateChanged.class, gameStateChange);
if (gameState == GameState.LOGGED_IN)
{
int plane = client.getPlane();
RSScene scene = client.getScene();
RSTile[][][] tiles = scene.getTiles();
RSNodeDeque[][][] allItemDeque = client.getGroundItemDeque();
RSNodeDeque[][] planeItems = allItemDeque[plane];
for (int x = 0; x < 104; x++)
{
for (int y = 0; y < 104; y++)
{
RSNodeDeque itemDeque = planeItems[x][y];
if (itemDeque != null)
{
RSTile tile = tiles[plane][x][y];
RSNode head = itemDeque.getSentinel();
for (RSNode current = head.getNext(); current != head; current = current.getNext())
{
RSTileItem item = (RSTileItem) current;
item.setX(x);
item.setY(y);
ItemSpawned event = new ItemSpawned(tile, item);
client.getCallbacks().post(ItemSpawned.class, event);
}
}
}
}
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* Copyright (c) 2020, ThatGamerBlue <thatgamerblue@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,6 +31,7 @@ import net.runelite.api.CollisionData;
import net.runelite.api.CollisionDataFlag;
import net.runelite.api.Constants;
import net.runelite.api.DecorativeObject;
import net.runelite.api.GameState;
import net.runelite.api.GroundObject;
import net.runelite.api.TileItemPile;
import net.runelite.api.Node;
@@ -466,12 +468,19 @@ public abstract class RSTileMixin implements RSTile
RSNodeDeque oldQueue = lastGroundItems[z][x][y];
RSNodeDeque newQueue = groundItemDeque[z][x][y];
if (client.getGameState() != GameState.LOGGED_IN)
{
lastGroundItems[z][x][y] = newQueue;
client.setLastItemDespawn(null);
return;
}
if (oldQueue != newQueue)
{
if (oldQueue != null)
{
// despawn everything in old ..
RSNode head = oldQueue.getHead();
RSNode head = oldQueue.getSentinel();
for (RSNode cur = head.getNext(); cur != head; cur = cur.getNext())
{
RSTileItem item = (RSTileItem) cur;
@@ -512,54 +521,42 @@ public abstract class RSTileMixin implements RSTile
}
// The new item gets added to either the head, or the tail, depending on its price
RSNode head = itemDeque.getHead();
RSNode current = null;
RSNode previous = head.getPrevious();
boolean forward = false;
if (head != previous)
RSNode head = itemDeque.getSentinel();
RSTileItem current = null;
RSNode next = head.getPrevious();
//boolean forward = false;
if (head != next)
{
RSTileItem prev = (RSTileItem) previous;
RSTileItem prev = (RSTileItem) next;
if (x != prev.getX() || y != prev.getY())
{
current = prev;
}
}
RSNode next = head.getNext();
if (current == null && head != next)
RSNode previous = head.getNext();
if (current == null && head != previous)
{
RSTileItem n = (RSTileItem) next;
RSTileItem n = (RSTileItem) previous;
if (x != n.getX() || y != n.getY())
{
current = n;
forward = true;
//forward = true;
}
}
if (lastUnlink != null && lastUnlink != previous && lastUnlink != next)
if (lastUnlink != null && lastUnlink != next && lastUnlink != previous)
{
ItemDespawned itemDespawned = new ItemDespawned(this, lastUnlink);
client.getCallbacks().post(ItemDespawned.class, itemDespawned);
}
if (current == null)
if (current != null)
{
return; // already seen this spawn, or no new item
current.setX(x);
current.setY(y);
ItemSpawned event = new ItemSpawned(this, current);
client.getCallbacks().post(ItemSpawned.class, event);
}
do
{
RSTileItem item = (RSTileItem) current;
item.setX(x);
item.setY(y);
ItemSpawned itemSpawned = new ItemSpawned(this, item);
client.getCallbacks().post(ItemSpawned.class, itemSpawned);
current = forward ? current.getNext() : current.getPrevious();
// Send spawn events for anything on this tile which is at the wrong location, which happens
// when the scene base changes
} while (current != head && (((RSTileItem) current).getX() != x || ((RSTileItem) current).getY() != y));
}
}

View File

@@ -1,3 +1,27 @@
/*
* Copyright (c) 2020, ThatGamerBlue <thatgamerblue@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.rs.api;
import net.runelite.mapping.Import;
@@ -8,7 +32,7 @@ public interface RSNodeDeque
RSNode getCurrent();
@Import("sentinel")
RSNode getHead();
RSNode getSentinel();
@Import("last")
RSNode last();