| 1 | package net.minecraft.client.audio;
|
| 2 |
|
| 3 | import java.util.Random;
|
| 4 | import net.minecraft.client.Minecraft;
|
| 5 | import net.minecraft.util.ITickable;
|
| 6 | import net.minecraft.util.MathHelper;
|
| 7 | import net.minecraft.util.ResourceLocation;
|
| 8 |
|
| 9 | public class MusicTicker implements ITickable
|
| 10 | {
|
| 11 | private final Random rand = new Random();
|
| 12 | private final Minecraft mc;
|
| 13 | private ISound currentMusic;
|
| 14 | private int timeUntilNextMusic = 100;
|
| 15 |
|
| 16 | public MusicTicker(Minecraft mcIn)
|
| 17 | {
|
| 18 | this.mc = mcIn;
|
| 19 | }
|
| 20 |
|
| 21 | /**
|
| 22 | * Like the old updateEntity(), except more generic.
|
| 23 | */
|
| 24 | public void update()
|
| 25 | {
|
| 26 | MusicTicker.MusicType musicticker$musictype = this.mc.getAmbientMusicType();
|
| 27 |
|
| 28 | if (this.currentMusic != null)
|
| 29 | {
|
| 30 | if (!musicticker$musictype.getMusicLocation().equals(this.currentMusic.getSoundLocation()))
|
| 31 | {
|
| 32 | this.mc.getSoundHandler().stopSound(this.currentMusic);
|
| 33 | this.timeUntilNextMusic = MathHelper.getRandomIntegerInRange(this.rand, 0, musicticker$musictype.getMinDelay() / 2);
|
| 34 | }
|
| 35 |
|
| 36 | if (!this.mc.getSoundHandler().isSoundPlaying(this.currentMusic))
|
| 37 | {
|
| 38 | this.currentMusic = null;
|
| 39 | this.timeUntilNextMusic = Math.min(MathHelper.getRandomIntegerInRange(this.rand, musicticker$musictype.getMinDelay(), musicticker$musictype.getMaxDelay()), this.timeUntilNextMusic);
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | if (this.currentMusic == null && this.timeUntilNextMusic-- <= 0)
|
| 44 | {
|
| 45 | this.func_181558_a(musicticker$musictype);
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | public void func_181558_a(MusicTicker.MusicType p_181558_1_)
|
| 50 | {
|
| 51 | this.currentMusic = PositionedSoundRecord.create(p_181558_1_.getMusicLocation());
|
| 52 | this.mc.getSoundHandler().playSound(this.currentMusic);
|
| 53 | this.timeUntilNextMusic = Integer.MAX_VALUE;
|
| 54 | }
|
| 55 |
|
| 56 | public void func_181557_a()
|
| 57 | {
|
| 58 | if (this.currentMusic != null)
|
| 59 | {
|
| 60 | this.mc.getSoundHandler().stopSound(this.currentMusic);
|
| 61 | this.currentMusic = null;
|
| 62 | this.timeUntilNextMusic = 0;
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | public static enum MusicType
|
| 67 | {
|
| 68 | MENU(new ResourceLocation("minecraft:music.menu"), 20, 600),
|
| 69 | GAME(new ResourceLocation("minecraft:music.game"), 12000, 24000),
|
| 70 | CREATIVE(new ResourceLocation("minecraft:music.game.creative"), 1200, 3600),
|
| 71 | CREDITS(new ResourceLocation("minecraft:music.game.end.credits"), Integer.MAX_VALUE, Integer.MAX_VALUE),
|
| 72 | NETHER(new ResourceLocation("minecraft:music.game.nether"), 1200, 3600),
|
| 73 | END_BOSS(new ResourceLocation("minecraft:music.game.end.dragon"), 0, 0),
|
| 74 | END(new ResourceLocation("minecraft:music.game.end"), 6000, 24000);
|
| 75 |
|
| 76 | private final ResourceLocation musicLocation;
|
| 77 | private final int minDelay;
|
| 78 | private final int maxDelay;
|
| 79 |
|
| 80 | private MusicType(ResourceLocation location, int minDelayIn, int maxDelayIn)
|
| 81 | {
|
| 82 | this.musicLocation = location;
|
| 83 | this.minDelay = minDelayIn;
|
| 84 | this.maxDelay = maxDelayIn;
|
| 85 | }
|
| 86 |
|
| 87 | public ResourceLocation getMusicLocation()
|
| 88 | {
|
| 89 | return this.musicLocation;
|
| 90 | }
|
| 91 |
|
| 92 | public int getMinDelay()
|
| 93 | {
|
| 94 | return this.minDelay;
|
| 95 | }
|
| 96 |
|
| 97 | public int getMaxDelay()
|
| 98 | {
|
| 99 | return this.maxDelay;
|
| 100 | }
|
| 101 | }
|
| 102 | }
|
| 103 |
|