From 95ab9453ba1237b38176caa57a9169963717d425 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 16 Aug 2024 12:02:59 +0300 Subject: [PATCH] Implemented Antique sorting --- .../jewelsorting/ae2/mixin/MixinRepo.java | 7 ++++ ...xinQIOItemViewerContainerListSortType.java | 7 ++++ .../quark/mixin/MixinSortingHandler.java | 9 +++++ .../mixin/MixinIdGridSorter.java | 8 ++++ .../mixin/MixinNameGridSorter.java | 8 ++++ .../mixin/MixinQuantityGridSorter.java | 8 ++++ .../mixin/MixinInventorySorter.java | 14 +++++++ .../mixin/MixinNetworkWidget.java | 4 ++ .../MixinStoredItemStackComparatorAmount.java | 8 ++++ .../MixinStoredItemStackComparatorName.java | 8 ++++ .../jewelsorting/utils/SortingHelper.java | 38 +++++++++++++++++++ 11 files changed, 119 insertions(+) diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java index cd6b24e..85f01f4 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java @@ -403,6 +403,13 @@ else if (leftId == ModItems.BOOSTER_PACK.getRegistryName()) rightWhat.toTag().getCompound("tag"), ascending); } + else if (leftId == ModItems.ANTIQUE.getRegistryName()) + { + return SortingHelper.compareAntique( + leftWhat.toTag().getCompound("tag"), + rightWhat.toTag().getCompound("tag"), + ascending); + } else { VaultGearData leftData = CustomVaultGearData.read(leftWhat.toTag().getCompound("tag")); diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java index 04020c7..d4a83ea 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java @@ -486,6 +486,13 @@ else if (firstItem.getItem() == ModItems.BOOSTER_PACK) secondItem.getTag(), ascending); } + else if (firstItem.getItem() == ModItems.ANTIQUE) + { + return SortingHelper.compareAntique( + firstItem.getTag(), + secondItem.getTag(), + ascending); + } else { return 0; diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java index 6c8a1ed..2b96fb8 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java @@ -251,5 +251,14 @@ else if (stack1.getItem() == ModItems.CARD) callbackInfoReturnable.cancel(); } + else if (stack1.getItem() == ModItems.ANTIQUE) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareAntique(stack1.getTag(), + stack2.getTag(), + true)); + + callbackInfoReturnable.cancel(); + } } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java index eb334e6..bcd940d 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java @@ -269,6 +269,14 @@ else if (leftStack.getItem() == ModItems.BOOSTER_PACK) rightStack.getTag(), sortingDirection == SortingDirection.ASCENDING)); } + else if (leftStack.getItem() == ModItems.ANTIQUE) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareAntique( + leftStack.getTag(), + rightStack.getTag(), + sortingDirection == SortingDirection.ASCENDING)); + } } } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java index e7eb308..10c5e94 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java @@ -269,6 +269,14 @@ else if (leftStack.getItem() == ModItems.BOOSTER_PACK) rightStack.getTag(), sortingDirection == SortingDirection.ASCENDING)); } + else if (leftStack.getItem() == ModItems.ANTIQUE) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareAntique( + leftStack.getTag(), + rightStack.getTag(), + sortingDirection == SortingDirection.ASCENDING)); + } } } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java index c5a3619..2c46792 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java @@ -275,6 +275,14 @@ else if (leftStack.getItem() == ModItems.BOOSTER_PACK) rightStack.getTag(), sortingDirection == SortingDirection.ASCENDING)); } + else if (leftStack.getItem() == ModItems.ANTIQUE) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareAntique( + leftStack.getTag(), + rightStack.getTag(), + sortingDirection == SortingDirection.ASCENDING)); + } } } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java index 3fb1b7a..e9c25d8 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java @@ -201,6 +201,13 @@ else if (firstStack.getItem() == ModItems.BOOSTER_PACK) secondStack.getTag(), true); } + else if (firstStack.getItem() == ModItems.ANTIQUE) + { + return SortingHelper.compareAntique( + firstStack.getTag(), + secondStack.getTag(), + true); + } return 0; }); @@ -383,6 +390,13 @@ else if (firstStack.getItem() == ModItems.BOOSTER_PACK) secondStack.getTag(), true); } + else if (firstStack.getItem() == ModItems.ANTIQUE) + { + return SortingHelper.compareAntique( + firstStack.getTag(), + secondStack.getTag(), + true); + } return 0; }); diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java index 6e42004..9188413 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java @@ -340,6 +340,10 @@ else if (first.getItem() == ModItems.BOOSTER_PACK) { return SortingHelper.compareBoosterPacks(first.getTag(), second.getTag(), true); } + else if (first.getItem() == ModItems.ANTIQUE) + { + return SortingHelper.compareAntique(first.getTag(), second.getTag(), true); + } return 0; }); diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorAmount.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorAmount.java index 60c1896..f3337a3 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorAmount.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorAmount.java @@ -260,6 +260,14 @@ else if (leftStack.getItem() == ModItems.BOOSTER_PACK) rightStack.getTag(), !this.reversed)); } + else if (leftStack.getItem() == ModItems.ANTIQUE) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareAntique( + leftStack.getTag(), + rightStack.getTag(), + !this.reversed)); + } } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorName.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorName.java index 026c91b..515aa31 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorName.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/tomsstorage/mixin/MixinStoredItemStackComparatorName.java @@ -258,6 +258,14 @@ else if (leftStack.getItem() == ModItems.BOOSTER_PACK) rightStack.getTag(), !this.reversed)); } + else if (leftStack.getItem() == ModItems.ANTIQUE) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareAntique( + leftStack.getTag(), + rightStack.getTag(), + !this.reversed)); + } } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java index bf3bdcd..f22b3a2 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java @@ -814,6 +814,37 @@ else if (leftTag != null && leftTag.contains(DATA, Tag.TAG_COMPOUND)) } + /** + * This method compares antiques by their "id" tag value. + * @param leftTag The left tag of antique + * @param rightTag The right tag of antique + * @param ascending the order of sort + * @return the comparison of two given antiques tags. + */ + public static int compareAntique(CompoundTag leftTag, CompoundTag rightTag, boolean ascending) + { + int returnValue; + + if (leftTag != null && rightTag != null) + { + returnValue = SortingHelper.compareString( + leftTag.getString(ANTIQUE), + rightTag.getString(ANTIQUE)); + } + else if (leftTag != null) + { + returnValue = 1; + + } + else + { + returnValue = -1; + } + + return ascending ? returnValue : -returnValue; + } + + // --------------------------------------------------------------------- // Section: Internal Sorting Methods // --------------------------------------------------------------------- @@ -1802,6 +1833,11 @@ public enum CardOptions */ public static final String DATA = "data"; + /** + * The antique variable + */ + public static final String ANTIQUE = "antique"; + /** * The name of the cache. */ @@ -1884,5 +1920,7 @@ public enum CardOptions CUSTOM_SORTING.add(ModItems.CARD.getRegistryName()); CUSTOM_SORTING.add(ModItems.CARD_DECK.getRegistryName()); CUSTOM_SORTING.add(ModItems.BOOSTER_PACK.getRegistryName()); + + CUSTOM_SORTING.add(ModItems.ANTIQUE.getRegistryName()); } }