@@ -104,9 +104,11 @@ public static int countSack(int slotID) {
104104 public static void clickWindow (int windowID , int slotID , int button , int clickType ) {
105105 mc .playerController .windowClick (windowID , slotID , button , clickType , mc .thePlayer );
106106 }
107+
107108 public static void clickWindow (int windowID , int slotID , int button ) {
108109 clickWindow (windowID , slotID , button , 0 );
109110 }
111+
110112 public static void clickWindow (int windowID , int slotID ) {
111113 clickWindow (windowID , slotID , 0 );
112114 }
@@ -130,6 +132,9 @@ public static void waitForItemClick(int slotID, String displayName, int clickSlo
130132 ItemStack stack = mc .thePlayer .openContainer .getSlot (slotID ).getStack ();
131133 ItemStack clickStack ;
132134 while (stack == null || (!stack .getDisplayName ().contains (displayName ))) {
135+ System .out .println ("Waiting for item: " + displayName );
136+ System .out .println ("waitForItemClick - status: " +Thread .currentThread ().isInterrupted ());
137+ if (Thread .currentThread ().isInterrupted ()) throw new Exception ("Detected interrupt - stopping" );
133138 clickStack = mc .thePlayer .openContainer .getSlot (clickSlotID ).getStack ();
134139 stack = mc .thePlayer .openContainer .getSlot (slotID ).getStack ();
135140 if (clickStack != null && (clickStack .getDisplayName ().contains (clickDisplayName ) && !clickStack .getDisplayName ().contains (exclude ))) {
@@ -147,6 +152,7 @@ public static void waitForItemClick(int slotID, String displayName, int clickSlo
147152 ItemStack stack = mc .thePlayer .openContainer .getSlot (slotID ).getStack ();
148153 ItemStack clickStack ;
149154 while (stack == null || !stack .getDisplayName ().contains (displayName )) {
155+ if (Thread .currentThread ().isInterrupted ()) throw new Exception ("Detected interrupt - stopping" );
150156 clickStack = mc .thePlayer .openContainer .getSlot (clickSlotID ).getStack ();
151157 stack = mc .thePlayer .openContainer .getSlot (slotID ).getStack ();
152158 if (checkItem (clickStack , item )) {
@@ -227,111 +233,109 @@ private static List<ItemStack> copyInventory(ItemStack[] inventory) {
227233 }
228234
229235 public static void getInventoryDifference (ItemStack [] currentInventory ) {
230- while (FarmHelper .enabled ) {
231- List <ItemStack > newInventory = copyInventory (currentInventory );
232- Map <String , Pair <Integer , NBTTagCompound >> previousInventoryMap = new HashMap <>();
233- Map <String , Pair <Integer , NBTTagCompound >> newInventoryMap = new HashMap <>();
234-
235- if (previousInventory != null ) {
236- for (int i = 0 ; i < newInventory .size (); i ++) {
237- if (i == 8 ) { // Skip the SkyBlock Menu slot altogether (which includes the Quiver Arrow now)
238- continue ;
239- }
236+ List <ItemStack > newInventory = copyInventory (currentInventory );
237+ Map <String , Pair <Integer , NBTTagCompound >> previousInventoryMap = new HashMap <>();
238+ Map <String , Pair <Integer , NBTTagCompound >> newInventoryMap = new HashMap <>();
239+
240+ if (previousInventory != null ) {
241+ for (int i = 0 ; i < newInventory .size (); i ++) {
242+ if (i == 8 ) { // Skip the SkyBlock Menu slot altogether (which includes the Quiver Arrow now)
243+ continue ;
244+ }
240245
241- ItemStack previousItem = null ;
242- ItemStack newItem = null ;
246+ ItemStack previousItem = null ;
247+ ItemStack newItem = null ;
243248
244- try {
245- previousItem = previousInventory .get (i );
246- newItem = newInventory .get (i );
249+ try {
250+ previousItem = previousInventory .get (i );
251+ newItem = newInventory .get (i );
247252
248- if (previousItem != null ) {
249- int amount ;
250- if (previousInventoryMap .containsKey (previousItem .getDisplayName ())) {
251- amount = previousInventoryMap .get (previousItem .getDisplayName ()).getKey () + previousItem .stackSize ;
252- } else {
253- amount = previousItem .stackSize ;
254- }
255- NBTTagCompound extraAttributes = getExtraAttributes (previousItem );
256- if (extraAttributes != null ) {
257- extraAttributes = (NBTTagCompound ) extraAttributes .copy ();
258- }
259- previousInventoryMap .put (previousItem .getDisplayName (), new Pair <>(amount , extraAttributes ));
253+ if (previousItem != null ) {
254+ int amount ;
255+ if (previousInventoryMap .containsKey (previousItem .getDisplayName ())) {
256+ amount = previousInventoryMap .get (previousItem .getDisplayName ()).getKey () + previousItem .stackSize ;
257+ } else {
258+ amount = previousItem .stackSize ;
259+ }
260+ NBTTagCompound extraAttributes = getExtraAttributes (previousItem );
261+ if (extraAttributes != null ) {
262+ extraAttributes = (NBTTagCompound ) extraAttributes .copy ();
260263 }
264+ previousInventoryMap .put (previousItem .getDisplayName (), new Pair <>(amount , extraAttributes ));
265+ }
261266
262- if (newItem != null ) {
263- if (newItem .getDisplayName ().contains (" " + EnumChatFormatting .DARK_GRAY + "x" )) {
264- String newName = newItem .getDisplayName ().substring (0 , newItem .getDisplayName ().lastIndexOf (" " ));
265- newItem .setStackDisplayName (newName ); // This is a workaround for merchants, it adds x64 or whatever to the end of the name.
266- }
267- int amount ;
268- if (newInventoryMap .containsKey (newItem .getDisplayName ())) {
269- amount = newInventoryMap .get (newItem .getDisplayName ()).getKey () + newItem .stackSize ;
270- } else {
271- amount = newItem .stackSize ;
272- }
273- NBTTagCompound extraAttributes = getExtraAttributes (newItem );
274- if (extraAttributes != null ) {
275- extraAttributes = (NBTTagCompound ) extraAttributes .copy ();
276- }
277- newInventoryMap .put (newItem .getDisplayName (), new Pair <>(amount , extraAttributes ));
267+ if (newItem != null ) {
268+ if (newItem .getDisplayName ().contains (" " + EnumChatFormatting .DARK_GRAY + "x" )) {
269+ String newName = newItem .getDisplayName ().substring (0 , newItem .getDisplayName ().lastIndexOf (" " ));
270+ newItem .setStackDisplayName (newName ); // This is a workaround for merchants, it adds x64 or whatever to the end of the name.
278271 }
279- } catch (Throwable e ) {
280- e .printStackTrace ();
272+ int amount ;
273+ if (newInventoryMap .containsKey (newItem .getDisplayName ())) {
274+ amount = newInventoryMap .get (newItem .getDisplayName ()).getKey () + newItem .stackSize ;
275+ } else {
276+ amount = newItem .stackSize ;
277+ }
278+ NBTTagCompound extraAttributes = getExtraAttributes (newItem );
279+ if (extraAttributes != null ) {
280+ extraAttributes = (NBTTagCompound ) extraAttributes .copy ();
281+ }
282+ newInventoryMap .put (newItem .getDisplayName (), new Pair <>(amount , extraAttributes ));
281283 }
284+ } catch (Throwable e ) {
285+ e .printStackTrace ();
282286 }
287+ }
283288
284- List <ItemDiff > inventoryDifference = new LinkedList <>();
285- Set <String > keySet = new HashSet <>(previousInventoryMap .keySet ());
286- keySet .addAll (newInventoryMap .keySet ());
287-
288- keySet .forEach (key -> {
289- int previousAmount = 0 ;
290- if (previousInventoryMap .containsKey (key )) {
291- previousAmount = previousInventoryMap .get (key ).getKey ();
292- }
289+ List <ItemDiff > inventoryDifference = new LinkedList <>();
290+ Set <String > keySet = new HashSet <>(previousInventoryMap .keySet ());
291+ keySet .addAll (newInventoryMap .keySet ());
293292
294- int newAmount = 0 ;
295- if (newInventoryMap .containsKey (key )) {
296- newAmount = newInventoryMap .get (key ).getKey ();
297- }
293+ keySet .forEach (key -> {
294+ int previousAmount = 0 ;
295+ if (previousInventoryMap .containsKey (key )) {
296+ previousAmount = previousInventoryMap .get (key ).getKey ();
297+ }
298298
299- int diff = newAmount - previousAmount ;
300- if (diff != 0 ) { // Get the NBT tag from whichever map the name exists in
301- inventoryDifference .add (new ItemDiff (key , diff , newInventoryMap .getOrDefault (key , previousInventoryMap .get (key )).getValue ()));
302- }
303- });
304-
305- // Add changes to already logged changes of the same item, so it will increase/decrease the amount
306- // instead of displaying the same item twice
307- if (true ) {
308- for (ItemDiff diff : inventoryDifference ) {
309- Collection <ItemDiff > itemDiffs = itemPickupLog .get (diff .getDisplayName ());
310- if (itemDiffs .size () <= 0 ) {
311- itemPickupLog .put (diff .getDisplayName (), diff );
299+ int newAmount = 0 ;
300+ if (newInventoryMap .containsKey (key )) {
301+ newAmount = newInventoryMap .get (key ).getKey ();
302+ }
312303
313- } else {
314- boolean added = false ;
315- for (ItemDiff loopDiff : itemDiffs ) {
316- if ((diff .getAmount () < 0 && loopDiff .getAmount () < 0 ) || (diff .getAmount () > 0 && loopDiff .getAmount () > 0 )) {
317- loopDiff .add (diff .getAmount ());
318- added = true ;
319- }
320- }
321- if (!added ) {
322- itemPickupLog .put (diff .getDisplayName (), diff );
304+ int diff = newAmount - previousAmount ;
305+ if (diff != 0 ) { // Get the NBT tag from whichever map the name exists in
306+ inventoryDifference .add (new ItemDiff (key , diff , newInventoryMap .getOrDefault (key , previousInventoryMap .get (key )).getValue ()));
307+ }
308+ });
309+
310+ // Add changes to already logged changes of the same item, so it will increase/decrease the amount
311+ // instead of displaying the same item twice
312+ if (true ) {
313+ for (ItemDiff diff : inventoryDifference ) {
314+ Collection <ItemDiff > itemDiffs = itemPickupLog .get (diff .getDisplayName ());
315+ if (itemDiffs .size () <= 0 ) {
316+ itemPickupLog .put (diff .getDisplayName (), diff );
317+
318+ } else {
319+ boolean added = false ;
320+ for (ItemDiff loopDiff : itemDiffs ) {
321+ if ((diff .getAmount () < 0 && loopDiff .getAmount () < 0 ) || (diff .getAmount () > 0 && loopDiff .getAmount () > 0 )) {
322+ loopDiff .add (diff .getAmount ());
323+ added = true ;
323324 }
324325 }
326+ if (!added ) {
327+ itemPickupLog .put (diff .getDisplayName (), diff );
328+ }
325329 }
326330 }
327331 }
332+ }
328333
329- previousInventory = newInventory ;
330- try {
331- Thread .sleep (5 );
332- } catch (InterruptedException e ) {
333- e .printStackTrace ();
334- }
334+ previousInventory = newInventory ;
335+ try {
336+ Thread .sleep (5 );
337+ } catch (InterruptedException e ) {
338+ e .printStackTrace ();
335339 }
336340 }
337341
0 commit comments