Added music to Aether menu,

This commit is contained in:
bconlon 2020-07-06 10:26:46 -07:00
parent 94a5d5b2bc
commit b2a72f193b
2 changed files with 72 additions and 2 deletions

View file

@ -5,6 +5,8 @@ import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundCategory;
import net.minecraft.client.audio.SoundEventAccessor;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiScreenWorking;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.sound.PlaySoundEvent17;
@ -27,6 +29,7 @@ public class AetherMusicHandler {
public void onClientTick(TickEvent.ClientTickEvent event) throws Exception {
TickEvent.Phase phase = event.phase;
TickEvent.Type type = event.type;
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
if (phase == TickEvent.Phase.END) {
if (type.equals(TickEvent.Type.CLIENT)) {
@ -42,11 +45,29 @@ public class AetherMusicHandler {
{
musicTicker.trackRecord(null);
}
if (AetherConfig.config.get("Misc", "Enables the Aether Menu", false).getBoolean() && Minecraft.getMinecraft().theWorld == null && !(screen instanceof GuiScreenWorking))
{
if (!musicTicker.playingMenuMusic())
{
musicTicker.playMenuMusic();
}
if (musicTicker.playingMinecraftMusic())
{
musicTicker.stopMinecraftMusic();
}
}
else
{
musicTicker.stopMenuMusic();
}
}
@SubscribeEvent
public void onMusicControl(PlaySoundEvent17 event) {
ISound sound = event.result;
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
if (sound == null) {
return;
@ -62,6 +83,15 @@ public class AetherMusicHandler {
return;
}
}
if (sound.getPositionedSoundLocation().toString().equals("minecraft:music.menu"))
{
musicTicker.trackMinecraftMusic(sound);
if (AetherConfig.config.get("Misc", "Enables the Aether Menu", false).getBoolean() && Minecraft.getMinecraft().theWorld == null && !(screen instanceof GuiScreenWorking))
{
event.result = null;
}
}
} else if (category == SoundCategory.RECORDS && !(event.name.contains("note"))) {
this.musicTicker.trackRecord(event.sound);
this.mc.getSoundHandler().stopSounds();

View file

@ -21,7 +21,7 @@ public class AetherMusicTicker implements IUpdatePlayerListBox {
private final Random rand = new Random();
private final Minecraft mc;
private ISound currentMusic, currentRecord;
private ISound currentMusic, currentRecord, menuMusic, minecraftMusic;
private int timeUntilNextMusic = 100;
public AetherMusicTicker(Minecraft mcIn) {
@ -69,6 +69,16 @@ public class AetherMusicTicker implements IUpdatePlayerListBox {
return this.currentRecord != null;
}
public boolean playingMenuMusic()
{
return this.menuMusic != null;
}
public boolean playingMinecraftMusic()
{
return this.minecraftMusic != null;
}
public ISound getRecord()
{
return this.currentRecord;
@ -91,6 +101,17 @@ public class AetherMusicTicker implements IUpdatePlayerListBox {
this.currentRecord = record;
}
public void trackMinecraftMusic(ISound record)
{
this.minecraftMusic = record;
}
public void playMenuMusic()
{
this.menuMusic = PositionedSoundRecord.func_147673_a(TrackType.TRACK_MENU.getMusicLocation());
this.mc.getSoundHandler().playSound(this.menuMusic);
}
public void stopMusic() {
if (this.currentMusic != null) {
this.mc.getSoundHandler().stopSound(this.currentMusic);
@ -99,12 +120,31 @@ public class AetherMusicTicker implements IUpdatePlayerListBox {
}
}
public void stopMenuMusic()
{
if (this.menuMusic != null)
{
this.mc.getSoundHandler().stopSound(this.menuMusic);
this.menuMusic = null;
}
}
public void stopMinecraftMusic()
{
if (this.minecraftMusic != null)
{
this.mc.getSoundHandler().stopSound(this.minecraftMusic);
this.minecraftMusic = null;
}
}
@SideOnly(Side.CLIENT)
public static enum TrackType {
TRACK_ONE(Aether.locate("music.aether1"), 1200, 1500),
TRACK_TWO(Aether.locate("music.aether2"), 1200, 1500),
TRACK_THREE(Aether.locate("music.aether3"), 1200, 1500),
TRACK_FOUR(Aether.locate("music.aether4"), 1200, 1500);
TRACK_FOUR(Aether.locate("music.aether4"), 1200, 1500),
TRACK_MENU(Aether.locate("music.menu"), 1200, 1500);
private final ResourceLocation musicLocation;
private final int minDelay;