From 66edf22adfe352fdbe4c48cc42a64cbfaa935520 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Wed, 31 Jan 2024 22:27:58 +1100 Subject: Fix some getItemStack errors (#967) Fixed some getItemStack errors. #967 --- src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt') 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>() private val recipesCache = mutableMapOf>() private val ingredientsCache = mutableMapOf>() - private val enchantmentNamePattern = Pattern.compile("^(?(?:§.)+)(?[^§]+) (?[IVXL]+)$") + var allItemsCache = mapOf() // item name -> internal name var allInternalNames = mutableListOf() + 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("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 "") -- cgit