Skip to content

Commit

Permalink
Merge pull request #929 from Team-RTG/1.10.2/CME-stuff
Browse files Browse the repository at this point in the history
Structures fail gracefully when they fail.
  • Loading branch information
whichonespink44 authored Aug 29, 2016
2 parents 3b5ea94 + e2ba08a commit 3c71117
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 62 deletions.
11 changes: 6 additions & 5 deletions etc/config/RTG/rtg.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ caves {


debugging {
# Instead of crashing when it experiences 'java.util.ConcurrentModificationException' (or any other exception)
# during structure generation, RTG will stop trying to generate that structure and continue generating the world.
# You should only set this to TRUE if you have been instructed to do so by an RTG developer, or if you know what you're doing.
# [default: false]
B:"Crash on Structure Exceptions"=false

# WARNING: This should only be enabled if you know what you're doing.
# [default: false]
B:"Enable Debugging"=false
Expand Down Expand Up @@ -454,11 +460,6 @@ villages {
# Higher values = bigger villages; 0 = Vanilla
# [range: 0 ~ 10, default: 0]
I:"Size of villages"=0

# Set this to TRUE to if you are experiencing 'java.util.ConcurrentModificationException' crashes related to village generation.
# Defaults to FALSE unless EnviroMine is installed, in which case it defaults to TRUE.
# [default: false]
B:"Village Crash Fix"=false
}


Expand Down
33 changes: 20 additions & 13 deletions src/main/java/rtg/config/rtg/ConfigRTG.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ConfigRTG {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static boolean enableDebugging = false;
public static boolean crashOnStructureExceptions = false;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Dunes
Expand Down Expand Up @@ -245,8 +246,6 @@ public class ConfigRTG {
public static int minDistanceVillages = 12; // Vanilla = 8
public static int maxDistanceVillages = 48; // Vanilla = 32

public static boolean villageCrashFix = (Loader.isModLoaded("enviromine"));

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Volcanoes
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -362,7 +361,25 @@ public static void init(File configFile) {
// Debugging
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

enableDebugging = config.getBoolean("Enable Debugging", "Debugging", enableDebugging, "WARNING: This should only be enabled if you know what you're doing." + Configuration.NEW_LINE);
enableDebugging = config.getBoolean(
"Enable Debugging",
"Debugging",
enableDebugging,
"WARNING: This should only be enabled if you know what you're doing."
+ Configuration.NEW_LINE
);

crashOnStructureExceptions = config.getBoolean(
"Crash on Structure Exceptions",
"Debugging",
crashOnStructureExceptions,
"Instead of crashing when it experiences 'java.util.ConcurrentModificationException' (or any other exception)"
+ Configuration.NEW_LINE +
"during structure generation, RTG will stop trying to generate that structure and continue generating the world."
+ Configuration.NEW_LINE +
"You should only set this to TRUE if you have been instructed to do so by an RTG developer, or if you know what you're doing."
+ Configuration.NEW_LINE
);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Dunes
Expand Down Expand Up @@ -831,16 +848,6 @@ public static void init(File configFile) {
minDistanceVillages = config.getInt("Minimum distance between villages", "Villages", minDistanceVillages, 1, Integer.MAX_VALUE, "Higher values = villages further apart; 8 = Vanilla" + Configuration.NEW_LINE);
maxDistanceVillages = config.getInt("Maximum distance between villages", "Villages", maxDistanceVillages, 1, Integer.MAX_VALUE, "Lower values = villages closer together; 32 = Vanilla" + Configuration.NEW_LINE);

villageCrashFix = config.getBoolean(
"Village Crash Fix",
"Villages",
villageCrashFix,
"Set this to TRUE to if you are experiencing 'java.util.ConcurrentModificationException' crashes related to village generation."
+ Configuration.NEW_LINE +
"Defaults to FALSE unless EnviroMine is installed, in which case it defaults to TRUE."
+ Configuration.NEW_LINE
);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Volcanoes
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
201 changes: 157 additions & 44 deletions src/main/java/rtg/world/gen/ChunkProviderRTG.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,35 +294,73 @@ public Chunk provideChunk(final int cx, final int cy)
if (mapFeaturesEnabled) {

if (ConfigRTG.generateMineshafts) {
mineshaftGenerator.generate(this.worldObj, cx, cy, primer);
try {
mineshaftGenerator.generate(this.worldObj, cx, cy, primer);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}

if (ConfigRTG.generateStrongholds) {
strongholdGenerator.generate(this.worldObj, cx, cy, primer);
try {
strongholdGenerator.generate(this.worldObj, cx, cy, primer);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}

if (ConfigRTG.generateVillages) {

if (ConfigRTG.villageCrashFix) {

try {
villageGenerator.generate(this.worldObj, cx, cy, primer);
try {
villageGenerator.generate(this.worldObj, cx, cy, primer);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
catch (Exception e) {
// Do nothing.
else {
Logger.fatal(e.getMessage(), e);
}
}
else {
villageGenerator.generate(this.worldObj, cx, cy, primer);
}
}

if (ConfigRTG.generateScatteredFeatures) {
scatteredFeatureGenerator.generate(this.worldObj, cx, cy, primer);
try {
scatteredFeatureGenerator.generate(this.worldObj, cx, cy, primer);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}

if (ConfigRTG.generateOceanMonuments) {
oceanMonumentGenerator.generate(this.worldObj, cx, cy, primer);
try {
oceanMonumentGenerator.generate(this.worldObj, cx, cy, primer);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}
}

Expand Down Expand Up @@ -684,44 +722,82 @@ private void doPopulate(int chunkX, int chunkZ)

TimeTracker.manager.start("Mineshafts");
if (ConfigRTG.generateMineshafts) {
mineshaftGenerator.generateStructure(worldObj, rand, chunkCoords);
try {
mineshaftGenerator.generateStructure(worldObj, rand, chunkCoords);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}
TimeTracker.manager.stop("Mineshafts");

TimeTracker.manager.start("Strongholds");
if (ConfigRTG.generateStrongholds) {
strongholdGenerator.generateStructure(worldObj, rand, chunkCoords);
try {
strongholdGenerator.generateStructure(worldObj, rand, chunkCoords);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}
TimeTracker.manager.stop("Strongholds");

TimeTracker.manager.start("Villages");
if (ConfigRTG.generateVillages) {

if (ConfigRTG.villageCrashFix) {

try {
hasPlacedVillageBlocks = villageGenerator.generateStructure(worldObj, rand, chunkCoords);
try {
hasPlacedVillageBlocks = villageGenerator.generateStructure(worldObj, rand, chunkCoords);
}
catch (Exception e) {
hasPlacedVillageBlocks = false;
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
catch (Exception e) {
hasPlacedVillageBlocks = false;
else {
Logger.fatal(e.getMessage(), e);
}
}
else {

hasPlacedVillageBlocks = villageGenerator.generateStructure(worldObj, rand, chunkCoords);
}
}
TimeTracker.manager.stop("Villages");

TimeTracker.manager.start("Scattered");
if (ConfigRTG.generateScatteredFeatures) {
scatteredFeatureGenerator.generateStructure(worldObj, rand, chunkCoords);
try {
scatteredFeatureGenerator.generateStructure(worldObj, rand, chunkCoords);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}
TimeTracker.manager.stop("Scattered");

TimeTracker.manager.start("Monuments");
if (ConfigRTG.generateOceanMonuments) {
oceanMonumentGenerator.generateStructure(this.worldObj, rand, chunkCoords);
try {
oceanMonumentGenerator.generateStructure(this.worldObj, rand, chunkCoords);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}
TimeTracker.manager.stop("Monuments");
}
Expand Down Expand Up @@ -1005,36 +1081,73 @@ public void recreateStructures(Chunk chunk, int par1, int par2) {
if (mapFeaturesEnabled) {

if (ConfigRTG.generateMineshafts) {
mineshaftGenerator.generate(worldObj, par1, par2, null);
try {
mineshaftGenerator.generate(worldObj, par1, par2, null);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}

if (ConfigRTG.generateStrongholds) {
strongholdGenerator.generate(worldObj, par1, par2, null);
try {
strongholdGenerator.generate(worldObj, par1, par2, null);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}

if (ConfigRTG.generateVillages) {

if (ConfigRTG.villageCrashFix) {

try {
villageGenerator.generate(this.worldObj, par1, par2, null);
try {
villageGenerator.generate(this.worldObj, par1, par2, null);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
catch (Exception e) {
// Do nothing.
else {
Logger.fatal(e.getMessage(), e);
}

}
else {
villageGenerator.generate(this.worldObj, par1, par2, null);
}
}

if (ConfigRTG.generateScatteredFeatures) {
scatteredFeatureGenerator.generate(this.worldObj, par1, par2, null);
try {
scatteredFeatureGenerator.generate(this.worldObj, par1, par2, null);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}

if (ConfigRTG.generateOceanMonuments) {
oceanMonumentGenerator.generate(this.worldObj, par1, par2, null);
try {
oceanMonumentGenerator.generate(this.worldObj, par1, par2, null);
}
catch (Exception e) {
if (ConfigRTG.crashOnStructureExceptions) {
throw new RuntimeException(e.getMessage());
}
else {
Logger.fatal(e.getMessage(), e);
}
}
}
}
}
Expand Down

0 comments on commit 3c71117

Please sign in to comment.