2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client.controllers;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2024-05-14 17:52:19 -05:00
|
|
|
import net.minecraft.client.audio.ISound;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.audio.SoundHandler;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
|
|
|
|
|
public class MusicController {
|
|
|
|
|
public static MusicController Instance;
|
2024-05-14 17:52:19 -05:00
|
|
|
public ScriptClientSound sound;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public MusicController(){
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopMusic(){
|
2024-05-14 17:52:19 -05:00
|
|
|
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
|
|
|
|
|
soundHandler.stopSounds();
|
2024-05-14 17:59:25 -05:00
|
|
|
if (this.isPlaying()) {
|
|
|
|
|
this.sound.stopSound();
|
|
|
|
|
this.sound = null;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2024-02-20 20:30:18 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public void playStreaming(String music, Entity entity){
|
2024-05-14 17:52:19 -05:00
|
|
|
if (this.isPlaying(music)) {
|
2018-09-13 12:03:28 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2024-05-14 17:52:19 -05:00
|
|
|
|
|
|
|
|
ScriptClientSound clientSound = new ScriptClientSound(music);
|
|
|
|
|
clientSound.setPos((float)entity.posX, (float)entity.posY, (float)entity.posZ);
|
|
|
|
|
clientSound.setVolume(4.0F);
|
|
|
|
|
clientSound.setAttenuationType(ISound.AttenuationType.LINEAR);
|
|
|
|
|
this.sound = clientSound;
|
|
|
|
|
|
|
|
|
|
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
|
|
|
|
|
soundHandler.playSound(clientSound);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void playMusic(String music, Entity entity) {
|
2024-05-14 17:52:19 -05:00
|
|
|
if (this.isPlaying(music)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2024-05-14 17:52:19 -05:00
|
|
|
ScriptClientSound clientSound = new ScriptClientSound(music);
|
|
|
|
|
clientSound.setEntity(entity);
|
|
|
|
|
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
|
|
|
|
|
soundHandler.playSound(clientSound);
|
|
|
|
|
this.sound = clientSound;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2024-02-20 20:30:18 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public boolean isPlaying(String music) {
|
2024-05-14 17:52:19 -05:00
|
|
|
if (this.sound != null && this.sound.sound.equals(music)) {
|
|
|
|
|
ResourceLocation resource = new ResourceLocation(music);
|
|
|
|
|
if (!this.sound.getPositionedSoundLocation().equals(resource)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(this.sound);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2024-02-20 20:30:18 -05:00
|
|
|
|
2024-05-14 17:52:19 -05:00
|
|
|
public boolean isPlaying() {
|
|
|
|
|
return this.sound != null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public void playSound(String music, float x, float y, float z) {
|
|
|
|
|
Minecraft.getMinecraft().theWorld.playSound(x, y, z, music, 1, 1, false);
|
|
|
|
|
}
|
|
|
|
|
}
|