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

Backend: AreaChangeEvent and Islands in HandleEvent #2535

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ class EventHandler<T : SkyHanniEvent> private constructor(val name: String, priv
val invoker: Consumer<Any>,
val options: HandleEvent,
val generic: Class<*>?,
val onlyOnIslandTypes: Set<IslandType> = options.onlyOnIslands.toSet(),
)
) {
val onlyOnIslandTypes: Set<IslandType> = getIslands(options)

companion object {
private fun getIslands(options: HandleEvent): Set<IslandType> =
if (options.onlyOnIslands.isEmpty()) setOf(options.onlyOnIsland)
else options.onlyOnIslands.toSet()
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/api/event/HandleEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ annotation class HandleEvent(

/**
* If the event should only be received while on a specific skyblock island.
* To specify multiple islands, use [onlyOnIslands] instead.
*/
vararg val onlyOnIslands: IslandType = [IslandType.ANY],
val onlyOnIsland: IslandType = IslandType.ANY,

/**
* If the event should only be received while being on specific skyblock islands.
* To specify only one island, use [onlyOnIsland] instead.
*/
vararg val onlyOnIslands: IslandType = [],

/**
* The priority of when the event will be called, lower priority will be called first, see the companion object.
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.WidgetUpdateEvent
import at.hannibal2.skyhanni.events.minecraft.ClientDisconnectEvent
import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent
import at.hannibal2.skyhanni.features.bingo.BingoAPI
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.rift.RiftAPI
Expand Down Expand Up @@ -319,8 +320,13 @@ object HypixelData {
loop@ for (line in ScoreboardData.sidebarLinesFormatted) {
skyblockAreaPattern.matchMatcher(line) {
val originalLocation = group("area").removeColor()
skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation
val area = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation
skyBlockAreaWithSymbol = line.trim()
if (area != skyBlockArea) {
val previousArea = skyBlockArea
skyBlockArea = area
ScoreboardAreaChangeEvent(area, previousArea).post()
}
break@loop
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object LocationFixData {

private var locationFixes = mutableListOf<LocationFix>()
private var locationFixes = mutableMapOf<IslandType, List<LocationFix>>()

class LocationFix(val island: IslandType, val area: AxisAlignedBB, val realLocation: String)
private data class LocationFix(val area: AxisAlignedBB, val realLocation: String)

// priority set to low so that IslandType can load their island names from repo earlier
@SubscribeEvent(priority = EventPriority.LOW)
Expand All @@ -26,11 +26,18 @@ object LocationFixData {
val area = fix.a.axisAlignedTo(fix.b)
val realLocation = fix.realLocation

locationFixes.add(LocationFix(island, area, realLocation))
val list = locationFixes[island]

val locationFix = LocationFix(area, realLocation)

if (list == null) locationFixes[island] = listOf(locationFix)
else locationFixes[island] = list + locationFix
}
}

fun fixLocation(skyBlockIsland: IslandType) = locationFixes
.firstOrNull { skyBlockIsland == it.island && it.area.isPlayerInside() }
?.realLocation
fun fixLocation(skyBlockIsland: IslandType): String? =
locationFixes[skyBlockIsland]
?.find { it.area.isPlayerInside() }
?.realLocation

}
25 changes: 14 additions & 11 deletions src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.BlockClickEvent
import at.hannibal2.skyhanni.events.ColdUpdateEvent
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
Expand All @@ -11,6 +13,7 @@ import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent
import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
import at.hannibal2.skyhanni.events.mining.OreMinedEvent
import at.hannibal2.skyhanni.events.player.PlayerDeathEvent
import at.hannibal2.skyhanni.events.skyblock.ScoreboardAreaChangeEvent
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern
import at.hannibal2.skyhanni.features.mining.OreBlock
import at.hannibal2.skyhanni.features.mining.isTitanium
Expand Down Expand Up @@ -69,8 +72,6 @@ object MiningAPI {
var currentAreaOreBlocks = setOf<OreBlock>()
private set

private var lastSkyblockArea: String? = null

private val recentClickedBlocks = ConcurrentSet<Pair<LorenzVec, SimpleTimeMark>>()
private val surroundingMinedBlocks = ConcurrentLinkedQueue<Pair<MinedBlock, LorenzVec>>()
private val allowedSoundNames = setOf("dig.glass", "dig.stone", "dig.gravel", "dig.cloth", "random.orb")
Expand Down Expand Up @@ -203,10 +204,6 @@ object MiningAPI {
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!inCustomMiningIsland()) return

if (LorenzUtils.lastWorldSwitch.passedSince() < 4.seconds) return
updateLocation()

if (currentAreaOreBlocks.isEmpty()) return

// if somehow you take more than 20 seconds to mine a single block, congrats
Expand All @@ -219,6 +216,17 @@ object MiningAPI {
resetOreEvent()
}

@HandleEvent
fun onAreaChange(event: ScoreboardAreaChangeEvent) {
if (!inCustomMiningIsland()) return
updateLocation()
}

@SubscribeEvent
fun onIslandChange(event: IslandChangeEvent) {
updateLocation()
}

private fun runEvent() {
resetOreEvent()

Expand Down Expand Up @@ -287,11 +295,6 @@ object MiningAPI {
}

private fun updateLocation() {
val currentArea = LorenzUtils.skyBlockArea
// TODO add area change event with HypixelData.skyBlockArea instead
if (currentArea == lastSkyblockArea) return
lastSkyblockArea = currentArea

inGlacite = inGlaciteArea()
inTunnels = inGlacialTunnels()
inMineshaft = inMineshaft()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package at.hannibal2.skyhanni.events.skyblock

import at.hannibal2.skyhanni.api.event.SkyHanniEvent

// Detect area changes by looking at the scoreboard.
class ScoreboardAreaChangeEvent(val area: String, val previousArea: String?) : SkyHanniEvent()
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object ArachneSpawnTimer {
}
}

@HandleEvent(onlyOnIslands = [IslandType.SPIDER_DEN], priority = HandleEvent.LOW, receiveCancelled = true)
@HandleEvent(onlyOnIsland = IslandType.SPIDER_DEN, priority = HandleEvent.LOW, receiveCancelled = true)
fun onPacketReceive(event: PacketReceivedEvent) {
if (!saveNextTickParticles) return
if (searchTime.passedSince() < 3.seconds) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object DungeonShadowAssassinNotification {

private val config get() = SkyHanniMod.feature.dungeon

@HandleEvent(onlyOnIslands = [IslandType.CATACOMBS])
@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onWorldBorderChange(event: PacketReceivedEvent) {
if (!isEnabled()) return
if (DungeonAPI.dungeonFloor?.contains("3") == true && DungeonAPI.inBossRoom) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object GriffinBurrowParticleFinder {
}
}

@HandleEvent(onlyOnIslands = [IslandType.HUB], priority = HandleEvent.LOW, receiveCancelled = true)
@HandleEvent(onlyOnIsland = IslandType.HUB, priority = HandleEvent.LOW, receiveCancelled = true)
fun onPacketReceive(event: PacketReceivedEvent) {
if (!isEnabled()) return
if (!config.burrowsSoopyGuess) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ object InquisitorWaypointShare {
HypixelCommands.partyChat("x: $x, y: $y, z: $z ")
}

@HandleEvent(onlyOnIslands = [IslandType.HUB], priority = HandleEvent.LOW, receiveCancelled = true)
@HandleEvent(onlyOnIsland = IslandType.HUB, priority = HandleEvent.LOW, receiveCancelled = true)
fun onFirstChatEvent(event: PacketReceivedEvent) {
if (!isEnabled()) return
val packet = event.packet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object GardenAPI {
"BINGHOE",
)

@HandleEvent(onlyOnIslands = [IslandType.GARDEN])
@HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onSendPacket(event: PacketSentEvent) {
if (event.packet !is C09PacketHeldItemChange) return
checkItemInHand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ object PestAPI {
PestUpdateEvent().post()
}

@HandleEvent(onlyOnIslands = [IslandType.GARDEN])
@HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onPestSpawn(event: PestSpawnEvent) {
PestSpawnTimer.lastSpawnTime = SimpleTimeMark.now()
val plotNames = event.plotNames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object PestParticleWaypoint {
++particles
}

@HandleEvent(onlyOnIslands = [IslandType.GARDEN])
@HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onFireWorkSpawn(event: PacketReceivedEvent) {
if (event.packet !is S0EPacketSpawnObject) return
if (!config.hideParticles) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object VisitorListener {
}

// TODO make event
@HandleEvent(onlyOnIslands = [IslandType.GARDEN])
@HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onSendEvent(event: PacketSentEvent) {
val packet = event.packet
if (packet !is C02PacketUseEntity) return
Expand Down Expand Up @@ -136,7 +136,7 @@ object VisitorListener {
inventory.handleMouseClick_skyhanni(slot, slot.slotIndex, 0, 0)
}

@HandleEvent(onlyOnIslands = [IslandType.GARDEN])
@HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onTooltip(event: ItemHoverEvent) {
if (!GardenAPI.onBarnPlot) return
if (!VisitorAPI.inInventory) return
Expand Down
Loading