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:
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/main/resources/assets/replaymod/renderSuccess.wav
Normal file
BIN
src/main/resources/assets/replaymod/renderSuccess.wav
Normal file
Binary file not shown.
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"renderSuccess":{"category": "master", "sounds":["renderSuccess"]}
|
|
||||||
}
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user