aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-17 03:05:11 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-17 03:05:11 -0500
commit1a8e45d8519a8ae69e14db8ea103a7fdf7b80923 (patch)
tree5568ffc7575c4da682a9526199ea535be57ae637 /src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
parent2003a3d2be24ae3faed0e45a8c6cc5e0b8343cc3 (diff)
downloadDulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.tar.gz
DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.tar.bz2
DulkirMod-Fabric-1a8e45d8519a8ae69e14db8ea103a7fdf7b80923.zip
wip
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt')
-rw-r--r--src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
new file mode 100644
index 0000000..86a3863
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/features/CooldownDisplays.kt
@@ -0,0 +1,61 @@
+package com.dulkirfabric.features
+
+import com.dulkirfabric.events.PlaySoundEvent
+import com.dulkirfabric.events.WorldLoadEvent
+import com.dulkirfabric.util.SoundInfo
+import com.dulkirfabric.util.TrackedCooldown
+import meteordevelopment.orbit.EventHandler
+import net.minecraft.item.ItemStack
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
+
+object CooldownDisplays {
+ private val trackedCooldowns: Map<SoundInfo, TrackedCooldown> = mapOf(
+ Pair(
+ SoundInfo("mob.zombie.remedy", 1f, .5f),
+ TrackedCooldown("(REAPER_CHESTPLATE)|(REAPER_LEGGINGS)|(REAPER_BOOTS)".toRegex(), 25000, 0)
+ ),
+ Pair(
+ SoundInfo("mob.zombie.remedy", 0.6984127f, 1f),
+ TrackedCooldown("(HYPERION|ASTRAEA|SCYLLA|VALKYRIE)".toRegex(), 5000, 0)
+ )
+ )
+
+ fun shouldDisplay(stack: ItemStack, cir: CallbackInfoReturnable<Boolean>) {
+ val cooldown = fetchCooldownItem(stack) ?: return
+ cir.returnValue = true
+ // cir.returnValue = System.currentTimeMillis() - cooldown.lastUsage < cooldown.cooldownDuration
+ }
+
+ fun calcDurability(stack: ItemStack, cir: CallbackInfoReturnable<Int>) {
+ val cooldown = fetchCooldownItem(stack) ?: return
+ cir.returnValue = 300
+ }
+ @EventHandler
+ fun onSound(event: PlaySoundEvent) {
+ val path = event.sound.id.path
+ val pitch = event.sound.pitch
+ val volume = event.sound.volume
+
+ // Figure out if we have a match in trackedCooldowns
+ val matchResult = trackedCooldowns[SoundInfo(path, pitch, volume)] ?: return
+ matchResult.lastUsage = System.currentTimeMillis()
+ }
+
+ @EventHandler
+ fun onWorldLoad(event: WorldLoadEvent) {
+ trackedCooldowns.forEach {
+ it.value.lastUsage = 0
+ }
+ }
+
+ private fun fetchCooldownItem(stack: ItemStack): TrackedCooldown? {
+ val tag = stack.nbt ?: return null
+ val id = tag.getCompound("ExtraAttributes").get("id") ?: return null
+ val idStr = id.toString().trim('"')
+ trackedCooldowns.forEach {
+ if (idStr matches it.value.itemID)
+ return it.value
+ }
+ return null
+ }
+} \ No newline at end of file