Use vanilla sound engine to play render success sound (fixes #286)
This commit is contained in:
@@ -80,9 +80,16 @@ import org.lwjgl.glfw.GLFW;
|
||||
//$$ import java.io.IOException;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11400
|
||||
import net.minecraft.client.sound.PositionedSoundInstance;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10904
|
||||
import com.replaymod.render.blend.mixin.ParticleAccessor;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
//#endif
|
||||
|
||||
@@ -758,6 +765,20 @@ public class MCVer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void playSound(Identifier sound) {
|
||||
getMinecraft().getSoundManager().play(
|
||||
//#if MC>=11400
|
||||
PositionedSoundInstance.master(new SoundEvent(sound), 1.0F)
|
||||
//#elseif MC>=10904
|
||||
//$$ PositionedSoundRecord.getMasterRecord(new SoundEvent(sound), 1.0F)
|
||||
//#elseif MC>=10800
|
||||
//$$ PositionedSoundRecord.create(sound, 1.0F)
|
||||
//#else
|
||||
//$$ PositionedSoundRecord.createPositionedSoundRecord(sound, 1.0F)
|
||||
//#endif
|
||||
);
|
||||
}
|
||||
|
||||
//#if MC>=11400
|
||||
private static Boolean hasOptifine;
|
||||
public static boolean hasOptifine() {
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.replaymod.render.gui.GuiRenderingDone;
|
||||
import com.replaymod.render.gui.GuiVideoRenderer;
|
||||
import com.replaymod.render.metadata.MetadataInjector;
|
||||
import com.replaymod.render.mixin.WorldRendererAccessor;
|
||||
import com.replaymod.render.utils.SoundHandler;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
@@ -29,6 +28,7 @@ import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import com.mojang.blaze3d.platform.GLX;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
@@ -422,7 +422,7 @@ public class VideoRenderer implements RenderInfo {
|
||||
}
|
||||
}
|
||||
|
||||
new SoundHandler().playRenderSuccessSound();
|
||||
MCVer.playSound(new Identifier("replaymod", "render_success"));
|
||||
|
||||
try {
|
||||
if (!hasFailed() && ffmpegWriter != null) {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.replaymod.render.utils;
|
||||
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.Clip;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SoundHandler {
|
||||
|
||||
private final Identifier successSoundLocation = new Identifier("replaymod", "render_success.wav");
|
||||
|
||||
public void playRenderSuccessSound() {
|
||||
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(Identifier loc) {
|
||||
try {
|
||||
InputStream is = MCVer.getMinecraft().getResourceManager().getResource(loc).getInputStream();
|
||||
byte[] bytes = IOUtils.toByteArray(is);
|
||||
is.close();
|
||||
AudioInputStream ais = AudioSystem.getAudioInputStream(new ByteArrayInputStream(bytes));
|
||||
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(ais);
|
||||
clip.start();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user