aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java2
-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
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtil.kt215
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt66
7 files changed, 142 insertions, 225 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 855a3870f..5c7d11070 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.fishing.TrophyFishMessages;
import at.hannibal2.skyhanni.inventory.anvil.AnvilCombineHelper;
import at.hannibal2.skyhanni.items.HideNotClickableItems;
import at.hannibal2.skyhanni.items.ItemDisplayOverlayFeatures;
+import at.hannibal2.skyhanni.items.VanillaItemManager;
import at.hannibal2.skyhanni.items.abilitycooldown.ItemAbilityCooldown;
import at.hannibal2.skyhanni.misc.*;
import at.hannibal2.skyhanni.repo.RepoManager;
@@ -57,6 +58,7 @@ public class SkyHanniMod {
MinecraftForge.EVENT_BUS.register(new ScoreboardData());
MinecraftForge.EVENT_BUS.register(new ApiData());
MinecraftForge.EVENT_BUS.register(new SeaCreatureManager());
+ MinecraftForge.EVENT_BUS.register(new VanillaItemManager());
MinecraftForge.EVENT_BUS.register(new BazaarOrderHelper());
MinecraftForge.EVENT_BUS.register(new ChatFilter());
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
diff --git a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt
index 9b5e9621f..3d2611517 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt
@@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.test
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.GuiRender.renderString
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.LorenzDebug
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -28,7 +28,7 @@ class LorenzTest {
print("===")
print("ITEM LORE")
print("display name: '" + itemStack.displayName.toString() + "'")
- val itemID = itemStack.getSBItemID()
+ val itemID = itemStack.getInternalName()
print("itemID: '$itemID'")
// val rarity: ItemRarityOld = ItemUtils.getRarity(itemStack)
// print("rarity: '$rarity'")
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtil.kt
deleted file mode 100644
index 73f507964..000000000
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtil.kt
+++ /dev/null
@@ -1,215 +0,0 @@
-package at.hannibal2.skyhanni.utils
-
-import net.minecraft.init.Items
-import net.minecraft.item.ItemStack
-import net.minecraft.nbt.NBTTagCompound
-import net.minecraft.nbt.NBTTagList
-import net.minecraft.nbt.NBTTagString
-import net.minecraftforge.common.util.Constants
-import java.util.*
-
-object ItemUtil {
- private val PET_PATTERN = "§7\\[Lvl \\d+] (?<color>§[0-9a-fk-or]).+".toRegex()
- const val NBT_INTEGER = 3
- private const val NBT_STRING = 8
- private const val NBT_LIST = 9
- private const val NBT_COMPOUND = 10
-
- /**
- * Returns the display name of a given item
- * @author Mojang
- * @param item the Item to get the display name of
- * @return the display name of the item
- */
- @JvmStatic
- fun getDisplayName(item: ItemStack): String {
- var s = item.item.getItemStackDisplayName(item)
- if (item.tagCompound != null && item.tagCompound.hasKey("display", 10)) {
- val nbtTagCompound = item.tagCompound.getCompoundTag("display")
- if (nbtTagCompound.hasKey("Name", 8)) {
- s = nbtTagCompound.getString("Name")
- }
- }
- return s
- }
-
- /**
- * Returns the Skyblock Item ID of a given Skyblock item
- *
- * @author BiscuitDevelopment
- * @param item the Skyblock item to check
- * @return the Skyblock Item ID of this item or `null` if this isn't a valid Skyblock item
- */
- @JvmStatic
- fun getSkyBlockItemID(item: ItemStack?): String? {
- if (item == null) {
- return null
- }
- val extraAttributes = getExtraAttributes(item) ?: return null
- return if (!extraAttributes.hasKey("id", NBT_STRING)) {
- null
- } else extraAttributes.getString("id")
- }
-
- /**
- * Returns the `ExtraAttributes` compound tag from the item's NBT data.
- *
- * @author BiscuitDevelopment
- * @param item the item to get the tag from
- * @return the item's `ExtraAttributes` compound tag or `null` if the item doesn't have one
- */
- @JvmStatic
- fun getExtraAttributes(item: ItemStack?): NBTTagCompound? {
- return if (item == null || !item.hasTagCompound()) {
- null
- } else item.getSubCompound("ExtraAttributes", false)
- }
-
- /**
- * Returns the Skyblock Item ID of a given Skyblock Extra Attributes NBT Compound
- *
- * @author BiscuitDevelopment
- * @param extraAttributes the NBT to check
- * @return the Skyblock Item ID of this item or `null` if this isn't a valid Skyblock NBT
- */
- @JvmStatic
- fun getSkyBlockItemID(extraAttributes: NBTTagCompound?): String? {
- if (extraAttributes != null) {
- val itemId = extraAttributes.getString("id")
- if (itemId.isNotEmpty()) {
- return itemId
- }
- }
- return null
- }
-
- /**
- * Returns a string list containing the nbt lore of an ItemStack, or
- * an empty list if this item doesn't have a lore. The returned lore
- * list is unmodifiable since it has been converted from an NBTTagList.
- *
- * @author BiscuitDevelopment
- * @param itemStack the ItemStack to get the lore from
- * @return the lore of an ItemStack as a string list
- */
- @JvmStatic
- fun getItemLore(itemStack: ItemStack): List<String> {
- if (itemStack.hasTagCompound() && itemStack.tagCompound.hasKey("display", NBT_COMPOUND)) {
- val display = itemStack.tagCompound.getCompoundTag("display")
- if (display != null) {
- if (display.hasKey("Lore", NBT_LIST)) {
- val lore = display.getTagList("Lore", NBT_STRING)
- val loreAsList = ArrayList<String>(lore.tagCount())
- for (lineNumber in 0 until lore.tagCount()) {
- loreAsList.add(lore.getStringTagAt(lineNumber))
- }
- return Collections.unmodifiableList(loreAsList)
- }
- }
- }
- return emptyList()
- }
-
-// @JvmStatic
-// fun hasRightClickAbility(itemStack: ItemStack): Boolean {
-// for (line in getItemLore(itemStack)) {
-// val stripped = line.stripControlCodes()
-// if (stripped.startsWith("Item Ability:") && stripped.endsWith("RIGHT CLICK")) return true
-// }
-// return false
-// }
-
-// /**
-// * Returns the rarity of a given Skyblock item
-// * Modified
-// * @author BiscuitDevelopment
-// * @param item the Skyblock item to check
-// * @return the rarity of the item if a valid rarity is found, `null` if no rarity is found, `null` if item is `null`
-// */
-// fun getRarity(item: ItemStack?): ItemRarity {
-// if (item == null || !item.hasTagCompound()) {
-// return ItemRarity.NONE
-// }
-// val display = item.getSubCompound("display", false)
-// if (display == null || !display.hasKey("Lore")) {
-// return ItemRarity.NONE
-// }
-// val lore = display.getTagList("Lore", Constants.NBT.TAG_STRING)
-// val name = display.getString("Name")
-//
-// // Determine the item's rarity
-// for (i in (lore.tagCount() - 1) downTo 0) {
-// val currentLine = lore.getStringTagAt(i)
-// val rarityMatcher = RARITY_PATTERN.find(currentLine)
-// if (rarityMatcher != null) {
-// val rarity = rarityMatcher.groups["rarity"]?.value ?: continue
-// ItemRarity.values().find {
-// it.rarityName == rarity.stripControlCodes().substringAfter("SHINY ")
-// }?.let {
-// return it
-// }
-// }
-// }
-// val petRarityMatcher = PET_PATTERN.find(name)
-// if (petRarityMatcher != null) {
-// val color = petRarityMatcher.groupValues.getOrNull(1) ?: return ItemRarity.NONE
-// return ItemRarity.byBaseColor(color) ?: ItemRarity.NONE
-// }
-//
-// // If the item doesn't have a valid rarity, return null
-// return ItemRarity.NONE
-// }
-
- fun isPet(item: ItemStack?): Boolean {
- if (item == null || !item.hasTagCompound()) {
- return false
- }
- val display = item.getSubCompound("display", false)
- if (display == null || !display.hasKey("Lore")) {
- return false
- }
- val name = display.getString("Name")
-
- return PET_PATTERN.matches(name)
- }
-
- fun setSkullTexture(item: ItemStack, texture: String, SkullOwner: String): ItemStack {
- val textureTagCompound = NBTTagCompound()
- textureTagCompound.setString("Value", texture)
-
- val textures = NBTTagList()
- textures.appendTag(textureTagCompound)
-
- val properties = NBTTagCompound()
- properties.setTag("textures", textures)
-
- val skullOwner = NBTTagCompound()
- skullOwner.setString("Id", SkullOwner)
- skullOwner.setTag("Properties", properties)
-
- val nbtTag = NBTTagCompound()
- nbtTag.setTag("SkullOwner", skullOwner)
-
- item.tagCompound = nbtTag
- return item
- }
-
- fun getSkullTexture(item: ItemStack): String? {
- if (item.item != Items.skull) return null
- val nbt = item.tagCompound
- if (!nbt.hasKey("SkullOwner")) return null
- return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties")
- .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value")
- }
-
- fun ItemStack.setLore(lines: List<String>): ItemStack {
- setTagInfo("display", getSubCompound("display", true).apply {
- setTag("Lore", NBTTagList().apply {
- for (line in lines) appendTag(NBTTagString(line))
- })
- })
- return this
- }
-
- fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) }
-} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 8a822d7b9..db1767214 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -7,9 +7,10 @@ import com.google.gson.JsonObject
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.item.ItemStack
-import java.util.LinkedList
+import java.util.*
object ItemUtils {
+ private val gson = GsonBuilder().setPrettyPrinting().create()
fun ItemStack.cleanName() = this.displayName.removeColorCodes()
@@ -32,7 +33,18 @@ object ItemUtils {
fun isSack(name: String): Boolean = name.endsWith(" Sack")//TODO change
- fun ItemStack.getLore() = ItemUtil.getItemLore(this)
+ fun ItemStack.getLore() = getLoree(this)
+
+
+ fun getLoree(`is`: ItemStack): List<String> {
+ val tagCompound = `is`.tagCompound ?: return emptyList()
+ val tagList = tagCompound.getCompoundTag("display").getTagList("Lore", 8)
+ val list: MutableList<String> = ArrayList()
+ for (i in 0 until tagList.tagCount()) {
+ list.add(tagList.getStringTagAt(i))
+ }
+ return list
+ }
fun isCoopSoulBound(stack: ItemStack): Boolean =
stack.getLore().any {
@@ -120,7 +132,53 @@ object ItemUtils {
return false
}
- fun ItemStack.getSBItemID(): String {
- return ItemUtil.getSkyBlockItemID(this) ?: ""
+ fun ItemStack.getInternalName(): String {
+ val tag = tagCompound
+ if (tag == null || !tag.hasKey("ExtraAttributes", 10)) return ""
+
+ val extraAttributes = tag.getCompoundTag("ExtraAttributes")
+ var internalName = if (extraAttributes.hasKey("id", 8)) {
+ extraAttributes.getString("id").replace(":".toRegex(), "-")
+ } else {
+ return ""
+ }
+
+ if (internalName == "PET") {
+ val petInfo = extraAttributes.getString("petInfo")
+ if (petInfo.isNotEmpty()) {
+ val petInfoObject: JsonObject = gson.fromJson(petInfo, JsonObject::class.java)
+ internalName = petInfoObject["type"].asString
+ return when (petInfoObject["tier"].asString) {
+ "COMMON" -> "$internalName;0"
+ "UNCOMMON" -> "$internalName;1"
+ "RARE" -> "$internalName;2"
+ "EPIC" -> "$internalName;3"
+ "LEGENDARY" -> "$internalName;4"
+ "MYTHIC" -> "$internalName;5"
+ else -> internalName
+ }
+ }
+ }
+
+ if (internalName == "ENCHANTED_BOOK" && extraAttributes.hasKey("enchantments", 10)) {
+ val enchants = extraAttributes.getCompoundTag("enchantments")
+ for (enchantment in enchants.keySet) {
+ return enchantment.uppercase(Locale.getDefault()) + ";" + enchants.getInteger(enchantment)
+ }
+ }
+
+ if (internalName == "RUNE" && extraAttributes.hasKey("runes", 10)) {
+ val rune = extraAttributes.getCompoundTag("runes")
+ for (enchantment in rune.keySet) {
+ return enchantment.uppercase(Locale.getDefault()) + "_RUNE" + ";" + rune.getInteger(enchantment)
+ }
+ }
+
+ if (internalName == "PARTY_HAT_CRAB" && extraAttributes.getString("party_hat_color") != null) {
+ val crabHat = extraAttributes.getString("party_hat_color")
+ return "PARTY_HAT_CRAB" + "_" + crabHat.uppercase(Locale.getDefault())
+ }
+
+ return internalName
}
} \ No newline at end of file