Jump to content

Recommended Posts

Posted

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.

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.