Posted November 29, 201212 yr I'm working on replacing some of the default behavior of mobs by adding my own AI Tasks, then iterating and removing the original versions, when the onEntityJoinWorld event fires. As expected, this occasionally results in a ConcurrentModificationException when some other method is iterating over the taskEntries as I remove. Is there any way around this or some method I'm missing to take care of this for me? Code: @ForgeSubscribe public void onEntityJoinedWorld (EntityJoinWorldEvent event) { if (event.entity instanceof EntityAnimal) animal = (EntityAnimal)event.entity; if (animal != null) { //System.out.println("Adding replacement tasks for animals"); animal.tasks.addTask(9, new EntityAIWanderAnimal(animal, 0.3F)); // Remove EntityAIWander task Iterator i = animal.tasks.taskEntries.iterator(); while (i.hasNext()) { try { AITask = (EntityAITaskEntry)i.next(); } catch (java.util.ConcurrentModificationException e) { System.out.println("Exception caught.. continuing.."); break; } finally { } if (AITask.action instanceof EntityAIWander) { //System.out.println("Found match. Removing AIWander"); i.remove(); } } } } I'm fixing the stupid villagers. http://www.minecraftforum.net/topic/1588460-
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.