use of net.runelite.api.ItemLayer in project runelite by runelite.
the class DevToolsOverlay method renderGroundItems.
private void renderGroundItems(Graphics2D graphics, Tile tile, Player player) {
ItemLayer itemLayer = tile.getItemLayer();
if (itemLayer != null) {
if (player.getLocalLocation().distanceTo(itemLayer.getLocalLocation()) <= MAX_DISTANCE) {
Node current = itemLayer.getBottom();
while (current instanceof Item) {
Item item = (Item) current;
OverlayUtil.renderTileOverlay(graphics, itemLayer, "ID: " + item.getId() + " Qty:" + item.getQuantity(), RED);
current = current.getNext();
}
}
}
}
use of net.runelite.api.ItemLayer in project runelite by runelite.
the class GroundItemsPlugin method checkItems.
void checkItems() {
final Player player = client.getLocalPlayer();
if (!dirty || player == null || client.getViewportWidget() == null) {
return;
}
dirty = false;
final Region region = client.getRegion();
final Tile[][][] tiles = region.getTiles();
final int z = client.getPlane();
final LocalPoint from = player.getLocalLocation();
final int lowerX = Math.max(0, from.getRegionX() - MAX_RANGE);
final int lowerY = Math.max(0, from.getRegionY() - MAX_RANGE);
final int upperX = Math.min(from.getRegionX() + MAX_RANGE, REGION_SIZE - 1);
final int upperY = Math.min(from.getRegionY() + MAX_RANGE, REGION_SIZE - 1);
groundItems.clear();
for (int x = lowerX; x <= upperX; ++x) {
for (int y = lowerY; y <= upperY; ++y) {
Tile tile = tiles[z][x][y];
if (tile == null) {
continue;
}
ItemLayer itemLayer = tile.getItemLayer();
if (itemLayer == null) {
continue;
}
Node current = itemLayer.getBottom();
// adds the items on the ground to the ArrayList to be drawn
while (current instanceof Item) {
final Item item = (Item) current;
// Continue iteration
current = current.getNext();
// Build ground item
final GroundItem groundItem = buildGroundItem(tile, item);
if (groundItem != null) {
groundItems.add(groundItem);
}
}
}
}
// Group ground items together and sort them properly
collectedGroundItems.clear();
Lists.reverse(groundItems).stream().collect(groundItemMapCollector);
}
use of net.runelite.api.ItemLayer in project runelite by runelite.
the class GroundItemsPlugin method onMenuEntryAdded.
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event) {
if ((config.highlightMenuOption() || config.highlightMenuItemName()) && event.getOption().equals("Take") && event.getType() == MenuAction.GROUND_ITEM_THIRD_OPTION.getId()) {
int itemId = event.getIdentifier();
ItemComposition itemComposition = client.getItemDefinition(itemId);
if (isHidden(itemComposition.getName())) {
return;
}
Region region = client.getRegion();
Tile tile = region.getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()];
ItemLayer itemLayer = tile.getItemLayer();
if (itemLayer == null) {
return;
}
MenuEntry[] menuEntries = client.getMenuEntries();
MenuEntry lastEntry = menuEntries[menuEntries.length - 1];
int quantity = 1;
Node current = itemLayer.getBottom();
while (current instanceof Item) {
Item item = (Item) current;
if (item.getId() == itemId) {
quantity = item.getQuantity();
}
current = current.getNext();
}
ItemPrice itemPrice = getItemPrice(itemComposition);
int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice();
int cost = quantity * price;
Color color = overlay.getCostColor(cost, isHighlighted(itemComposition.getName()), isHidden(itemComposition.getName()));
if (!color.equals(config.defaultColor())) {
String hexColor = Integer.toHexString(color.getRGB() & 0xFFFFFF);
String colTag = "<col=" + hexColor + ">";
if (config.highlightMenuOption()) {
lastEntry.setOption(colTag + "Take");
}
if (config.highlightMenuItemName()) {
String target = lastEntry.getTarget().substring(lastEntry.getTarget().indexOf(">") + 1);
lastEntry.setTarget(colTag + target);
}
}
if (config.showMenuItemQuantities() && itemComposition.isStackable() && quantity > 1) {
lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")");
}
client.setMenuEntries(menuEntries);
}
}
Aggregations