mirror of
https://github.com/GTNewHorizons/gendustry.git
synced 2026-11-26 06:53:05 +00:00
Added custom mutations
This commit is contained in:
1 parent
1e5e4d6080
commit
3ee554ed56
6 files changed
+146
-7
No files matched your search
@@ -39,4 +39,6 @@ cfg Bees {
|
||||
Humidity_Tolerance = "forestry.toleranceBoth4" // Override a single trait
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutation: 10% "forestry.speciesIndustrious" + "forestry.speciesDiligent" = "gendustry.bee.Iron" Req Temperature Hot
|
||||
@@ -183,5 +183,8 @@ gendustry.givesample.success=Given sample (Species=%s, Chromosome=%s, Allele=%s)
|
||||
gendustry.bee.species.Iron=Iron
|
||||
gendustry.bee.species.Iron.description=Theese strudy bees can collect small chunks of iron from the environment
|
||||
|
||||
gendustry.req.temperature=Requires temperature: %s
|
||||
gendustry.req.humidity=Requires humidity: %s
|
||||
|
||||
#this will be moved to bdlib at some point
|
||||
bdlib.label.empty=Empty
|
||||
@@ -69,6 +69,7 @@ object Gendustry {
|
||||
@EventHandler
|
||||
def postInit(event: FMLPostInitializationEvent) {
|
||||
CustomContent.registerTemplates()
|
||||
CustomContent.registerMuations()
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -25,6 +25,8 @@ object Tuning extends ConfigSection
|
||||
|
||||
object TuningLoader {
|
||||
|
||||
// Modifiers for apiary upgrades
|
||||
|
||||
abstract class EntryModifier extends CfgEntry
|
||||
|
||||
case class EntryModifierAdd(v: Float) extends EntryModifier
|
||||
@@ -35,6 +37,8 @@ object TuningLoader {
|
||||
|
||||
case class EntryModifierDiv(v: Float) extends EntryModifier
|
||||
|
||||
// Statements
|
||||
|
||||
case class StMutagen(st: StackRef, mb: Int) extends DelayedStatement
|
||||
|
||||
case class StLiquidDNA(st: StackRef, mb: Int) extends DelayedStatement
|
||||
@@ -43,8 +47,18 @@ object TuningLoader {
|
||||
|
||||
case class StAssembly(rec: List[(Char, Int)], power: Int, result: StackRef, cnt: Int) extends CraftingStatement
|
||||
|
||||
// Mutations
|
||||
|
||||
abstract class MutationRequirement
|
||||
|
||||
case class StMutation(parent1: String, parent2: String, result: String, chance: Float, secret: Boolean, requirements: List[MutationRequirement]) extends DelayedStatement
|
||||
|
||||
case class MReqTemperature(temperature: String) extends MutationRequirement
|
||||
|
||||
case class MReqHumidity(humidity: String) extends MutationRequirement
|
||||
|
||||
class Parser extends RecipeParser with GenericConfigParser with LootListParser {
|
||||
override def delayedStatement = mutagen | dna | protein | assembly | super.delayedStatement
|
||||
override def delayedStatement = mutagen | dna | protein | assembly | stMutation | super.delayedStatement
|
||||
|
||||
def mutagen = "mutagen" ~> ":" ~> spec ~ ("->" ~> int) ^^ {
|
||||
case sp ~ n => StMutagen(sp, n)
|
||||
@@ -62,6 +76,17 @@ object TuningLoader {
|
||||
case ch ~ cnt => (ch, cnt.getOrElse(1))
|
||||
}
|
||||
|
||||
def mrTemperature = "Req" ~> "Temperature" ~> ident ^^ MReqTemperature
|
||||
def mrHumidity = "Req" ~> "Humidity" ~> ident ^^ MReqHumidity
|
||||
|
||||
def mutationReq = mrTemperature | mrHumidity
|
||||
|
||||
def stMutation = "secret".? ~ ("mutation" ~> ":") ~ (decimalNumber <~ "%") ~ str ~ "+" ~ str ~ "=" ~ str ~ mutationReq.* ^^ {
|
||||
case secret ~ mutation ~ chance ~ p1 ~ plus ~ p2 ~ eq ~ res ~ req =>
|
||||
StMutation(parent1 = p1, parent2 = p2, result = res,
|
||||
chance = chance.toFloat, secret = secret.isDefined, requirements = req)
|
||||
}
|
||||
|
||||
def assembly = "assembly" ~> ":" ~> (charWithCount <~ ",").+ ~ (int <~ "mj") ~ ("=>" ~> specWithCount) ^^ {
|
||||
case r ~ p ~ (s ~ n) => StAssembly(r, p, s, n.getOrElse(1))
|
||||
}
|
||||
@@ -74,6 +99,9 @@ object TuningLoader {
|
||||
def cfgDiv = ident ~ ("/" ~> "=" ~> decimalNumber) ^^ { case id ~ n => CfgVal(id, EntryModifierDiv(n.toFloat)) }
|
||||
}
|
||||
|
||||
// Mutations are collected here for later processing
|
||||
var mutations = List.empty[StMutation]
|
||||
|
||||
class Loader extends RecipeLoader with GenericConfigLoader with LootListLoader {
|
||||
val cfgStore = Tuning
|
||||
|
||||
@@ -115,6 +143,8 @@ object TuningLoader {
|
||||
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(stacks.toArray, power, outStack))
|
||||
log.info("Done")
|
||||
|
||||
case x: StMutation => mutations +:= x
|
||||
|
||||
case _ => super.processDelayedStatement(s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.custom
|
||||
|
||||
import forestry.api.apiculture.{IAlleleBeeSpecies, IBeeRoot, IBeeHousing, IBeeMutation}
|
||||
import forestry.api.genetics.{AlleleManager, IGenome, IAllele}
|
||||
import forestry.api.core.{EnumHumidity, EnumTemperature}
|
||||
import net.bdew.lib.Misc
|
||||
|
||||
class BeeMutation(parent1: IAlleleBeeSpecies, parent2: IAlleleBeeSpecies, result: IAlleleBeeSpecies, chance: Float) extends IBeeMutation {
|
||||
|
||||
var reqTemperature = Option[EnumTemperature](null)
|
||||
var reqHumidity = Option[EnumHumidity](null)
|
||||
|
||||
// === IBeeMutation ===
|
||||
|
||||
override def getChance(housing: IBeeHousing, allele0: IAllele, allele1: IAllele, genome0: IGenome, genome1: IGenome) =
|
||||
if (reqTemperature.isDefined && reqTemperature.get != housing.getTemperature) 0
|
||||
else if (reqHumidity.isDefined && reqHumidity.get != housing.getHumidity) 0
|
||||
else chance
|
||||
|
||||
override val getRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees").asInstanceOf[IBeeRoot]
|
||||
|
||||
// === IMutation ===
|
||||
|
||||
var isSecret = false
|
||||
|
||||
override def getPartner(allele: IAllele) =
|
||||
if (allele == parent1) parent2
|
||||
else if (allele == parent2) parent1
|
||||
else null
|
||||
|
||||
override def isPartner(allele: IAllele) =
|
||||
allele == parent1 || allele == parent2
|
||||
|
||||
override def getSpecialConditions = {
|
||||
import scala.collection.JavaConversions._
|
||||
reqTemperature.map(x => Misc.toLocalF("gendustry.req.temperature", x)) ++
|
||||
reqHumidity.map(x => Misc.toLocalF("gendustry.req.humidity", x))
|
||||
}
|
||||
|
||||
override def getBaseChance = chance
|
||||
|
||||
override val getTemplate = getRoot.getTemplate(result.getUID)
|
||||
override def getAllele1 = parent1
|
||||
override def getAllele0 = parent2
|
||||
}
|
||||
@@ -9,30 +9,79 @@
|
||||
|
||||
package net.bdew.gendustry.custom
|
||||
|
||||
import net.bdew.gendustry.config.Tuning
|
||||
import net.bdew.gendustry.config.{TuningLoader, Tuning}
|
||||
import net.bdew.lib.recipes.gencfg.ConfigSection
|
||||
import forestry.api.genetics.AlleleManager
|
||||
import forestry.api.genetics.IClassification.EnumClassLevel
|
||||
import net.bdew.gendustry.Gendustry
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies
|
||||
import forestry.api.core.{EnumTemperature, EnumHumidity}
|
||||
|
||||
object CustomContent {
|
||||
val reg = AlleleManager.alleleRegistry
|
||||
var mySpecies = List.empty[BeeSpecies]
|
||||
|
||||
def registerBranches() {
|
||||
Tuning.getSection("Branches").filterType(classOf[ConfigSection]).foreach({
|
||||
Gendustry.logInfo("Registering branches")
|
||||
val added = (Tuning.getSection("Branches").filterType(classOf[ConfigSection]) collect {
|
||||
case (_, cfg) =>
|
||||
Gendustry.logInfo("%s -> %s (%s)", cfg.getString("Parent"), cfg.getString("UID"), cfg.getString("Scientific"))
|
||||
val cls = reg.createAndRegisterClassification(EnumClassLevel.GENUS, cfg.getString("UID"), cfg.getString("Scientific"))
|
||||
reg.getClassification("family." + cfg.getString("Parent")).addMemberGroup(cls)
|
||||
})
|
||||
}).size
|
||||
Gendustry.logInfo("Registered %d branches", added)
|
||||
}
|
||||
|
||||
def registerSpecies() {
|
||||
Tuning.getSection("Bees").filterType(classOf[ConfigSection]).foreach({
|
||||
Gendustry.logInfo("Registering bees")
|
||||
val added = (Tuning.getSection("Bees").filterType(classOf[ConfigSection]) collect {
|
||||
case (uid, cfg) =>
|
||||
val species = new BeeSpecies(cfg, uid)
|
||||
Gendustry.logInfo("Registering %s", species.getUID)
|
||||
mySpecies +:= species
|
||||
reg.registerAllele(species)
|
||||
})
|
||||
}).size
|
||||
Gendustry.logInfo("Registered %d bees", added)
|
||||
}
|
||||
|
||||
def lookupBeeSpecies(uid: String) =
|
||||
Option(AlleleManager.alleleRegistry.getAllele(uid))
|
||||
.getOrElse(sys.error("Species '%s' not found".format(uid)))
|
||||
.asInstanceOf[IAlleleBeeSpecies]
|
||||
|
||||
def registerMuations() {
|
||||
Gendustry.logInfo("Registering mutations")
|
||||
|
||||
val added = TuningLoader.mutations count { st =>
|
||||
try {
|
||||
|
||||
Gendustry.logInfo("Registering mutation %s + %s = %s", st.parent1, st.parent2, st.result)
|
||||
|
||||
val mutation = new BeeMutation(
|
||||
lookupBeeSpecies(st.parent1),
|
||||
lookupBeeSpecies(st.parent2),
|
||||
lookupBeeSpecies(st.result),
|
||||
st.chance)
|
||||
|
||||
if (st.secret) mutation.isSecret = true
|
||||
|
||||
st.requirements foreach {
|
||||
case TuningLoader.MReqHumidity(hum: String) =>
|
||||
mutation.reqHumidity = Some(EnumHumidity.valueOf(hum.toUpperCase))
|
||||
case TuningLoader.MReqTemperature(temp: String) =>
|
||||
mutation.reqTemperature = Some(EnumTemperature.valueOf(temp.toUpperCase))
|
||||
}
|
||||
|
||||
mutation.getRoot.registerMutation(mutation)
|
||||
|
||||
true
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
Gendustry.logWarn("Adding mutation failed: %s (%s)", e.getMessage, st)
|
||||
false
|
||||
}
|
||||
}
|
||||
Gendustry.logInfo("Registered %d mutations", added)
|
||||
}
|
||||
|
||||
def registerTemplates() {
|
||||
|
||||
Reference in new issue
Block a user