Skip to content

Commit bd35875

Browse files
committed
Added SoundManager
1 parent ef6567f commit bd35875

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

common/src/main/kotlin/com/lambda/core/Loader.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ object Loader {
2222
LambdaFont.Loader,
2323
GuiConfigurable,
2424
FriendManager,
25+
SoundManager,
2526
)
2627

2728
fun initialize() {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.lambda.core
2+
3+
import com.lambda.Lambda
4+
import com.lambda.context.SafeContext
5+
import net.minecraft.client.sound.PositionedSoundInstance
6+
import net.minecraft.registry.Registries
7+
import net.minecraft.registry.Registry
8+
import net.minecraft.sound.SoundEvent
9+
import net.minecraft.util.Identifier
10+
11+
object SoundManager : Loadable {
12+
13+
override fun load(): String {
14+
LambdaSound.entries.forEach {
15+
Registry.register(Registries.SOUND_EVENT, it.id, it.event)
16+
}
17+
18+
return "Loaded ${LambdaSound.entries.size} sounds"
19+
}
20+
21+
enum class LambdaSound(val id: Identifier) {
22+
MODULE_TOGGLE("module_toggle".toIdentifier());
23+
24+
val event: SoundEvent = SoundEvent.of(id)
25+
}
26+
27+
fun SafeContext.playSound(event: SoundEvent, pitch: Float = 1.0f) {
28+
mc.soundManager.play(
29+
PositionedSoundInstance.master(event, pitch)
30+
)
31+
}
32+
33+
private fun String.toIdentifier() = Identifier("${Lambda.MOD_ID}:${this}")
34+
}

common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BooleanButton.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.lambda.gui.impl.clickgui.buttons.setting
22

33
import com.lambda.config.settings.comparable.BooleanSetting
4+
import com.lambda.core.SoundManager
5+
import com.lambda.core.SoundManager.playSound
46
import com.lambda.graphics.animation.Animation.Companion.exp
57
import com.lambda.gui.api.GuiEvent
68
import com.lambda.gui.api.component.core.list.ChildLayer
79
import com.lambda.gui.impl.clickgui.buttons.SettingButton
810
import com.lambda.module.modules.client.GuiSettings
11+
import com.lambda.threading.runSafe
912
import com.lambda.util.Mouse
1013
import com.lambda.util.math.ColorUtils.setAlpha
1114
import com.lambda.util.math.MathUtils.lerp
@@ -47,5 +50,8 @@ class BooleanButton(
4750

4851
override fun performClickAction(e: GuiEvent.MouseClick) {
4952
if (e.button == Mouse.Button.Left) value = !value
53+
runSafe {
54+
playSound(SoundManager.LambdaSound.MODULE_TOGGLE.event)
55+
}
5056
}
5157
}

common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.gson.*
44
import com.lambda.brigadier.CommandResult
55
import com.lambda.config.RotationSettings
66
import com.lambda.context.SafeContext
7+
import com.lambda.core.SoundManager.playSound
78
import com.lambda.core.TimerManager
89
import com.lambda.event.EventFlow.lambdaScope
910
import com.lambda.event.events.KeyPressEvent
@@ -25,9 +26,7 @@ import com.lambda.util.FolderRegister.locationBoundDirectory
2526
import com.lambda.util.Formatting.asString
2627
import com.lambda.util.Formatting.getTime
2728
import com.lambda.util.KeyCode
28-
import com.lambda.util.SoundUtils.playSound
2929
import com.lambda.util.StringUtils.sanitizeForFilename
30-
import com.lambda.util.math.MathUtils.roundToStep
3130
import com.lambda.util.primitives.extension.rotation
3231
import com.lambda.util.text.*
3332
import kotlinx.coroutines.Dispatchers

common/src/main/kotlin/com/lambda/util/SoundUtils.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.
8.63 KB
Binary file not shown.

0 commit comments

Comments
 (0)