Set all sound volume levels (except for master) to 0 before rendering a video to prevent all sounds the replay might produce from being played, but GUI interactions still play sounds

This commit is contained in:
CrushedPixel
2015-08-03 16:25:40 +02:00
parent eb281b9df4
commit 7d2895af3a
3 changed files with 33 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import eu.crushedpixel.replaymod.utils.CameraPathValidator;
import eu.crushedpixel.replaymod.video.VideoRenderer;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundCategory;
import net.minecraft.client.gui.GuiErrorScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.chunk.RenderChunk;
@@ -22,6 +23,8 @@ import net.minecraft.util.ReportedException;
import org.lwjgl.opengl.Display;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ReplayProcess {
@@ -47,6 +50,12 @@ public class ReplayProcess {
return isVideoRecording;
}
//a copy of the initial sound settings,
//which we will modify to prevent game sounds from annoying us while rendering
@SuppressWarnings("unchecked") //I, too, blame Forge for not re-adding generics to that Map.
private static Map<SoundCategory, Float> mapSoundLevelsBefore = null;
private static void resetProcess() {
firstTime = true;
@@ -101,12 +110,30 @@ public class ReplayProcess {
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.pathstarted", ChatMessageType.INFORMATION);
mc.timer.timerSpeed = 1;
//set the sound level map to null
//so a previous map doesn't override the current game settings after a camera path
mapSoundLevelsBefore = null;
} else {
//if FBOs are not enabled/supported, prevent the user from resizing the MC window
if(!OpenGlHelper.isFramebufferEnabled()) {
Display.setResizable(false);
}
//if rendering, disable all game sounds except for gui sounds
@SuppressWarnings("unchecked") //I, too, blame Forge for not re-adding generics to that Map.
Map<SoundCategory, Float> orgMap = (Map<SoundCategory, Float>)mc.gameSettings.mapSoundLevels;
mapSoundLevelsBefore = new HashMap<SoundCategory, Float>(orgMap);
//turn down for what? to mute all sound of course!
//the GUI sounds (button clicks etc) are not muted this way.
for(SoundCategory category : SoundCategory.values()) {
if(category == SoundCategory.MASTER) continue;
orgMap.put(category, 0f);
}
mc.gameSettings.mapSoundLevels = orgMap;
initialTimestamp = 0;
boolean success = false;
try {
@@ -149,6 +176,9 @@ public class ReplayProcess {
//re-enable window resizing after rendering
Display.setResizable(true);
//restore the sound settings
mc.gameSettings.mapSoundLevels = mapSoundLevelsBefore;
}
//if justCheck is true, no Screenshot will be taken, it will only be checked

View File

@@ -7,7 +7,6 @@ import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.entities.CameraEntity;
import eu.crushedpixel.replaymod.events.handlers.RecordingHandler;
import eu.crushedpixel.replaymod.holders.PacketData;
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
import eu.crushedpixel.replaymod.utils.ReplayFile;
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
import io.netty.channel.ChannelHandler.Sharable;
@@ -286,12 +285,6 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
protected Packet processPacket(Packet p) throws Exception {
if(BAD_PACKETS.contains(p.getClass())) return null;
if (p instanceof S29PacketSoundEffect || p instanceof S28PacketEffect) {
if (!asyncMode || isHurrying()) {
return null;
}
}
if(p instanceof S48PacketResourcePackSend) {
S48PacketResourcePackSend packet = (S48PacketResourcePackSend) p;
String url = packet.func_179783_a();

View File

@@ -99,5 +99,8 @@ public net.minecraft.client.particle.EffectRenderer field_78876_b # fxLayers
# IntegratedServer
public net.minecraft.server.integrated.IntegratedServer field_71348_o # isGamePaused
# GameSettings
public net.minecraft.client.settings.GameSettings field_151446_aD # mapSoundLevels
# Example
# public net.minecraft.package.ClassName func_some_id(Ljava/lang/Class;IZS)V # methodName