aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/VoltHighlighter.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt10
4 files changed, 38 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java
index 7814b954e..445fb6cc6 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java
@@ -12,7 +12,7 @@ public class SlayerConfig {
public boolean enderman = false;
@Expose
- @ConfigOption(name = "Highlight Yang Glyph", desc = "Highlight the enderman slayer Yang Glyph (beacon) in red color. Supports beacon in hand and beacon flying.")
+ @ConfigOption(name = "Highlight Yang Glyph", desc = "Highlight the enderman slayer Yang Glyph (beacon) in red color and added an timer when he explodes. Supports beacon in hand and beacon flying.")
@ConfigEditorBoolean
@ConfigAccordionId(id = 0)
public boolean slayerEndermanBeacon = false;
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/VoltHighlighter.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/VoltHighlighter.kt
index 38c9ceb7c..bef442c31 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/VoltHighlighter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/dreadfarm/VoltHighlighter.kt
@@ -11,7 +11,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SpecialColour
-import at.hannibal2.skyhanni.utils.TimeUtils
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraft.client.Minecraft
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
@@ -76,7 +76,7 @@ class VoltHighlighter {
if (dischargeTimeLeft > Duration.ZERO) {
event.drawDynamicText(
event.exactLocation(entity).add(0.0, 2.5, 0.0),
- "§eLightning: ${TimeUtils.formatDuration(dischargeTimeLeft, showMilliSeconds = true)}",
+ "§eLightning: ${dischargeTimeLeft.format(showMilliSeconds = true)}",
2.5
)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt
index 609eb6737..00e8b2065 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/enderman/EndermanSlayerFeatures.kt
@@ -9,22 +9,25 @@ import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.EntityUtils.getBlockInHand
import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture
import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.RenderUtils.drawColor
-import at.hannibal2.skyhanni.utils.RenderUtils.drawString
+import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
+import at.hannibal2.skyhanni.utils.TimeUtils.format
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.monster.EntityEnderman
import net.minecraft.init.Blocks
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
class EndermanSlayerFeatures {
private val config get() = SkyHanniMod.feature.slayer
private val endermenWithBeacons = mutableListOf<EntityEnderman>()
private val flyingBeacons = mutableListOf<EntityArmorStand>()
private val nukekebiSkulls = mutableListOf<EntityArmorStand>()
- private val sittingBeacon = mutableListOf<LorenzVec>()
+ private var sittingBeacon = mapOf<LorenzVec, SimpleTimeMark>()
private val logger = LorenzLogger("slayer/enderman")
private val nukekebiSkulTexture =
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWIwNzU5NGUyZGYyNzM5MjFhNzdjMTAxZDBiZmRmYTExMTVhYmVkNWI5YjIwMjllYjQ5NmNlYmE5YmRiYjRiMyJ9fX0="
@@ -92,11 +95,28 @@ class EndermanSlayerFeatures {
endermenWithBeacons.map { it.getLorenzVec().add(-0.5, 0.2, -0.5) }
.forEach { event.drawColor(it, LorenzColor.DARK_RED, alpha = 1f) }
- for (location in sittingBeacon.toMutableList()) {
+ for ((location, time) in sittingBeacon) {
+ val duration = 5.seconds - time.passedSince()
+ val durationFormat = duration.format(showMilliSeconds = true)
event.drawColor(location, LorenzColor.DARK_RED, alpha = 1f)
event.drawWaypointFilled(location, LorenzColor.RED.toColor(), true, true)
- event.drawString(location.add(0.5, 0.5, 0.5), "§4Beacon", true)
+ event.drawDynamicText(location.add(0, 1, 0), "§4Beacon §b$durationFormat", 1.8)
+ }
+ }
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!IslandType.THE_END.isInIsland()) return
+ if (!config.slayerEndermanBeacon) return
+ if (!event.repeatSeconds(1)) return
+
+ // Removing the beacon if It's still there after 7 sesconds.
+ // This is just a workaround for the cases where the ServerBlockChangeEvent don't detect the beacon despawn info.
+ val toRemove = sittingBeacon.filter { it.value.passedSince() > 7.seconds }
+ if (toRemove.isNotEmpty()) {
+ sittingBeacon = sittingBeacon.editCopy {
+ toRemove.keys.forEach { remove(it) }
+ }
}
}
@@ -110,13 +130,13 @@ class EndermanSlayerFeatures {
val armorStand = flyingBeacons.find { location.distance(it.getLorenzVec()) < 3 }
if (armorStand != null) {
flyingBeacons.remove(armorStand)
- sittingBeacon.add(location)
+ sittingBeacon = sittingBeacon.editCopy { this[location] = SimpleTimeMark.now() }
logger.log("Replaced flying beacon with sitting beacon at $location")
}
} else {
if (location in sittingBeacon) {
logger.log("Removed sitting beacon $location")
- sittingBeacon.remove(location)
+ sittingBeacon = sittingBeacon.editCopy { remove(location) }
}
}
}
@@ -126,7 +146,7 @@ class EndermanSlayerFeatures {
endermenWithBeacons.clear()
flyingBeacons.clear()
nukekebiSkulls.clear()
- sittingBeacon.clear()
+ sittingBeacon = emptyMap()
logger.log("Reset everything (world change)")
}
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index c088ded64..bcc4bff5f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -8,15 +8,21 @@ object TimeUtils {
private val pattern =
"(?:(?<y>\\d+) ?y(?:\\w* ?)?)?(?:(?<d>\\d+) ?d(?:\\w* ?)?)?(?:(?<h>\\d+) ?h(?:\\w* ?)?)?(?:(?<m>\\d+) ?m(?:\\w* ?)?)?(?:(?<s>\\d+) ?s(?:\\w* ?)?)?".toPattern()
-
fun formatDuration(
duration: Duration,
biggestUnit: TimeUnit = TimeUnit.YEAR,
showMilliSeconds: Boolean = false,
longName: Boolean = false,
maxUnits: Int = -1
+ ): String = duration.format(biggestUnit, showMilliSeconds, longName, maxUnits)
+
+ fun Duration.format(
+ biggestUnit: TimeUnit = TimeUnit.YEAR,
+ showMilliSeconds: Boolean = false,
+ longName: Boolean = false,
+ maxUnits: Int = -1
): String = formatDuration(
- duration.inWholeMilliseconds - 999, biggestUnit, showMilliSeconds, longName, maxUnits
+ inWholeMilliseconds - 999, biggestUnit, showMilliSeconds, longName, maxUnits
)
fun formatDuration(