diff --git a/forestry_common/core/forestry/core/config/Config.java b/forestry_common/core/forestry/core/config/Config.java index 605c2b3ec..3f4ba4243 100755 --- a/forestry_common/core/forestry/core/config/Config.java +++ b/forestry_common/core/forestry/core/config/Config.java @@ -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); diff --git a/forestry_common/core/forestry/core/genetics/Chromosome.java b/forestry_common/core/forestry/core/genetics/Chromosome.java index 95ee20bba..3768ef75c 100755 --- a/forestry_common/core/forestry/core/genetics/Chromosome.java +++ b/forestry_common/core/forestry/core/genetics/Chromosome.java @@ -103,9 +103,20 @@ public class Chromosome implements IChromosome { public void overrideInvalidAlleles(IAllele template, Class chromosomeClass) { if (primary == null || !chromosomeClass.isInstance(primary)) primary = template; + if (secondary == null || !chromosomeClass.isInstance(secondary)) secondary = template; } + + public boolean hasInvalidAlleles(Class 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) { diff --git a/forestry_common/core/forestry/core/genetics/Genome.java b/forestry_common/core/forestry/core/genetics/Genome.java index 616549576..3d25864ec 100755 --- a/forestry_common/core/forestry/core/genetics/Genome.java +++ b/forestry_common/core/forestry/core/genetics/Genome.java @@ -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\"."); } } }