diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-04-17 15:46:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 15:46:19 +0200 |
commit | 2d93420195fbcde780372b1597a38ac4f960519a (patch) | |
tree | 5b81df5c80fbc40c2d24a1fb9779376eb9a732aa /src/main/java/at/hannibal2 | |
parent | a99499ab99aee3e827cd77de50ec07ab81c0baf5 (diff) | |
download | skyhanni-2d93420195fbcde780372b1597a38ac4f960519a.tar.gz skyhanni-2d93420195fbcde780372b1597a38ac4f960519a.tar.bz2 skyhanni-2d93420195fbcde780372b1597a38ac4f960519a.zip |
Feature: Highlight own Golden/Diamond Goblin (#1466)
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 98 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index dbca1c71d..bce2dec95 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -264,6 +264,7 @@ import at.hannibal2.skyhanni.features.itemabilities.ChickenHeadTimer import at.hannibal2.skyhanni.features.itemabilities.FireVeilWandParticles import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityCooldown import at.hannibal2.skyhanni.features.mining.DeepCavernsGuide +import at.hannibal2.skyhanni.features.mining.GoldenGoblinHighlight import at.hannibal2.skyhanni.features.mining.HighlightMiningCommissionMobs import at.hannibal2.skyhanni.features.mining.KingTalismanHelper import at.hannibal2.skyhanni.features.mining.MiningNotifications @@ -812,6 +813,7 @@ class SkyHanniMod { loadModule(LockMouseLook) loadModule(SensitivityReducer) loadModule(DungeonFinderFeatures()) + loadModule(GoldenGoblinHighlight()) loadModule(TabWidgetSettings()) loadModule(PabloHelper()) loadModule(FishingBaitWarnings()) @@ -828,7 +830,7 @@ class SkyHanniMod { loadModule(HighlightPlaceableNpcs()) loadModule(PresentWaypoints()) loadModule(MiningEventTracker()) - loadModule(MiningNotifications()) + loadModule(MiningNotifications) loadModule(JyrreTimer()) loadModule(TotemOfCorruption()) loadModule(NewYearCakeReminder()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java index a4f7f299e..aebb842bc 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/MiningConfig.java @@ -60,4 +60,10 @@ public class MiningConfig { @ConfigEditorBoolean @FeatureToggle public boolean privateIslandNoPickaxeAbility = false; + + @Expose + @ConfigOption(name = "Highlight your Golden Goblin", desc = "Highlights golden goblins you have spawned in green.") + @ConfigEditorBoolean + @FeatureToggle + public boolean highlightYourGoldenGoblin = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt b/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt index 4eab5d881..d35d46759 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt @@ -3,7 +3,9 @@ package at.hannibal2.skyhanni.data.mob import at.hannibal2.skyhanni.data.mob.Mob.Type import at.hannibal2.skyhanni.data.mob.MobFilter.summonOwnerPattern import at.hannibal2.skyhanni.events.MobEvent +import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.utils.CollectionUtils.toSingletonListOrEmpty +import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha import at.hannibal2.skyhanni.utils.EntityUtils.canBeSeen import at.hannibal2.skyhanni.utils.EntityUtils.cleanName import at.hannibal2.skyhanni.utils.EntityUtils.isCorrupted @@ -16,6 +18,7 @@ import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraft.entity.monster.EntityZombie import net.minecraft.util.AxisAlignedBB +import java.awt.Color /** * Represents a Mob in Hypixel Skyblock. @@ -97,6 +100,23 @@ class Mob( fun isInvisible() = if (baseEntity !is EntityZombie) baseEntity.isInvisible else false + private var highlightColor: Color? = null + fun highlight(color: Color) { + highlightColor = color + internalHighlight() + } + + private fun internalHighlight() { + highlightColor?.let { + RenderLivingEntityHelper.setEntityColorWithNoHurtTime(baseEntity, it.withAlpha(127)) { true } + } + } + + private fun internalRemoveColor() { + if (highlightColor == null) return + RenderLivingEntityHelper.removeCustomRender(baseEntity) + } + val boundingBox: AxisAlignedBB get() = relativeBoundingBox?.offset(baseEntity.posX, baseEntity.posY, baseEntity.posZ) ?: baseEntity.entityBoundingBox @@ -135,7 +155,9 @@ class Mob( internal fun internalAddEntity(entity: EntityLivingBase) { if (baseEntity.entityId > entity.entityId) { extraEntitiesList.add(0, baseEntity) + internalRemoveColor() baseEntity = entity + internalHighlight() } else { extraEntitiesList.add(extraEntitiesList.lastIndex + 1, entity) } @@ -146,14 +168,21 @@ class Mob( internal fun internalAddEntity(entities: Collection<EntityLivingBase>) { val list = entities.drop(1).toMutableList().apply { add(baseEntity) } extraEntitiesList.addAll(0, list) + internalRemoveColor() baseEntity = entities.first() + internalHighlight() updateBoundingBox() removeExtraEntitiesFromChecking() MobData.entityToMob.putAll(entities.associateWith { this }) } internal fun internalUpdateOfEntity(entity: EntityLivingBase) = when (entity.entityId) { - baseEntity.entityId -> baseEntity = entity + baseEntity.entityId -> { + internalRemoveColor() + baseEntity = entity + internalHighlight() + } + armorStand?.entityId ?: Int.MIN_VALUE -> armorStand = entity as EntityArmorStand else -> { extraEntitiesList.remove(entity) diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt new file mode 100644 index 000000000..bd5a5baf4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/GoldenGoblinHighlight.kt @@ -0,0 +1,56 @@ +package at.hannibal2.skyhanni.features.mining + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.mob.Mob +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.MobEvent +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class GoldenGoblinHighlight { + + private val config get() = SkyHanniMod.feature.mining.highlightYourGoldenGoblin + + private val goblinPattern by RepoPattern.pattern("mining.mob.golden.goblin", "Golden Goblin|Diamond Goblin") + + private fun isEnabled() = LorenzUtils.inMiningIsland() && config + + private val timeOut = 10.0.seconds + + private var lastChatMessage = SimpleTimeMark.farPast() + private var lastGoblinSpawn = SimpleTimeMark.farPast() + private var lastGoblin: Mob? = null + + @SubscribeEvent + fun onChatEvent(event: LorenzChatEvent) { + if (!isEnabled()) return + if (!MiningNotifications.goldenGoblinSpawn.matches(event.message) && + !MiningNotifications.diamondGoblinSpawn.matches(event.message) + ) return + lastChatMessage = SimpleTimeMark.now() + handle() + } + + @SubscribeEvent + fun onMobEvent(event: MobEvent.Spawn.SkyblockMob) { + if (!isEnabled()) return + if (!goblinPattern.matches(event.mob.name)) return + lastGoblin = event.mob + lastGoblinSpawn = SimpleTimeMark.now() + handle() + } + + private fun handle() { + if (lastChatMessage.passedSince() > timeOut || lastGoblinSpawn.passedSince() > timeOut) return + lastChatMessage = SimpleTimeMark.farPast() + lastGoblinSpawn = SimpleTimeMark.farPast() + lastGoblin?.highlight(LorenzColor.GREEN.toColor()) + lastGoblin = null + } + +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt index 3115ac48a..acaa23ff5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/MiningNotifications.kt @@ -19,7 +19,7 @@ import kotlin.math.absoluteValue import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds -class MiningNotifications { +object MiningNotifications { enum class MiningNotificationList(val str: String, val notification: String) { MINESHAFT_SPAWN("§bGlacite Mineshaft", "§bMineshaft"), @@ -42,11 +42,11 @@ class MiningNotifications { "scrapdrop", "§6§lEXCAVATOR! §r§fYou found a §r§9Suspicious Scrap§r§f!" ) - private val goldenGoblinSpawn by patternGroup.pattern( + val goldenGoblinSpawn by patternGroup.pattern( "goblin.goldspawn", "§6A Golden Goblin has spawned!" ) - private val diamondGoblinSpawn by patternGroup.pattern( + val diamondGoblinSpawn by patternGroup.pattern( "goblin.diamondspawn", "§6A §r§bDiamond Goblin §r§6has spawned!" ) |