diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-09-12 00:01:31 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-09-12 00:01:31 +0200 |
commit | c6b688f864c28fcd7c1cbcb248086e5caee7f230 (patch) | |
tree | dc3a1f86ae8fa46d520567a668dbff2be181a9ac /src/main/java/at/hannibal2/skyhanni/features/items | |
parent | 8e55249bf19a44d829d802f14d31668a12239a12 (diff) | |
download | skyhanni-c6b688f864c28fcd7c1cbcb248086e5caee7f230.tar.gz skyhanni-c6b688f864c28fcd7c1cbcb248086e5caee7f230.tar.bz2 skyhanni-c6b688f864c28fcd7c1cbcb248086e5caee7f230.zip |
edited features order and made better wording
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/items')
7 files changed, 0 insertions, 1120 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt deleted file mode 100644 index 2829742dc..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/HideNotClickableItems.kt +++ /dev/null @@ -1,418 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.utils.* -import at.hannibal2.skyhanni.utils.ItemUtils.cleanName -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import com.google.gson.JsonObject -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.inventory.ContainerChest -import net.minecraft.item.ItemStack -import net.minecraftforge.event.entity.player.ItemTooltipEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class HideNotClickableItems { - - private var hideReason = "" - - private var lastClickTime = 0L - private var bypassUntil = 0L - - private val hideNpcSellFilter = MultiFilter() - private val hideInStorageFilter = MultiFilter() - private val tradeNpcFilter = MultiFilter() - private val itemsToSalvage = mutableListOf<String>() - private val hidePlayerTradeFilter = MultiFilter() - private val notAuctionableFilter = MultiFilter() - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - try { - val hideNotClickableItems = event.getConstant("HideNotClickableItems")!! - hideNpcSellFilter.load(hideNotClickableItems["hide_npc_sell"].asJsonObject) - hideInStorageFilter.load(hideNotClickableItems["hide_in_storage"].asJsonObject) - tradeNpcFilter.load(event.getConstant("TradeNpcs")!!) - updateSalvageList(hideNotClickableItems) - hidePlayerTradeFilter.load(hideNotClickableItems["hide_player_trade"].asJsonObject) - notAuctionableFilter.load(hideNotClickableItems["not_auctionable"].asJsonObject) - - } catch (e: Exception) { - e.printStackTrace() - LorenzUtils.error("error in RepositoryReloadEvent") - } - } - - private fun updateSalvageList(hideNotClickableItems: JsonObject) { - itemsToSalvage.clear() - val salvage = hideNotClickableItems["salvage"].asJsonObject - itemsToSalvage.addAll(salvage.asJsonObject["items"].asJsonArray.map { it.asString }) - for (armor in salvage.asJsonObject["armor"].asJsonArray.map { it.asString }) { - itemsToSalvage.add("$armor Helmet") - itemsToSalvage.add("$armor Chestplate") - itemsToSalvage.add("$armor Leggings") - itemsToSalvage.add("$armor Boots") - } - } - - @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!LorenzUtils.inSkyblock) return - if (isDisabled()) return - if (event.gui !is GuiChest) return - val guiChest = event.gui - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - for (slot in chest.inventorySlots) { - if (slot == null) continue - - if (slot.slotNumber == slot.slotIndex) continue - if (slot.stack == null) continue - - if (hide(chestName, slot.stack)) { -// val color = LorenzColor.DARK_GRAY.addOpacity(160) -// val color = LorenzColor.DARK_GRAY.addOpacity(LorenzTest.a.toInt()) - val opacity = SkyHanniMod.feature.inventory.hideNotClickableOpacity - val color = LorenzColor.DARK_GRAY.addOpacity(opacity) - slot.stack.background = color.rgb - } - } - } - - @SubscribeEvent(priority = EventPriority.LOWEST) - fun onTooltip(event: ItemTooltipEvent) { - if (isDisabled()) return - if (event.toolTip == null) return - val guiChest = Minecraft.getMinecraft().currentScreen - if (guiChest !is GuiChest) return - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - val stack = event.itemStack - if (InventoryUtils.getItemsInOpenChest().map { it.stack }.contains(stack)) return - if (!ItemUtils.getItemsInInventory().contains(stack)) return - - if (hide(chestName, stack)) { - val first = event.toolTip[0] - event.toolTip.clear() - event.toolTip.add("§7" + first.removeColor()) - event.toolTip.add("") - if (hideReason == "") { - event.toolTip.add("§4No hide reason!") - LorenzUtils.warning("No hide reason for not clickable item!") - } else { - event.toolTip.add("§c$hideReason") - } - } - } - - @SubscribeEvent - fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - if (isDisabled()) return - if (event.gui !is GuiChest) return - val guiChest = event.gui - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - val slot = event.slot ?: return - - if (slot.slotNumber == slot.slotIndex) return - if (slot.stack == null) return - - val stack = slot.stack - - if (hide(chestName, stack)) { - event.isCanceled = true - - if (System.currentTimeMillis() > lastClickTime + 5_000) { - lastClickTime = System.currentTimeMillis() - } - return - } - } - - private fun isDisabled(): Boolean { - if (bypassUntil > System.currentTimeMillis()) return true - - return !SkyHanniMod.feature.inventory.hideNotClickableItems - } - - private fun hide(chestName: String, stack: ItemStack): Boolean { - hideReason = "" - return when { - hideNpcSell(chestName, stack) -> true - hideInStorage(chestName, stack) -> true - hideSalvage(chestName, stack) -> true - hidePlayerTrade(chestName, stack) -> true - hideBazaarOrAH(chestName, stack) -> true - hideAccessoryBag(chestName, stack) -> true - hideSackOfSacks(chestName, stack) -> true - hideFishingBag(chestName, stack) -> true - hidePotionBag(chestName, stack) -> true - hidePrivateIslandChest(chestName, stack) -> true - hideAttributeFusion(chestName, stack) -> true - hideYourEquipment(chestName, stack) -> true - else -> false - } - } - - private fun hideYourEquipment(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Your Equipment")) return false - - val list = listOf( - "HELMET", - "CHESTPLATE", - "LEGGINGS", - "BOOTS", - - "NECKLACE", - "CLOAK", - "BELT", - "GLOVES", - "BRACELET" - ) - for (type in list) { - if (stack.getLore().any { it.contains("§l") && it.contains(type) }) {//todo use item api - return false - } - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the potion bag!" - return true - } - - hideReason = "This item cannot be put into your equipment!" - return true - } - - private fun hideAttributeFusion(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Attribute Fusion")) return false - - if (ItemUtils.hasAttributes(stack)) return false - - hideReason = "This item has no attributes!" - return true - } - - private fun hidePrivateIslandChest(chestName: String, stack: ItemStack): Boolean { - if (chestName != "Chest" && chestName != "Large Chest") return false - //TODO make check if player is on private island - - if (!ItemUtils.isSoulBound(stack)) return false - - hideReason = "This item cannot be stored into a chest!" - return true - } - - private fun hidePotionBag(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Potion Bag")) return false - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the potion bag!" - return true - } - - if (stack.cleanName().endsWith(" Potion")) return false - - hideReason = "This item is not a potion!" - return true - } - - private fun hideFishingBag(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Fishing Bag")) return false - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the fishing bag!" - return true - } - - if (stack.getLore().any { it.removeColor() == "Fishing Bait" }) { - return false - } - hideReason = "This item is not a fishing bait!" - return true - } - - private fun hideSackOfSacks(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Sack of Sacks")) return false - - val name = stack.cleanName() - if (ItemUtils.isSack(name)) return false - if (isSkyBlockMenuItem(stack)) return false - - hideReason = "This item is not a sack!" - return true - } - - private fun hideAccessoryBag(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("Accessory Bag")) return false - - if (stack.getLore().any { it.contains("ACCESSORY") }) return false - if (isSkyBlockMenuItem(stack)) return false - - hideReason = "This item is not an accessory!" - return true - } - - private fun hidePlayerTrade(chestName: String, stack: ItemStack): Boolean { - if (!chestName.startsWith("You ")) return false - - if (ItemUtils.isCoopSoulBound(stack)) { - hideReason = "Soulbound items cannot be traded!" - return true - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be traded!" - return true - } - - val name = stack.cleanName() - - if (ItemUtils.isSack(name)) { - hideReason = "Sacks cannot be traded!" - return true - } - - val result = hidePlayerTradeFilter.match(name) - LorenzDebug.log("hidePlayerTradeList filter result for '$name': $result") - - if (result) hideReason = "This item cannot be traded!" - return result - } - - private fun hideNpcSell(chestName: String, stack: ItemStack): Boolean { - if (!tradeNpcFilter.match(chestName)) return false - - var name = stack.cleanName() - val size = stack.stackSize - val amountText = " x$size" - if (name.endsWith(amountText)) { - name = name.substring(0, name.length - amountText.length) - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be sold at the NPC!" - return true - } - - 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!" - return true - } - - private fun hideInStorage(chestName: String, stack: ItemStack): Boolean { - if (!chestName.contains("Ender Chest") && !chestName.contains("Backpack") && chestName != "Storage") return false - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be put into the storage!" - return true - } - - val name = stack.cleanName() - - if (ItemUtils.isSack(name)) { - hideReason = "Sacks cannot be put into the storage!" - return true - } - - val result = hideInStorageFilter.match(name) - - if (result) hideReason = "Bags cannot be put into the storage!" - return result - } - - private fun hideSalvage(chestName: String, stack: ItemStack): Boolean { - if (chestName != "Salvage Item") return false - - if (ItemUtils.isRecombobulated(stack)) { - hideReason = "This item should not be salvaged! (Recombobulated)" - return true - } - for (line in stack.getLore()) { - if (line.contains("LEGENDARY DUNGEON")) { - hideReason = "This item should not be salvaged! (Legendary)" - return true - } - } - - if (isSkyBlockMenuItem(stack)) { - hideReason = "The SkyBlock Menu cannot be salvaged!" - return true - } - - val name = stack.cleanName() - for (item in itemsToSalvage) { - if (name.endsWith(item)) { - return false - } - } - - hideReason = "This item cannot be salvaged!" - return true - } - - private fun hideBazaarOrAH(chestName: String, stack: ItemStack): Boolean { - val bazaarInventory = BazaarApi.isBazaarInventory(chestName) - - val auctionHouseInventory = - chestName == "Co-op Auction House" || chestName == "Auction House" || chestName == "Create BIN Auction" || chestName == "Create Auction" - if (!bazaarInventory && !auctionHouseInventory) return false - - - - if (isSkyBlockMenuItem(stack)) { - if (bazaarInventory) hideReason = "The SkyBlock Menu is not a Bazaar Product!" - if (auctionHouseInventory) hideReason = "The SkyBlock Menu cannot be auctioned!" - return true - } - - if (bazaarInventory != BazaarApi.isBazaarItem(stack)) { - if (bazaarInventory) hideReason = "This item is not a Bazaar Product!" - if (auctionHouseInventory) hideReason = "Bazaar Products cannot be auctioned!" - - return true - } - - if (isNotAuctionable(stack)) return true - - return false - } - - private fun isNotAuctionable(stack: ItemStack): Boolean { - if (ItemUtils.isCoopSoulBound(stack)) { - hideReason = "Soulbound items cannot be auctioned!" - return true - } - - val name = stack.cleanName() - - if (ItemUtils.isSack(name)) { - hideReason = "Sacks cannot be auctioned!" - return true - } - - val result = notAuctionableFilter.match(name) - if (result) hideReason = "This item cannot be auctioned!" - return result - } - - private fun isSkyBlockMenuItem(stack: ItemStack): Boolean = stack.getInternalName() == "SKYBLOCK_MENU" -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt deleted file mode 100644 index bc4caf181..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/ItemDisplayOverlayFeatures.kt +++ /dev/null @@ -1,120 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.utils.ItemUtils -import at.hannibal2.skyhanni.utils.ItemUtils.cleanName -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between -import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex -import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.item.ItemStack -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class ItemDisplayOverlayFeatures { - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - val stack = event.stack ?: return - - if (!LorenzUtils.inSkyblock || stack.stackSize != 1) return - - val stackTip = getStackTip(stack) - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - private fun getStackTip(item: ItemStack): String { - val name = item.cleanName() - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(0)) { - when (name) { - "First Master Star" -> return "1" - "Second Master Star" -> return "2" - "Third Master Star" -> return "3" - "Fourth Master Star" -> return "4" - "Fifth Master Star" -> return "5" - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(1)) { - if (name.matchRegex("(.*)Master Skull - Tier .")) { - return name.substring(name.length - 1) - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(2)) { - if (name.contains("Golden ") || name.contains("Diamond ")) { - when { - name.contains("Bonzo") -> return "1" - name.contains("Scarf") -> return "2" - name.contains("Professor") -> return "3" - name.contains("Thorn") -> return "4" - name.contains("Livid") -> return "5" - name.contains("Sadan") -> return "6" - name.contains("Necron") -> return "7" - } - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(3)) { - if (name.startsWith("New Year Cake (")) { - return "§b" + name.between("(Year ", ")") - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(4)) { - if (ItemUtils.isPet(name)) { - val level = name.between("Lvl ", "] ").toInt() - if (level != ItemUtils.maxPetLevel(name)) { - return "$level" - } - } - } - - if (SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(5)) { - if (name.contains(" Minion ")) { - if (item.getLore().any { it.contains("Place this minion") }) { - val array = name.split(" ") - val last = array[array.size - 1] - return last.romanToDecimal().toString() - } - } - } - - if (SkyHanniMod.feature.inventory.displaySackName) { - if (ItemUtils.isSack(name)) { - //TODO fix this and replace other -// val sackName = grabSackName(name) - val split = name.split(" ") - val sackName = split[split.size - 2] - return (if (name.contains("Enchanted")) "§5" else "") + sackName.substring(0, 2) - } - } - - return "" - } - -// private fun grabSackName(name: String): String { -// val split = name.split(" ") -// val text = split[0] -// for (line in arrayOf("Large", "Medium", "Small", "Enchanted")) { -// if (text == line) return grabSackName(name.substring(text.length + 1)) -// } -// return text -// } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt b/src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt deleted file mode 100644 index 0301ddb53..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/ItemStars.kt +++ /dev/null @@ -1,150 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.client.renderer.GlStateManager -import net.minecraftforge.event.entity.player.ItemTooltipEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.regex.Pattern - -class ItemStars { - - private val armorNames = mutableListOf<String>() - private val tiers = mutableMapOf<String, Int>() - private val STAR_FIND_PATCHER = Pattern.compile("(.*)§.✪(.*)") - private val armorParts = listOf("Helmet", "Chestplate", "Leggings", "Boots") - - @SubscribeEvent(priority = EventPriority.LOW) - fun onTooltip(event: ItemTooltipEvent) { - if (!LorenzUtils.inSkyblock) return - - val stack = event.itemStack ?: return - if (stack.stackSize != 1) return - if (!SkyHanniMod.feature.inventory.itemStars) return - - val itemName = stack.name ?: return - val stars = getStars(itemName) - - if (stars > 0) { - var name = itemName - while (STAR_FIND_PATCHER.matcher(name).matches()) { - name = name.replaceFirst("§.✪".toRegex(), "") - } - name = name.trim() - event.toolTip[0] = "$name §c$stars✪" - } - } - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - try { - val items = event.getConstant("Items")!! - if (items.has("crimson_armors")) { - armorNames.clear() - armorNames.addAll(items.getAsJsonArray("crimson_armors").map { it.asString }) - } - - tiers.clear() - if (items.has("crimson_tiers")) { - items.getAsJsonObject("crimson_tiers").entrySet().forEach { - tiers[it.key] = it.value.asInt - } - } - - } catch (e: Exception) { - e.printStackTrace() - LorenzUtils.error("error in RepositoryReloadEvent") - } - } - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - if (!LorenzUtils.inSkyblock) return - if (!SkyHanniMod.feature.inventory.itemNumberAsStackSize.contains(6)) return - - val stack = event.stack ?: return - if (stack.stackSize != 1) return - val number = getCrimsonStars(stack.name ?: return) - val stackTip = if (number == -1) "" else number.toString() - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(),//TODO search for this line and replace all other methods into an api - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - private fun getStars(name: String): Int { - val stars = getCrimsonStars(name) - if (stars != -1) { - return stars - } - - return getOtherStars(name) - } - - private fun getCrimsonStars(name: String): Int { - if (!armorNames.any { name.contains(it) } || !armorParts.any { name.contains(it) }) { - return -1 - } - var name1 = name - var gold = 0 - var pink = 0 - var aqua = 0 - while (name1.contains("§6✪")) { - name1 = name1.replaceFirst("§6✪", "") - gold++ - } - while (name1.contains("§d✪")) { - name1 = name1.replaceFirst("§d✪", "") - pink++ - } - while (name1.contains("§b✪")) { - name1 = name1.replaceFirst("§b✪", "") - aqua++ - } - return (tiers.entries.find { name1.contains(it.key) }?.value ?: 0) + if (aqua > 0) { - 10 + aqua - } else if (pink > 0) { - 5 + pink - } else { - gold - } - } - - private fun getOtherStars(originalName: String): Int { - var name = originalName - - var gold = 0 - var red = 0 - while (name.contains("§6✪")) { - name = name.replaceFirst("§6✪", "") - gold++ - } - while (name.contains("§c✪")) { - name = name.replaceFirst("§c✪", "") - red++ - } - while (name.contains("§d✪")) { - name = name.replaceFirst("§d✪", "") - red++ - } - - if (red > 0) return 5 + red - if (gold > 0) return gold - - return -1 - } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt deleted file mode 100644 index 19c4ea249..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/RngMeterInventory.kt +++ /dev/null @@ -1,91 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between -import at.hannibal2.skyhanni.utils.RenderUtils.highlight -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.inventory.ContainerChest -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class RngMeterInventory { - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - if (!LorenzUtils.inSkyblock) return - - val screen = Minecraft.getMinecraft().currentScreen - if (screen !is GuiChest) return - val chest = screen.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - var stackTip = "" - - val stack = event.stack ?: return - if (SkyHanniMod.feature.inventory.rngMeterFloorName) { - if (chestName == "Catacombs RNG Meter") { - val name = stack.name ?: return - if (name.removeColor() == "RNG Meter") { - stackTip = stack.getLore()[0].between("(", ")") - } - } - } - - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - @SubscribeEvent(priority = EventPriority.LOW) - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!LorenzUtils.inSkyblock) return - - if (event.gui !is GuiChest) return - val guiChest = event.gui - val chest = guiChest.inventorySlots as ContainerChest - val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() - - if (SkyHanniMod.feature.inventory.rngMeterNoDrop) { - if (chestName == "Catacombs RNG Meter") { - for (slot in InventoryUtils.getItemsInOpenChest()) { - val stack = slot.stack - if (stack.getLore().any { it.contains("You don't have an RNG drop") }) { - slot highlight LorenzColor.RED - } - } - } - } - - if (SkyHanniMod.feature.inventory.rngMeterSelectedDrop) { - if (chestName.endsWith(" RNG Meter")) { - for (slot in InventoryUtils.getItemsInOpenChest()) { - val stack = slot.stack - if (stack.getLore().any { it.contains("§aSELECTED") }) { - slot highlight LorenzColor.YELLOW - } - } - } - } - } -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt b/src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt deleted file mode 100644 index f138d9c23..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/VanillaItemManager.kt +++ /dev/null @@ -1,53 +0,0 @@ -package at.hannibal2.skyhanni.features.items - -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) - } - } - } - - } - - 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/features/items/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/ItemAbilityCooldown.kt deleted file mode 100644 index b2974837b..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/ItemAbilityCooldown.kt +++ /dev/null @@ -1,214 +0,0 @@ -package at.hannibal2.skyhanni.features.items.abilitycooldown - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background -import at.hannibal2.skyhanni.events.GuiRenderItemEvent -import at.hannibal2.skyhanni.events.LorenzActionBarEvent -import at.hannibal2.skyhanni.utils.ItemUtils -import at.hannibal2.skyhanni.utils.ItemUtils.cleanName -import at.hannibal2.skyhanni.utils.LorenzColor -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between -import net.minecraft.client.Minecraft -import net.minecraft.client.renderer.GlStateManager -import net.minecraft.item.ItemStack -import net.minecraftforge.common.MinecraftForge -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -class ItemAbilityCooldown { - - var lastAbility = "" - var tick = 0 - val items = mutableMapOf<ItemStack, ItemText>() - val witherImpactDetection = WitherImpactDetection(this) - - init { - MinecraftForge.EVENT_BUS.register(witherImpactDetection) - } - - fun clickWitherImpact() { - Ability.WITHER_IMPACT.click() - } - - @SubscribeEvent - fun onActionBar(event: LorenzActionBarEvent) { - if (!isEnabled()) return - - val message: String = event.message - if (message.contains(" (§6")) { - if (message.contains("§b) ")) { - val name: String = message.between(" (§6", "§b) ") - if (name == lastAbility) return - lastAbility = name - for (ability in Ability.values()) { - if (ability.abilityName == name) { - click(ability) - return - } - } - return - } - } - lastAbility = "" - } - - private fun isEnabled(): Boolean { - return LorenzUtils.inSkyblock && SkyHanniMod.feature.abilities.itemAbilityCooldown - } - - private fun click(ability: Ability) { -// if (ability.isActive()) return - if (!ability.actionBarDetection) return - ability.click() - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!isEnabled()) return - - tick++ - if (tick % 2 == 0) { - checkHotbar() - } - } - - private fun checkHotbar() { - items.clear() - for ((stack, slot) in ItemUtils.getItemsInInventoryWithSlots(true)) { -// val inHotbar = slot in 36..43 - - val itemName: String = stack.cleanName() - val ability = hasAbility(itemName) - if (ability != null) { - - if (ability.isOnCooldown()) { - val duration: Long = ability.lastClick + ability.getCooldown() - System.currentTimeMillis() - val color = if (duration < 600) LorenzColor.RED else LorenzColor.YELLOW - items[stack] = ItemText(color, ability.getDurationText(), true) - } else { - items[stack] = ItemText(LorenzColor.GREEN, "R", false) - } - } - } - - } - - @SubscribeEvent - fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) { - if (!isEnabled()) return - - val item = event.stack ?: return - if (item.stackSize != 1) return - - var stackTip = "" - - val guiOpen = Minecraft.getMinecraft().currentScreen != null - val itemText = items.filter { it.key == item } - .firstNotNullOfOrNull { it.value } ?: return - if (guiOpen && !itemText.onCooldown) return - - val color = itemText.color - stackTip = color.getChatColor() + itemText.text - - if (SkyHanniMod.feature.abilities.itemAbilityCooldownBackground) { - var opacity = 130 - if (color == LorenzColor.GREEN) { - opacity = 80 - } - item.background = color.addOpacity(opacity).rgb - } - - if (stackTip.isNotEmpty()) { - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.disableBlend() - event.fontRenderer.drawStringWithShadow( - stackTip, - (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(), - (event.y + 9).toFloat(), - 16777215 - ) - GlStateManager.enableLighting() - GlStateManager.enableDepth() - } - } - - private fun hasAbility(itemName: String): Ability? { - for (ability in Ability.values()) { - for (name in ability.itemNames) { - if (itemName.contains(name)) { - return ability - } - } - } - return null - } - - enum class Ability( - val abilityName: String, - val cooldownInSeconds: Long, - vararg val itemNames: String, - var lastClick: Long = 0L, - val actionBarDetection: Boolean = true, - ) { - //TODO add into repo - ATOMSPLIT("Soulcry", 4, "Atomsplit Katana", "Vorpal Katana", "Voidedge Katana"), - WITHER_IMPACT("Wither Impact", 5, "Hyperion", "Scylla", "Valkyrie", "Astrea", actionBarDetection = false), - - HEAL_1("Small Heal", 7, "Wand of Healing"), - HEAL_2("Medium Heal", 7, "Wand of Mending"), - HEAL_3("Big Heal", 7, "Wand of Restoration"), - HEAL_4("Huge Heal", 7, "Wand of Atonement"), - - ICE_SPRAY("Ice Spray", 5, "Ice Spray Wand"), - GYRO("Gravity Storm", 30, "Gyrokinetic Wand"), - GIANTS_SWORD("Giant's Slam", 30, "Giant's Sword"), - - STAR_FALL("Starfall", 2, "Starlight Wand"), - VODOO_DOLL("Acupuncture", 5, "Voodoo Doll"), - INK_WAND("Ink Bomb", 30, "Ink Wand"), - GOLEM_SWORD("Iron Punch", 3, "Golem Sword"), - EMBER_ROD("Fire Blast", 30, "Ember Rod"), - ENDER_BOW("Ender Warp", 30, "Ender Bow"), - - LIVID_DAGGER("Throw", 5, "Livid Dagger"), - WEIRD_TUBA("Howl", 20, "Weird Tuba"), - - ENDSTONE_SWORD("Extreme Focus", 5, "End Stone Sword"), - PIGMAN_SWORD("Burning Souls", 5, "Pigman Sword"), - - SOULWARD("Soulward", 20, "Soul Esoward"), - ECHO("Echo", 3, "Ancestral Spade"), - - FIRE_VEIL("Fire Veil", 5, "Fire Veil Wand"), - //TODO add new crimson isle weapons - - ; - - fun click() { - lastClick = System.currentTimeMillis() - } - - fun isOnCooldown(): Boolean = lastClick + getCooldown() > System.currentTimeMillis() - - fun getCooldown(): Long = cooldownInSeconds * 1000 - - fun getDurationText(): String { - var duration: Long = lastClick + getCooldown() - System.currentTimeMillis() - return if (duration < 1600) { - duration /= 100 - var d = duration.toDouble() - d /= 10.0 - LorenzUtils.formatDouble(d) - } else { - duration /= 1000 - duration++ - LorenzUtils.formatInteger(duration.toInt()) - } - } - - } - - class ItemText(val color: LorenzColor, val text: String, val onCooldown: Boolean) -}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt b/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt deleted file mode 100644 index da0d5068c..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/items/abilitycooldown/WitherImpactDetection.kt +++ /dev/null @@ -1,74 +0,0 @@ -package at.hannibal2.skyhanni.features.items.abilitycooldown - -import at.hannibal2.skyhanni.events.PacketEvent -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 -import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.common.util.Constants -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -/** - * Taken from Skytils under AGPL 3.0 - * Modified - * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md - * @author Skytils - */ -class WitherImpactDetection(private val itemAbilityCooldown: ItemAbilityCooldown) { - - val S2APacketParticles.type: EnumParticleTypes - get() = this.particleType - var lastShieldUse = -1L - var lastShieldClick = 0L - - @SubscribeEvent - fun onReceivePacket(event: PacketEvent.ReceiveEvent) { - val mc = Minecraft.getMinecraft() - if (!LorenzUtils.inSkyblock || mc.theWorld == null) return - - event.packet.apply { - - if (this is S1CPacketEntityMetadata && lastShieldClick != -1L && entityId == mc.thePlayer?.entityId && System.currentTimeMillis() - lastShieldClick <= 500 && func_149376_c()?.any { it.dataValueId == 17 } == true) { - lastShieldUse = System.currentTimeMillis() - lastShieldClick = -1 - itemAbilityCooldown.clickWitherImpact() - } - } - } - - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - val mc = Minecraft.getMinecraft() - if (!LorenzUtils.inSkyblock || lastShieldUse != -1L || mc.thePlayer?.heldItem == null) return - if (event.packet is C08PacketPlayerBlockPlacement && mc.thePlayer.heldItem.item == Items.iron_sword && getExtraAttributes( - mc.thePlayer.heldItem - )?.getTagList("ability_scroll", Constants.NBT.TAG_STRING)?.asStringSet() - ?.contains("WITHER_SHIELD_SCROLL") == true - ) { - lastShieldClick = System.currentTimeMillis() - } - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (lastShieldUse != -1L) { - val diff = ((lastShieldUse + 5000 - System.currentTimeMillis()) / 1000f) - 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 |