mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
71 lines
2.0 KiB
Java
71 lines
2.0 KiB
Java
package noppes.npcs.client.controllers;
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.audio.ISound;
|
|
import net.minecraft.client.audio.PositionedSoundRecord;
|
|
import net.minecraft.client.audio.SoundCategory;
|
|
import net.minecraft.client.audio.SoundHandler;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
|
public class MusicController {
|
|
|
|
public static MusicController Instance;
|
|
public PositionedSoundRecord playing;
|
|
public ResourceLocation playingResource;
|
|
public Entity playingEntity;
|
|
|
|
public MusicController(){
|
|
Instance = this;
|
|
}
|
|
|
|
public void stopMusic(){
|
|
SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
|
|
if(playing != null)
|
|
handler.stopSound(playing);
|
|
handler.stopSounds();
|
|
playingResource = null;
|
|
playingEntity = null;
|
|
playing = null;
|
|
}
|
|
|
|
public void playStreaming(String music, Entity entity){
|
|
if(isPlaying(music)){
|
|
return;
|
|
}
|
|
stopMusic();
|
|
playingEntity = entity;
|
|
playingResource = new ResourceLocation(music);
|
|
SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
|
|
playing = PositionedSoundRecord.func_147675_a(playingResource, (float)entity.posX, (float)entity.posY, (float)entity.posZ);
|
|
handler.playSound(playing);
|
|
}
|
|
|
|
public void playMusic(String music, Entity entity) {
|
|
if(isPlaying(music))
|
|
return;
|
|
stopMusic();
|
|
playingResource = new ResourceLocation(music);
|
|
|
|
playingEntity = entity;
|
|
|
|
SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
|
|
playing = PositionedSoundRecord.func_147673_a(playingResource);
|
|
handler.playSound(playing);
|
|
}
|
|
|
|
|
|
public boolean isPlaying(String music) {
|
|
ResourceLocation resource = new ResourceLocation(music);
|
|
if(playingResource == null || !playingResource.equals(resource)){
|
|
return false;
|
|
}
|
|
return Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(playing);
|
|
}
|
|
|
|
public void playSound(String music, float x, float y, float z) {
|
|
Minecraft.getMinecraft().theWorld.playSound(x, y, z, music, 1, 1, false);
|
|
}
|
|
}
|