Advertisement
Guest User

OSBot Inventory Painter

a guest
Dec 25th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1.     /*
  2.      * Draws the rectangle bounds of the inventory items includes item names +
  3.      * item id's in the middle of the bounds
  4.      *
  5.      * @Param g - g relates to the parameter of the OSBot painter interface
  6.      * Visibility of this method public as it's in it's own class script is the
  7.      * instance of the MethodProvider
  8.      */
  9.  
  10.     public void paintInventory(Graphics g) {
  11.         // Declaring the inventory
  12.         Inventory inventory = script.client.getInventory();
  13.         // Grabbing the items on the inventory interface
  14.         Item[] inventoryItems = inventory.getItems();
  15.         // Opening a list to keep track of the slot locations of items
  16.         ArrayList<Integer> slots = new ArrayList<Integer>();
  17.         // Opening a list to keep track of the slot's rectangle bounds
  18.         ArrayList<Rectangle> rectangleDestinations = new ArrayList<Rectangle>();
  19.  
  20.         // Null check + length check
  21.         if (inventoryItems != null && inventoryItems.length > 0) {
  22.             // Illiterating through the array of items
  23.             for (int i = 0; i < inventoryItems.length; i++) {
  24.                 // Null checking the item
  25.                 if (inventoryItems[i] != null)
  26.                     // Adding the slot to the list we opened before
  27.                     slots.add(inventory.getSlotForId(inventoryItems[i].getId()));
  28.             }
  29.         }
  30.  
  31.         // Null check + length check on the slots of the inventory
  32.         if (slots != null && slots.size() > 0) {
  33.             // Illiterating through the inventory slots
  34.             for (int i : slots) {
  35.                 // Adding the rectangle bounds of the slots to the list
  36.                 rectangleDestinations.add(inventory.getDestinationForSlot(i));
  37.             }
  38.         }
  39.  
  40.         // Null + Length check on the rectangle bounds of slots
  41.         if (rectangleDestinations != null && rectangleDestinations.size() > 0) {
  42.             // Illiterating through the rectangle bound list
  43.             for (Rectangle r : rectangleDestinations) {
  44.                 // Illiterating through the inventory items
  45.                 for (Item item : inventoryItems) {
  46.                     // Null check of the rectangle bounds
  47.                     if (r != null) {
  48.                         // Setting a easily visible colour
  49.                         g.setColor(Color.BLACK);
  50.                         // Drawing the rectangle bounds
  51.                         g.drawRect(r.x, r.y, r.width, r.height);
  52.                     }
  53.                     // Null check of the item and checking that the slot of item
  54.                     // is equal to r
  55.                     if (item != null
  56.                             && (inventory.getDestinationForSlot(inventory
  57.                                     .getSlotForId(item.getId())).equals(r))) {
  58.                         // Setting to another easily visible colour
  59.                         g.setColor(Color.WHITE);
  60.                         // Constructing a font with bold text
  61.                         Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
  62.                         // Setting the font we just constructed
  63.                         g.setFont(font);
  64.                         // Null check of the item's name
  65.                         if (item.getName() != null) {
  66.                             // Drawing the text in the middle of the rectangle
  67.                             g.drawString("" + item.getName(), r.x
  68.                                     + (r.width / 2), r.y + (r.height / 2));
  69.                         }
  70.                         // Checking if the item has an ID
  71.                         if (item.getId() != 0) {
  72.                             // Drawing the Item ID under the item name
  73.                             // - 8 on the x due to the font metrics
  74.                             g.drawString("" + item.getId(),
  75.                                     r.x + (r.width / 2), r.y - 5
  76.                                             + (r.height / 2) - 10);
  77.                         }
  78.  
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.  
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement