Created a Method to play Sounds directly from .wav files instead of using the buggy Minecraft Sound System and uses it in SoundHandler#playRenderSuccessSound(), fixing https://trello.com/c/d8hDHkc5/

This commit is contained in:
CrushedPixel
2015-06-30 14:48:48 +02:00
parent 38b49d8f4c
commit 45d69dff77
4 changed files with 24 additions and 6 deletions

View File

@@ -1,15 +1,36 @@
package eu.crushedpixel.replaymod.sound; package eu.crushedpixel.replaymod.sound;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.InputStream;
public class SoundHandler { public class SoundHandler {
private final Minecraft mc = Minecraft.getMinecraft(); private final Minecraft mc = Minecraft.getMinecraft();
private final ResourceLocation successSoundLocation = new ResourceLocation("replaymod:renderSuccess"); private final ResourceLocation successSoundLocation = new ResourceLocation("replaymod", "renderSuccess.wav");
public void playRenderSuccessSound() { public void playRenderSuccessSound() {
mc.getSoundHandler().playSound(PositionedSoundRecord.create(successSoundLocation, 1.0F)); playSound(successSoundLocation);
}
/**
* Plays a <b>.wav</b> Sound from a ResourceLocation. This method does <b>not</b> respect Game Settings like Audio Volume.
* @param loc The Sound File's ResourceLocation
*/
public void playSound(ResourceLocation loc) {
try {
InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream();
AudioInputStream ais = AudioSystem.getAudioInputStream(is);
Clip clip = AudioSystem.getClip();
clip.open(ais);
clip.start();
} catch(Exception e) {
e.printStackTrace();
}
} }
} }

Binary file not shown.

View File

@@ -1,3 +0,0 @@
{
"renderSuccess":{"category": "master", "sounds":["renderSuccess"]}
}