Guest User

Untitled

a guest
Sep 28th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1.     // WARNING: Untested code
  2.    
  3.     /** Holds the amount of willows we have cut */
  4.     private int willowsCut = 0;
  5.     /** Holds the last inventory that was compared */
  6.     private Item[] lastInv;
  7.    
  8.     /**
  9.      * Simple getter
  10.      * @return the number of willows cut
  11.      */
  12.     public int getWillowsCut() {
  13.         return willowsCut;
  14.     }
  15.    
  16.     /**
  17.      * Compares your last inventory with the current inventory.
  18.      */
  19.     public void compareItems() {
  20.         if (lastInv == null) {
  21.             lastInv = getInventory().getItems();
  22.             return; // It will be the same, no need to check
  23.         }
  24.        
  25.         String item = "Willow logs";
  26.         Item[] currInv = getInventory().getItems();
  27.         for (int i = 0; i < 28; i++) {
  28.             // Check for the same thing
  29.             if ((currInv[i] == null && lastInv == null)
  30.                     || currInv[i].getName().equals(lastInv[i].getName()))
  31.                 continue; // Its the same, continue
  32.            
  33.             if (currInv[i] != null) {
  34.                 // We have an item when we didn't
  35.                 if (currInv[i].getName().equals(item))
  36.                     willowsCut++; // It was a willow log, ++
  37.             } else {
  38.                 // We don't have an item when we did
  39.                 if (lastInv[i].getName().equals(item))
  40.                     willowsCut--; // It was a willow log, --
  41.             }
  42.         }
  43.         lastInv = currInv; // Update the inv
  44.     }
  45.    
  46.     /**
  47.      * Run this when the lastInv needs refreshing, aka after banking
  48.      */
  49.     public void resetItems() {
  50.         lastInv = getInventory().getItems();
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment