-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Totem Of Corruption Overlay & Effective Area (#1139)
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com>
- Loading branch information
1 parent
54aba6c
commit 44014aa
Showing
5 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/at/hannibal2/skyhanni/config/features/fishing/TotemOfCorruptionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package at.hannibal2.skyhanni.config.features.fishing; | ||
|
||
import at.hannibal2.skyhanni.config.FeatureToggle; | ||
import at.hannibal2.skyhanni.config.core.config.Position; | ||
import com.google.gson.annotations.Expose; | ||
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; | ||
import io.github.moulberry.moulconfig.annotations.ConfigEditorColour; | ||
import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider; | ||
import io.github.moulberry.moulconfig.annotations.ConfigOption; | ||
|
||
public class TotemOfCorruptionConfig { | ||
|
||
@Expose | ||
@ConfigOption(name = "Show Overlay", desc = "Show the Totem of Corruption overlay." + | ||
"\nShows the totem, in which effective area you are in, with the longest time left." + | ||
"\n§cThis needs to be enabled for the other options to work.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean showOverlay = true; | ||
|
||
@Expose | ||
@ConfigOption(name = "Distance Threshold", desc = "The minimum distance to the Totem of Corruption for the overlay." + | ||
"\nThe effective distance of the totem is 16." + | ||
"\n§cLimited by how far you can see the nametags.") | ||
@ConfigEditorSlider(minValue = 0, maxValue = 100, minStep = 1) | ||
public int distanceThreshold = 16; | ||
|
||
@Expose | ||
@ConfigOption(name = "Hide Particles", desc = "Hide the particles of the Totem of Corruption.") | ||
@ConfigEditorBoolean | ||
public boolean hideParticles = true; | ||
|
||
@Expose | ||
@ConfigOption(name = "Show Effective Area", desc = "Show the effective area (16 blocks) of the Totem of Corruption.") | ||
@ConfigEditorBoolean | ||
public boolean showEffectiveArea = true; | ||
|
||
@Expose | ||
@ConfigOption(name = "Color of the area", desc = "The color of the area of the Totem of Corruption.") | ||
@ConfigEditorColour | ||
public String color = "0:153:18:159:85"; | ||
|
||
@Expose | ||
@ConfigOption(name = "Warn when about to expire", desc = "Select the time in seconds when the totem is about to expire to warn you." + | ||
"\nSelect 0 to disable.") | ||
@ConfigEditorSlider(minValue = 0, maxValue = 60, minStep = 1) | ||
public int warnWhenAboutToExpire = 5; | ||
|
||
@Expose | ||
public Position position = new Position(50, 20, false, true); | ||
} |
143 changes: 143 additions & 0 deletions
143
src/main/java/at/hannibal2/skyhanni/features/fishing/TotemOfCorruption.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package at.hannibal2.skyhanni.features.fishing | ||
|
||
import at.hannibal2.skyhanni.SkyHanniMod | ||
import at.hannibal2.skyhanni.events.GuiRenderEvent | ||
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent | ||
import at.hannibal2.skyhanni.events.LorenzTickEvent | ||
import at.hannibal2.skyhanni.events.ReceiveParticleEvent | ||
import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor | ||
import at.hannibal2.skyhanni.utils.EntityUtils | ||
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer | ||
import at.hannibal2.skyhanni.utils.LorenzUtils | ||
import at.hannibal2.skyhanni.utils.LorenzUtils.sendTitle | ||
import at.hannibal2.skyhanni.utils.LorenzVec | ||
import at.hannibal2.skyhanni.utils.RenderUtils.drawSphereInWorld | ||
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings | ||
import at.hannibal2.skyhanni.utils.SoundUtils.playPlingSound | ||
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher | ||
import at.hannibal2.skyhanni.utils.StringUtils.matches | ||
import at.hannibal2.skyhanni.utils.TimeUnit | ||
import at.hannibal2.skyhanni.utils.TimeUtils.format | ||
import at.hannibal2.skyhanni.utils.getLorenzVec | ||
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern | ||
import net.minecraft.entity.item.EntityArmorStand | ||
import net.minecraft.util.EnumParticleTypes | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class TotemOfCorruption { | ||
|
||
private val config get() = SkyHanniMod.feature.fishing.totemOfCorruption | ||
|
||
private var display = emptyList<String>() | ||
private var totems: List<Totem> = emptyList() | ||
|
||
private val group = RepoPattern.group("fishing.totemofcorruption") | ||
private val totemNamePattern by group.pattern( | ||
"totemname", | ||
"§5§lTotem of Corruption" | ||
) | ||
private val timeRemainingPattern by group.pattern( | ||
"timeremaining", | ||
"§7Remaining: §e(?:(?<min>\\d+)m )?(?<sec>\\d+)s" | ||
) | ||
private val ownerPattern by group.pattern( | ||
"owner", | ||
"§7Owner: §e(?<owner>.+)" | ||
) | ||
|
||
@SubscribeEvent | ||
fun onRender(event: GuiRenderEvent.GuiOverlayRenderEvent) { | ||
if (!isOverlayEnabled() || display.isEmpty()) return | ||
config.position.renderStrings(display, posLabel = "Totem of Corruption") | ||
} | ||
|
||
@SubscribeEvent | ||
fun onTick(event: LorenzTickEvent) { | ||
if (!event.repeatSeconds(2)) return | ||
if (!isOverlayEnabled()) return | ||
|
||
totems = getTotems() | ||
display = createDisplay() | ||
} | ||
|
||
@SubscribeEvent | ||
fun onChatPacket(event: ReceiveParticleEvent) { | ||
if (!isHideParticlesEnabled()) return | ||
|
||
for (totem in totems) { | ||
if (event.type == EnumParticleTypes.SPELL_WITCH && event.speed == 0.0f) { | ||
if (totem.location.distance(event.location) < 4.0) { | ||
event.isCanceled = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
fun onRenderWorld(event: LorenzRenderWorldEvent) { | ||
if (!isEffectiveAreaEnabled()) return | ||
|
||
val color = config.color.toChromaColor() | ||
for (totem in totems) { | ||
// The center of the totem is the upper part | ||
event.drawSphereInWorld(color, totem.location.add(y = 1), 16f) | ||
} | ||
} | ||
|
||
private fun getTimeRemaining(totem: EntityArmorStand): Duration? = | ||
EntityUtils.getEntitiesNearby<EntityArmorStand>(totem.getLorenzVec(), 2.0) | ||
.firstNotNullOfOrNull { entity -> | ||
timeRemainingPattern.matchMatcher(entity.name) { | ||
val minutes = group("min")?.toIntOrNull() ?: 0 | ||
val seconds = group("sec")?.toInt() ?: 0 | ||
(minutes * 60 + seconds).seconds | ||
} | ||
} | ||
|
||
private fun getOwner(totem: EntityArmorStand): String? = | ||
EntityUtils.getEntitiesNearby<EntityArmorStand>(totem.getLorenzVec(), 2.0) | ||
.firstNotNullOfOrNull { entity -> | ||
ownerPattern.matchMatcher(entity.name) { | ||
group("owner") | ||
} | ||
} | ||
|
||
|
||
private fun createDisplay() = buildList { | ||
val totem = getTotemToShow() ?: return@buildList | ||
add("§5§lTotem of Corruption") | ||
add("§7Remaining: §e${totem.timeRemaining.format(TimeUnit.MINUTE)}") | ||
add("§7Owner: §e${totem.ownerName}") | ||
} | ||
|
||
private fun getTotemToShow(): Totem? = totems | ||
.filter { it.distance < config.distanceThreshold } | ||
.maxByOrNull { it.timeRemaining } | ||
|
||
private fun getTotems(): List<Totem> = EntityUtils.getEntitiesNextToPlayer<EntityArmorStand>(100.0) | ||
.filter { totemNamePattern.matches(it.name) }.toList() | ||
.mapNotNull { totem -> | ||
val timeRemaining = getTimeRemaining(totem) ?: return@mapNotNull null | ||
val owner = getOwner(totem) ?: return@mapNotNull null | ||
|
||
val timeToWarn = config.warnWhenAboutToExpire.seconds | ||
if (timeToWarn > 0.seconds && timeRemaining == timeToWarn) { | ||
playPlingSound() | ||
sendTitle("§c§lTotem of Corruption §eabout to expire!", 5.seconds) | ||
} | ||
Totem(totem.getLorenzVec(), timeRemaining, owner) | ||
} | ||
|
||
private fun isOverlayEnabled() = LorenzUtils.inSkyBlock && config.showOverlay | ||
private fun isHideParticlesEnabled() = LorenzUtils.inSkyBlock && config.hideParticles | ||
private fun isEffectiveAreaEnabled() = LorenzUtils.inSkyBlock && config.showEffectiveArea | ||
} | ||
|
||
class Totem( | ||
val location: LorenzVec, | ||
val timeRemaining: Duration, | ||
val ownerName: String, | ||
val distance: Double = location.distanceToPlayer() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters