It's possible, but tricky. I did something like this for my music mod, and I could share some of the code with ya if you're interested.
The basic idea is that you need a song that can be split up into modular parts. Minecraft's sound system doesn't allow you to fade music in or out, meaning the bossfight either has to be exactly the duration of the song, or you need to play multiple snippets of a song at set intervals when the bossfight is active, in such a way that they string together into one song. Needless to say, this is kind of complicated, and a bit of a headache to get working properly.
But yeah, you need to use a player-persistent variable as a timer between segments of the song, need to be aware of what segments can be strung together, and need to cut to the end segment when the boss is defeated, or the player is out of range. You will also likely want to cancel all other music sfx when the boss battle starts.
It's possible, but tricky. I did something like this for my music mod, and I could share some of the code with ya if you're interested.
The basic idea is that you need a song that can be split up into modular parts. Minecraft's sound system doesn't allow you to fade music in or out, meaning the bossfight either has to be exactly the duration of the song, or you need to play multiple snippets of a song at set intervals when the bossfight is active, in such a way that they string together into one song. Needless to say, this is kind of complicated, and a bit of a headache to get working properly.
But yeah, you need to use a player-persistent variable as a timer between segments of the song, need to be aware of what segments can be strung together, and need to cut to the end segment when the boss is defeated, or the player is out of range. You will also likely want to cancel all other music sfx when the boss battle starts.