diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-01-31 22:27:58 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 12:27:58 +0100 |
commit | 66edf22adfe352fdbe4c48cc42a64cbfaa935520 (patch) | |
tree | 24a81bf447115d489c7f2176ae684c2c22cd80a2 /src/main | |
parent | 5b12fb9bd5c6c4ea221024ab28bc1dc3e25d09ab (diff) | |
download | skyhanni-66edf22adfe352fdbe4c48cc42a64cbfaa935520.tar.gz skyhanni-66edf22adfe352fdbe4c48cc42a64cbfaa935520.tar.bz2 skyhanni-66edf22adfe352fdbe4c48cc42a64cbfaa935520.zip |
Fix some getItemStack errors (#967)
Fixed some getItemStack errors. #967
Diffstat (limited to 'src/main')
4 files changed, 21 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 90c4a03ae..eb269da5b 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -350,6 +350,7 @@ import at.hannibal2.skyhanni.utils.EntityOutlineRenderer import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter.Companion.initLogging +import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.UtilsPatterns @@ -455,6 +456,7 @@ class SkyHanniMod { loadModule(FishingAPI) loadModule(FishingDetection) loadModule(LorenzUtils) + loadModule(NEUItems) // features loadModule(BazaarOrderHelper()) diff --git a/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt b/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt index 2419d6161..e70a572df 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/HighlightMissingRepoItems.kt @@ -3,14 +3,11 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.MultiFilter import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.highlight -import at.hannibal2.skyhanni.data.jsonobjects.repo.MultiFilterJson import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.gui.inventory.GuiInventory @@ -19,7 +16,6 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class HighlightMissingRepoItems { - private val ignoreItems = MultiFilter() @SubscribeEvent(priority = EventPriority.LOWEST) fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { @@ -41,7 +37,7 @@ class HighlightMissingRepoItems { for (slot in slots) { val internalName = slot.stack?.getInternalNameOrNull() ?: continue if (NEUItems.allInternalNames.contains(internalName)) continue - if (ignoreItems.match(internalName.asString())) continue + if (NEUItems.ignoreItemsFilter.match(internalName.asString())) continue slot highlight LorenzColor.RED } @@ -53,12 +49,6 @@ class HighlightMissingRepoItems { } @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - val ignoredItems = event.getConstant<MultiFilterJson>("IgnoredItems") - ignoreItems.load(ignoredItems) - } - - @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(3, "dev.highlightMissingRepo", "dev.debug.highlightMissingRepo") } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 8a909f15e..cd1838bdc 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.ConfigManager +import at.hannibal2.skyhanni.data.jsonobjects.repo.MultiFilterJson +import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.bazaar.BazaarDataHolder import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem @@ -29,8 +31,8 @@ import net.minecraft.init.Blocks import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.lwjgl.opengl.GL11 -import java.util.regex.Pattern object NEUItems { val manager: NEUManager get() = NotEnoughUpdates.INSTANCE.manager @@ -38,9 +40,10 @@ object NEUItems { private val multiplierCache = mutableMapOf<NEUInternalName, Pair<NEUInternalName, Int>>() private val recipesCache = mutableMapOf<NEUInternalName, Set<NeuRecipe>>() private val ingredientsCache = mutableMapOf<NeuRecipe, Set<Ingredient>>() - private val enchantmentNamePattern = Pattern.compile("^(?<format>(?:§.)+)(?<name>[^§]+) (?<level>[IVXL]+)$") + var allItemsCache = mapOf<String, NEUInternalName>() // item name -> internal name var allInternalNames = mutableListOf<NEUInternalName>() + val ignoreItemsFilter = MultiFilter() private val fallbackItem by lazy { Utils.createItemStack( @@ -50,6 +53,12 @@ object NEUItems { ) } + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + val ignoredItems = event.getConstant<MultiFilterJson>("IgnoredItems") + ignoreItemsFilter.load(ignoredItems) + } + // TODO remove @Deprecated("Use NEUInternalName rather than String", ReplaceWith("getInternalNameFromItemName()")) fun getRawInternalName(itemName: String): String { @@ -190,7 +199,8 @@ object NEUItems { fun NEUInternalName.getItemStack(): ItemStack = getItemStackOrNull() ?: run { - if (getPriceOrNull() == null) return@run fallbackItem + getPriceOrNull() ?: return@run fallbackItem + if (ignoreItemsFilter.match(this.asString())) return@run fallbackItem ErrorManager.logError( IllegalStateException("Something went wrong!"), "Encountered an error getting the item for §7$this§c. " + @@ -348,7 +358,7 @@ object NEUItems { // Taken and edited from NEU private fun resolveEnchantmentByName(enchantmentName: String) = - enchantmentNamePattern.matchMatcher(enchantmentName) { + UtilsPatterns.enchantmentNamePattern.matchMatcher(enchantmentName) { val name = group("name").trim { it <= ' ' } val ultimate = group("format").lowercase().contains("§l") ((if (ultimate && name != "Ultimate Wise") "ULTIMATE_" else "") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt index b391c07ac..b381ddf1c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt @@ -30,6 +30,10 @@ object UtilsPatterns { "item.name.enchanted.book", ".{2}?Enchanted Book" ) + val enchantmentNamePattern by patternGroup.pattern( + "item.neuitems.enchantmentname", + "^(?<format>(?:§.)+)(?<name>[^§]+) (?<level>[IVXL]+)$" + ) val potionPattern by patternGroup.pattern( "item.name.potion", |