Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added ULTRA RARE Book Notification. #1738

Merged
merged 21 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ import at.hannibal2.skyhanni.features.inventory.ShiftClickNPCSell
import at.hannibal2.skyhanni.features.inventory.SkyblockGuideHighlightFeature
import at.hannibal2.skyhanni.features.inventory.StatsTuning
import at.hannibal2.skyhanni.features.inventory.SuperCraftFeatures
import at.hannibal2.skyhanni.features.inventory.SuperpairsClicksAlert
import at.hannibal2.skyhanni.features.inventory.UltraRareBookAlert
import at.hannibal2.skyhanni.features.inventory.auctionhouse.AuctionHouseCopyUnderbidPrice
import at.hannibal2.skyhanni.features.inventory.auctionhouse.AuctionHouseOpenPriceWebsite
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi
Expand Down Expand Up @@ -356,7 +358,6 @@ import at.hannibal2.skyhanni.features.misc.ReplaceRomanNumerals
import at.hannibal2.skyhanni.features.misc.RestorePieceOfWizardPortalLore
import at.hannibal2.skyhanni.features.misc.ServerRestartTitle
import at.hannibal2.skyhanni.features.misc.SkyBlockKickDuration
import at.hannibal2.skyhanni.features.misc.SuperpairsClicksAlert
import at.hannibal2.skyhanni.features.misc.TabWidgetSettings
import at.hannibal2.skyhanni.features.misc.TimeFeatures
import at.hannibal2.skyhanni.features.misc.TpsCounter
Expand Down Expand Up @@ -878,6 +879,7 @@ class SkyHanniMod {
loadModule(Translator())
loadModule(CosmeticFollowingLine())
loadModule(SuperpairsClicksAlert())
loadModule(UltraRareBookAlert)
loadModule(PowderTracker)
loadModule(ModifyVisualWords)
loadModule(TabListReader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 45
const val CONFIG_VERSION = 46
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear
import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI
import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker
import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics
import at.hannibal2.skyhanni.features.inventory.UltraRareBookAlert
import at.hannibal2.skyhanni.features.mining.KingTalismanHelper
import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker
import at.hannibal2.skyhanni.features.minion.MinionFeatures
Expand Down Expand Up @@ -531,6 +532,10 @@ object Commands {
"shaddfoundburrowlocationsfromclipboard",
"Add all ever found burrow locations from clipboard"
) { AllBurrowsList.addFromClipboard() }
registerCommand(
"shtestultrararebook",
"Display the notification related to finding an ultra rare book"
) { UltraRareBookAlert.notification ("Enchantment VII") }
}

private fun internalCommands() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ public static class HarpConfig {
@ConfigOption(name = "Tia Relay Abiphone Network Maintenance", desc = "")
@Accordion
public TiaRelayConfig tiaRelay = new TiaRelayConfig();

@Expose
@ConfigOption(name = "Enchanting", desc = "")
@Accordion
public EnchantingConfig enchanting = new EnchantingConfig();

public static class EnchantingConfig {
@Expose
@ConfigOption(name = "Superpairs Clicks Alert", desc = "Display an alert when you reach the maximum clicks gained from Chronomatron or Ultrasequencer.")
@ConfigEditorBoolean
@FeatureToggle
public boolean superpairsClicksAlert = false;

@Expose
@ConfigOption(name = "ULTRA-RARE Book Alert", desc = "Sends a chat message, title and sound when you find an ULTRA-RARE book.")
@ConfigEditorBoolean
@FeatureToggle
public boolean ultraRareBookAlert = false;
}

}
raaaaaven marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ public class MiscConfig {
@FeatureToggle
public boolean accountUpgradeReminder = true;

@Expose
@ConfigOption(name = "Superpairs Clicks Alert", desc = "Display an alert when you reach the maximum clicks gained from Chronomatron or Ultrasequencer.")
@ConfigEditorBoolean
@FeatureToggle
public boolean superpairsClicksAlert = false;

@Expose
@ConfigOption(name = "NEU Heavy Pearls", desc = "Fixing NEU Heavy Pearl detection.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.misc
package at.hannibal2.skyhanni.features.inventory

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.utils.ChatUtils
Expand All @@ -11,7 +12,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class SuperpairsClicksAlert {

private val config get() = SkyHanniMod.feature.misc
private val config get() = SkyHanniMod.feature.inventory.helper.enchanting

private var roundsNeeded = -1
private val roundsNeededRegex = Regex("""(?:Chain|Series) of (\d+):""")
Expand Down Expand Up @@ -59,4 +60,9 @@ class SuperpairsClicksAlert {
roundsNeeded = -1
}
}

@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(46, "misc.superpairsClicksAlert", "inventory.helper.superpairsClicksAlert")
}
CalMWolfs marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package at.hannibal2.skyhanni.features.inventory

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils.createSound
import at.hannibal2.skyhanni.utils.SoundUtils.playSound
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.GlStateManager
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import kotlin.time.Duration.Companion.seconds

object UltraRareBookAlert {

private val config get() = SkyHanniMod.feature.inventory.helper.enchanting
private val dragonSound by lazy { createSound("mob.enderdragon.growl", 1f) }

private val patternGroup = RepoPattern.group("data.enchanting")
private val superpairsGui by patternGroup.pattern(
"inventory.experimentstable.gui",
"Superpairs.*"
)
private val ultraRarePattern by patternGroup.pattern(
"inventory.experimentstable.ultrarare",
"§d§kXX§5 ULTRA-RARE BOOK! §d§kXX"
)
private val bookPattern by patternGroup.pattern(
"inventory.experimentstable.book",
"§9(?<enchant>.*)"
)

private var enchantsFound = false

private var lastNotificationTime = SimpleTimeMark.farPast()

fun notification(enchantsName: String) {
dragonSound.playSound()
ChatUtils.chat("You have uncovered a §d§kXX§5 ULTRA-RARE BOOK! §d§kXX§e! You found: §9$enchantsName")
}

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.ultraRareBookAlert) return
if (!superpairsGui.matches(InventoryUtils.openInventoryName())) return
if (lastNotificationTime.passedSince() > 5.seconds) return
val gui = Minecraft.getMinecraft().currentScreen as? GuiContainer ?: return

GlStateManager.pushMatrix()
GlStateManager.translate(0f, -150f, 500f)

Renderable.drawInsideRoundedRect(
Renderable.string("§d§kXX§5 ULTRA-RARE BOOK! §d§kXX", 1.5),
Color(Color.DARK_GRAY.withAlpha(0), true),
horizontalAlign = RenderUtils.HorizontalAlignment.CENTER,
verticalAlign = RenderUtils.VerticalAlignment.CENTER,
).renderXYAligned(0, 125, gui.width,gui.height)

GlStateManager.translate(0f, 150f, -500f)
GlStateManager.popMatrix()
}

@SubscribeEvent
fun onInventoryUpdated(event: InventoryUpdatedEvent) {
if (!LorenzUtils.inSkyBlock) return
if (!config.ultraRareBookAlert) return
if (enchantsFound) return
if (!superpairsGui.matches(event.inventoryName)) return

for ((slotId, item) in event.inventoryItems) {
val firstLine = item.getLore().firstOrNull() ?: continue
if (!ultraRarePattern.matches(firstLine)) continue
val bookNameLine = item.getLore().getOrNull(2) ?: continue
bookPattern.matchMatcher(bookNameLine){
val enchantsName = group ("enchant")
notification(enchantsName)
enchantsFound = true
lastNotificationTime = SimpleTimeMark.now()
}
}
}

@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
enchantsFound = false
}
}
Loading