Aether Music more common

This commit is contained in:
Kino 2017-03-04 21:17:41 -05:00
parent b643f656e8
commit 47017db75a
3 changed files with 128 additions and 50 deletions

View file

@ -4,12 +4,16 @@ import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import com.legacy.aether.client.audio.music.AetherMusicTicker;
import com.legacy.aether.client.gui.AetherLoadingScreen;
import com.legacy.aether.server.AetherConfig;
public class ClientTickHandler
{
public static Minecraft mc = Minecraft.getMinecraft();
private Minecraft mc = Minecraft.getMinecraft();
private AetherMusicTicker musicTicker = new AetherMusicTicker(mc);
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) throws Exception
@ -25,6 +29,11 @@ public class ClientTickHandler
{
mc.loadingScreen = new AetherLoadingScreen(mc);
}
if (!mc.isGamePaused() && mc.thePlayer != null && mc.thePlayer.dimension == AetherConfig.getAetherDimensionID())
{
musicTicker.update();
}
}
}
}

View file

@ -1,11 +1,8 @@
package com.legacy.aether.client.audio;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
@ -13,7 +10,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.legacy.aether.server.Aether;
import com.legacy.aether.server.AetherConfig;
import com.legacy.aether.server.registry.sounds.SoundsAether;
@ -22,40 +18,24 @@ public class AetherMusicHandler
private Minecraft mc = Minecraft.getMinecraft();
private Random random;
public AetherMusicHandler()
{
this.random = new Random();
}
@SubscribeEvent
public void onMusicControl(PlaySoundEvent event)
{
if (event.getSound().getCategory() == SoundCategory.MUSIC)
SoundCategory category = event.getSound().getCategory();
if (category == SoundCategory.MUSIC)
{
if (this.mc.thePlayer != null)
{
if (this.mc.thePlayer.dimension == AetherConfig.getAetherDimensionID())
if (!event.getSound().getSoundLocation().getResourceDomain().contains("aether_legacy") && this.mc.thePlayer.dimension == AetherConfig.getAetherDimensionID())
{
if (event.getSound().getSoundLocation() == this.mc.getAmbientMusicType().getMusicLocation().getSoundName() && !this.isAetherSongPlaying(event.getSound()))
{
int songNum = this.random.nextInt(4);
event.setResultSound(null);
event.setResultSound(getSound(Aether.locate("music.aether" + (songNum + 1))));
return;
}
else
{
event.setResultSound(null);
return;
}
return;
}
}
}
else if (event.getSound().getCategory() == SoundCategory.RECORDS)
else if (category == SoundCategory.RECORDS)
{
this.mc.getSoundHandler().stopSounds();
@ -63,23 +43,6 @@ public class AetherMusicHandler
}
}
private boolean isAetherSongPlaying(ISound sound)
{
boolean aether1Playing = this.mc.getSoundHandler().isSoundPlaying(getSound(new ResourceLocation("aether_legacy:music.aether1")));
boolean aether2Playing = this.mc.getSoundHandler().isSoundPlaying(getSound(new ResourceLocation("aether_legacy:music.aether2")));
boolean aether3Playing = this.mc.getSoundHandler().isSoundPlaying(getSound(new ResourceLocation("aether_legacy:music.aether3")));
boolean aether4Playing = this.mc.getSoundHandler().isSoundPlaying(getSound(new ResourceLocation("aether_legacy:music.aether4")));
return aether1Playing || aether2Playing || aether3Playing || aether4Playing;
}
public void playSound(SoundEvent event)
{
ISound sound = new PositionedSoundRecord(event.getSoundName(), SoundCategory.PLAYERS, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0, 0, 0);
this.mc.getSoundHandler().playSound(sound);
}
@SideOnly(Side.CLIENT)
public static ISound getAchievementSound(int number)
{
@ -88,9 +51,4 @@ public class AetherMusicHandler
return new PositionedSoundRecord(sound.getSoundName(), SoundCategory.PLAYERS, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0, 0, 0);
}
public static ISound getSound(ResourceLocation location)
{
return new PositionedSoundRecord(location, SoundCategory.MUSIC, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0, 0, 0);
}
}

View file

@ -0,0 +1,111 @@
package com.legacy.aether.client.audio.music;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.legacy.aether.server.registry.sounds.SoundsAether;
@SideOnly(Side.CLIENT)
public class AetherMusicTicker implements ITickable
{
private final Random rand = new Random();
private final Minecraft mc;
private ISound currentMusic;
private int timeUntilNextMusic = 100;
public AetherMusicTicker(Minecraft mcIn)
{
this.mc = mcIn;
}
public void update()
{
TrackType tracktype = this.getRandomTrack();
if (this.currentMusic != null)
{
if (!this.mc.getSoundHandler().isSoundPlaying(this.currentMusic))
{
System.out.println("MUSIC STOPPED!!");
this.currentMusic = null;
this.timeUntilNextMusic = Math.min(MathHelper.getRandomIntegerInRange(this.rand, tracktype.getMinDelay(), tracktype.getMaxDelay()), this.timeUntilNextMusic);
}
}
this.timeUntilNextMusic = Math.min(this.timeUntilNextMusic, tracktype.getMaxDelay());
if (this.currentMusic == null && this.timeUntilNextMusic-- <= 0)
{
System.out.println("Playing new Music!!!");
this.playMusic(tracktype);
}
}
public AetherMusicTicker.TrackType getRandomTrack()
{
int num = this.rand.nextInt(4);
return num == 0 ? TrackType.TRACK_ONE : num == 1 ? TrackType.TRACK_TWO : num == 2 ? TrackType.TRACK_THREE : TrackType.TRACK_FOUR;
}
public void playMusic(TrackType requestedMusicType)
{
this.currentMusic = PositionedSoundRecord.getMusicRecord(requestedMusicType.getMusicLocation());
this.mc.getSoundHandler().playSound(this.currentMusic);
this.timeUntilNextMusic = Integer.MAX_VALUE;
}
public void stopMusic()
{
if (this.currentMusic != null)
{
this.mc.getSoundHandler().stopSound(this.currentMusic);
this.currentMusic = null;
this.timeUntilNextMusic = 0;
}
}
@SideOnly(Side.CLIENT)
public static enum TrackType
{
TRACK_ONE(SoundsAether.aether1, 1200, 1500),
TRACK_TWO(SoundsAether.aether2, 1200, 1500),
TRACK_THREE(SoundsAether.aether3, 1200, 1500),
TRACK_FOUR(SoundsAether.aether4, 1200, 1500);
private final SoundEvent musicLocation;
private final int minDelay;
private final int maxDelay;
private TrackType(SoundEvent musicLocationIn, int minDelayIn, int maxDelayIn)
{
this.musicLocation = musicLocationIn;
this.minDelay = minDelayIn;
this.maxDelay = maxDelayIn;
}
public SoundEvent getMusicLocation()
{
return this.musicLocation;
}
public int getMinDelay()
{
return this.minDelay;
}
public int getMaxDelay()
{
return this.maxDelay;
}
}
}