Jump to content

[Solved] Creating seamless music loop from a tile entity: is it possible?


Recommended Posts

Posted

So I'm working on a mod that generates a huge (32 x 32 x 32) maze and I want it to have custom background music for added atmosphere. I have achieved this by creating a block at the entrance that plays the pre-loop part when a player touches its bounds and then the tileEntity it creates handles the looped portion from there on. The problem is that there is a short but clear seam between each playSound and it ruins the atmosphere. I thought of making playSound() happen before the previous one ends but I don't know how that can be done considering the sound is not synchronized with the amount of times the update() method is fired in the tileEntity. Is there another way to play background music where I can get a consistent amount of ticks or something else that allows the music to always line up seamlessly? On top of that, I have no idea how to keep the default Minecraft music from starting in the middle of my custom music but I'll leave that for another thread unless someone wants to tell me here.

 

Here is my code: (I'm aware there's no code yet to stop the music but I might as well leave it for when I actually know if this is possible)

 

BlockChaosLabyrinthEntrance.java

 

  Reveal hidden contents

 

 

TileEntityChaosLabyrinthEntrance.java

 

  Reveal hidden contents

 

Posted

So I replaced the tile entity with a movingsound and I can't get anything to play. I'm also not sure how to get the preloop to work with this without a seam but for now I just want to be able to get it to play the looped portion. Can anyone see what I did wrong here? I couldn't find anything online about registering movingsounds so if they actually do need to be registered then that's likely part of my problem if not the whole problem.

 

MovingSoundChaosLabyrinthBGM.java

 

  Reveal hidden contents

 

Posted

I might be wrong but PositionedSound seems to only play sounds from a location where I want it to play for a player regardless of location. If you actually just meant MovingSound then it would make more sense since you suggested MovingSound in the first place. If you did mean PositionedSound, how do I get it to follow the player?

Posted

I still can't get anything to play. I tried making it the same as a MovingSound code I found in another thread where they said it works and nothing plays. You said to send a packet to the client but I can't seem to find how to do that.

Posted

What I have tried is this:

 

MovingSoundChaosLabyrinthBGM.java

 

  Reveal hidden contents

 

 

I've never really worked with packets and I'm not sure how I would apply your tutorial to a sound.

Posted

Unless you just mean calling SoundHandler.playSound() from the tile entity, I still don't know how I would apply the method in your tutorial to this. I'm also confused about whether I even need the tile entity when I have the moving sound. If I just have to call playSound() from the tile entity then do I just call the moving sound like I would a non-tickable sound?

Posted

I tried the playSound with the tile entity and it's still not working. When you're talking about using packets, I can't tell if you're referring to how everything works internally or if you're saying I need to do what it's in your tutorial. If the latter, it's not obvious to me what needs to be changed in that code for it to work with a sound instead of a message and I can't seem to find any other examples for it.

Posted

Nevermind, I had two versions of the same boolean and I only had it enabled in one of them. It seems to work now and loops as well even though there's a minor click in between. So my next question is how can I play the preloop part of the music and then switch to the looped part without a seam?

Posted

Alright, here's my TE code:

 

TileEntityChaosLabyrinthEntrance.java

 

  Reveal hidden contents

 

 

I found out before you posted that the audio file was actually the problem with the looped click and I've since fixed it. I want to know here if I can play the preloop and transition to the looped portion without a seam but if not I can just fade in the looped portion. ChaosBlock is the main mod class in case you might think it's a block.

Posted

If that's the case, how do I play the sound without accessing the SoundHandler (Edit: I found out I can probably just use "this.worldObj" but if I can just play it on the player's client then I'd like to know how to do that)? Also, to tell if the song is playing (so as to not play another copy over itself if the block collision is triggered twice), do I just use the BGMActivated boolean alone?

Posted

But "send the packet" doesn't tell me how to code it. I have no experience with packets and I don't know what in your tutorial example is only necessary for text, what is necessary for all packets, or what I might need to add for it to work with a sound.

Posted

Alright, so if I want to send a packet to the player, do I just put a second constructor in the tile entity to take the triggering player as an argument and send the packet to that player? I don't know if it will matter if that variable is overwritten by a second triggering player and that's why I'm asking.

Posted

The following code is in the block's collision code:

 

 

  Reveal hidden contents

 

 

It seems to work in SP (obviously because it's doing what I did before) but I haven't tried MP yet. Does this look correct given the following class?

 

bgmPacket.java

 

  Reveal hidden contents

 

 

If so, thanks a lot and I'd like to know more about using "SoundSourceEvent" to stop the regular background music because I couldn't find any information regarding that.

Posted

The == thing was just out of habit because I don't use Java nearly as much as Javascript and other web-based languages.

 

If I do nothing on the client, where does playSound even execute in single player? If I try to send the packet in single player it tells me EntityPlayerSP can't be cast to EntityPlayerMP.

 

Also, what are you saying shouldn't be static? Are you referring to the MovingSound? I made it static because I don't know how I would be able to access it from the packet handler otherwise.

Posted

Only once at a time since it's music and wouldn't sound very good with overlap. If I create the sound in the packet, do I just set the activated boolean to true before I send the packet so it doesn't play twice?

Posted

It sounds like you want me to put the method in the common proxy but I don't know of any way to separate client and server from within the common proxy. Am I supposed to put the method in the client proxy and if not, could you show me how I can only affect the client proxy from within the common proxy?

Posted

Well I have three proxies with the third being ServerProxy. I got that from a tutorial when I was starting the mod, should I only have the two?

 

I think I misunderstood something because nothing is happening when I send the packet.

 

bgmPacket.java

 

  Reveal hidden contents

 

 

ClientProxy.java

 

  Reveal hidden contents

 

 

CommonProxy (server proxy) has the method public void playBGM(EntityPlayer player) except blank. Can you see what I did wrong?

Posted

Alright, I finally figured out what you meant. Apparently I didn't read your code comments well enough to see that I was supposed to use EntityPlayerSP thePlayer from Minecraft.getMinecraft() and not the EntityPlayerMP from the server. I see that you were saying that the whole time, I just didn't understand until now. I'd like to get the default background music to stop but I suppose that's for another thread.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.