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 58257ed..e817c53 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 @@ -241,6 +241,38 @@ else if (leftWhat.getId() == ModItems.TRINKET.getRegistryName()) ascending); }; } + else if (SortingHelper.VAULT_CHARMS.contains(leftWhat.getId())) + { + AttributeGearData leftData = CustomVaultGearData.read(leftWhat.toTag().getCompound("tag")); + AttributeGearData rightData = CustomVaultGearData.read(rightWhat.toTag().getCompound("tag")); + + return switch (sortOrder) { + case NAME -> SortingHelper.compareCharms(leftName, + leftData, + leftWhat.toTag().getCompound("tag"), + rightName, + rightData, + rightWhat.toTag().getCompound("tag"), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + ascending); + case AMOUNT -> SortingHelper.compareCharms(leftName, + leftData, + leftWhat.toTag().getCompound("tag"), + rightName, + rightData, + rightWhat.toTag().getCompound("tag"), + VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount(), + ascending); + case MOD -> SortingHelper.compareCharms(leftName, + leftData, + leftWhat.toTag().getCompound("tag"), + rightName, + rightData, + rightWhat.toTag().getCompound("tag"), + VaultJewelSorting.CONFIGURATION.getCharmSortingByMod(), + ascending); + }; + } else if (leftWhat.getId() == ModItems.VAULT_DOLL.getRegistryName()) { return switch (sortOrder) { @@ -304,23 +336,11 @@ else if (leftWhat.getId() == ModItems.VAULT_DOLL.getRegistryName()) private static boolean isSortable(ResourceLocation id) { return id.equals(ModItems.JEWEL.getRegistryName()) || - id.equals(ModItems.HELMET.getRegistryName()) || - id.equals(ModItems.CHESTPLATE.getRegistryName()) || - id.equals(ModItems.LEGGINGS.getRegistryName()) || - id.equals(ModItems.BOOTS.getRegistryName()) || - id.equals(ModItems.SWORD.getRegistryName()) || - id.equals(ModItems.AXE.getRegistryName()) || - id.equals(ModItems.SHIELD.getRegistryName()) || - id.equals(ModItems.FOCUS.getRegistryName()) || - id.equals(ModItems.IDOL_BENEVOLENT.getRegistryName()) || - id.equals(ModItems.IDOL_OMNISCIENT.getRegistryName()) || - id.equals(ModItems.IDOL_TIMEKEEPER.getRegistryName()) || - id.equals(ModItems.IDOL_MALEVOLENCE.getRegistryName()) || - id.equals(ModItems.WAND.getRegistryName()) || - id.equals(ModItems.MAGNET.getRegistryName()) || id.equals(ModItems.INSCRIPTION.getRegistryName()) || id.equals(ModItems.VAULT_CRYSTAL.getRegistryName()) || id.equals(ModItems.TRINKET.getRegistryName()) || + SortingHelper.VAULT_CHARMS.contains(id) || + SortingHelper.VAULT_GEAR_SET.contains(id) || id.equals(ModItems.VAULT_DOLL.getRegistryName()); } } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java index e2d0b58..bceb362 100644 --- a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java @@ -26,12 +26,12 @@ public class Configuration */ public Configuration() { - this.builder = new ForgeConfigSpec.Builder(); + ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); - this.builder.comment("This category holds options how Jewels are sorted"); - this.builder.push("Jewel Sorting"); + builder.comment("This category holds options how Jewels are sorted"); + builder.push("Jewel Sorting"); - this.jewelSortingByName = this.builder. + this.jewelSortingByName = builder. comment("The order of Jewels if they are sorted by the name."). comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT"). defineList("jewel_sorting_by_name", @@ -43,7 +43,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.JewelOptions.class, value.toUpperCase()).isPresent()); - this.jewelSortingByAmount = this.builder. + this.jewelSortingByAmount = builder. comment("The order of Jewels if they are sorted by the amount/size."). comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT"). defineList("jewel_sorting_by_amount", @@ -51,7 +51,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.JewelOptions.class, value.toUpperCase()).isPresent()); - this.jewelSortingByMod = this.builder. + this.jewelSortingByMod = builder. comment("The order of Jewels if they are sorted by the mod."). comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT"). defineList("jewel_sorting_by_mod", @@ -59,12 +59,12 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.JewelOptions.class, value.toUpperCase()).isPresent()); - this.builder.pop(); + builder.pop(); - this.builder.comment("This category holds options how Gear are sorted"); - this.builder.push("Gear Sorting"); + builder.comment("This category holds options how Gear are sorted"); + builder.push("Gear Sorting"); - this.gearSortingByName = this.builder. + this.gearSortingByName = builder. comment("The order of Gear if they are sorted by the name."). comment("Supported Values: NAME, STATE, RARITY, LEVEL, MODEL"). defineList("gear_sorting_by_name", @@ -76,7 +76,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.GearOptions.class, value.toUpperCase()).isPresent()); - this.gearSortingByAmount = this.builder. + this.gearSortingByAmount = builder. comment("The order of Gear if they are sorted by the amount/size."). comment("Supported Values: NAME, STATE, RARITY, LEVEL, MODEL"). defineList("gear_sorting_by_amount", @@ -84,7 +84,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.GearOptions.class, value.toUpperCase()).isPresent()); - this.gearSortingByMod = this.builder. + this.gearSortingByMod = builder. comment("The order of Gear if they are sorted by the mod."). comment("Supported Values: NAME, STATE, RARITY, LEVEL, MODEL"). defineList("gear_sorting_by_mod", @@ -92,7 +92,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.GearOptions.class, value.toUpperCase()).isPresent()); - this.rarityOrder = this.builder. + this.rarityOrder = builder. comment("The order of Rarities Pools in the sorting for unidentified gear."). defineList("rarity_order", Arrays.asList("Scrappy", @@ -114,12 +114,12 @@ public Configuration() "Gladiator"), entry -> true); - this.builder.pop(); + builder.pop(); - this.builder.comment("This category holds options how Inscriptions are sorted"); - this.builder.push("Inscription Sorting"); + builder.comment("This category holds options how Inscriptions are sorted"); + builder.push("Inscription Sorting"); - this.inscriptionSortingByName = this.builder. + this.inscriptionSortingByName = builder. comment("The order of Inscriptions if they are sorted by the name."). comment("Supported Values: NAME, INSTABILITY, TIME, COMPLETION, ROOMS"). defineList("inscription_sorting_by_name", @@ -131,7 +131,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.InscriptionOptions.class, value.toUpperCase()).isPresent()); - this.inscriptionSortingByAmount = this.builder. + this.inscriptionSortingByAmount = builder. comment("The order of Inscriptions if they are sorted by the amount/size."). comment("Supported Values: NAME, INSTABILITY, TIME, COMPLETION, ROOMS"). defineList("inscription_sorting_by_amount", @@ -139,7 +139,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.InscriptionOptions.class, value.toUpperCase()).isPresent()); - this.inscriptionSortingByMod = this.builder. + this.inscriptionSortingByMod = builder. comment("The order of Inscriptions if they are sorted by the mod."). comment("Supported Values: NAME, INSTABILITY, TIME, COMPLETION, ROOMS"). defineList("inscription_sorting_by_mod", @@ -147,12 +147,12 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.InscriptionOptions.class, value.toUpperCase()).isPresent()); - this.builder.pop(); + builder.pop(); - this.builder.comment("This category holds options how Vault Crystals are sorted"); - this.builder.push("Vault Crystal Sorting"); + builder.comment("This category holds options how Vault Crystals are sorted"); + builder.push("Vault Crystal Sorting"); - this.vaultCrystalSortingByName = this.builder. + this.vaultCrystalSortingByName = builder. comment("The order of Vault Crystal if they are sorted by the name."). comment("Supported Values: NAME, LEVEL, TYPE"). defineList("crystal_sorting_by_name", @@ -162,7 +162,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.CrystalOptions.class, value.toUpperCase()).isPresent()); - this.vaultCrystalSortingByAmount = this.builder. + this.vaultCrystalSortingByAmount = builder. comment("The order of Vault Crystal if they are sorted by the amount/size."). comment("Supported Values: NAME, LEVEL, TYPE"). defineList("crystal_sorting_by_amount", @@ -170,7 +170,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.CrystalOptions.class, value.toUpperCase()).isPresent()); - this.vaultCrystalSortingByMod = this.builder. + this.vaultCrystalSortingByMod = builder. comment("The order of Vault Crystal if they are sorted by the mod."). comment("Supported Values: NAME, LEVEL, TYPE"). defineList("crystal_sorting_by_mod", @@ -178,12 +178,12 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.CrystalOptions.class, value.toUpperCase()).isPresent()); - this.builder.pop(); + builder.pop(); - this.builder.comment("This category holds options how Trinkets are sorted"); - this.builder.push("Trinkets Sorting"); + builder.comment("This category holds options how Trinkets are sorted"); + builder.push("Trinkets Sorting"); - this.trinketSortingByName = this.builder. + this.trinketSortingByName = builder. comment("The order of Trinkets if they are sorted by the name."). comment("Supported Values: NAME, SLOT, TYPE, USES"). defineList("trinket_sorting_by_name", @@ -194,7 +194,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.TrinketOptions.class, value.toUpperCase()).isPresent()); - this.trinketSortingByAmount = this.builder. + this.trinketSortingByAmount = builder. comment("The order of Trinkets if they are sorted by the amount/size."). comment("Supported Values: NAME, SLOT, TYPE, USES"). defineList("trinket_sorting_by_amount", @@ -202,7 +202,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.TrinketOptions.class, value.toUpperCase()).isPresent()); - this.trinketSortingByMod = this.builder. + this.trinketSortingByMod = builder. comment("The order of Trinkets if they are sorted by the mod."). comment("Supported Values: NAME, SLOT, TYPE, USES"). defineList("trinket_sorting_by_mod", @@ -210,12 +210,12 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.TrinketOptions.class, value.toUpperCase()).isPresent()); - this.builder.pop(); + builder.pop(); - this.builder.comment("This category holds options how Vault Dolls are sorted"); - this.builder.push("Vault Doll Sorting"); + builder.comment("This category holds options how Vault Dolls are sorted"); + builder.push("Vault Doll Sorting"); - this.dollSortingByName = this.builder. + this.dollSortingByName = builder. comment("The order of dolls if they are sorted by the name."). comment("Supported Values: NAME, OWNER, COMPLETED, XP, LOOT"). defineList("vault_doll_sorting_by_name", @@ -227,7 +227,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.DollOptions.class, value.toUpperCase()).isPresent()); - this.dollSortingByAmount = this.builder. + this.dollSortingByAmount = builder. comment("The order of dolls if they are sorted by the amount/size."). comment("Supported Values: NAME, OWNER, COMPLETED, XP, LOOT"). defineList("vault_doll_sorting_by_amount", @@ -235,7 +235,7 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.DollOptions.class, value.toUpperCase()).isPresent()); - this.dollSortingByMod = this.builder. + this.dollSortingByMod = builder. comment("The order of dolls if they are sorted by the mod."). comment("Supported Values: NAME, OWNER, COMPLETED, XP, LOOT"). defineList("vault_doll_sorting_by_mod", @@ -243,9 +243,40 @@ public Configuration() entry -> entry instanceof String value && Enums.getIfPresent(SortingHelper.DollOptions.class, value.toUpperCase()).isPresent()); - this.builder.pop(); + builder.pop(); - Configuration.GENERAL_SPEC = this.builder.build(); + builder.comment("This category holds options how Vault Charms are sorted"); + builder.push("Vault Charm Sorting"); + + this.charmSortingByName = builder. + comment("The order of charms if they are sorted by the name."). + comment("Supported Values: NAME, USES, VALUE"). + defineList("charm_sorting_by_name", + Arrays.asList(SortingHelper.CharmOptions.NAME.name(), + SortingHelper.CharmOptions.USES.name(), + SortingHelper.CharmOptions.VALUE.name()), + entry -> entry instanceof String value && + Enums.getIfPresent(SortingHelper.CharmOptions.class, value.toUpperCase()).isPresent()); + + this.charmSortingByAmount = builder. + comment("The order of charms if they are sorted by the amount/size."). + comment("Supported Values: NAME, USES, VALUE"). + defineList("charm_sorting_by_amount", + Collections.emptyList(), + entry -> entry instanceof String value && + Enums.getIfPresent(SortingHelper.CharmOptions.class, value.toUpperCase()).isPresent()); + + this.charmSortingByMod = builder. + comment("The order of charms if they are sorted by the mod."). + comment("Supported Values: NAME, USES, VALUE"). + defineList("charm_sorting_by_mod", + Collections.emptyList(), + entry -> entry instanceof String value && + Enums.getIfPresent(SortingHelper.CharmOptions.class, value.toUpperCase()).isPresent()); + + builder.pop(); + + Configuration.GENERAL_SPEC = builder.build(); } @@ -458,6 +489,39 @@ public List getDollSortingByMod() } + /** + * Gets Doll sorting by name. + * + * @return the Doll sorting by name + */ + public List getCharmSortingByName() + { + return this.convertStringToCharmEnum(this.charmSortingByName.get()); + } + + + /** + * Gets Charm sorting by amount. + * + * @return the Charm sorting by amount + */ + public List getCharmSortingByAmount() + { + return this.convertStringToCharmEnum(this.charmSortingByAmount.get()); + } + + + /** + * Gets Charm sorting by mod. + * + * @return the Charm sorting by mod + */ + public List getCharmSortingByMod() + { + return this.convertStringToCharmEnum(this.charmSortingByMod.get()); + } + + /** * This method converts String list to Enum list. * @param value The string list that need to be converted. @@ -554,16 +618,27 @@ private List convertStringToDollEnum(List convertStringToCharmEnum(List value) + { + return value.stream(). + map(String::toUpperCase). + filter(upperCase -> Enums.getIfPresent(SortingHelper.CharmOptions.class, upperCase).isPresent()). + map(SortingHelper.CharmOptions::valueOf). + distinct(). + toList(); + } + + // --------------------------------------------------------------------- // Section: Variables // --------------------------------------------------------------------- - /** - * The main builder for the config. - */ - private final ForgeConfigSpec.Builder builder; - /** * The config value for jewel sorting by name. */ @@ -659,6 +734,21 @@ private List convertStringToDollEnum(List> dollSortingByMod; + /** + * The config value for vault charm sorting by name. + */ + private final ForgeConfigSpec.ConfigValue> charmSortingByName; + + /** + * The config value for vault charm sorting by amount. + */ + private final ForgeConfigSpec.ConfigValue> charmSortingByAmount; + + /** + * The config value for vault charm sorting by mod. + */ + private final ForgeConfigSpec.ConfigValue> charmSortingByMod; + /** * The general config spec. */ 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 62d9c6f..95cf66d 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 @@ -24,6 +24,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -250,6 +251,42 @@ else if (firstItem.getItem() instanceof TrinketItem && true); }; } + else if (firstItem.getItem() instanceof CharmItem && + secondItem.getItem() instanceof CharmItem) + { + String leftName = firstItem.getDisplayName().getString(); + String rightName = secondItem.getDisplayName().getString(); + AttributeGearData leftData = AttributeGearData.read(firstItem); + AttributeGearData rightData = AttributeGearData.read(secondItem); + + return switch (instance) + { + case NAME -> SortingHelper.compareCharms(leftName, + leftData, + firstItem.getTag(), + rightName, + rightData, + secondItem.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + true); + case SIZE -> SortingHelper.compareCharms(leftName, + leftData, + firstItem.getTag(), + rightName, + rightData, + secondItem.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount(), + true); + case MOD -> SortingHelper.compareCharms(leftName, + leftData, + firstItem.getTag(), + rightName, + rightData, + secondItem.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByMod(), + true); + }; + } else if (firstItem.getItem() instanceof VaultDollItem && secondItem.getItem() instanceof VaultDollItem) { @@ -479,6 +516,41 @@ else if (firstItem.getItem() instanceof TrinketItem && false); }; } + else if (firstItem.getItem() instanceof CharmItem && + secondItem.getItem() instanceof CharmItem) + { + String leftName = firstItem.getDisplayName().getString(); + String rightName = secondItem.getDisplayName().getString(); + AttributeGearData leftData = AttributeGearData.read(firstItem); + AttributeGearData rightData = AttributeGearData.read(secondItem); + + return switch (instance) { + case NAME -> SortingHelper.compareCharms(leftName, + leftData, + firstItem.getTag(), + rightName, + rightData, + secondItem.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + false); + case SIZE -> SortingHelper.compareCharms(leftName, + leftData, + firstItem.getTag(), + rightName, + rightData, + secondItem.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount(), + false); + case MOD -> SortingHelper.compareCharms(leftName, + leftData, + firstItem.getTag(), + rightName, + rightData, + secondItem.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByMod(), + false); + }; + } else if (firstItem.getItem() instanceof VaultDollItem && secondItem.getItem() instanceof VaultDollItem) { 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 f297754..89aad9f 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 @@ -21,6 +21,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -150,6 +151,24 @@ else if (stack1.getItem() instanceof TrinketItem && callbackInfoReturnable.cancel(); } } + else if (stack1.getItem() instanceof CharmItem && + stack2.getItem() instanceof CharmItem) + { + if (!VaultJewelSorting.CONFIGURATION.getCharmSortingByName().isEmpty()) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareCharms(stack1.getDisplayName().getString(), + AttributeGearData.read(stack1), + stack1.getTag(), + stack2.getDisplayName().getString(), + AttributeGearData.read(stack2), + stack2.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + true)); + + callbackInfoReturnable.cancel(); + } + } else if (stack1.getItem() instanceof VaultDollItem && stack2.getItem() instanceof VaultDollItem) { 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 38110f7..670f725 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 @@ -24,6 +24,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -158,6 +159,23 @@ else if (leftStack.getItem() instanceof TrinketItem && callbackInfoReturnable.cancel(); } } + else if (leftStack.getItem() instanceof CharmItem && + rightStack.getItem() instanceof CharmItem) + { + if (!VaultJewelSorting.CONFIGURATION.getCharmSortingByMod().isEmpty()) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareCharms(leftStack.getDisplayName().getString(), + AttributeGearData.read(leftStack), + leftStack.getTag(), + rightStack.getDisplayName().getString(), + AttributeGearData.read(rightStack), + rightStack.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByMod(), + sortingDirection == SortingDirection.ASCENDING)); + callbackInfoReturnable.cancel(); + } + } else if (leftStack.getItem() instanceof VaultDollItem && rightStack.getItem() instanceof VaultDollItem) { 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 19bef7c..19a72b4 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 @@ -24,6 +24,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -148,6 +149,23 @@ else if (leftStack.getItem() instanceof TrinketItem && callbackInfoReturnable.cancel(); } } + else if (leftStack.getItem() instanceof CharmItem && + rightStack.getItem() instanceof CharmItem) + { + if (!VaultJewelSorting.CONFIGURATION.getCharmSortingByName().isEmpty()) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareCharms(leftStack.getDisplayName().getString(), + AttributeGearData.read(leftStack), + leftStack.getTag(), + rightStack.getDisplayName().getString(), + AttributeGearData.read(rightStack), + rightStack.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + sortingDirection == SortingDirection.ASCENDING)); + callbackInfoReturnable.cancel(); + } + } else if (leftStack.getItem() instanceof VaultDollItem && rightStack.getItem() instanceof VaultDollItem) { 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 5365af9..a03049b 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 @@ -24,6 +24,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -165,6 +166,22 @@ else if (leftStack.getItem() instanceof TrinketItem && sortingDirection == SortingDirection.ASCENDING)); } } + else if (leftStack.getItem() instanceof CharmItem && + rightStack.getItem() instanceof CharmItem) + { + if (!VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount().isEmpty()) + { + callbackInfoReturnable.setReturnValue( + SortingHelper.compareCharms(leftStack.getDisplayName().getString(), + AttributeGearData.read(leftStack), + leftStack.getTag(), + rightStack.getDisplayName().getString(), + AttributeGearData.read(rightStack), + rightStack.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount(), + sortingDirection == SortingDirection.ASCENDING)); + } + } else if (leftStack.getItem() instanceof VaultDollItem && rightStack.getItem() instanceof VaultDollItem) { 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 f7e4563..2b60c19 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 @@ -8,6 +8,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -113,6 +114,21 @@ else if (first.getKey().getStack().getItem() instanceof TrinketItem && true); } } + else if (first.getKey().getStack().getItem() instanceof CharmItem && + second.getKey().getStack().getItem() instanceof CharmItem) + { + if (!VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount().isEmpty()) + { + return SortingHelper.compareCharms(first.getKey().getStack().getDisplayName().getString(), + AttributeGearData.read(first.getKey().getStack()), + first.getKey().getStack().getTag(), + second.getKey().getStack().getDisplayName().getString(), + AttributeGearData.read(second.getKey().getStack()), + second.getKey().getStack().getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount(), + true); + } + } else if (first.getKey().getStack().getItem() instanceof VaultDollItem && second.getKey().getStack().getItem() instanceof VaultDollItem) { @@ -215,6 +231,21 @@ else if (first.getKey().getStack().getItem() instanceof TrinketItem && true); } } + else if (first.getKey().getStack().getItem() instanceof CharmItem && + second.getKey().getStack().getItem() instanceof CharmItem) + { + if (!VaultJewelSorting.CONFIGURATION.getCharmSortingByName().isEmpty()) + { + return SortingHelper.compareCharms(first.getKey().getStack().getDisplayName().getString(), + AttributeGearData.read(first.getKey().getStack()), + first.getKey().getStack().getTag(), + second.getKey().getStack().getDisplayName().getString(), + AttributeGearData.read(second.getKey().getStack()), + second.getKey().getStack().getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + true); + } + } else if (first.getKey().getStack().getItem() instanceof VaultDollItem && second.getKey().getStack().getItem() instanceof VaultDollItem) { 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 2cbaa87..32a21ba 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 @@ -18,6 +18,7 @@ import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; +import iskallia.vault.item.gear.CharmItem; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; @@ -224,6 +225,36 @@ else if (first.getItem() instanceof TrinketItem && true); }; } + else if (first.getItem() instanceof CharmItem && + second.getItem() instanceof CharmItem) + { + return switch (this.gui.getSort()) { + case NAME -> SortingHelper.compareCharms(first.getDisplayName().getString(), + AttributeGearData.read(first), + first.getTag(), + second.getDisplayName().getString(), + AttributeGearData.read(second), + second.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByName(), + true); + case AMOUNT -> SortingHelper.compareCharms(first.getDisplayName().getString(), + AttributeGearData.read(first), + first.getTag(), + second.getDisplayName().getString(), + AttributeGearData.read(second), + second.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByAmount(), + true); + case MOD -> SortingHelper.compareCharms(first.getDisplayName().getString(), + AttributeGearData.read(first), + first.getTag(), + second.getDisplayName().getString(), + AttributeGearData.read(second), + second.getTag(), + VaultJewelSorting.CONFIGURATION.getCharmSortingByMod(), + true); + }; + } else if (first.getItem() instanceof VaultDollItem && second.getItem() instanceof VaultDollItem) { 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 921cd53..015ade4 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 @@ -42,10 +42,14 @@ public static int compareRegistryNames(ResourceLocation leftReg, boolean ascending) { String leftName = VAULT_GEAR_SET.contains(leftReg) ? - VaultMod.sId("gear") : leftReg.toString(); + VaultMod.sId("gear") : + VAULT_CHARMS.contains(leftReg) ? + VaultMod.sId("charm"): leftReg.toString(); String rightName = VAULT_GEAR_SET.contains(rightReg) ? - VaultMod.sId("gear") : rightReg.toString(); + VaultMod.sId("gear") : + VAULT_CHARMS.contains(rightReg) ? + VaultMod.sId("charm"): rightReg.toString(); return ascending ? SortingHelper.compareString(leftName, rightName) : @@ -434,6 +438,50 @@ public static int compareVaultDolls(String leftName, } + /** + * This method compares two given vault charms by their sorting order. + * @param leftName the left name + * @param leftData the left data + * @param leftTag the left tag + * @param rightName the right name + * @param rightData the right data + * @param rightTag the right tag + * @param sortingOrder the sorting order + * @param ascending the ascending + * @return the comparison of two given vault charms items. + */ + public static int compareCharms(String leftName, + AttributeGearData leftData, + CompoundTag leftTag, + String rightName, + AttributeGearData rightData, + CompoundTag rightTag, + List sortingOrder, + boolean ascending) + { + int returnValue = Boolean.compare(isIdentified(leftData), isIdentified(rightData)); + + if (!isIdentified(leftData) && returnValue == 0) + { + // Exit fast. Unidentified items are not comparable. + return 0; + } + + for (int i = 0, sortingOrderSize = sortingOrder.size(); returnValue == 0 && i < sortingOrderSize; i++) + { + CharmOptions sortOptions = sortingOrder.get(i); + + returnValue = switch (sortOptions) { + case NAME -> SortingHelper.compareString(leftName, rightName); + case USES -> Integer.compare(getRemainingUses(leftTag), getRemainingUses(rightTag)); + case VALUE -> Float.compare(getCharmValue(leftTag), getCharmValue(rightTag)); + }; + } + + return ascending ? returnValue : -returnValue; + } + + // --------------------------------------------------------------------- // Section: Internal Sorting Methods // --------------------------------------------------------------------- @@ -988,6 +1036,17 @@ private static boolean getDollCompletion(CompoundTag tag) } + /** + * This method returns name of charm value %. + * @param tag The tag of the item. + * @return The charm value %. + */ + private static float getCharmValue(CompoundTag tag) + { + return tag.contains("charmValue") ? tag.getFloat("charmValue") : 0f; + } + + /** * This method checks if given gear is identified. * @param data The data of the gear. @@ -1165,6 +1224,26 @@ public enum DollOptions } + /** + * This enum holds all possible values for vault charm sorting order + */ + public enum CharmOptions + { + /** + * The name of item + */ + NAME, + /** + * The god affinity value of charm + */ + VALUE, + /** + * The uses of charm + */ + USES + } + + /** * The name of the cache. */ @@ -1185,8 +1264,16 @@ public enum DollOptions */ public static final String EXTRA_GEAR_LEVEL = "extra_gear_level"; + /** + * The set of items that are considered vault gear. + */ public static final Set VAULT_GEAR_SET = new HashSet<>(); + /** + * The set of items that are considered vault charms. + */ + public static final Set VAULT_CHARMS = new HashSet<>(); + // Put all vault gear items into the set. static { @@ -1207,5 +1294,12 @@ public enum DollOptions VAULT_GEAR_SET.add(ModItems.IDOL_OMNISCIENT.getRegistryName()); VAULT_GEAR_SET.add(ModItems.IDOL_TIMEKEEPER.getRegistryName()); VAULT_GEAR_SET.add(ModItems.IDOL_MALEVOLENCE.getRegistryName()); + + VAULT_GEAR_SET.add(ModItems.FOCUS.getRegistryName()); + + VAULT_CHARMS.add(ModItems.SMALL_CHARM.getRegistryName()); + VAULT_CHARMS.add(ModItems.LARGE_CHARM.getRegistryName()); + VAULT_CHARMS.add(ModItems.GRAND_CHARM.getRegistryName()); + VAULT_CHARMS.add(ModItems.MAJESTIC_CHARM.getRegistryName()); } }