Skip to content

Commit 3db39f0

Browse files
committed
Fixed sound manager
1 parent bd35875 commit 3db39f0

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.lambda.core
2+
3+
import com.lambda.core.SoundManager.toIdentifier
4+
import net.minecraft.sound.SoundEvent
5+
import net.minecraft.util.Identifier
6+
7+
enum class LambdaSound(val id: Identifier) {
8+
MODULE_TOGGLE("module_toggle".toIdentifier());
9+
10+
val event: SoundEvent = SoundEvent.of(id)
11+
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.lambda.core
22

33
import com.lambda.Lambda
4-
import com.lambda.context.SafeContext
4+
import com.lambda.Lambda.mc
55
import net.minecraft.client.sound.PositionedSoundInstance
66
import net.minecraft.registry.Registries
77
import net.minecraft.registry.Registry
@@ -18,17 +18,11 @@ object SoundManager : Loadable {
1818
return "Loaded ${LambdaSound.entries.size} sounds"
1919
}
2020

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) {
21+
fun playSound(event: SoundEvent, pitch: Float = 1.0f) {
2822
mc.soundManager.play(
2923
PositionedSoundInstance.master(event, pitch)
3024
)
3125
}
3226

33-
private fun String.toIdentifier() = Identifier("${Lambda.MOD_ID}:${this}")
27+
fun String.toIdentifier() = Identifier(Lambda.MOD_ID, this)
3428
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +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.LambdaSound
45
import com.lambda.core.SoundManager
56
import com.lambda.core.SoundManager.playSound
67
import com.lambda.graphics.animation.Animation.Companion.exp
78
import com.lambda.gui.api.GuiEvent
89
import com.lambda.gui.api.component.core.list.ChildLayer
910
import com.lambda.gui.impl.clickgui.buttons.SettingButton
1011
import com.lambda.module.modules.client.GuiSettings
11-
import com.lambda.threading.runSafe
1212
import com.lambda.util.Mouse
1313
import com.lambda.util.math.ColorUtils.setAlpha
1414
import com.lambda.util.math.MathUtils.lerp
@@ -50,8 +50,6 @@ class BooleanButton(
5050

5151
override fun performClickAction(e: GuiEvent.MouseClick) {
5252
if (e.button == Mouse.Button.Left) value = !value
53-
runSafe {
54-
playSound(SoundManager.LambdaSound.MODULE_TOGGLE.event)
55-
}
53+
playSound(LambdaSound.MODULE_TOGGLE.event)
5654
}
5755
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"module_toggle": {
3+
"sounds": [
4+
"lambda:ui/module_toggle"
5+
]
6+
}
7+
}

common/src/main/resources/assets/lambda/sound/test.ogg renamed to common/src/main/resources/assets/lambda/sounds/ui/module_toggle.ogg

File renamed without changes.

0 commit comments

Comments
 (0)