Jump to content

ConcurrentModificaitionException Spawning Entity and Strange Classloader Issue


Recommended Posts

Posted (edited)

Mappings: official mojang mappings, version 1.16.5

 

Forge version: 1.16.5-36.2.0

 

I've been trying to replace vanilla zombies with a custom class to play around with their AI. I've experienced a couple strange issues so far:

 

 

First, simply trying to replace zombies that spawn with a new zombie produces a strange classpath error. I have the following utility functions:

  Reveal hidden contents

I wrote them to avoid attempting to spawn in entities in chunks that aren't finished loading. Then I use the following logic to override vanilla spawn behavior:

  Reveal hidden contents

Here is the tail of the log file when the client crashes:

  Reveal hidden contents

This seemed strange to me, stranger still is that swapping the zombie out for a pig (changing EntityZombie to EntityPig) produces an entirely different issue- a ConcurrentModificationException. Code change:

  Reveal hidden contents

Exception:

  Reveal hidden contents

I tried synchronizing the addZombieIfReady method (even knowing the event handlers will be run within the same thread) and that didn't change the result. What are the causes of the two exceptions and why does swapping the zombie out for a pig change behavior so much?

Edited by Drosophila
  • Drosophila changed the title to ConcurrentModificaitionException Spawning Entity and Strange Classloader Issue
Posted
  On 12/14/2021 at 8:35 AM, diesieben07 said:

You don't need to replace the entire entity to modify the AI.

Expand  

Ah, because goalSelector and targetSelector are both public. The clean way to do this would be to update them in the spawn event handler?

  On 12/14/2021 at 8:35 AM, diesieben07 said:

Why is this synchronized?

Expand  

It shouldn't be. I did that because I was confused by the concurrent modification exception and new to forge. I wanted to confirm that the handlers were not somehow firing in parallel. 

  On 12/14/2021 at 8:35 AM, diesieben07 said:

This Map is a giant memory leak.

Expand  

Ah yep I should probably just keep reusing the same block position object and updating its coordinates, then it could just be a List of entity objects that have a much longer lifetime.

  On 12/14/2021 at 8:35 AM, diesieben07 said:

You listen for EntityJoinWorldEvent and check if a zombie spawned. If so, you cancel the event and spawn a zombie. This triggers your event handler. You cancel the event and spawn a zombie. This triggers your event handler. You cancel the event and spawn a zombie. This goes on forever until the JVM tells you to stop being silly.

Expand  

Oops. Thanks. That was pretty silly.

  On 12/14/2021 at 8:35 AM, diesieben07 said:

You cannot spawn entities during EntityJoinWorldEvent usually. Check out ForgeInternalHandler#onEntityJoinWorld for how to do it properly.

Expand  

So actually I should be submitting the task to the work queue that corresponds to the logical side calling the event handler like this?

ThreadTaskExecutor<Runnable> executor = LogicalSidedProvider.WORKQUEUE.get(event.getWorld().isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER);
executor.tell(new TickDelayedTask(0, () -> event.getWorld().addFreshEntity(newEntity)));

Does that mean that an EntityJoinWorldEvent will never fire for an entity in a chunk that hasn't loaded yet?

Posted
  On 12/14/2021 at 9:44 PM, diesieben07 said:

Yes it will, which is precisely why you need this.

Expand  

Will the TickDelayedTask not execute until the junk has loaded? Or do I still need extra logic to queue up entities and periodically check to see if their positions are finished loading?

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.