Made more adjustments to the off range of music, and made the music properly repeat. Background bard music always plays at the player.

This commit is contained in:
luisc committed 2024-05-14 18:32:30 -05:00
1 parent 2d9063cf24
commit 56bb6751b1
5 files changed
+31 -8

No files matched your search

@@ -8,6 +8,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import kamkeel.addon.DBCAddon;
import kamkeel.addon.client.DBCClient;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
@@ -57,7 +58,14 @@ public class ClientTickHandler{
if(prevWorld != mc.theWorld){
prevWorld = mc.theWorld;
MusicController.Instance.stopMusic();
}
} else if (MusicController.Instance.isPlaying() && MusicController.Instance.getEntity() != null) {
Entity entity = MusicController.Instance.getEntity();
if (MusicController.Instance.getOffRange() > 0 &&
(Minecraft.getMinecraft().thePlayer.getDistanceToEntity(entity) > MusicController.Instance.getOffRange()
|| entity.dimension != Minecraft.getMinecraft().thePlayer.dimension)) {
MusicController.Instance.stopMusic();
}
}
ScriptSoundController.Instance.onUpdate();
if(Minecraft.getMinecraft().thePlayer!=null && (prevWidth!=mc.displayWidth || prevHeight!=mc.displayHeight)){
prevWidth = mc.displayWidth;
@@ -32,7 +32,6 @@ import noppes.npcs.config.ConfigClient;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Animation;
@@ -166,7 +165,7 @@ public class PacketHandlerClient extends PacketHandlerServer{
NoppesUtil.setLastNpc((EntityNPCInterface) entity);
}
else if(type == EnumPacketClient.PLAY_MUSIC){
MusicController.Instance.playMusic(Server.readString(buffer), player);
MusicController.Instance.playMusicBackground(Server.readString(buffer), player, Integer.MAX_VALUE);
}
else if(type == EnumPacketClient.PLAY_SOUND){
MusicController.Instance.playSound(Server.readString(buffer),buffer.readFloat(),buffer.readFloat(),buffer.readFloat());
@@ -9,7 +9,9 @@ import net.minecraft.util.ResourceLocation;
public class MusicController {
public static MusicController Instance;
public ScriptClientSound sound;
private Entity entity;
private int offRange;
public MusicController(){
Instance = this;
@@ -24,31 +26,37 @@ public class MusicController {
}
}
public void playStreaming(String music, Entity entity){
public void playMusicJukebox(String music, Entity entity, int offRange){
if (this.isPlaying(music)) {
return;
}
this.stopMusic();
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);
clientSound.setRepeat(true);
this.sound = clientSound;
this.entity = entity;
this.offRange = offRange;
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
soundHandler.playSound(clientSound);
}
public void playMusic(String music, Entity entity) {
public void playMusicBackground(String music, Entity entity, int offRange) {
if (this.isPlaying(music)) {
return;
}
this.stopMusic();
ScriptClientSound clientSound = new ScriptClientSound(music);
clientSound.setEntity(entity);
clientSound.setEntity(Minecraft.getMinecraft().thePlayer);
clientSound.setRepeat(true);
this.sound = clientSound;
this.entity = entity;
this.offRange = offRange;
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
soundHandler.playSound(clientSound);
@@ -74,6 +82,10 @@ public class MusicController {
return this.entity;
}
public int getOffRange() {
return this.offRange;
}
public void playSound(String music, float x, float y, float z) {
Minecraft.getMinecraft().theWorld.playSound(x, y, z, music, 1, 1, false);
}
@@ -84,4 +84,8 @@ public class ScriptClientSound extends MovingSound implements ITickableSound {
public void setAttenuationType(AttenuationType attenuationType) {
this.field_147666_i = attenuationType;
}
public void setRepeat(boolean repeat) {
this.repeat = repeat;
}
}
+2 -2
View File
@@ -118,9 +118,9 @@ public class JobBard extends JobInterface{
if(!list.contains(CustomNpcs.proxy.getPlayer()))
return;
if(isStreamer)
MusicController.Instance.playStreaming(song, npc);
MusicController.Instance.playMusicJukebox(song, npc, hasOffRange ? maxRange : 0);
else
MusicController.Instance.playMusic(song, npc);
MusicController.Instance.playMusicBackground(song, npc, hasOffRange ? maxRange : 0);
}
@Override