tinycodinglm / mc /mc-0007.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
2.05 kB
opencode trace
System You are an expert Fabric mod developer. You write idiomatic Minecraft Fabric mods using Java, Fabric API, and Yarn mappings.

You are an expert Fabric mod developer. You write idiomatic Minecraft Fabric mods using Java, Fabric API, and Yarn mappings.

User

How do I add custom sound events and set up sounds.json for my Fabric mod?

Assistant

Register sound events:

java
public class MySounds {
    public static final SoundEvent CUSTOM_USE = SoundEvent.of(Identifier.of("mymod", "custom_use"));
    public static final SoundEvent CUSTOM_EXPLOSION = SoundEvent.of(Identifier.of("mymod", "custom_explosion"));
    public static final SoundEvent CUSTOM_AMBIENT = SoundEvent.of(Identifier.of("mymod", "custom_ambient"));

    public static void register() {
        Registry.register(Registries.SOUND_EVENT, CUSTOM_USE.getId(), CUSTOM_USE);
        Registry.register(Registries.SOUND_EVENT, CUSTOM_EXPLOSION.getId(), CUSTOM_EXPLOSION);
        Registry.register(Registries.SOUND_EVENT, CUSTOM_AMBIENT.getId(), CUSTOM_AMBIENT);
    }
}

sounds.json (assets/mymod/sounds.json):

json
{"custom_use": {"category": "block", "sounds": [{"name": "mymod:custom_use_1", "stream": false}]},
 "custom_explosion": {"category": "hostile", "sounds": [{"name": "mymod:custom_explosion", "stream": true, "attenuation_distance": 16}]},
 "custom_ambient": {"category": "ambient", "sounds": [{"name": "mymod:custom_ambient", "stream": true, "preload": true}]}}

Sound files: src/main/resources/assets/mymod/sounds/custom_use_1.ogg, custom_explosion.ogg, custom_ambient.ogg

Playing sounds:

java
player.playSound(MySounds.CUSTOM_USE, 1.0f, 1.0f);
world.playSound(null, pos, MySounds.CUSTOM_EXPLOSION, SoundSource.HOSTILE, 1.0f, 1.0f);
MinecraftClient.getInstance().player.playSound(MySounds.CUSTOM_AMBIENT, 0.5f, 1.0f);