Search in sources :

Example 1 with CustomSoundMap

use of net.modificationstation.stationapi.api.client.resource.CustomSoundMap in project StationAPI by ModificationStation.

the class MixinSoundHelper method loadModAudio.

@Environment(EnvType.CLIENT)
private static void loadModAudio(SoundMap array, String channel) {
    try {
        for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) {
            ModMetadata stationMod = modContainer.getMetadata();
            Path basePath = Paths.get("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel);
            if (MixinSoundHelper.class.getResource(basePath.toString().replace("\\", "/")) != null) {
                RecursiveReader recursiveReader = new RecursiveReader("/assets/" + stationMod.getId() + "/stationapi/sounds/" + channel, (filepath) -> filepath.endsWith(".ogg") || filepath.endsWith(".mp3") || filepath.endsWith(".wav"));
                for (URL audioUrl : recursiveReader.read()) {
                    String audioID = audioUrl.toString().replace("\\", "/").split("/stationapi/sounds/" + channel)[1].replaceFirst("/", "");
                    ((CustomSoundMap) array).putSound(stationMod.getId() + ":" + audioID, audioUrl);
                }
            }
        }
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }
}
Also used : RecursiveReader(net.modificationstation.stationapi.api.resource.RecursiveReader) ModContainer(net.fabricmc.loader.api.ModContainer) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) CustomSoundMap(net.modificationstation.stationapi.api.client.resource.CustomSoundMap) Environment(net.fabricmc.api.Environment)

Aggregations

Environment (net.fabricmc.api.Environment)1 ModContainer (net.fabricmc.loader.api.ModContainer)1 ModMetadata (net.fabricmc.loader.api.metadata.ModMetadata)1 CustomSoundMap (net.modificationstation.stationapi.api.client.resource.CustomSoundMap)1 RecursiveReader (net.modificationstation.stationapi.api.resource.RecursiveReader)1