From bc2ccc0c39495921aee82664266c1756f016b388 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Fri, 29 Jul 2022 16:14:04 +0200 Subject: added support for vanilla items from neu. allowing all vanilla items to be sold to npc --- .../skyhanni/items/HideNotClickableItems.kt | 9 +++- .../hannibal2/skyhanni/items/VanillaItemManager.kt | 58 ++++++++++++++++++++++ .../items/abilitycooldown/WitherImpactDetection.kt | 13 ++++- 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/items/VanillaItemManager.kt (limited to 'src/main/java/at/hannibal2/skyhanni/items') diff --git a/src/main/java/at/hannibal2/skyhanni/items/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/items/HideNotClickableItems.kt index 8a8088c34..17299253e 100644 --- a/src/main/java/at/hannibal2/skyhanni/items/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/items/HideNotClickableItems.kt @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.ItemUtils.cleanName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.getSBItemID +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils.removeColorCodes import at.hannibal2.skyhanni.utils.RenderUtils.highlight import com.google.gson.JsonObject @@ -330,6 +330,11 @@ class HideNotClickableItems { if (!ItemUtils.isRecombobulated(stack)) { if (hideNpcSellFilter.match(name)) return false + + val id = stack.getInternalName() + if (VanillaItemManager.isVanillaItem(id) && !stack.isItemEnchanted) { + return false + } } hideReason = "This item should not be sold at the NPC!" @@ -433,5 +438,5 @@ class HideNotClickableItems { return result } - private fun isSkyBlockMenuItem(stack: ItemStack): Boolean = stack.getSBItemID() == "SKYBLOCK_MENU" + private fun isSkyBlockMenuItem(stack: ItemStack): Boolean = stack.getInternalName() == "SKYBLOCK_MENU" } diff --git a/src/main/java/at/hannibal2/skyhanni/items/VanillaItemManager.kt b/src/main/java/at/hannibal2/skyhanni/items/VanillaItemManager.kt new file mode 100644 index 000000000..15ad83d13 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/items/VanillaItemManager.kt @@ -0,0 +1,58 @@ +package at.hannibal2.skyhanni.items + +import at.hannibal2.skyhanni.utils.LorenzDebug +import com.google.gson.GsonBuilder +import com.google.gson.JsonObject +import java.io.BufferedReader +import java.io.File +import java.io.FileInputStream +import java.io.InputStreamReader +import java.nio.charset.StandardCharsets + +class VanillaItemManager { + private val gson = GsonBuilder().setPrettyPrinting().create() + + companion object { + private val vanillaItems: MutableList = ArrayList() + + fun isVanillaItem(internalName: String): Boolean { + return vanillaItems.contains(internalName) + } + } + + init { + load() + } + + private fun load() { + vanillaItems.clear() + val itemDirectory = File("config/notenoughupdates/repo/items") + if (!itemDirectory.isDirectory) return + val files = itemDirectory.listFiles() ?: return + for (file in files) { + val jsonObject = getJsonFromFile(file) + if (jsonObject != null) { + if (jsonObject.has("vanilla") && jsonObject["vanilla"].asBoolean) { + val name = file.name + val internalName = name.split(".")[0] + vanillaItems.add(internalName) + } + } else { + LorenzDebug.log("cannot read file: '$file'") + } + } + + LorenzDebug.log("all vanilla items: ${vanillaItems.size}") + vanillaItems.forEach { LorenzDebug.log(it) } + } + + private fun getJsonFromFile(file: File): JsonObject? { + try { + BufferedReader(InputStreamReader(FileInputStream(file), + StandardCharsets.UTF_8 + )).use { reader -> return gson.fromJson(reader, JsonObject::class.java) } + } catch (e: Exception) { + return null + } + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt b/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt index 52caa59d0..4bc2939fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt +++ b/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt @@ -1,11 +1,12 @@ package at.hannibal2.skyhanni.items.abilitycooldown import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.ItemUtil.asStringSet -import at.hannibal2.skyhanni.utils.ItemUtil.getExtraAttributes import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.client.Minecraft import net.minecraft.init.Items +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound +import net.minecraft.nbt.NBTTagList import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement import net.minecraft.network.play.server.S1CPacketEntityMetadata import net.minecraft.network.play.server.S2APacketParticles @@ -62,4 +63,12 @@ class WitherImpactDetection(private val itemAbilityCooldown: ItemAbilityCooldown if (diff < 0) lastShieldUse = -1 } } + + private fun getExtraAttributes(item: ItemStack?): NBTTagCompound? { + return if (item == null || !item.hasTagCompound()) { + null + } else item.getSubCompound("ExtraAttributes", false) + } + + private fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) } } \ No newline at end of file -- cgit