I have the following code (Note it is being run in a separate thread, and the entire thread needs to pause until its done):
public void BreakBlock(boolean enforceRotation){
Minecraft mc = Minecraft.getMinecraft();
RayTraceResult result = rayTrace(5);
int rotation = (int)mc.player.rotationYaw;
int pitch = (int)mc.player.rotationPitch;
try {
int elapsed = 0;
while (mc.world.getBlockState(result.getBlockPos()).getMaterial() != Material.AIR && elapsed < 15000) {
if (enforceRotation) HardSetFacing(rotation, pitch);
if (mc.playerController.onPlayerDamageBlock(result.getBlockPos(), result.sideHit)) mc.player.swingArm(EnumHand.MAIN_HAND);
Thread.sleep(40);
elapsed += 40;
}
}
catch (Exception ex)
{
Main.logger.error(ex.getMessage());
}
}
However, occasionally, this will lead to the following crash (Game fully crashes and returns to launcher):
[21:55:28] [main/FATAL] [net.minecraft.client.Minecraft]: 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.func_148605_d(SoundManager.java:252) ~[chm.class:?]
at net.minecraft.client.audio.SoundHandler.func_73660_a(SoundHandler.java:293) ~[cho.class:?]
at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1857) ~[bib.class:?]
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1097) ~[bib.class:?]
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:397) [bib.class:?]
at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51]
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:?]
Any thoughts on how to solve this?