From 25fb78ace82779fa6e5b45fc20fa428570c63a59 Mon Sep 17 00:00:00 2001 From: nea Date: Tue, 18 Jul 2023 02:52:25 +0200 Subject: DUDUDUDUDUDUDUDUDUDUDUDUDUDU --- .../com/dulkirfabric/features/IPhoneAlarm.kt | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/kotlin/com/dulkirfabric/features/IPhoneAlarm.kt (limited to 'src/main/kotlin/com/dulkirfabric/features') 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() + + @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 -- cgit