Skip to content

Commit

Permalink
Fixed a rare chance of ConcurrentModificationException in Custom Cele…
Browse files Browse the repository at this point in the history
…stial Selection Screen during rendering (GuiCelestialSelection#drawCircles) and updating bodiesToRender list (Fixes issue #767)
  • Loading branch information
MJRLegends committed Apr 24, 2024
1 parent 751b573 commit ac29765
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import net.minecraftforge.fml.common.Loader;

public class CustomCelestialSelection extends GuiCelestialSelection {

private List<CelestialBody> updatedBodiesToRender; // Make a temp list so we don't cause a rare chance of ConcurrentModificationException during rendering(GuiCelestialSelection#drawCircles) and updating bodiesToRender list.

// Galaxy System
private List<String> galaxies = new ArrayList<String>();
Expand Down Expand Up @@ -98,19 +100,20 @@ public CustomCelestialSelection(boolean mapMode, List<CelestialBody> possibleBod
*/
@Override
public void initGui() {
this.updatedBodiesToRender = Lists.newArrayList();

// Used to add only researched bodies from planet progressions & Event lists
CustomCelestialGUIEvent.PreLoadingCelestialBodies preEvent = new CustomCelestialGUIEvent.PreLoadingCelestialBodies();
MinecraftForge.EVENT_BUS.post(preEvent);

this.bodiesToRender.clear();

for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) {
if(preEvent.bodyUnlocalizedNamesToIgnore.contains(solarSystem.getUnlocalizedName()))
continue;
if(preEvent.bodyNamesToIgnore.contains(solarSystem.getName()))
continue;

if (solarSystem.getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) {
this.bodiesToRender.add(solarSystem.getMainStar());
this.updatedBodiesToRender.add(solarSystem.getMainStar());
}
}
for (Planet planet : GalaxyRegistry.getRegisteredPlanets().values()) {
Expand All @@ -122,10 +125,10 @@ public void initGui() {
if (planet.getParentSolarSystem().getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) {
if (Loader.isModLoaded("planetprogression")) {
if (PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, planet)) {
this.bodiesToRender.add(planet);
this.updatedBodiesToRender.add(planet);
}
} else {
this.bodiesToRender.add(planet);
this.updatedBodiesToRender.add(planet);
}
}
}
Expand All @@ -138,10 +141,10 @@ public void initGui() {
if (moon.getParentPlanet() != null && moon.getParentPlanet().getParentSolarSystem().getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) {
if (Loader.isModLoaded("planetprogression")) {
if (PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, moon.getParentPlanet()) && PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, moon)) {
this.bodiesToRender.add(moon);
this.updatedBodiesToRender.add(moon);
}
} else {
this.bodiesToRender.add(moon);
this.updatedBodiesToRender.add(moon);
}
} else if (moon.getParentPlanet() == null)
MessageUtilities.fatalErrorMessageToLog(Constants.modID, "The moon " + moon.getUnlocalizedName() + " seems to have a null parent planet. Please check the log for other errors!");
Expand All @@ -156,10 +159,10 @@ public void initGui() {
if (satellite.getParentPlanet().getParentSolarSystem().getUnlocalizedParentGalaxyName().equalsIgnoreCase(this.currentGalaxyName)) {
if (Loader.isModLoaded("planetprogression")) {
if (PlanetProgressionCompatibility.isResearched(Minecraft.getMinecraft().player, satellite.getParentPlanet())) {
this.bodiesToRender.add(satellite);
this.updatedBodiesToRender.add(satellite);
}
} else {
this.bodiesToRender.add(satellite);
this.updatedBodiesToRender.add(satellite);
}
}
}
Expand Down Expand Up @@ -1083,6 +1086,11 @@ public void drawButtons(int mousePosX, int mousePosY) {
*/
@Override
public void drawScreen(int mousePosX, int mousePosY, float partialTicks) {
if(this.updatedBodiesToRender != null && this.updatedBodiesToRender.size() != 0) {
this.bodiesToRender.clear();
this.bodiesToRender.addAll(this.updatedBodiesToRender);
this.updatedBodiesToRender.clear();
}
this.mousePosX = mousePosX;
this.mousePosY = mousePosY;
this.partialTicks = partialTicks;
Expand Down

0 comments on commit ac29765

Please sign in to comment.