@@ -341,90 +341,78 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac
341
341
} else if (checkAmount && item .getAmount () < sfitem .getAmount ()) {
342
342
return false ;
343
343
}
344
+
344
345
SlimefunItem sf_sfitem = SlimefunItem .getByItem (sfitem );
345
- SlimefunItem sf_item = SlimefunItem .getByItem (item );
346
-
347
- if (sf_sfitem != null && sf_item != null ) {
348
- if (!sf_sfitem .getId ().equals (sf_item .getId ())) {
349
- return false ;
346
+ if (!item .hasItemMeta ()) {
347
+ return !sfitem .hasItemMeta ();
348
+ }
349
+
350
+ Debug .log (TestCase .CARGO_INPUT_TESTING , "SlimefunUtils#isItemSimilar - item.hasItemMeta()" );
351
+ ItemMeta itemMeta = item .getItemMeta ();
352
+
353
+ if (sf_sfitem != null ) {
354
+ String id = Slimefun .getItemDataService ().getItemData (itemMeta ).orElse (null );
355
+
356
+ if (id == null ) {
357
+ ItemMeta meta = sfitem .getItemMeta ();
358
+ return equalsItemMeta (itemMeta , meta , checkLore );
359
+ }
360
+
361
+ if (!checkDistinction ) {
362
+ return id .equals ((sf_sfitem .getId ()));
350
363
}
364
+
351
365
/*
352
366
* PR #3417
353
367
*
354
368
* Some items can't rely on just IDs matching and will implement {@link DistinctiveItem}
355
369
* in which case we want to use the method provided to compare
356
370
*/
357
- if (checkDistinction && sf_sfitem instanceof DistinctiveItem distinctive && sf_item instanceof DistinctiveItem ) {
358
- return distinctive .canStack (sfitem .getItemMeta (), item .getItemMeta ());
371
+ Optional <DistinctiveItem > optionalDistinctive = getDistinctiveItem (id );
372
+ if (optionalDistinctive .isPresent ()) {
373
+ ItemMeta sfItemMeta = sfitem .getItemMeta ();
374
+ return optionalDistinctive .get ().canStack (sfItemMeta , itemMeta );
359
375
}
360
- return true ;
361
- } else if (item .hasItemMeta ()) {
362
- Debug .log (TestCase .CARGO_INPUT_TESTING , "SlimefunUtils#isItemSimilar - item.hasItemMeta()" );
363
- ItemMeta itemMeta = item .getItemMeta ();
364
-
365
- if (sf_sfitem != null ) {
366
- String id = Slimefun .getItemDataService ().getItemData (itemMeta ).orElse (null );
367
-
368
- if (id != null ) {
369
- if (checkDistinction ) {
370
- /*
371
- * PR #3417
372
- *
373
- * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem}
374
- * in which case we want to use the method provided to compare
375
- */
376
- Optional <DistinctiveItem > optionalDistinctive = getDistinctiveItem (id );
377
- if (optionalDistinctive .isPresent ()) {
378
- ItemMeta sfItemMeta = sfitem .getItemMeta ();
379
- return optionalDistinctive .get ().canStack (sfItemMeta , itemMeta );
380
- }
381
- }
382
- return id .equals ((sf_sfitem .getId ()));
383
- }
384
376
385
- ItemMeta meta = sfitem .getItemMeta ();
386
- return equalsItemMeta (itemMeta , meta , checkLore );
387
- } else if (sfitem instanceof ItemStackWrapper && sfitem .hasItemMeta ()) {
388
- Debug .log (TestCase .CARGO_INPUT_TESTING , " is wrapper" );
377
+ return id .equals ((sf_sfitem .getId ()));
378
+ } else if (sfitem instanceof ItemStackWrapper && sfitem .hasItemMeta ()) {
379
+ Debug .log (TestCase .CARGO_INPUT_TESTING , " is wrapper" );
380
+ /*
381
+ * Cargo optimization (PR #3258)
382
+ *
383
+ * Slimefun items may be ItemStackWrapper's in the context of cargo
384
+ * so let's try to do an ID comparison before meta comparison
385
+ */
386
+ Debug .log (TestCase .CARGO_INPUT_TESTING , " sfitem is ItemStackWrapper - possible SF Item: {}" , sfitem );
387
+
388
+ ItemMeta possibleSfItemMeta = sfitem .getItemMeta ();
389
+ String id = Slimefun .getItemDataService ().getItemData (itemMeta ).orElse (null );
390
+ String possibleItemId = Slimefun .getItemDataService ().getItemData (possibleSfItemMeta ).orElse (null );
391
+ // Prioritize SlimefunItem id comparison over ItemMeta comparison
392
+ if (id != null && id .equals (possibleItemId )) {
393
+ Debug .log (TestCase .CARGO_INPUT_TESTING , " Item IDs matched!" );
394
+
389
395
/*
390
- * Cargo optimization ( PR #3258)
396
+ * PR #3417
391
397
*
392
- * Slimefun items may be ItemStackWrapper's in the context of cargo
393
- * so let's try to do an ID comparison before meta comparison
398
+ * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem}
399
+ * in which case we want to use the method provided to compare
394
400
*/
395
- Debug .log (TestCase .CARGO_INPUT_TESTING , " sfitem is ItemStackWrapper - possible SF Item: {}" , sfitem );
396
-
397
- ItemMeta possibleSfItemMeta = sfitem .getItemMeta ();
398
- String id = Slimefun .getItemDataService ().getItemData (itemMeta ).orElse (null );
399
- String possibleItemId = Slimefun .getItemDataService ().getItemData (possibleSfItemMeta ).orElse (null );
400
- // Prioritize SlimefunItem id comparison over ItemMeta comparison
401
- if (id != null && id .equals (possibleItemId )) {
402
- Debug .log (TestCase .CARGO_INPUT_TESTING , " Item IDs matched!" );
403
-
404
- /*
405
- * PR #3417
406
- *
407
- * Some items can't rely on just IDs matching and will implement {@link DistinctiveItem}
408
- * in which case we want to use the method provided to compare
409
- */
410
- Optional <DistinctiveItem > optionalDistinctive = getDistinctiveItem (id );
411
- if (optionalDistinctive .isPresent ()) {
412
- return optionalDistinctive .get ().canStack (possibleSfItemMeta , itemMeta );
413
- }
414
- return true ;
415
- } else {
416
- Debug .log (TestCase .CARGO_INPUT_TESTING , " Item IDs don't match, checking meta {} == {} (lore: {})" , itemMeta , possibleSfItemMeta , checkLore );
417
- return equalsItemMeta (itemMeta , possibleSfItemMeta , checkLore );
401
+ Optional <DistinctiveItem > optionalDistinctive = getDistinctiveItem (id );
402
+ if (optionalDistinctive .isPresent ()) {
403
+ return optionalDistinctive .get ().canStack (possibleSfItemMeta , itemMeta );
418
404
}
419
- } else if (sfitem .hasItemMeta ()) {
420
- ItemMeta sfItemMeta = sfitem .getItemMeta ();
421
- Debug .log (TestCase .CARGO_INPUT_TESTING , " Comparing meta (vanilla items?) - {} == {} (lore: {})" , itemMeta , sfItemMeta , checkLore );
422
- return equalsItemMeta (itemMeta , sfItemMeta , checkLore );
405
+ return true ;
423
406
} else {
424
- return false ;
407
+ Debug .log (TestCase .CARGO_INPUT_TESTING , " Item IDs don't match, checking meta {} == {} (lore: {})" , itemMeta , possibleSfItemMeta , checkLore );
408
+ return equalsItemMeta (itemMeta , possibleSfItemMeta , checkLore );
425
409
}
410
+ } else if (sfitem .hasItemMeta ()) {
411
+ ItemMeta sfItemMeta = sfitem .getItemMeta ();
412
+ Debug .log (TestCase .CARGO_INPUT_TESTING , " Comparing meta (vanilla items?) - {} == {} (lore: {})" , itemMeta , sfItemMeta , checkLore );
413
+ return equalsItemMeta (itemMeta , sfItemMeta , checkLore );
426
414
} else {
427
- return ! sfitem . hasItemMeta () ;
415
+ return false ;
428
416
}
429
417
}
430
418
0 commit comments