Posted September 27, 201510 yr I've been helping a mod team create an animation system for entities that has turned out really well, except for one thing: sometimes sounds and animations that are initiated at same time on server (i.e. in an AI class) get out of sync so that the animation happens a couple seconds after sound starts playing. Now first off, I realized that sound sync isn't something that vanilla Minecraft really doesn't care much about, since when a vanilla cow makes a moo sound the cow itself doesn't do any animation. That's just one of the quirky fun styles of Minecraft. I'm pretty sure sounds are probably handled on their own thread and I think that when game is lagging, I've noticed sounds get out of sync before. Like you'll hear a block break and then later it will visually break. Can others confirm that this sort of sound sync problem happens when game starts to lag, even with vanilla? My code is pretty simple in this regard. On server, in an AI class it will decide to play a sound and also to send a packet to update the animation ID. On client for debug purpose I handle the PlaySoundAtEntityEvent and also have message on when animation packet is received, and those both happen. The animation packet simply updates the entity state, and the model class for the entity will see that change on next tick and will start the animation. I can share some code if needed, but since this is work for a group mod I can't share too much. Mostly I'm interested in knowing: a) Does even vanilla sounds get out of sync? e.g. hear block break a couple seconds before you see it break? b) Has anyone solved this sort of problem before? c) Is there a way to play the sound only on the client? If so, then I could have sound played there rather than sent from server and perhaps that could help. Right now the playsound methods I use I believe send packets to all clients which then play the sound... Check out my tutorials here: http://jabelarminecraft.blogspot.com/
September 27, 201510 yr 1) Sounds are indeed separate thread. In eclipse, you can see it when switch perspective to "Debug" mode. (It's LWJGL thread. LWJGL is java connector to OpenAl and OpenGl). 2) playSound sends packet (i think you know that) to everybody and then clients play convenient ISound in Minecraft.getMinecraft().getSoundHandler().playSound(ISound) This means, that you can play sound on client directly by creating new ISound and passing it to sound handler. Note that vanilla mc has already created helper classes such as PositionedSound , ITickableSound and MovingSound . You can use them too, or extend/implement your own (needed in certain cases, for example repeating sound like riding in minecart, which has it's own MovingSoundMinecart implementation). Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
September 27, 201510 yr Author Perfect, thanks. That was the info I needed. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.