diff options
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt | 1 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/Registrations.kt | 2 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt | 15 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/features/IPhoneAlarm.kt | 36 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/util/SoundUtil.kt | 37 | ||||
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/util/TimeMark.kt | 23 | ||||
-rw-r--r-- | src/main/resources/assets/dulkirmod/sounds.json | 7 | ||||
-rw-r--r-- | src/main/resources/assets/dulkirmod/sounds/iphone.ogg | bin | 0 -> 68461 bytes |
8 files changed, 118 insertions, 3 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt b/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt index 80f4dc2..0610bd9 100644 --- a/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt +++ b/src/main/kotlin/com/dulkirfabric/DulkirModFabric.kt @@ -14,6 +14,7 @@ package com.dulkirfabric import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.util.SoundUtil import com.llamalad7.mixinextras.MixinExtrasBootstrap import meteordevelopment.orbit.EventBus import net.fabricmc.api.ModInitializer diff --git a/src/main/kotlin/com/dulkirfabric/Registrations.kt b/src/main/kotlin/com/dulkirfabric/Registrations.kt index 16d6354..099ccb6 100644 --- a/src/main/kotlin/com/dulkirfabric/Registrations.kt +++ b/src/main/kotlin/com/dulkirfabric/Registrations.kt @@ -10,6 +10,7 @@ import com.dulkirfabric.events.chat.ModifyCommandEvent import com.dulkirfabric.events.chat.OverlayReceivedEvent import com.dulkirfabric.features.* import com.dulkirfabric.features.chat.AbiPhoneDND +import com.dulkirfabric.util.SoundUtil import com.dulkirfabric.util.TablistUtils import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents @@ -57,6 +58,7 @@ object Registrations { EVENT_BUS.subscribe(CustomBlockOutline) EVENT_BUS.subscribe(AbiPhoneDND) EVENT_BUS.subscribe(InventoryScale) + EVENT_BUS.subscribe(IPhoneAlarm) EVENT_BUS.subscribe(AliasImpl) EVENT_BUS.subscribe(EffigyDisplay) EVENT_BUS.subscribe(TablistUtils) diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index 6a72252..b612156 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -105,6 +105,14 @@ class DulkirConfig { general.addEntry( entryBuilder.mkToggle(Text.literal("Hide Armor Overlay in Skyblock"), configOptions::hideArmorOverlay) ) + general.addEntry( + entryBuilder.startIntSlider(Text.literal("Anti Downtime Alarm"), configOptions.alarmTimeout, 0, 1000) + .setSaveConsumer { + configOptions.alarmTimeout = it + } + .setTooltip(Text.literal("Set to 0 to disable. (Time in seconds)")) + .build() + ) val shortcuts = builder.getOrCreateCategory(Text.literal("Shortcuts")) shortcuts.addEntry( @@ -204,7 +212,6 @@ class DulkirConfig { var statusEffectHidden: Boolean = false, var inactiveEffigyDisplay: Boolean = false, var disableExplosionParticles: Boolean = false, - var duraCooldown: Boolean = false, var hideArmorOverlay: Boolean = false, var heldItemPosX: Int = 0, var heldItemPosY: Int = 0, @@ -212,8 +219,10 @@ class DulkirConfig { var heldItemRotX: Int = 0, var heldItemRotY: Int = 0, var heldItemRotZ: Int = 0, - var heldItemScale: Float = 0f - ) + var heldItemScale: Float = 0f, + var duraCooldown: Boolean = false, + var alarmTimeout: Int = 300, + ) @Serializable data class Macro( diff --git a/src/main/kotlin/com/dulkirfabric/features/IPhoneAlarm.kt b/src/main/kotlin/com/dulkirfabric/features/IPhoneAlarm.kt new file mode 100644 index 0000000..4dcdc69 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/features/IPhoneAlarm.kt @@ -0,0 +1,36 @@ +package com.dulkirfabric.features + +import com.dulkirfabric.DulkirModFabric.mc +import com.dulkirfabric.config.DulkirConfig +import com.dulkirfabric.events.ClientTickEvent +import com.dulkirfabric.util.SoundUtil +import com.dulkirfabric.util.TimeMark +import meteordevelopment.orbit.EventHandler +import net.minecraft.client.sound.SoundInstance +import net.minecraft.util.math.BlockPos +import java.time.Duration + +object IPhoneAlarm { + var lastPosition: BlockPos? = null + var lastMoved = TimeMark.farPast() + val soundInstances = mutableListOf<SoundInstance>() + + @EventHandler + fun onTick(event: ClientTickEvent) { + if (DulkirConfig.configOptions.alarmTimeout <= 0) return + val p = mc.player ?: return + val lastPosition = this.lastPosition + this.lastPosition = p.blockPos + if (lastPosition != this.lastPosition) { + lastMoved = TimeMark.now() + SoundUtil.stop(soundInstances) + soundInstances.clear() + } else { + if (lastMoved.timePassed() > Duration.ofSeconds(DulkirConfig.configOptions.alarmTimeout.toLong())) { + soundInstances.add(SoundUtil.playIPhoneAlarm()) + lastMoved = TimeMark.ago(Duration.ofSeconds(4L)) + } + } + } + +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/SoundUtil.kt b/src/main/kotlin/com/dulkirfabric/util/SoundUtil.kt new file mode 100644 index 0000000..7d623f6 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/SoundUtil.kt @@ -0,0 +1,37 @@ +package com.dulkirfabric.util + +import net.minecraft.client.MinecraftClient +import net.minecraft.client.sound.PositionedSoundInstance +import net.minecraft.client.sound.SoundInstance +import net.minecraft.sound.SoundCategory +import net.minecraft.sound.SoundEvent +import net.minecraft.util.Identifier +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.random.LocalRandom + +object SoundUtil { + val iphone = SoundEvent.of(Identifier("dulkirmod:iphone")) + + + fun stop(sounds: List<SoundInstance>) { + val m = MinecraftClient.getInstance().soundManager + sounds.forEach(m::stop) + } + + fun playSoundAtPlayer(event: SoundEvent): PositionedSoundInstance { + val instance = PositionedSoundInstance( + event, + SoundCategory.MASTER, + 1F, + 1F, + LocalRandom(0L), + MinecraftClient.getInstance().player?.blockPos ?: BlockPos(0, 0, 0) + ) + MinecraftClient.getInstance().soundManager.play(instance) + return instance + } + + fun playIPhoneAlarm(): PositionedSoundInstance { + return playSoundAtPlayer(iphone) + } +}
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt b/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt new file mode 100644 index 0000000..c6b2427 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/util/TimeMark.kt @@ -0,0 +1,23 @@ +package com.dulkirfabric.util + +import java.time.Duration + +data class TimeMark(val timestamp: Long) { + companion object { + fun now(): TimeMark { + return TimeMark(System.currentTimeMillis()) + } + + fun ago(duration: Duration): TimeMark { + return TimeMark(System.currentTimeMillis() - duration.toMillis()) + } + + fun farPast(): TimeMark { + return TimeMark(0L) + } + } + + fun timePassed(): Duration { + return Duration.ofMillis(System.currentTimeMillis() - timestamp) + } +}
\ No newline at end of file diff --git a/src/main/resources/assets/dulkirmod/sounds.json b/src/main/resources/assets/dulkirmod/sounds.json new file mode 100644 index 0000000..d0af12f --- /dev/null +++ b/src/main/resources/assets/dulkirmod/sounds.json @@ -0,0 +1,7 @@ +{ + "iphone": { + "sounds": [ + "dulkirmod:iphone" + ] + } +}
\ No newline at end of file diff --git a/src/main/resources/assets/dulkirmod/sounds/iphone.ogg b/src/main/resources/assets/dulkirmod/sounds/iphone.ogg Binary files differnew file mode 100644 index 0000000..1ab98d2 --- /dev/null +++ b/src/main/resources/assets/dulkirmod/sounds/iphone.ogg |