summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/items
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-07-29 16:14:04 +0200
committerLorenz <lo.scherf@gmail.com>2022-07-29 16:14:04 +0200
commitbc2ccc0c39495921aee82664266c1756f016b388 (patch)
tree5b4e931b96952673fc79822213b721cc8529afbb /src/main/java/at/hannibal2/skyhanni/items
parent1cacb26349e3b8bbe6c82ee7fd26782bb98f49ba (diff)
downloadskyhanni-bc2ccc0c39495921aee82664266c1756f016b388.tar.gz
skyhanni-bc2ccc0c39495921aee82664266c1756f016b388.tar.bz2
skyhanni-bc2ccc0c39495921aee82664266c1756f016b388.zip
added support for vanilla items from neu. allowing all vanilla items to be sold to npc
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/items')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/items/HideNotClickableItems.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/items/VanillaItemManager.kt58
-rw-r--r--src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt13
3 files changed, 76 insertions, 4 deletions
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<String> = 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