Skip to content

Commit 1e6a384

Browse files
Custom Sound Example in Wiki. (#4179)
1 parent c649748 commit 1e6a384

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Custom Sounds
3+
---
4+
5+
6+
## Creating a Custom Sound
7+
8+
!!! Warning
9+
Registering custom sounds is currently only supported in Java, though you can use your sound in kubejs scripts once it's defined.
10+
11+
To add a new sound, a sounds class is required.
12+
This class prepares for registrate to register the sounds.
13+
An example of a custom sound can be found below.
14+
15+
```java
16+
import static com.examplemod.common.registry.ExampleRegistration.REGISTRATE;
17+
18+
public class ExampleSound {
19+
20+
public static final SoundEntry MICROVERSE = REGISTRATE.sound("microverse").build();
21+
22+
public static void init() {}
23+
}
24+
```
25+
26+
Before you run datagen, the sound needs to be prepared for use. For a sound to be registered it must be in .ogg format and be inside `assets/examplemod/sounds`.
27+
!!! note "mono vs. stereo audio"
28+
29+
Your audio file should be mono, as Minecraft's attentuation logic only works with single-channel audio. Stereo sounds won't fade out (they'll be played at the same volume at any distance from the source) and should only be used for background tracks such as the main menu music.
30+
31+
After you make this class, prepare your sound, and initialize it in your main mod class, you want to setup datagen for the sounds.
32+
It's a bit more complicated than normal datagen, so an example can be found below.
33+
34+
```java
35+
@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
36+
public class ExampleDataGenerators {
37+
38+
@SubscribeEvent
39+
public static void gatherData(GatherDataEvent event) {
40+
PackOutput packOutput = event.getGenerator().getPackOutput();
41+
42+
if (event.includeClient()) {
43+
event.getGenerator().addProvider(
44+
true,
45+
new SoundEntryBuilder.SoundEntryProvider(packOutput, examplemod.MOD_ID));
46+
}
47+
}
48+
}
49+
50+
```

0 commit comments

Comments
 (0)