Skip to content

Commit

Permalink
Added custom flower alleles (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdew committed Dec 27, 2015
1 parent 746bcf6 commit 7a55a63
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ curseforge.id=70492
bdlib.version=1.9.4.109

minecraft.version=1.7.10
forge.version=10.13.4.1558-1.7.10
forge.version=10.13.4.1566-1.7.10

nei.version=1.0.5.118
ccl.version=1.1.3.140
ccc.version=1.0.7.47

buildcraft.version=7.1.14
ic2.version=2.2.802-experimental
forestry.version=4.2.1.48
forestry.version=4.2.3.51
waila.version=1.5.10
mekanism.version=8.1.7.5

Expand Down
9 changes: 9 additions & 0 deletions example_configs/example_bees.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if HaveForestryModule Bees <<
cfg Traits {
Base = "forestry.speciesForest" // Copy traits from another species
Nocturnal = "forestry.boolTrue" // Override a single trait
Flower_Provider = "gendustry.flowersGoldBlocks" // See below
}
}
}
Expand All @@ -63,6 +64,14 @@ if HaveForestryModule Bees <<
}
}

// Custom Flower allele that accepts gold blocks and spreads gold ore

FlowerAllele goldBlocks { // Allele UID will be gendustry.flowersGoldBlocks (note the capitalization)
Dominant // can be either Dominant or Recessive
Accepts OD:blockGold, OD:blockIron // List of blocks that are accepted as "flowers"
Spread OD:oreGold 1.0 // A block that will be spread randomly, with weight
}

recipes {

// http://bdew.net/gendustry/configuration/centrifuge-recipes/
Expand Down
3 changes: 2 additions & 1 deletion example_configs/example_bees.en_US.lang
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
gendustry.bees.species.Test=Test
gendustry.bees.species.Test.description=A curious species of bees, used to demonstrate the config system
gendustry.honeycomb.test.name=Test Comb
gendustry.honeydrop.test.name=Test Honey Drop
gendustry.honeydrop.test.name=Test Honey Drop
gendustry.allele.flowers.goldBlocks=Gold Bocks
3 changes: 2 additions & 1 deletion src/net/bdew/gendustry/Gendustry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import net.bdew.gendustry.compat.triggers.TriggerProvider
import net.bdew.gendustry.compat.{ForestryHelper, PowerProxy}
import net.bdew.gendustry.config._
import net.bdew.gendustry.config.loader.TuningLoader
import net.bdew.gendustry.custom.{CustomContent, CustomHives}
import net.bdew.gendustry.custom.{CustomContent, CustomFlowerAlleles, CustomHives}
import net.bdew.gendustry.forestry.GeneRecipe
import net.bdew.gendustry.gui.HintIcons
import net.bdew.gendustry.machines.apiary.GendustryErrorStates
Expand Down Expand Up @@ -113,6 +113,7 @@ object Gendustry {
def postInit(event: FMLPostInitializationEvent) {
TuningLoader.loadDelayed()
if (ForestryHelper.haveRoot("Bees")) {
CustomFlowerAlleles.registerAlleles()
CustomContent.registerTemplates()
CustomContent.registerMutations()
CustomHives.registerHives()
Expand Down
4 changes: 3 additions & 1 deletion src/net/bdew/gendustry/config/loader/Loader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import forestry.api.recipes.RecipeManagers
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.compat.ForestryHelper
import net.bdew.gendustry.config.Tuning
import net.bdew.gendustry.custom.CustomHives
import net.bdew.gendustry.custom.{CustomFlowerAlleles, CustomHives}
import net.bdew.gendustry.fluids.{LiquidDNASources, MutagenSources, ProteinSources}
import net.bdew.lib.recipes._
import net.bdew.lib.recipes.gencfg.GenericConfigLoader
Expand Down Expand Up @@ -112,6 +112,8 @@ class Loader extends RecipeLoader with GenericConfigLoader with LootListLoader {
override def processConfigStatement(s: ConfigStatement): Unit = s match {
case x: CSHiveDefinition =>
CustomHives.registerHiveDefinition(x)
case x: CSFlowerAllele =>
CustomFlowerAlleles.addDefinition(x)
case _ => super.processConfigStatement(s)
}
}
2 changes: 1 addition & 1 deletion src/net/bdew/gendustry/config/loader/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.bdew.lib.recipes.RecipeParser
import net.bdew.lib.recipes.gencfg.{CfgVal, GenericConfigParser}
import net.bdew.lib.recipes.lootlist.LootListParser

class Parser extends RecipeParser with GenericConfigParser with LootListParser with ParserHives {
class Parser extends RecipeParser with GenericConfigParser with LootListParser with ParserHives with ParserAlleles {
override def recipeStatement = mutagen | dna | protein | assembly | stMutation | centrifuge | squeezer | super.recipeStatement

// === Machine Recipes ===
Expand Down
28 changes: 28 additions & 0 deletions src/net/bdew/gendustry/config/loader/ParserAlleles.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) bdew, 2013 - 2015
* 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
* http://bdew.net/minecraft-mod-public-license/
*/

package net.bdew.gendustry.config.loader

import net.bdew.lib.recipes.RecipeParser
import net.bdew.lib.recipes.gencfg.GenericConfigParser

trait ParserAlleles extends RecipeParser with GenericConfigParser {
private def blocks = spec ~ ("," ~> spec).* ^^ { case sp1 ~ spl => List(sp1) ++ spl }

private def flowerStatement = (
"Accepts" ~> blocks ^^ FADAccepts
| "Spread" ~> spec ~ decimalNumber ^^ { case spec ~ chance => FADSpread(spec, chance.toDouble) }
| "Dominant" ^^^ FADDominant(true)
| "Recessive" ^^^ FADDominant(false)
)

private def flowerDef = "FlowerAllele" ~> str ~ ("{" ~> flowerStatement.* <~ "}") ^^ { case id ~ statements => CSFlowerAllele(id, statements) }

override def configStatement = super.configStatement | flowerDef
}
22 changes: 22 additions & 0 deletions src/net/bdew/gendustry/config/loader/ast-alleles.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) bdew, 2013 - 2015
* 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
* http://bdew.net/minecraft-mod-public-license/
*/

package net.bdew.gendustry.config.loader

import net.bdew.lib.recipes.{ConfigStatement, StackRef}

case class CSFlowerAllele(id: String, definition: List[FlowerAlleleDefStatement]) extends ConfigStatement

trait FlowerAlleleDefStatement

case class FADAccepts(accepts: List[StackRef]) extends FlowerAlleleDefStatement

case class FADSpread(block: StackRef, weight: Double) extends FlowerAlleleDefStatement

case class FADDominant(dominant: Boolean) extends FlowerAlleleDefStatement
80 changes: 80 additions & 0 deletions src/net/bdew/gendustry/custom/CustomFlowerAlleles.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) bdew, 2013 - 2015
* 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
* http://bdew.net/minecraft-mod-public-license/
*/

package net.bdew.gendustry.custom

import forestry.api.apiculture.{EnumBeeChromosome, FlowerManager}
import forestry.api.genetics._
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.config.loader._
import net.bdew.lib.Misc
import net.minecraft.block.Block
import net.minecraftforge.oredict.OreDictionary

object CustomFlowerAlleles {
var definitions = List.empty[CSFlowerAllele]
lazy val flowerRegistry = FlowerManager.flowerRegistry

def addDefinition(definition: CSFlowerAllele) = definitions +:= definition

def registerAlleles(): Unit = {
for (CSFlowerAllele(id, definition) <- definitions) {
val dominant = {
val entries = Misc.filterType(definition, classOf[FADDominant])
if (entries.isEmpty) {
Gendustry.logWarn("Flower allele %s has no Dominant/Recessive flag, assuming dominant", id)
true
} else {
if (entries.size > 1) {
Gendustry.logWarn("Flower allele %s has multiple Dominant/Recessive flags, only the first will be used", id)
}
entries.head.dominant
}

}

val flowerType = "gendustry." + id

val flowerProvider = CustomFlowerProvider(flowerType, id)

Gendustry.logDebug("Registering custom flower allele %s", id)

AlleleManager.alleleFactory.createFlowers(Gendustry.modId, "flowers", id, flowerProvider, dominant, EnumBeeChromosome.FLOWER_PROVIDER)

for {
entry <- Misc.filterType(definition, classOf[FADAccepts])
stackRef <- entry.accepts
item <- TuningLoader.loader.getAllConcreteStacks(stackRef)
block <- Option(Block.getBlockFromItem(item.getItem))
} {
Gendustry.logDebug("Registering custom acceptable flower for allele %s: %s", id, item)
if (item.getItemDamage == OreDictionary.WILDCARD_VALUE) {
flowerRegistry.registerAcceptableFlower(block, flowerType)
} else {
flowerRegistry.registerAcceptableFlower(block, item.getItemDamage, flowerType)
}
}

for {
FADSpread(stackRef, weight) <- Misc.filterType(definition, classOf[FADSpread])
} {
val item = TuningLoader.loader.getConcreteStackNoWildcard(stackRef)
val block = Block.getBlockFromItem(item.getItem)
Gendustry.logDebug("Registering custom spread flower for allele %s: %s (weight %.03f)", id, item, weight)
if (block == null)
Gendustry.logWarn("Definition %s in flower allele %s doesn't refer to a block, it will be ignored", stackRef, id)
else if (item.getItemDamage == OreDictionary.WILDCARD_VALUE)
flowerRegistry.registerPlantableFlower(block, 0, weight, flowerType)
else
flowerRegistry.registerPlantableFlower(block, item.getItemDamage, weight, flowerType)
}
}
definitions = List.empty
}
}
37 changes: 37 additions & 0 deletions src/net/bdew/gendustry/custom/CustomFlowerProvider.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) bdew, 2013 - 2015
* 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
* http://bdew.net/minecraft-mod-public-license/
*/

package net.bdew.gendustry.custom

import forestry.api.apiculture.FlowerManager
import forestry.api.genetics.{IFlowerProvider, IIndividual, IPollinatable}
import net.bdew.lib.Misc
import net.minecraft.item.ItemStack
import net.minecraft.world.World
import net.minecraftforge.common.EnumPlantType

case class CustomFlowerProvider(flowerType: String, name: String) extends IFlowerProvider {
def getFlowerType = flowerType

def isAcceptedPollinatable(world: World, pollinatable: IPollinatable) = {
val plantTypes = pollinatable.getPlantType
plantTypes.size > 1 || !plantTypes.contains(EnumPlantType.Nether)
}

def growFlower(world: World, individual: IIndividual, x: Int, y: Int, z: Int) =
FlowerManager.flowerRegistry.growFlower(flowerType, world, individual, x, y, z)

def getDescription: String =
Misc.toLocal("gendustry.allele.flowers." + name)

def affectProducts(world: World, individual: IIndividual, x: Int, y: Int, z: Int, products: Array[ItemStack]): Array[ItemStack] =
products

def getFlowers = FlowerManager.flowerRegistry.getAcceptableFlowers(flowerType)
}

0 comments on commit 7a55a63

Please sign in to comment.