Jump to content

[1.6.2] Modifying PotentialSpawns.list is destructive


bacomatic

Recommended Posts

Short story: Writing something that dynamically affects wold spawn behavior (key word "dynamic"). Noticed that after a while only spiders, endermen and slimes were showing up in the potential spawn list (now imagine a world stuffed full of endermen and spiders, eek!). It turns out that my removal of entity classes from the PotentialSpawns event was causing those types to never be considered again for whatever chunk was being checked.

 

I don't know if this was intentional so I thought I'd check in here before filing a ticket on GitHub.

 

I dug into the problem:

When you change the list of entity classes in WorldEvent.PotentialSpawns, that change becomes permanent for whatever chuck that list belongs to. The chunk code simply returns a list stored in a field, the Forge event code then passes this along and finally the list field in PotentialSpawns is final so you cannot simply swap it out.

 

I recommend making a copy of oldList (new ArrayList(oldList)) in the PotentialSpawns constructor. The other option would be to make it non-final which would have marginally less performance and heap impact, but brings other issues to the table (like potential compatibility issues between mods).

 

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.