Fixed background music not cancelling when moving within another bard NPC's range

This commit is contained in:
luisc committed 2024-05-14 19:17:21 -05:00
1 parent 56bb6751b1
commit f6244434f7
2 files changed
+18 -6

No files matched your search

@@ -34,7 +34,7 @@ public class MusicController {
ScriptClientSound clientSound = new ScriptClientSound(music);
clientSound.setPos((float)entity.posX, (float)entity.posY, (float)entity.posZ);
clientSound.setVolume(4.0F);
clientSound.setVolume(Math.max(1, offRange/16.0F));
clientSound.setAttenuationType(ISound.AttenuationType.LINEAR);
clientSound.setRepeat(true);
this.sound = clientSound;
@@ -86,6 +86,14 @@ public class MusicController {
return this.offRange;
}
public double getDistance() {
Entity player = Minecraft.getMinecraft().thePlayer;
if (this.entity != null && this.entity.dimension == player.dimension) {
return player.getDistanceToEntity(this.entity);
}
return Double.MAX_VALUE;
}
public void playSound(String music, float x, float y, float z) {
Minecraft.getMinecraft().theWorld.playSound(x, y, z, music, 1, 1, false);
}
+9 -5
View File
@@ -93,13 +93,15 @@ public class JobBard extends JobInterface{
return;
if(!MusicController.Instance.isPlaying()){
this.play();
if (!this.play()) return;
}
else if(MusicController.Instance.getEntity() != npc){
EntityPlayer player = CustomNpcs.proxy.getPlayer();
if(npc.getDistanceToEntity(player) < MusicController.Instance.sound.getDistance()){
double distanceToPlayer = npc.getDistanceToEntity(player);
double distanceToMusic = MusicController.Instance.getDistance();
if(distanceToPlayer < distanceToMusic){
MusicController.Instance.stopMusic();
this.play();
if (!this.play()) return;
}
}
else if(hasOffRange){
@@ -113,14 +115,16 @@ public class JobBard extends JobInterface{
}
}
private void play() {
private boolean play() {
List<EntityPlayer> list = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(minRange, minRange/2, minRange));
if(!list.contains(CustomNpcs.proxy.getPlayer()))
return;
return false;
if(isStreamer)
MusicController.Instance.playMusicJukebox(song, npc, hasOffRange ? maxRange : 0);
else
MusicController.Instance.playMusicBackground(song, npc, hasOffRange ? maxRange : 0);
return true;
}
@Override