Better message when there are invalid alleles

Added detection of chromosomes with invalid alleles. Cause Exception
with more explicit message.
This commit is contained in:
SandGrainOne committed 2014-08-04 23:42:59 +02:00
1 parent 1ec85b4e79
commit 3cbbb22b52
3 files changed
+17 -1

No files matched your search

@@ -209,7 +209,7 @@ public class Config {
applePickup = Boolean.parseBoolean(appleHarvest.Value);
Property clearGenome = config.get("genetics.clear.invalid.chromosomes", CATEGORY_COMMON, clearInvalidChromosomes);
clearGenome.Comment = "NEW: set to true to clear chromosomes which contain invalid alleles. might rescue your save if it is crashing after removal of a bee addon.";
clearGenome.Comment = "set to true to clear chromosomes which contain invalid alleles. might rescue your save if it is crashing after the removal of a bee addon.";
clearInvalidChromosomes = Boolean.parseBoolean(clearGenome.Value);
Property dungeonLootRarity = config.get("difficulty.dungeonloot.rare", CATEGORY_COMMON, false);
@@ -103,9 +103,20 @@ public class Chromosome implements IChromosome {
public void overrideInvalidAlleles(IAllele template, Class<? extends IAllele> chromosomeClass) {
if (primary == null || !chromosomeClass.isInstance(primary))
primary = template;
if (secondary == null || !chromosomeClass.isInstance(secondary))
secondary = template;
}
public boolean hasInvalidAlleles(Class<? extends IAllele> chromosomeClass) {
if (primary == null || !chromosomeClass.isInstance(primary))
return true;
if (secondary == null || !chromosomeClass.isInstance(secondary))
return true;
return false;
}
/* HELPER FUNCTIONS */
public static Chromosome loadChromosomeFromNBT(NBTTagCompound compound) {
@@ -46,11 +46,16 @@ public abstract class Genome implements IGenome {
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
byte byte0 = nbttagcompound1.getByte(SLOT_TAG);
if (byte0 >= 0 && byte0 < chromosomes.length) {
Chromosome chromosome = Chromosome.loadChromosomeFromNBT(nbttagcompound1);
chromosomes[byte0] = chromosome;
if (Config.clearInvalidChromosomes)
chromosome.overrideInvalidAlleles(getDefaultTemplate()[byte0], getSpeciesRoot().getKaryotype()[byte0].getAlleleClass());
if (chromosome.hasInvalidAlleles(getSpeciesRoot().getKaryotype()[byte0].getAlleleClass()))
throw new RuntimeException("Found Chromosome with invalid Alleles. See config option \"genetics.clear.invalid.chromosomes\".");
}
}
}