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: Migrate some events to be GenericSkyHanniEvent #2753

Merged
merged 14 commits into from
Dec 5, 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
9 changes: 5 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/api/DataWatcherAPI.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package at.hannibal2.skyhanni.api

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.DataWatcherUpdatedEvent
import at.hannibal2.skyhanni.events.EntityCustomNameUpdateEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraft.entity.Entity

@SkyHanniModule
object DataWatcherAPI {

private const val DATA_VALUE_CUSTOM_NAME = 2

@SubscribeEvent
fun onDataWatcherUpdate(event: DataWatcherUpdatedEvent) {
@HandleEvent
fun onDataWatcherUpdate(event: DataWatcherUpdatedEvent<Entity>) {
for (updatedEntry in event.updatedEntries) {
if (updatedEntry.dataValueId == DATA_VALUE_CUSTOM_NAME) {
EntityCustomNameUpdateEvent(event.entity.customNameTag, event.entity).postAndCatch()
EntityCustomNameUpdateEvent(event.entity, event.entity.customNameTag).post()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/EntityData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object EntityData {

private fun postRenderNametag(entity: Entity, chatComponent: ChatComponentText) = nametagCache.getOrPut(entity) {
val event = EntityDisplayNameEvent(entity, chatComponent)
event.postAndCatch()
event.post()
event.chatComponent
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.EntityMoveEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
Expand All @@ -16,6 +17,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.entity.Entity
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.milliseconds
Expand Down Expand Up @@ -68,9 +70,9 @@ object EntityMovementData {
nextTeleport = null
}

@SubscribeEvent
fun onPlayerMove(event: EntityMoveEvent) {
if (!LorenzUtils.inSkyBlock || event.entity != Minecraft.getMinecraft().thePlayer) return
@HandleEvent(onlyOnSkyblock = true)
fun onPlayerMove(event: EntityMoveEvent<EntityPlayerSP>) {
if (!event.isLocalPlayer) return

val nextData = nextTeleport ?: return

Expand Down Expand Up @@ -99,7 +101,7 @@ object EntityMovementData {
val distance = newLocation.distance(oldLocation)
if (distance > 0.01) {
entityLocation[entity] = newLocation
EntityMoveEvent(entity, oldLocation, newLocation, distance).postAndCatch()
EntityMoveEvent(entity, oldLocation, newLocation, distance).post()
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/IslandGraphs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import at.hannibal2.skyhanni.utils.chat.Text.onClick
import at.hannibal2.skyhanni.utils.chat.Text.send
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import java.io.File
Expand Down Expand Up @@ -329,9 +330,9 @@ object IslandGraphs {
}
}

@SubscribeEvent
fun onPlayerMove(event: EntityMoveEvent) {
if (currentIslandGraph != null && event.entity == Minecraft.getMinecraft().thePlayer) {
@HandleEvent(onlyOnSkyblock = true)
fun onPlayerMove(event: EntityMoveEvent<EntityPlayerSP>) {
if (currentIslandGraph != null && event.isLocalPlayer) {
hasMoved = true
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.GenericSkyHanniEvent
import net.minecraft.client.renderer.culling.ICamera
import net.minecraft.entity.Entity
import net.minecraftforge.fml.common.eventhandler.Cancelable

@Cancelable
data class CheckRenderEntityEvent<T : Entity>(
val entity: T,
val camera: ICamera,
val camX: Double,
val camY: Double,
val camZ: Double,
) : LorenzEvent()
) : GenericSkyHanniEvent<T>(entity.javaClass)
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.GenericSkyHanniEvent
import net.minecraft.entity.DataWatcher
import net.minecraft.entity.Entity

data class DataWatcherUpdatedEvent(
val entity: Entity,
data class DataWatcherUpdatedEvent<T : Entity>(
val entity: T,
val updatedEntries: List<DataWatcher.WatchableObject>,
) : LorenzEvent()
) : GenericSkyHanniEvent<T>(entity.javaClass)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.GenericSkyHanniEvent
import net.minecraft.entity.Entity

data class EntityCustomNameUpdateEvent(
data class EntityCustomNameUpdateEvent<T : Entity>(
val entity: T,
val newName: String?,
val entity: Entity,
) : LorenzEvent()
) : GenericSkyHanniEvent<T>(entity.javaClass)
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.GenericSkyHanniEvent
import net.minecraft.entity.Entity
import net.minecraft.item.ItemStack

data class EntityEquipmentChangeEvent(
val entity: Entity,
data class EntityEquipmentChangeEvent<T : Entity>(
val entity: T,
val equipmentSlot: Int,
val newItemStack: ItemStack?,
) : LorenzEvent() {
) : GenericSkyHanniEvent<T>(entity.javaClass) {

val isHead get() = equipmentSlot == EQUIPMENT_SLOT_HEAD
val isChest get() = equipmentSlot == EQUIPMENT_SLOT_CHEST
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/events/EntityMoveEvent.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.api.event.GenericSkyHanniEvent
import at.hannibal2.skyhanni.utils.LorenzVec
import net.minecraft.client.Minecraft
import net.minecraft.entity.Entity

class EntityMoveEvent(
val entity: Entity,
class EntityMoveEvent<T : Entity>(
val entity: T,
val oldLocation: LorenzVec,
val newLocation: LorenzVec,
val distance: Double,
) : LorenzEvent()
) : GenericSkyHanniEvent<T>(entity.javaClass) {
val isLocalPlayer by lazy { entity == Minecraft.getMinecraft().thePlayer }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.events.entity

import at.hannibal2.skyhanni.events.LorenzEvent
import at.hannibal2.skyhanni.api.event.GenericSkyHanniEvent
import net.minecraft.entity.Entity
import net.minecraft.util.ChatComponentText

class EntityDisplayNameEvent(val entity: Entity, var chatComponent: ChatComponentText) : LorenzEvent()
class EntityDisplayNameEvent<T : Entity>(val entity: T, var chatComponent: ChatComponentText) : GenericSkyHanniEvent<T>(entity.javaClass)
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package at.hannibal2.skyhanni.features.dungeon

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.DamageIndicatorFinalBossEvent
import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent
Expand All @@ -15,6 +17,7 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.entity.Entity
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.monster.EntityGuardian
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand Down Expand Up @@ -91,8 +94,8 @@ object DungeonCleanEnd {
}
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onCheckRender(event: CheckRenderEntityEvent<Entity>) {
if (!shouldBlock()) return

val entity = event.entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.dungeon
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.DungeonBossRoomEnterEvent
import at.hannibal2.skyhanni.events.DungeonEnterEvent
Expand Down Expand Up @@ -107,12 +108,9 @@ object DungeonCopilot {
nextStep = step
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (!DungeonAPI.inDungeon()) return

@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onCheckRender(event: CheckRenderEntityEvent<EntityArmorStand>) {
val entity = event.entity
if (entity !is EntityArmorStand) return

if (!searchForKey) return

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package at.hannibal2.skyhanni.features.dungeon

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.EntityMovementData
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.EntityMoveEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
Expand Down Expand Up @@ -42,10 +44,8 @@ object DungeonHideItems {

private fun isSkeletonSkull(entity: EntityArmorStand): Boolean = entity.getStandHelmet()?.cleanName() == "Skeleton Skull"

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (!DungeonAPI.inDungeon()) return

@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onCheckRender(event: CheckRenderEntityEvent<Entity>) {
val entity = event.entity

if (entity is EntityItem) {
Expand Down Expand Up @@ -170,12 +170,9 @@ object DungeonHideItems {
}
}

@SubscribeEvent
fun onEntityMove(event: EntityMoveEvent) {
if (!DungeonAPI.inDungeon()) return

@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onEntityMove(event: EntityMoveEvent<EntityArmorStand>) {
val entity = event.entity
if (entity !is EntityArmorStand) return

if (isSkeletonSkull(entity)) {
movingSkeletonSkulls[entity] = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.features.dungeon

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.mob.Mob
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
Expand Down Expand Up @@ -91,8 +93,8 @@ object DungeonLividFinder {
lividArmorStandId = null
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onCheckRender(event: CheckRenderEntityEvent<Entity>) {
if (!inLividBossRoom() || !config.hideWrong) return
if (livid == null && lividArmorStandId == null) return // in case livid detection fails, don't hide anything
if (event.entity.mob in fakeLivids) event.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ object UniqueGiftingOpportunitiesFeatures {
addGiftedPlayer(matchedPlayer.name)
}

@SubscribeEvent
fun onEntityChangeName(event: EntityCustomNameUpdateEvent) {
val entity = event.entity as? EntityArmorStand ?: return
analyzeArmorStand(entity)
@HandleEvent(onlyOnSkyblock = true)
fun onEntityChangeName(event: EntityCustomNameUpdateEvent<EntityArmorStand>) {
analyzeArmorStand(event.entity)
}

@HandleEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.init.Blocks
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Keyboard
Expand Down Expand Up @@ -179,10 +180,10 @@ object GriffinBurrowHelper {
update()
}

@SubscribeEvent
fun onPlayerMove(event: EntityMoveEvent) {
@HandleEvent
fun onPlayerMove(event: EntityMoveEvent<EntityPlayerSP>) {
if (!isEnabled()) return
if (event.distance > 10 && event.entity == Minecraft.getMinecraft().thePlayer) {
if (event.distance > 10 && event.isLocalPlayer) {
update()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.fishing

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
Expand Down Expand Up @@ -28,13 +29,11 @@ object ChumBucketHider {
reset()
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (!LorenzUtils.inSkyBlock) return
@HandleEvent(onlyOnSkyblock = true)
fun onCheckRender(event: CheckRenderEntityEvent<EntityArmorStand>) {
if (!config.enabled.get()) return

val entity = event.entity
if (entity !is EntityArmorStand) return

if (entity in hiddenEntities) {
event.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ object FishingHookDisplay {
potentialArmorStands.add(event.entity)
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
@HandleEvent
fun onCheckRender(event: CheckRenderEntityEvent<EntityArmorStand>) {
if (!isEnabled()) return
if (!config.hideArmorStand) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,13 @@ object VisitorListener {
GardenVisitorFeatures.onTooltip(visitor, event.itemStack, event.toolTip)
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (!GardenAPI.inGarden()) return
@HandleEvent(onlyOnIsland = IslandType.GARDEN)
fun onCheckRender(event: CheckRenderEntityEvent<EntityArmorStand>) {
if (!GardenAPI.onBarnPlot) return
if (config.highlightStatus != VisitorConfig.HighlightMode.NAME && config.highlightStatus != VisitorConfig.HighlightMode.BOTH) return

val entity = event.entity
if (entity is EntityArmorStand && entity.name == "§e§lCLICK") {
if (entity.name == "§e§lCLICK") {
event.cancel()
}
}
Expand Down
Loading
Loading