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

Open
wants to merge 9 commits into
base: beta
Choose a base branch
from
Open
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 @@ -63,9 +65,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 @@ -94,7 +96,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 @@ -327,9 +328,9 @@ object IslandGraphs {
}
}

@SubscribeEvent
fun onPlayerMove(event: EntityMoveEvent) {
if (LorenzUtils.inSkyBlock && event.entity == Minecraft.getMinecraft().thePlayer) {
@HandleEvent(onlyOnSkyblock = true)
fun onPlayerMove(event: EntityMoveEvent<EntityPlayerSP>) {
if (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 @@ -103,12 +104,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 @@ -63,10 +65,8 @@ object DungeonHideItems {
return itemStack != null && itemStack.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 @@ -158,7 +158,7 @@ object DungeonHideItems {
}

if (config.hideHealerFairy) {
// Healer Fairy texture is stored in id 0, not id 4 for some reasons.
// Healer Fairy texture is stored in id 0, not id 4 for some reason.
if (entity.inventory[0]?.getSkullTexture() == HEALER_FAIRY_TEXTURE) {
event.cancel()
return
Expand Down Expand Up @@ -192,12 +192,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.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
Expand All @@ -23,6 +25,7 @@ import net.minecraft.block.BlockStainedGlass
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.entity.Entity
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.potion.Potion
import net.minecraft.util.AxisAlignedBB
Expand Down Expand Up @@ -106,8 +109,8 @@ object DungeonLividFinder {
if (!it.isDead && it.health > 0.5) it else null
}

@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onCheckRender(event: CheckRenderEntityEvent<Entity>) {
if (!inDungeon()) return
if (!config.hideWrong) return
if (!config.enabled) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,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 @@ -39,6 +39,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 @@ -180,10 +181,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 All @@ -27,13 +28,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
Loading
Loading