diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index abac7499..aa9b8fd2 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1792,19 +1792,27 @@ public static class LoadSoundsCategory public EnumSoundModes utLoadSoundMode = EnumSoundModes.NOTHING; @Config.Name("[2] Minecraft Loaded Sounds") - @Config.Comment({"Sounds to play when Minecraft is loaded", "Syntax: eventname;pitch"}) + @Config.Comment + ({ + "Sounds to play when Minecraft is loaded", + "Syntax: eventname;pitch;volume" + }) public String[] utLoadSoundMC = new String[] { - "entity.experience_orb.pickup;1.0", - "entity.player.levelup;1.0" + "entity.experience_orb.pickup;1.0;1.0", + "entity.player.levelup;1.0;1.0" }; @Config.Name("[3] World Loaded Sounds") - @Config.Comment({"Sounds to play when the world is loaded", "Syntax: eventname;pitch"}) + @Config.Comment + ({ + "Sounds to play when the world is loaded", + "Syntax: eventname;pitch;volume" + }) public String[] utLoadSoundWorld = new String[] { - "entity.experience_orb.pickup;1.0", - "entity.player.levelup;1.0" + "entity.experience_orb.pickup;1.0;1.0", + "entity.player.levelup;1.0;1.0" }; public enum EnumSoundModes diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/loadsound/UTLoadSound.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/loadsound/UTLoadSound.java index b887eba5..4658aada 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/loadsound/UTLoadSound.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/loadsound/UTLoadSound.java @@ -5,10 +5,13 @@ import java.util.Random; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; @@ -31,6 +34,8 @@ public class UTLoadSound private static final List soundListWorld = new ArrayList<>(); private static final List pitchListMC = new ArrayList<>(); private static final List pitchListWorld = new ArrayList<>(); + private static final List volumeListMC = new ArrayList<>(); + private static final List volumeListWorld = new ArrayList<>(); private static boolean playedMenu = false; private static boolean playedWorld = false; @@ -40,36 +45,63 @@ public static void initLists() soundListWorld.clear(); pitchListMC.clear(); pitchListWorld.clear(); + volumeListMC.clear(); + volumeListWorld.clear(); + for (String sound : UTConfigTweaks.MISC.LOAD_SOUNDS.utLoadSoundMC) { String[] soundEntries = sound.split(";"); SoundEvent soundEvent = SoundEvent.REGISTRY.getObject(new ResourceLocation(soundEntries[0])); if (soundEvent != null) { - Float pitch = new Float(soundEntries[1]); + Float pitch = 1.0F; + Float volume = 1.0F; + try + { + pitch = new Float(soundEntries[1]); + volume = new Float(soundEntries[2]); + } + catch (Exception e) + { + UniversalTweaks.LOGGER.warn("Unable to parse sound properties for {}", new ResourceLocation(soundEntries[0])); + } soundListMC.add(soundEvent); pitchListMC.add(pitch); + volumeListMC.add(volume); } else { UniversalTweaks.LOGGER.warn("Unable to find sound: {}", new ResourceLocation(soundEntries[0])); } } + for (String sound : UTConfigTweaks.MISC.LOAD_SOUNDS.utLoadSoundWorld) { String[] soundEntries = sound.split(";"); SoundEvent soundEvent = SoundEvent.REGISTRY.getObject(new ResourceLocation(soundEntries[0])); if (soundEvent != null) { - Float pitch = new Float(soundEntries[1]); + Float pitch = 1.0F; + Float volume = 1.0F; + try + { + pitch = new Float(soundEntries[1]); + volume = new Float(soundEntries[2]); + } + catch (Exception e) + { + UniversalTweaks.LOGGER.warn("Unable to parse sound properties for {}", new ResourceLocation(soundEntries[0])); + } soundListWorld.add(soundEvent); pitchListWorld.add(pitch); + volumeListWorld.add(volume); } else { UniversalTweaks.LOGGER.warn("Unable to find sound: {}", new ResourceLocation(soundEntries[0])); } } + UniversalTweaks.LOGGER.info("Load Sound lists initialized"); } @@ -79,7 +111,8 @@ public static void playRandomSoundMC() int randomIndex = random.nextInt(soundListMC.size()); SoundEvent soundEvent = soundListMC.get(randomIndex); Float pitch = pitchListMC.get(randomIndex); - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(soundEvent, pitch)); + Float volume = volumeListMC.get(randomIndex); + Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.MASTER, volume, pitch, false, 0, ISound.AttenuationType.NONE, 0F, 0F, 0F)); } public static void playRandomSoundWorld() @@ -88,7 +121,9 @@ public static void playRandomSoundWorld() int randomIndex = random.nextInt(soundListWorld.size()); SoundEvent soundEvent = soundListWorld.get(randomIndex); Float pitch = pitchListWorld.get(randomIndex); - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(soundEvent, pitch)); + Float volume = volumeListWorld.get(randomIndex); + EntityPlayer player = Minecraft.getMinecraft().player; + Minecraft.getMinecraft().getSoundHandler().playSound(new PositionedSoundRecord(soundEvent.getSoundName(), SoundCategory.MASTER, volume, pitch, false, 0, ISound.AttenuationType.NONE, (float) player.posX, (float) player.posY, (float) player.posZ)); } @SubscribeEvent(priority = EventPriority.LOWEST)