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/java/at/hannibal2/skyhanni/utils | |
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/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 18 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/UtilsPatterns.kt | 4 |
2 files changed, 18 insertions, 4 deletions
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", |