From 272e941c529f814e65eb2b29f94b69bc5afaaa67 Mon Sep 17 00:00:00 2001 From: bdew Date: Sun, 4 May 2014 15:26:54 +0300 Subject: [PATCH] Implemented all reasearch-related stuff for custom bees --- src/net/bdew/gendustry/config/Fluids.scala | 7 +- .../bdew/gendustry/custom/BeeSpecies.scala | 73 ++++++++++++++++--- .../gendustry/forestry/ForestryItems.scala | 19 +++++ 3 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/net/bdew/gendustry/forestry/ForestryItems.scala diff --git a/src/net/bdew/gendustry/config/Fluids.scala b/src/net/bdew/gendustry/config/Fluids.scala index f5bd372..35e0575 100644 --- a/src/net/bdew/gendustry/config/Fluids.scala +++ b/src/net/bdew/gendustry/config/Fluids.scala @@ -16,11 +16,10 @@ import net.minecraftforge.fluids.{FluidStack, FluidContainerRegistry, FluidRegis import net.bdew.lib.Misc import cpw.mods.fml.common.registry.GameRegistry import net.minecraft.item.{Item, ItemStack} -import forestry.api.core.ItemInterface +import net.bdew.gendustry.forestry.ForestryItems object Fluids extends FluidManager(Config.IDs) { val emptyBucket = new ItemStack(Item.bucketEmpty) - val emptyCan = ItemInterface.getItem("canEmpty") def registerFluid(id: String, luminosity: Int = 0, @@ -54,9 +53,9 @@ object Fluids extends FluidManager(Config.IDs) { val bucket = Items.regItem(new ItemFluidBucket(ids.getItemId(id + "Bucket"), fluid), id + "Bucket") FluidContainerRegistry.registerFluidContainer(fluid, new ItemStack(bucket), emptyBucket) } - if (FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, 1000), emptyCan) == null) { + if (FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, 1000), ForestryItems.canEmpty) == null) { val can = Items.regItem(new ItemFluidCan(ids.getItemId(id + "Can"), fluid), id + "Can") - FluidContainerRegistry.registerFluidContainer(fluid, new ItemStack(can), emptyCan) + FluidContainerRegistry.registerFluidContainer(fluid, new ItemStack(can), ForestryItems.canEmpty) } return fluid } diff --git a/src/net/bdew/gendustry/custom/BeeSpecies.scala b/src/net/bdew/gendustry/custom/BeeSpecies.scala index b09840d..d0651eb 100644 --- a/src/net/bdew/gendustry/custom/BeeSpecies.scala +++ b/src/net/bdew/gendustry/custom/BeeSpecies.scala @@ -13,13 +13,17 @@ import forestry.api.apiculture._ import forestry.api.core.{EnumTemperature, EnumHumidity} import net.minecraft.item.ItemStack import net.minecraft.world.World -import forestry.api.genetics.{AlleleManager, IIndividual} +import forestry.api.genetics.{IAllele, AlleleManager, IIndividual} import cpw.mods.fml.relauncher.{Side, SideOnly} import net.bdew.lib.recipes.gencfg.{EntryStr, ConfigSection} import net.bdew.lib.Misc import net.bdew.gendustry.Gendustry import net.bdew.lib.recipes.lootlist.EntryLootList import net.bdew.gendustry.config.loader.TuningLoader +import net.bdew.gendustry.forestry.ForestryItems +import net.minecraftforge.oredict.OreDictionary +import net.bdew.lib.items.ItemUtils +import collection.mutable class BeeSpecies(cfg: ConfigSection, ident: String) extends IAlleleBeeSpecies { // IAllele @@ -45,9 +49,6 @@ class BeeSpecies(cfg: ConfigSection, ident: String) extends IAlleleBeeSpecies { override val hasEffect = cfg.getBoolean("Glowing") override val getHumidity = EnumHumidity.valueOf(cfg.getString("Humidity").toUpperCase) override val getTemperature = EnumTemperature.valueOf(cfg.getString("Temperature").toUpperCase) - override def getResearchBounty(world: World, researcher: String, individual: IIndividual, bountyLevel: Int) = ??? - override def getResearchSuitability(itemstack: ItemStack) = ??? - override def getComplexity = ??? override val getBranch = AlleleManager.alleleRegistry.getClassification("genus." + cfg.getString("Branch")) override val getAuthority = cfg.getString("Authority") override val getBinomial = cfg.getString("Binominal") @@ -69,19 +70,73 @@ class BeeSpecies(cfg: ConfigSection, ident: String) extends IAlleleBeeSpecies { def prepareLootList(name: String) = TuningLoader.loader.resolveLootList(cfg.rawget(name, classOf[EntryLootList])) - .toMap.map(x => x._2 -> new Integer(x._1)).asJava + .toMap.map(x => x._2 -> new Integer(x._1)) Gendustry.logInfo("Resolving products list for bee '%s'...", ident) - override val getProducts = prepareLootList("Products") - getProducts.asScala.foreach(x => Gendustry.logInfo(" [%d%%] %s", x._2, x._1)) + val products = prepareLootList("Products") + override val getProducts = products.asJava + products.foreach(x => Gendustry.logInfo(" [%d%%] %s", x._2, x._1)) Gendustry.logInfo("Resolving specialty list for bee '%s'...", ident) - override val getSpecialty = prepareLootList("Specialty") - getSpecialty.asScala.foreach(x => Gendustry.logInfo(" [%d%%] %s", x._2, x._1)) + val specialty = prepareLootList("Specialty") + override val getSpecialty = specialty.asJava + specialty.foreach(x => Gendustry.logInfo(" [%d%%] %s", x._2, x._1)) override val isNocturnal = cfg.getBoolean("Nocturnal") override val getRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees").asInstanceOf[IBeeRoot] + // ==== RESEARCH SYSTEM + + override lazy val getComplexity: Int = 1 + getMutationPathLength(this, mutable.Set.empty[IAllele]) + + private def getMutationPathLength(species: IAllele, excludeSpecies: mutable.Set[IAllele]): Int = { + var highest = 0 + excludeSpecies += species + import scala.collection.JavaConversions._ + getRoot.getPaths(species, EnumBeeChromosome.SPECIES.ordinal) foreach { mutation => + if (!excludeSpecies.contains(mutation.getAllele0)) { + val otherAdvance = getMutationPathLength(mutation.getAllele0, excludeSpecies) + if (otherAdvance > highest) highest = otherAdvance + } + if (!excludeSpecies.contains(mutation.getAllele1)) { + val otherAdvance = getMutationPathLength(mutation.getAllele1, excludeSpecies) + if (otherAdvance > highest) { + highest = otherAdvance + } + } + } + return 1 + (if (highest > 0) highest else 0) + } + + override def getResearchSuitability(itemStack: ItemStack): Float = { + import scala.collection.JavaConversions._ + if (itemStack == null || itemStack.getItem == null) return 0 + products.keys.find(itemStack.isItemEqual).foreach(return 1) + specialty.keys.find(itemStack.isItemEqual).foreach(return 1) + OreDictionary.getOres("beeComb").find(OreDictionary.itemMatches(_, itemStack, false)).foreach(return 0.4F) + OreDictionary.getOres("dropHoney").find(OreDictionary.itemMatches(_, itemStack, false)).foreach(return 0.5F) + if (itemStack.getItem.itemID == ForestryItems.honeydew.itemID) return 0.7F + getRoot.getResearchCatalysts.find(x => ItemUtils.isSameItem(x._1, itemStack)).foreach(x => return x._2) + return 0 + } + + override def getResearchBounty(world: World, researcher: String, individual: IIndividual, bountyLevel: Int): Array[ItemStack] = { + import scala.collection.JavaConversions._ + var res = List.empty[ItemStack] + if (world.rand.nextFloat() < 10F / bountyLevel) { + val combinations = getRoot.getCombinations(this).toList + if (combinations.size > 0) + res :+= AlleleManager.alleleRegistry.getMutationNoteStack(researcher, combinations(world.rand.nextInt(combinations.size))) + } + + if (bountyLevel > 10) + res ++= specialty.keys.map(x => ItemUtils.copyWithRandomSize(x, (bountyLevel / 2F).toInt, world.rand)) + + res ++= products.keys.map(x => ItemUtils.copyWithRandomSize(x, (bountyLevel / 2F).toInt, world.rand)) + + return res.toArray + } + // Internal stuff def getTemplate = { diff --git a/src/net/bdew/gendustry/forestry/ForestryItems.scala b/src/net/bdew/gendustry/forestry/ForestryItems.scala new file mode 100644 index 0000000..6670375 --- /dev/null +++ b/src/net/bdew/gendustry/forestry/ForestryItems.scala @@ -0,0 +1,19 @@ +/* + * 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.forestry + +import forestry.api.core.ItemInterface + +@SuppressWarnings(Array("deprecation")) +object ForestryItems { + lazy val honeydew = ItemInterface.getItem("honeydew") + lazy val canEmpty = ItemInterface.getItem("canEmpty") +} +