Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED] Playing sounds causes ConcurrentModificationException


leduyquang753
 Share

Recommended Posts

So I am making a Forge 1.12 mod that can play note block song (.nbs) files. But when I tried to play note block sounds to the client:

 

String name = Instrument.getInstrument(note.getInstrument()); // One of "block.note.harp", "block.note.bass", "block.note.basedrum",...
float pitch = (float)Math.pow(2.0D, (double)(note.getKey - 45) / 12.0D);  // Ranges from 1 to 2.
Minecraft.getMinecraft().player.playSound(new SoundEvent(new ResourceLocation("minecraft", name)), 1F, pitch);

 

it throws ConcurrentModificationException:

[8 | 22/4/2018 14h07:55] [main/FATAL]: Unreported exception thrown!
java.util.ConcurrentModificationException: null
	at com.google.common.collect.HashBiMap$Itr.hasNext(HashBiMap.java:401) ~[guava-21.0.jar:?]
	at net.minecraft.client.audio.SoundManager.updateAllSounds(SoundManager.java:272) ~[SoundManager.class:?]
	at net.minecraft.client.audio.SoundHandler.update(SoundHandler.java:297) ~[SoundHandler.class:?]
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1983) ~[Minecraft.class:?]
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186) ~[Minecraft.class:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]

 

Another thing to note is the mod plays multiple sounds at once.

Is this the right way to play multiple sounds in Forge? Or is there another way to handle this?

Edited by leduyquang753
Solved thanks to @diesieben07.
Link to comment
Share on other sites

4 minutes ago, leduyquang753 said:

So when I called EntityPlayerSP#playSound, it was run on both logical sides?

pretty much, you should be able to just surround your code with an world.isRemote check

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

13 minutes ago, leduyquang753 said:

I tried surrounding my code with World#isRemote on both Minecraft.player.world and Minecraft.world but it still crashes... Super confused.

Both of those are client side only. As soon as the server tries to load the Minecraft class, it fails to find it.

You're already being passed a world object, somewhere. Post more of your code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I am not downloading a zip file.

Post your code on GitHub.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

https://github.com/leduyquang753/NBS-Player/blob/master/src/main/java/com/xxmicloxx/NoteBlockAPI/SongPlayer.java#L85

 

You're creating your own threads?

Yeah, that won't create problems, ever.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.