diff --git a/build.gradle b/build.gradle index 437e706..26951ad 100644 --- a/build.gradle +++ b/build.gradle @@ -114,6 +114,7 @@ mixin { config "mixins.${mod_id}.rs.json" config "mixins.${mod_id}.sophisticatedcore.json" config "mixins.${mod_id}.storagenetwork.json" + config "mixins.${mod_id}.vaulthunters.json" } // Include resources generated by data generators. diff --git a/gradle.properties b/gradle.properties index 7990cda..0a057ac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,15 +21,15 @@ mapping_version=1.18.2 # The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} # Must match the String constant located in the main mod class annotated with @Mod. -mod_id=vaulthunters_jewel_sorting +mod_id=vault_hunters_jewel_sorting # The human-readable display name for the mod. -mod_name=VaultHunters Jewel Sorting +mod_name=Vault Hunters Jewel Sorting # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. -mod_license=ECPL-2.0 +mod_license=GNU-3.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html -mod_group_id=lv.id.bonne.vaultjewelsorting +mod_group_id=lv.id.bonne.vaulthunters.jewelsorting # The authors of the mod. This is a simple text string that is used for display purposes in the mod list. mod_authors=BONNe1704 # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. @@ -51,6 +51,6 @@ sophisticated_backpacks_version=4637292 # The version of Sophisticated Backpacks Mod storage_network_version=3868680 # The mod version. See https://semver.org/ -mod_version=2.2.0 +mod_version=2.3.0 # The change Log changelog=Initial Release \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 2e6231d..94d9b81 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,6 +5,7 @@ pluginManagement { name = 'MinecraftForge' url = 'https://maven.minecraftforge.net/' } + maven { url "https://cursemaven.com" } } } @@ -12,4 +13,4 @@ plugins { id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' } -rootProject.name = 'vaulthunters_jewel_sorting' +rootProject.name = 'vault_hunters_jewel_sorting' diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/VaultJewelSorting.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/VaultJewelSorting.java similarity index 86% rename from src/main/java/lv/id/bonne/vaultjewelsorting/VaultJewelSorting.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/VaultJewelSorting.java index 8eee3d0..bf1869a 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/VaultJewelSorting.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/VaultJewelSorting.java @@ -1,10 +1,12 @@ -package lv.id.bonne.vaultjewelsorting; +package lv.id.bonne.vaulthunters.jewelsorting; + import com.mojang.logging.LogUtils; +import org.slf4j.Logger; import iskallia.vault.gear.attribute.VaultGearAttribute; -import lv.id.bonne.vaultjewelsorting.config.Configuration; -import lv.id.bonne.vaultjewelsorting.utils.AttributeHelper; +import lv.id.bonne.vaulthunters.jewelsorting.utils.AttributeHelper; +import lv.id.bonne.vaulthunters.jewelsorting.config.Configuration; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.EventPriority; @@ -13,13 +15,11 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; -import org.slf4j.Logger; - /** * The main class for Vault Jewels Sorting mod. */ -@Mod("vaulthunters_jewel_sorting") +@Mod("vault_hunters_jewel_sorting") @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class VaultJewelSorting { diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/ae2/AE2IntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/AE2IntegrationModConfiguration.java similarity index 74% rename from src/main/java/lv/id/bonne/vaultjewelsorting/ae2/AE2IntegrationModConfiguration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/AE2IntegrationModConfiguration.java index 8543ccc..1290e77 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/ae2/AE2IntegrationModConfiguration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/AE2IntegrationModConfiguration.java @@ -4,10 +4,10 @@ // -package lv.id.bonne.vaultjewelsorting.ae2; +package lv.id.bonne.vaulthunters.jewelsorting.ae2; -import lv.id.bonne.vaultjewelsorting.config.MixinConfigPlugin; +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; import net.minecraftforge.fml.loading.LoadingModList; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/ae2/mixin/MixinRepo.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java similarity index 70% rename from src/main/java/lv/id/bonne/vaultjewelsorting/ae2/mixin/MixinRepo.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java index 4a7e92f..deb0d27 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/ae2/mixin/MixinRepo.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/ae2/mixin/MixinRepo.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.ae2.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.ae2.mixin; import org.spongepowered.asm.mixin.Mixin; @@ -24,10 +24,11 @@ import iskallia.vault.init.ModItems; import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.data.InscriptionData; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.CustomVaultGearData; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.CustomVaultGearData; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -77,29 +78,68 @@ public final void comparator(SortOrder sortOrder, if (leftWhat.getId() == ModItems.JEWEL.getRegistryName()) { - VaultGearData leftData = CustomVaultGearData.read(leftWhat.toTag().getCompound("tag")); - VaultGearData rightData = CustomVaultGearData.read(rightWhat.toTag().getCompound("tag")); + CompoundTag leftTag = leftWhat.toTag().getCompound("tag"); + CompoundTag rightTag = rightWhat.toTag().getCompound("tag"); - return switch (sortOrder) { - case NAME -> SortingHelper.compareJewels(leftName, - leftData, - rightName, - rightData, - VaultJewelSorting.CONFIGURATION.getJewelSortingByName(), - ascending); - case AMOUNT -> SortingHelper.compareJewels(leftName, - leftData, - rightName, - rightData, - VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(), - ascending); - case MOD -> SortingHelper.compareJewels(leftName, - leftData, - rightName, - rightData, - VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(), - ascending); - }; + if (!leftTag.contains("clientCache") || + !leftTag.getCompound("clientCache").contains(SortingHelper.EXTRA_ATTRIBUTE_INDEX) || + !leftTag.getCompound("clientCache").contains(SortingHelper.EXTRA_ATTRIBUTE_VALUE) || + !leftTag.getCompound("clientCache").contains(SortingHelper.EXTRA_GEAR_LEVEL) || + !leftTag.getCompound("clientCache").contains(SortingHelper.EXTRA_JEWEL_SIZE) || + !rightTag.contains("clientCache") || + !rightTag.getCompound("clientCache").contains(SortingHelper.EXTRA_ATTRIBUTE_INDEX) || + !rightTag.getCompound("clientCache").contains(SortingHelper.EXTRA_ATTRIBUTE_VALUE) || + !rightTag.getCompound("clientCache").contains(SortingHelper.EXTRA_GEAR_LEVEL) || + !rightTag.getCompound("clientCache").contains(SortingHelper.EXTRA_JEWEL_SIZE)) + { + // Client cache is not generated. Process everything manually. + VaultGearData leftData = CustomVaultGearData.read(leftTag); + VaultGearData rightData = CustomVaultGearData.read(rightTag); + + return switch (sortOrder) { + case NAME -> SortingHelper.compareJewels(leftName, + leftData, + rightName, + rightData, + VaultJewelSorting.CONFIGURATION.getJewelSortingByName(), + ascending); + case AMOUNT -> SortingHelper.compareJewels(leftName, + leftData, + rightName, + rightData, + VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(), + ascending); + case MOD -> SortingHelper.compareJewels(leftName, + leftData, + rightName, + rightData, + VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(), + ascending); + }; + } + else + { + return switch (sortOrder) { + case NAME -> SortingHelper.compareJewels(leftName, + leftTag.getCompound("clientCache"), + rightName, + rightTag.getCompound("clientCache"), + VaultJewelSorting.CONFIGURATION.getJewelSortingByName(), + ascending); + case AMOUNT -> SortingHelper.compareJewels(leftName, + leftTag.getCompound("clientCache"), + rightName, + rightTag.getCompound("clientCache"), + VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(), + ascending); + case MOD -> SortingHelper.compareJewels(leftName, + leftTag.getCompound("clientCache"), + rightName, + rightTag.getCompound("clientCache"), + VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(), + ascending); + }; + } } else if (leftWhat.getId() == ModItems.INSCRIPTION.getRegistryName()) { diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/config/Configuration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java similarity index 99% rename from src/main/java/lv/id/bonne/vaultjewelsorting/config/Configuration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java index d08788f..f58680c 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/config/Configuration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/Configuration.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.config; +package lv.id.bonne.vaulthunters.jewelsorting.config; import com.google.common.base.Enums; @@ -12,7 +12,7 @@ import java.util.Collections; import java.util.List; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraftforge.common.ForgeConfigSpec; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/config/MixinConfigPlugin.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/MixinConfigPlugin.java similarity index 95% rename from src/main/java/lv/id/bonne/vaultjewelsorting/config/MixinConfigPlugin.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/MixinConfigPlugin.java index 9dd4e2b..5c97ed2 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/config/MixinConfigPlugin.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/config/MixinConfigPlugin.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.config; +package lv.id.bonne.vaulthunters.jewelsorting.config; import org.objectweb.asm.tree.ClassNode; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/qio/QIOIntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/QIOIntegrationModConfiguration.java similarity index 77% rename from src/main/java/lv/id/bonne/vaultjewelsorting/qio/QIOIntegrationModConfiguration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/QIOIntegrationModConfiguration.java index 928c616..f7d41f2 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/qio/QIOIntegrationModConfiguration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/QIOIntegrationModConfiguration.java @@ -4,10 +4,10 @@ // -package lv.id.bonne.vaultjewelsorting.qio; +package lv.id.bonne.vaulthunters.jewelsorting.qio; -import lv.id.bonne.vaultjewelsorting.config.MixinConfigPlugin; +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; import net.minecraftforge.fml.loading.LoadingModList; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java similarity index 98% rename from src/main/java/lv/id/bonne/vaultjewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java index 4f42d78..385c2fb 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/qio/mixin/MixinQIOItemViewerContainerListSortType.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.qio.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.qio.mixin; import org.objectweb.asm.Opcodes; @@ -17,6 +17,7 @@ import java.util.Comparator; import iskallia.vault.gear.data.AttributeGearData; +import iskallia.vault.gear.data.GearDataCache; import iskallia.vault.gear.data.VaultGearData; import iskallia.vault.gear.item.VaultGearItem; import iskallia.vault.item.InscriptionItem; @@ -26,9 +27,8 @@ import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.CustomVaultGearData; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import mekanism.common.inventory.ISlotClickHandler; import mekanism.common.inventory.container.QIOItemViewerContainer; import net.minecraft.client.gui.screens.Screen; @@ -80,8 +80,8 @@ private Comparator redirectAscending(QIOItemV { String leftName = firstItem.getDisplayName().getString(); String rightName = secondItem.getDisplayName().getString(); - VaultGearData leftData = VaultGearData.read(firstItem); - VaultGearData rightData = VaultGearData.read(secondItem); + GearDataCache leftData = GearDataCache.of(firstItem); + GearDataCache rightData = GearDataCache.of(secondItem); return switch (instance) { case NAME -> SortingHelper.compareJewels(leftName, diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/quark/QuarkIntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/QuarkIntegrationModConfiguration.java similarity index 74% rename from src/main/java/lv/id/bonne/vaultjewelsorting/quark/QuarkIntegrationModConfiguration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/QuarkIntegrationModConfiguration.java index 7036fe4..3d55541 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/quark/QuarkIntegrationModConfiguration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/QuarkIntegrationModConfiguration.java @@ -4,10 +4,10 @@ // -package lv.id.bonne.vaultjewelsorting.quark; +package lv.id.bonne.vaulthunters.jewelsorting.quark; -import lv.id.bonne.vaultjewelsorting.config.MixinConfigPlugin; +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; import net.minecraftforge.fml.loading.LoadingModList; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/quark/mixin/MixinSortingHandler.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java similarity index 97% rename from src/main/java/lv/id/bonne/vaultjewelsorting/quark/mixin/MixinSortingHandler.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java index a9f264e..448c31f 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/quark/mixin/MixinSortingHandler.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/quark/mixin/MixinSortingHandler.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.quark.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.quark.mixin; import org.spongepowered.asm.mixin.Mixin; @@ -23,8 +23,8 @@ import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraft.world.item.ItemStack; import vazkii.quark.base.handler.SortingHandler; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/RefinedStorageIntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/RefinedStorageIntegrationModConfiguration.java similarity index 73% rename from src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/RefinedStorageIntegrationModConfiguration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/RefinedStorageIntegrationModConfiguration.java index f7791bc..4a83174 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/RefinedStorageIntegrationModConfiguration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/RefinedStorageIntegrationModConfiguration.java @@ -4,10 +4,10 @@ // -package lv.id.bonne.vaultjewelsorting.refinedstorage; +package lv.id.bonne.vaulthunters.jewelsorting.refinedstorage; -import lv.id.bonne.vaultjewelsorting.config.MixinConfigPlugin; +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; import net.minecraftforge.fml.loading.LoadingModList; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinIdGridSorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java similarity index 95% rename from src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinIdGridSorter.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java index a93515b..e243703 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinIdGridSorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinIdGridSorter.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.refinedstorage.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.refinedstorage.mixin; import com.refinedmods.refinedstorage.screen.grid.sorting.IdGridSorter; @@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import iskallia.vault.gear.data.AttributeGearData; +import iskallia.vault.gear.data.GearDataCache; import iskallia.vault.gear.data.VaultGearData; import iskallia.vault.gear.item.VaultGearItem; import iskallia.vault.item.InscriptionItem; @@ -25,8 +26,8 @@ import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.item.ItemStack; @@ -68,9 +69,9 @@ public void compare(IGridStack left, if (!VaultJewelSorting.CONFIGURATION.getJewelSortingByMod().isEmpty()) { callbackInfoReturnable.setReturnValue(SortingHelper.compareJewels(left.getName(), - VaultGearData.read(leftStack), + GearDataCache.of(leftStack), right.getName(), - VaultGearData.read(rightStack), + GearDataCache.of(rightStack), VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(), sortingDirection == SortingDirection.ASCENDING)); callbackInfoReturnable.cancel(); diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinNameGridSorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java similarity index 95% rename from src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinNameGridSorter.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java index a9e1ebe..9febb15 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinNameGridSorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinNameGridSorter.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.refinedstorage.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.refinedstorage.mixin; import com.refinedmods.refinedstorage.screen.grid.sorting.NameGridSorter; @@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import iskallia.vault.gear.data.AttributeGearData; +import iskallia.vault.gear.data.GearDataCache; import iskallia.vault.gear.data.VaultGearData; import iskallia.vault.gear.item.VaultGearItem; import iskallia.vault.item.InscriptionItem; @@ -25,8 +26,8 @@ import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.item.ItemStack; @@ -68,9 +69,9 @@ public void compare(IGridStack left, if (!VaultJewelSorting.CONFIGURATION.getJewelSortingByName().isEmpty()) { callbackInfoReturnable.setReturnValue(SortingHelper.compareJewels(left.getName(), - VaultGearData.read(leftStack), + GearDataCache.of(leftStack), right.getName(), - VaultGearData.read(rightStack), + GearDataCache.of(rightStack), VaultJewelSorting.CONFIGURATION.getJewelSortingByName(), sortingDirection == SortingDirection.ASCENDING)); callbackInfoReturnable.cancel(); diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java similarity index 95% rename from src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java index 61ef241..61949c6 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/refinedstorage/mixin/MixinQuantityGridSorter.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.refinedstorage.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.refinedstorage.mixin; import com.refinedmods.refinedstorage.screen.grid.sorting.QuantityGridSorter; @@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import iskallia.vault.gear.data.AttributeGearData; +import iskallia.vault.gear.data.GearDataCache; import iskallia.vault.gear.data.VaultGearData; import iskallia.vault.gear.item.VaultGearItem; import iskallia.vault.item.InscriptionItem; @@ -25,8 +26,8 @@ import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.item.ItemStack; @@ -69,9 +70,9 @@ public void compare(IGridStack left, { callbackInfoReturnable.setReturnValue(SortingHelper.compareJewels( left.getName(), - VaultGearData.read(leftStack), + GearDataCache.of(leftStack), right.getName(), - VaultGearData.read(rightStack), + GearDataCache.of(rightStack), VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(), sortingDirection == SortingDirection.ASCENDING)); callbackInfoReturnable.cancel(); diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/sophisticatedcore/SophisticatedCoreIntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/SophisticatedCoreIntegrationModConfiguration.java similarity index 66% rename from src/main/java/lv/id/bonne/vaultjewelsorting/sophisticatedcore/SophisticatedCoreIntegrationModConfiguration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/SophisticatedCoreIntegrationModConfiguration.java index 3abf600..bb2c181 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/sophisticatedcore/SophisticatedCoreIntegrationModConfiguration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/SophisticatedCoreIntegrationModConfiguration.java @@ -1,9 +1,10 @@ -package lv.id.bonne.vaultjewelsorting.sophisticatedcore; +package lv.id.bonne.vaulthunters.jewelsorting.sophisticatedcore; -import lv.id.bonne.vaultjewelsorting.config.MixinConfigPlugin; +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; import net.minecraftforge.fml.loading.LoadingModList; -public class SophisticatedCoreIntegrationModConfiguration extends MixinConfigPlugin { +public class SophisticatedCoreIntegrationModConfiguration extends MixinConfigPlugin +{ @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { return LoadingModList.get().getModFileById("sophisticatedcore") != null; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java similarity index 97% rename from src/main/java/lv/id/bonne/vaultjewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java index cd66536..dc57a03 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/sophisticatedcore/mixin/MixinInventorySorter.java @@ -1,6 +1,4 @@ -package lv.id.bonne.vaultjewelsorting.sophisticatedcore.mixin; - -import com.refinedmods.refinedstorage.screen.grid.sorting.SortingDirection; +package lv.id.bonne.vaulthunters.jewelsorting.sophisticatedcore.mixin; import iskallia.vault.gear.data.AttributeGearData; import iskallia.vault.gear.data.VaultGearData; @@ -12,8 +10,8 @@ import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.p3pp3rf1y.sophisticatedcore.inventory.ItemStackKey; import net.p3pp3rf1y.sophisticatedcore.util.InventorySorter; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/storagenetwork/StorageNetworkIntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/StorageNetworkIntegrationModConfiguration.java similarity index 75% rename from src/main/java/lv/id/bonne/vaultjewelsorting/storagenetwork/StorageNetworkIntegrationModConfiguration.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/StorageNetworkIntegrationModConfiguration.java index 1d447e7..e3b0909 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/storagenetwork/StorageNetworkIntegrationModConfiguration.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/StorageNetworkIntegrationModConfiguration.java @@ -1,6 +1,6 @@ -package lv.id.bonne.vaultjewelsorting.storagenetwork; +package lv.id.bonne.vaulthunters.jewelsorting.storagenetwork; -import lv.id.bonne.vaultjewelsorting.config.MixinConfigPlugin; +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; import net.minecraftforge.fml.loading.LoadingModList; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/storagenetwork/mixin/MixinNetworkWidget.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java similarity index 97% rename from src/main/java/lv/id/bonne/vaultjewelsorting/storagenetwork/mixin/MixinNetworkWidget.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java index e10773d..51d242a 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/storagenetwork/mixin/MixinNetworkWidget.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/storagenetwork/mixin/MixinNetworkWidget.java @@ -1,9 +1,8 @@ -package lv.id.bonne.vaultjewelsorting.storagenetwork.mixin; +package lv.id.bonne.vaulthunters.jewelsorting.storagenetwork.mixin; import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.gui.NetworkWidget; -import com.refinedmods.refinedstorage.screen.grid.sorting.SortingDirection; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,15 +14,14 @@ import iskallia.vault.gear.data.VaultGearData; import iskallia.vault.gear.item.VaultGearItem; import iskallia.vault.item.InscriptionItem; -import iskallia.vault.item.VaultCatalystItem; import iskallia.vault.item.crystal.CrystalData; import iskallia.vault.item.crystal.VaultCrystalItem; import iskallia.vault.item.data.InscriptionData; import iskallia.vault.item.gear.TrinketItem; import iskallia.vault.item.tool.JewelItem; import iskallia.vault.item.tool.ToolItem; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; -import lv.id.bonne.vaultjewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/utils/AttributeHelper.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/AttributeHelper.java similarity index 97% rename from src/main/java/lv/id/bonne/vaultjewelsorting/utils/AttributeHelper.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/AttributeHelper.java index 9c58b00..20d675c 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/utils/AttributeHelper.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/AttributeHelper.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.utils; +package lv.id.bonne.vaulthunters.jewelsorting.utils; import java.lang.reflect.Field; @@ -12,7 +12,7 @@ import iskallia.vault.gear.attribute.VaultGearAttribute; import iskallia.vault.init.ModGearAttributes; -import lv.id.bonne.vaultjewelsorting.VaultJewelSorting; +import lv.id.bonne.vaulthunters.jewelsorting.VaultJewelSorting; import net.minecraftforge.event.RegistryEvent; diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/utils/CustomVaultGearData.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/CustomVaultGearData.java similarity index 96% rename from src/main/java/lv/id/bonne/vaultjewelsorting/utils/CustomVaultGearData.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/CustomVaultGearData.java index f731d7f..783280c 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/utils/CustomVaultGearData.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/CustomVaultGearData.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.utils; +package lv.id.bonne.vaulthunters.jewelsorting.utils; import java.util.function.Function; diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/IExtraGearDataCache.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/IExtraGearDataCache.java new file mode 100644 index 0000000..8270c52 --- /dev/null +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/IExtraGearDataCache.java @@ -0,0 +1,59 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package lv.id.bonne.vaulthunters.jewelsorting.utils; + + +import org.jetbrains.annotations.Nullable; + + +/** + * This interface is used to create extra methods for accessing data in GearDataCache. + */ +public interface IExtraGearDataCache +{ + /** + * This method returns first attribute index. + * @return first attribute index. + */ + @Nullable + default Integer getExtraFirstAttributeIndex() + { + return null; + } + + + /** + * This method returns first attribute value. + * @return first attribute value. + */ + @Nullable + default Double getExtraFirstAttributeValue() + { + return null; + } + + + /** + * This method returns Jewel Size value. + * @return Jewel Size value. + */ + @Nullable + default Integer getExtraJewelSize() + { + return null; + } + + + /** + * This method returns Gear Level value. + * @return Gear Level value. + */ + default int getExtraGearLevel() + { + return 0; + } +} diff --git a/src/main/java/lv/id/bonne/vaultjewelsorting/utils/SortingHelper.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java similarity index 79% rename from src/main/java/lv/id/bonne/vaultjewelsorting/utils/SortingHelper.java rename to src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java index e2d8178..95a7bf0 100644 --- a/src/main/java/lv/id/bonne/vaultjewelsorting/utils/SortingHelper.java +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/utils/SortingHelper.java @@ -4,7 +4,7 @@ // -package lv.id.bonne.vaultjewelsorting.utils; +package lv.id.bonne.vaulthunters.jewelsorting.utils; import java.util.ArrayList; @@ -15,6 +15,7 @@ import iskallia.vault.gear.attribute.VaultGearAttribute; import iskallia.vault.gear.attribute.VaultGearModifier; import iskallia.vault.gear.data.AttributeGearData; +import iskallia.vault.gear.data.GearDataCache; import iskallia.vault.gear.data.VaultGearData; import iskallia.vault.gear.trinket.TrinketEffect; import iskallia.vault.init.ModGearAttributes; @@ -82,6 +83,100 @@ public static int compareJewels( } + /** + * This method compares two given jewels by their sorting order. + * + * @param leftName the left name + * @param leftData the left data + * @param rightName the right name + * @param rightData the right data + * @param sortingOrder the sorting order + * @param ascending the ascending + * @return the comparison of two given jewels. + */ + public static int compareJewels( + String leftName, + GearDataCache leftData, + String rightName, + GearDataCache rightData, + List sortingOrder, + boolean ascending) + { + int returnValue = 0; + + IExtraGearDataCache leftExtraCache = (IExtraGearDataCache) leftData; + IExtraGearDataCache rightExtraCache = (IExtraGearDataCache) rightData; + + for (int i = 0, sortingOrderSize = sortingOrder.size(); returnValue == 0 && i < sortingOrderSize; i++) + { + JewelOptions sortOptions = sortingOrder.get(i); + + returnValue = switch (sortOptions) { + case NAME -> SortingHelper.compareString(leftName, rightName); + case ATTRIBUTE -> SortingHelper.compareIntegerValue(leftExtraCache.getExtraFirstAttributeIndex(), + rightExtraCache.getExtraFirstAttributeIndex()); + case ATTRIBUTE_VALUE -> SortingHelper.compareDoubleValue(leftExtraCache.getExtraFirstAttributeValue(), + rightExtraCache.getExtraFirstAttributeValue()); + case SIZE -> SortingHelper.compareIntegerValue(leftExtraCache.getExtraJewelSize(), + rightExtraCache.getExtraJewelSize()); + case ATTRIBUTE_WEIGHT -> SortingHelper.compareAttributeValueWeight(leftExtraCache, rightExtraCache); + case LEVEL -> SortingHelper.compareIntegerValue(leftExtraCache.getExtraGearLevel(), + rightExtraCache.getExtraGearLevel()); + }; + } + + return ascending ? returnValue : -returnValue; + } + + + /** + * This method compares two given jewels by their sorting order. + * + * @param leftName the left name + * @param leftData the left data + * @param rightName the right name + * @param rightData the right data + * @param sortingOrder the sorting order + * @param ascending the ascending + * @return the comparison of two given jewels. + */ + public static int compareJewels( + String leftName, + CompoundTag leftData, + String rightName, + CompoundTag rightData, + List sortingOrder, + boolean ascending) + { + int returnValue = 0; + for (int i = 0, sortingOrderSize = sortingOrder.size(); returnValue == 0 && i < sortingOrderSize; i++) + { + JewelOptions sortOptions = sortingOrder.get(i); + + returnValue = switch (sortOptions) { + case NAME -> SortingHelper.compareString(leftName, rightName); + case ATTRIBUTE -> SortingHelper.compareIntegerValue(leftData.getInt(EXTRA_ATTRIBUTE_INDEX), + rightData.getInt(EXTRA_ATTRIBUTE_INDEX)); + case ATTRIBUTE_VALUE -> SortingHelper.compareDoubleValue(leftData.getDouble(EXTRA_ATTRIBUTE_VALUE), + rightData.getDouble(EXTRA_ATTRIBUTE_VALUE)); + case SIZE -> SortingHelper.compareIntegerValue(leftData.getInt(EXTRA_JEWEL_SIZE), + rightData.getInt(EXTRA_JEWEL_SIZE)); + case ATTRIBUTE_WEIGHT -> + { + double leftWeight = leftData.getDouble(EXTRA_ATTRIBUTE_VALUE) / leftData.getInt(EXTRA_JEWEL_SIZE); + double rightWeight = rightData.getDouble(EXTRA_ATTRIBUTE_VALUE) / rightData.getInt(EXTRA_JEWEL_SIZE); + + yield SortingHelper.compareDoubleValue(leftWeight, rightWeight); + } + case LEVEL -> SortingHelper.compareIntegerValue(leftData.getInt(EXTRA_GEAR_LEVEL), + rightData.getInt(EXTRA_GEAR_LEVEL)); + }; + } + + return ascending ? returnValue : -returnValue; + } + + /** * This method compares two given vault gear by their sorting order. * @@ -647,6 +742,112 @@ else if (leftRooms == 1) } + /** + * This method compares 2 given integer values. + * @param leftValue The left value. + * @param rightValue The right value. + * @return Returns if left value is larger then right value. + */ + private static int compareIntegerValue(Integer leftValue, Integer rightValue) + { + if (leftValue == null && rightValue != null) + { + return -1; + } + else if (leftValue != null && rightValue == null) + { + return 1; + } + else if (leftValue == null) + { + return 0; + } + else + { + return Integer.compare(leftValue, rightValue); + } + } + + + /** + * This method compares 2 given double values. + * @param leftValue The left value. + * @param rightValue The right value. + * @return Returns if left value is larger then right value. + */ + private static int compareDoubleValue(Double leftValue, Double rightValue) + { + if (leftValue == null && rightValue != null) + { + return -1; + } + else if (leftValue != null && rightValue == null) + { + return 1; + } + else if (leftValue == null) + { + return 0; + } + else + { + return Double.compare(leftValue, rightValue); + } + } + + + /** + * This method compares 2 given IExtraGearDataCache values. + * @param leftValue The left value. + * @param rightValue The right value. + * @return Returns if left value is larger then right value. + */ + private static int compareAttributeValueWeight(IExtraGearDataCache leftValue, IExtraGearDataCache rightValue) + { + Integer leftSize = leftValue.getExtraJewelSize(); + Integer rightSize = rightValue.getExtraJewelSize(); + + if (leftSize == null && rightSize == null) + { + // No size, no comparison + return 0; + } + else if (leftSize == null || leftSize == 0) + { + // No size for first one. + return -1; + } + else if (rightSize == null || rightSize == 0) + { + // No size for second one. + return 1; + } + + // Now actually compare. + + Double leftAttributeValue = leftValue.getExtraFirstAttributeValue(); + Double rightAttributeValue = rightValue.getExtraFirstAttributeValue(); + + if (leftAttributeValue == null && rightAttributeValue == null) + { + // No attribute value, no comparison + return 0; + } + else if (leftAttributeValue == null) + { + // No attribute value for first one. + return -1; + } + else if (rightAttributeValue == null) + { + // No attribute value for second one. + return 1; + } + + return Double.compare(leftAttributeValue / leftSize, rightAttributeValue / rightSize); + } + + /** * This method returns remaining uses from given tag. * @param tag The tag of the item. @@ -827,4 +1028,25 @@ public enum TrinketOptions */ USES } + + + /** + * The name of the cache. + */ + public static final String EXTRA_ATTRIBUTE_INDEX = "extra_attribute_index"; + + /** + * The name of the cache. + */ + public static final String EXTRA_ATTRIBUTE_VALUE = "extra_attribute_value"; + + /** + * The name of the cache. + */ + public static final String EXTRA_JEWEL_SIZE = "extra_jewel_size"; + + /** + * The name of the cache. + */ + public static final String EXTRA_GEAR_LEVEL = "extra_gear_level"; } diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/VaultHuntersIntegrationModConfiguration.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/VaultHuntersIntegrationModConfiguration.java new file mode 100644 index 0000000..391da18 --- /dev/null +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/VaultHuntersIntegrationModConfiguration.java @@ -0,0 +1,17 @@ +package lv.id.bonne.vaulthunters.jewelsorting.vaulthunters; + +import lv.id.bonne.vaulthunters.jewelsorting.config.MixinConfigPlugin; +import net.minecraftforge.fml.loading.LoadingModList; + + +/** + * This Mixin configuration checks if VaultHunters mod is loaded. + */ +public class VaultHuntersIntegrationModConfiguration extends MixinConfigPlugin +{ + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) + { + return LoadingModList.get().getModFileById("the_vault") != null; + } +} diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/mixin/InvokerGearDataCache.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/mixin/InvokerGearDataCache.java new file mode 100644 index 0000000..fd2d022 --- /dev/null +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/mixin/InvokerGearDataCache.java @@ -0,0 +1,51 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package lv.id.bonne.vaulthunters.jewelsorting.vaulthunters.mixin; + + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import java.util.function.Function; + +import iskallia.vault.gear.data.GearDataCache; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; + + +/** + * This mixin allows access to private methods of GearDataCache. + */ +@Mixin(GearDataCache.class) +public interface InvokerGearDataCache +{ + /** + * This method allows to call private method queryIntCache. + * @param key The key of the cache. + * @param defaultValue The default value of the cache. + * @param cacheInit The cache init function. + * @return The value of the cache. + */ + @Invoker(value = "queryIntCache", remap = false) + public Integer callQueryIntCache(String key, int defaultValue, Function cacheInit); + + + /** + * This method allows to call private method queryCache. + * @param The type of the cache. + * @param The type of the cache. + * @param key The key of the cache. + * @param cacheRead The cache read function. + * @param cacheWrite The cache write function. + * @param cacheMissDefault The cache miss default value. + * @param cacheHitTransform The cache hit transform function. + * @param cacheInit The cache init function. + * @return The value of the cache. + */ + @Invoker(value = "queryCache", remap = false) + public T callQueryCache(String key, Function cacheRead, Function cacheWrite, T cacheMissDefault, Function cacheHitTransform, Function cacheInit); +} diff --git a/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/mixin/MixinGearDataCache.java b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/mixin/MixinGearDataCache.java new file mode 100644 index 0000000..6277880 --- /dev/null +++ b/src/main/java/lv/id/bonne/vaulthunters/jewelsorting/vaulthunters/mixin/MixinGearDataCache.java @@ -0,0 +1,261 @@ +// +// Created by BONNe +// Copyright - 2023 +// + + +package lv.id.bonne.vaulthunters.jewelsorting.vaulthunters.mixin; + + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +import iskallia.vault.gear.attribute.VaultGearAttribute; +import iskallia.vault.gear.attribute.VaultGearModifier; +import iskallia.vault.gear.data.GearDataCache; +import iskallia.vault.gear.data.VaultGearData; +import iskallia.vault.init.ModGearAttributes; +import iskallia.vault.item.tool.JewelItem; +import lv.id.bonne.vaulthunters.jewelsorting.utils.AttributeHelper; +import lv.id.bonne.vaulthunters.jewelsorting.utils.SortingHelper; +import lv.id.bonne.vaulthunters.jewelsorting.utils.IExtraGearDataCache; +import net.minecraft.nbt.DoubleTag; +import net.minecraft.world.item.ItemStack; + + +/** + * This mixin allows to add extra data to GearDataCache. + */ +@Mixin(value = GearDataCache.class, remap = false) +public class MixinGearDataCache implements IExtraGearDataCache +{ + /** + * This method injects code to createCache method. + * @param stack The stack to create cache from. + * @param ci Callback info. + * @param cache The cache to populate. + */ + @Inject(method = "createCache", + at = @At(value = "INVOKE", + target = "Liskallia/vault/gear/data/GearDataCache;getJewelColorComponents()Ljava/util/List;"), + locals = LocalCapture.CAPTURE_FAILSOFT) + private static void extraCreateCache(ItemStack stack, CallbackInfo ci, GearDataCache cache) + { + if (stack.getItem() instanceof JewelItem) + { + MixinGearDataCache.populateJewelCache(cache, stack); + } + } + + + /** + * This method populates jewel cache. + * @param cache The cache to populate. + * @param itemStack The item stack to populate cache from. + */ + private static void populateJewelCache(GearDataCache cache, ItemStack itemStack) + { + VaultGearData data = VaultGearData.read(itemStack); + + List> affixes = new ArrayList<>(); + affixes.addAll(data.getModifiers(VaultGearModifier.AffixType.PREFIX)); + affixes.addAll(data.getModifiers(VaultGearModifier.AffixType.SUFFIX)); + + ((InvokerGearDataCache) cache).callQueryIntCache(SortingHelper.EXTRA_ATTRIBUTE_INDEX, + -1, + (stack) -> + { + if (affixes.size() == 1) + { + return AttributeHelper.getAttributeIndex(affixes.get(0).getAttribute()); + } + else + { + return -1; + } + }); + + ((InvokerGearDataCache) cache).callQueryCache(SortingHelper.EXTRA_ATTRIBUTE_VALUE, + tag -> ((DoubleTag) tag).getAsDouble(), + DoubleTag::valueOf, + null, + Function.identity(), + (stack) -> + { + if (affixes.size() == 1) + { + VaultGearAttribute attribute = affixes.get(0).getAttribute(); + + if (AttributeHelper.isDoubleAttribute(attribute)) + { + Optional value = (Optional) data.getFirstValue(attribute); + return value.orElse(null); + } + else if (AttributeHelper.isFloatAttribute(attribute)) + { + Optional value = (Optional) data.getFirstValue(attribute); + return value.map(Double::valueOf).orElse(null); + } + else if (AttributeHelper.isIntegerAttribute(attribute)) + { + Optional value = (Optional) data.getFirstValue(attribute); + return value.map(Double::valueOf).orElse(null); + } + else + { + return null; + } + } + else + { + return null; + } + }); + + + ((InvokerGearDataCache) cache).callQueryIntCache(SortingHelper.EXTRA_JEWEL_SIZE, 0, (stack) -> + { + if (stack.getItem() instanceof JewelItem) + { + return data.getFirstValue(ModGearAttributes.JEWEL_SIZE).orElse(null); + } + else + { + return null; + } + }); + + ((InvokerGearDataCache) cache).callQueryIntCache(SortingHelper.EXTRA_GEAR_LEVEL, 0, (stack) -> + data.getItemLevel()); + } + + + /** + * This method returns first attribute index. + * @return first attribute index. + */ + @Override + @Unique + public Integer getExtraFirstAttributeIndex() + { + return ((InvokerGearDataCache) this).callQueryIntCache(SortingHelper.EXTRA_ATTRIBUTE_INDEX, + -1, + (stack) -> + { + VaultGearData data = VaultGearData.read(stack); + + List> affixes = new ArrayList<>(); + affixes.addAll(data.getModifiers(VaultGearModifier.AffixType.PREFIX)); + affixes.addAll(data.getModifiers(VaultGearModifier.AffixType.SUFFIX)); + + if (affixes.size() == 1) + { + return AttributeHelper.getAttributeIndex(affixes.get(0).getAttribute()); + } + else + { + return -1; + } + }); + } + + + /** + * This method returns first attribute value. + * @return first attribute value. + */ + @Override + @Unique + public Double getExtraFirstAttributeValue() + { + return ((InvokerGearDataCache) this).callQueryCache(SortingHelper.EXTRA_ATTRIBUTE_VALUE, + tag -> ((DoubleTag) tag).getAsDouble(), + DoubleTag::valueOf, + null, + Function.identity(), + (stack) -> + { + VaultGearData data = VaultGearData.read(stack); + + List> affixes = new ArrayList<>(); + affixes.addAll(data.getModifiers(VaultGearModifier.AffixType.PREFIX)); + affixes.addAll(data.getModifiers(VaultGearModifier.AffixType.SUFFIX)); + + if (affixes.size() == 1) + { + VaultGearAttribute attribute = affixes.get(0).getAttribute(); + + if (AttributeHelper.isDoubleAttribute(attribute)) + { + Optional value = (Optional) data.getFirstValue(attribute); + return value.orElse(null); + } + else if (AttributeHelper.isFloatAttribute(attribute)) + { + Optional value = (Optional) data.getFirstValue(attribute); + return value.map(Double::valueOf).orElse(null); + } + else if (AttributeHelper.isIntegerAttribute(attribute)) + { + Optional value = (Optional) data.getFirstValue(attribute); + return value.map(Double::valueOf).orElse(null); + } + else + { + return null; + } + } + else + { + return null; + } + }); + } + + + /** + * This method returns Jewel Size value. + * @return Jewel Size value. + */ + @Override + @Unique + public Integer getExtraJewelSize() + { + return ((InvokerGearDataCache) this).callQueryIntCache(SortingHelper.EXTRA_JEWEL_SIZE, 0, (stack) -> + { + if (stack.getItem() instanceof JewelItem) + { + VaultGearData data = VaultGearData.read(stack); + return data.getFirstValue(ModGearAttributes.JEWEL_SIZE).orElse(null); + } + else + { + return null; + } + }); + } + + + /** + * This method returns Gear Level value. + * @return Gear Level value. + */ + @Override + @Unique + public int getExtraGearLevel() + { + return ((InvokerGearDataCache) this).callQueryIntCache(SortingHelper.EXTRA_GEAR_LEVEL, 0, (stack) -> + { + VaultGearData data = VaultGearData.read(stack); + return data.getItemLevel(); + }); + } +} diff --git a/src/main/resources/mixins.vault_hunters_jewel_sorting.ae2.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.ae2.json new file mode 100644 index 0000000..452f859 --- /dev/null +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.ae2.json @@ -0,0 +1,10 @@ +{ + "package": "lv.id.bonne.vaulthunters.jewelsorting.ae2.mixin", + "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_17", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.ae2.AE2IntegrationModConfiguration", + "client": [ + "MixinRepo" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.vaulthunters_jewel_sorting.qio.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.qio.json similarity index 55% rename from src/main/resources/mixins.vaulthunters_jewel_sorting.qio.json rename to src/main/resources/mixins.vault_hunters_jewel_sorting.qio.json index fafa3b8..b3fa2ce 100644 --- a/src/main/resources/mixins.vaulthunters_jewel_sorting.qio.json +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.qio.json @@ -1,9 +1,9 @@ { - "package": "lv.id.bonne.vaultjewelsorting.qio.mixin", + "package": "lv.id.bonne.vaulthunters.jewelsorting.qio.mixin", "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_17", - "plugin": "lv.id.bonne.vaultjewelsorting.qio.QIOIntegrationModConfiguration", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.qio.QIOIntegrationModConfiguration", "client": [ "MixinQIOItemViewerContainerListSortType" ] diff --git a/src/main/resources/mixins.vaulthunters_jewel_sorting.quark.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.quark.json similarity index 51% rename from src/main/resources/mixins.vaulthunters_jewel_sorting.quark.json rename to src/main/resources/mixins.vault_hunters_jewel_sorting.quark.json index bcc929e..6daa215 100644 --- a/src/main/resources/mixins.vaulthunters_jewel_sorting.quark.json +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.quark.json @@ -1,9 +1,9 @@ { - "package": "lv.id.bonne.vaultjewelsorting.quark.mixin", + "package": "lv.id.bonne.vaulthunters.jewelsorting.quark.mixin", "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_17", - "plugin": "lv.id.bonne.vaultjewelsorting.quark.QuarkIntegrationModConfiguration", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.quark.QuarkIntegrationModConfiguration", "mixins": [ "MixinSortingHandler" ] diff --git a/src/main/resources/mixins.vault_hunters_jewel_sorting.rs.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.rs.json new file mode 100644 index 0000000..fe11088 --- /dev/null +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.rs.json @@ -0,0 +1,12 @@ +{ + "package": "lv.id.bonne.vaulthunters.jewelsorting.refinedstorage.mixin", + "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_17", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.refinedstorage.RefinedStorageIntegrationModConfiguration", + "client": [ + "MixinIdGridSorter", + "MixinNameGridSorter", + "MixinQuantityGridSorter" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.vault_hunters_jewel_sorting.sophisticatedcore.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.sophisticatedcore.json new file mode 100644 index 0000000..caaa87b --- /dev/null +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.sophisticatedcore.json @@ -0,0 +1,10 @@ +{ + "package": "lv.id.bonne.vaulthunters.jewelsorting.sophisticatedcore.mixin", + "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_17", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.sophisticatedcore.SophisticatedCoreIntegrationModConfiguration", + "mixins": [ + "MixinInventorySorter" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.vault_hunters_jewel_sorting.storagenetwork.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.storagenetwork.json new file mode 100644 index 0000000..3b872ea --- /dev/null +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.storagenetwork.json @@ -0,0 +1,10 @@ +{ + "package": "lv.id.bonne.vaulthunters.jewelsorting.storagenetwork.mixin", + "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_17", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.storagenetwork.StorageNetworkIntegrationModConfiguration", + "client": [ + "MixinNetworkWidget" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixins.vault_hunters_jewel_sorting.vaulthunters.json b/src/main/resources/mixins.vault_hunters_jewel_sorting.vaulthunters.json new file mode 100644 index 0000000..9f2cb78 --- /dev/null +++ b/src/main/resources/mixins.vault_hunters_jewel_sorting.vaulthunters.json @@ -0,0 +1,14 @@ +{ + "package": "lv.id.bonne.vaulthunters.jewelsorting.vaulthunters.mixin", + "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_17", + "plugin": "lv.id.bonne.vaulthunters.jewelsorting.vaulthunters.VaultHuntersIntegrationModConfiguration", + "client": [ + "InvokerGearDataCache", + "MixinGearDataCache" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/mixins.vaulthunters_jewel_sorting.ae2.json b/src/main/resources/mixins.vaulthunters_jewel_sorting.ae2.json deleted file mode 100644 index 471e470..0000000 --- a/src/main/resources/mixins.vaulthunters_jewel_sorting.ae2.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "package": "lv.id.bonne.vaultjewelsorting.ae2.mixin", - "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", - "minVersion": "0.8", - "compatibilityLevel": "JAVA_8", - "plugin": "lv.id.bonne.vaultjewelsorting.ae2.AE2IntegrationModConfiguration", - "client": [ - "MixinRepo" - ] -} \ No newline at end of file diff --git a/src/main/resources/mixins.vaulthunters_jewel_sorting.rs.json b/src/main/resources/mixins.vaulthunters_jewel_sorting.rs.json deleted file mode 100644 index 9754d1c..0000000 --- a/src/main/resources/mixins.vaulthunters_jewel_sorting.rs.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "package": "lv.id.bonne.vaultjewelsorting.refinedstorage.mixin", - "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", - "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", - "plugin": "lv.id.bonne.vaultjewelsorting.refinedstorage.RefinedStorageIntegrationModConfiguration", - "client": [ - "MixinNameGridSorter", - "MixinQuantityGridSorter", - "MixinIdGridSorter" - ] -} \ No newline at end of file diff --git a/src/main/resources/mixins.vaulthunters_jewel_sorting.sophisticatedcore.json b/src/main/resources/mixins.vaulthunters_jewel_sorting.sophisticatedcore.json deleted file mode 100644 index 00ce7d1..0000000 --- a/src/main/resources/mixins.vaulthunters_jewel_sorting.sophisticatedcore.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "package": "lv.id.bonne.vaultjewelsorting.sophisticatedcore.mixin", - "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", - "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", - "plugin": "lv.id.bonne.vaultjewelsorting.sophisticatedcore.SophisticatedCoreIntegrationModConfiguration", - "mixins": [ - "MixinInventorySorter" - ] -} \ No newline at end of file diff --git a/src/main/resources/mixins.vaulthunters_jewel_sorting.storagenetwork.json b/src/main/resources/mixins.vaulthunters_jewel_sorting.storagenetwork.json deleted file mode 100644 index a6760e9..0000000 --- a/src/main/resources/mixins.vaulthunters_jewel_sorting.storagenetwork.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "package": "lv.id.bonne.vaultjewelsorting.storagenetwork.mixin", - "refmap": "mixins.vaulthunters_jewel_sorting.refmap.json", - "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", - "plugin": "lv.id.bonne.vaultjewelsorting.storagenetwork.StorageNetworkIntegrationModConfiguration", - "client": [ - "MixinNetworkWidget" - ] -} \ No newline at end of file