Workaround for crash in MagicBees

This commit is contained in:
bdew committed 2015-04-14 19:49:04 +03:00
1 parent 7d6282756e
commit 0d07ff96cf
2 files changed
+15 -3

No files matched your search

@@ -17,6 +17,7 @@ import forestry.api.apiculture.{EnumBeeType, IBee, IBeeRoot}
import forestry.api.arboriculture.{EnumGermlingType, ITree, ITreeRoot}
import forestry.api.genetics._
import forestry.api.lepidopterology.{EnumFlutterType, IButterflyRoot}
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.config.Items
import net.bdew.gendustry.items.GeneTemplate
import net.bdew.gendustry.machines.mutatron.MachineMutatron
@@ -107,7 +108,7 @@ object GeneticsHelper {
}
} else {
// only 1 valid mutation - use it
valid(0)
valid.head
}
return getFinalMutationResult(selected, fromStack, true)
}
@@ -223,4 +224,15 @@ object GeneticsHelper {
AlleleManager.ersatzSaplings.find({ case (stack, _) => stack.getItemDamage == fixedMeta }) map (_._2)
} else None
}
// Because *insert sarcastic remark*
def safeMutationConditions(m: IMutation) =
try {
import scala.collection.JavaConversions._
Option(m.getSpecialConditions) map (_.toList) getOrElse List.empty
} catch {
case t: Throwable =>
Gendustry.logWarnException("Error getting conditions of mutation %s + %s => %s", t, m.getAllele0.getUID, m.getAllele1.getUID, m.getTemplate.head.getUID)
List.empty
}
}
@@ -11,7 +11,7 @@ package net.bdew.gendustry.misc
import forestry.api.genetics._
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.forestry.GeneSampleInfo
import net.bdew.gendustry.forestry.{GeneSampleInfo, GeneticsHelper}
import net.bdew.lib.Misc
object GeneticsCache {
@@ -80,7 +80,7 @@ object GeneticsCache {
val names = results map { mutation =>
mutation.getTemplate()(0).getName +
// Add * if there are special requirements
(if (Option(mutation.getSpecialConditions).map(_.size).getOrElse(0) > 0) "*" else "")
(if (GeneticsHelper.safeMutationConditions(mutation).size > 0) "*" else "")
} mkString ", "
// And print it out
Gendustry.logDebug("%s + %s => [%s]", sp1.getName, partner.getName, names)