Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WARNING: Untested code
- /** Holds the amount of willows we have cut */
- private int willowsCut = 0;
- /** Holds the last inventory that was compared */
- private Item[] lastInv;
- /**
- * Simple getter
- * @return the number of willows cut
- */
- public int getWillowsCut() {
- return willowsCut;
- }
- /**
- * Compares your last inventory with the current inventory.
- */
- public void compareItems() {
- if (lastInv == null) {
- lastInv = getInventory().getItems();
- return; // It will be the same, no need to check
- }
- String item = "Willow logs";
- Item[] currInv = getInventory().getItems();
- for (int i = 0; i < 28; i++) {
- // Check for the same thing
- if ((currInv[i] == null && lastInv == null)
- || currInv[i].getName().equals(lastInv[i].getName()))
- continue; // Its the same, continue
- if (currInv[i] != null) {
- // We have an item when we didn't
- if (currInv[i].getName().equals(item))
- willowsCut++; // It was a willow log, ++
- } else {
- // We don't have an item when we did
- if (lastInv[i].getName().equals(item))
- willowsCut--; // It was a willow log, --
- }
- }
- lastInv = currInv; // Update the inv
- }
- /**
- * Run this when the lastInv needs refreshing, aka after banking
- */
- public void resetItems() {
- lastInv = getInventory().getItems();
- }
Advertisement
Add Comment
Please, Sign In to add comment