Skip to content

Commit

Permalink
Merge branch 'forestry_unstable' into mc1710
Browse files Browse the repository at this point in the history
  • Loading branch information
bdew committed Oct 11, 2015
2 parents 49c827b + b29d057 commit 9c66c02
Show file tree
Hide file tree
Showing 25 changed files with 272 additions and 234 deletions.
4 changes: 3 additions & 1 deletion api-changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 2.3.0
* Deprecated IForestryMultiErrorSource - Use IErrorLogicSource from forestry API instead

### 2.2.0
* Added IConfigLoader - allows other mods to submit configs to be loaded Gendustry

Expand All @@ -11,4 +14,3 @@
* Added **registries.IMutatronOverrides** and **EnumMutationSetting** - allows overriding what mutations are available

Older changes were not recorded, you can see the commits [here](https://github.com/bdew/gendustry/commits/mc1710/src/net/bdew/gendustry/api).

6 changes: 3 additions & 3 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
gendustry.version=1.6.1
gendustry.api.version=2.2.0
gendustry.version=1.6.2
gendustry.api.version=2.3.0
curseforge.id=70492

bdlib.version=1.9.2.104
Expand All @@ -13,7 +13,7 @@ ccc.version=1.0.4.35

buildcraft.version=7.0.17
ic2.version=2.2.757-experimental
forestry.version=3.6.3.20
forestry.version=4.0.8.36
waila.version=1.5.10

cofhlib.cf=2246/918
Expand Down
2 changes: 2 additions & 0 deletions resources/assets/gendustry/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ itemGroup.bdew.templates=Genetic Templates
itemGroup.bdew.samples=Genetic Samples
itemGroup.bdew.hives=Custom Beehives

gendustry.errorstate.ok=No error

for.gendustry.errorstate.disabled.description=Disabled
for.gendustry.errorstate.disabled.help=The machine is disabled by it's configuration

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/net/bdew/gendustry/Gendustry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import net.minecraft.command.CommandHandler
import net.minecraftforge.oredict.RecipeSorter
import org.apache.logging.log4j.Logger

@Mod(modid = Gendustry.modId, version = "GENDUSTRY_VER", name = "Gendustry", dependencies = "required-after:Forestry@[3.6.0.0,);after:BuildCraft|energy;after:BuildCraft|Silicon;after:IC2;after:CoFHCore;after:BinnieCore;after:ExtraBees;after:ExtraTrees;after:MineFactoryReloaded;after:MagicBees;required-after:bdlib@[BDLIB_VER,)", modLanguage = "scala")
@Mod(modid = Gendustry.modId, version = "GENDUSTRY_VER", name = "Gendustry", dependencies = "required-after:Forestry@[4.0.0.0,);after:BuildCraft|energy;after:BuildCraft|Silicon;after:IC2;after:CoFHCore;after:BinnieCore;after:ExtraBees;after:ExtraTrees;after:MineFactoryReloaded;after:MagicBees;required-after:bdlib@[BDLIB_VER,)", modLanguage = "scala")
object Gendustry {
var log: Logger = null
var instance = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

import java.util.Set;

/**
* @deprecated use IErrorLogicSource from forestry API instead
*/
@Deprecated
public interface IForestryMultiErrorSource {
Set<IErrorState> getErrorStates();
}
51 changes: 31 additions & 20 deletions src/net/bdew/gendustry/compat/FakeMutatronBeeHousing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,46 @@

package net.bdew.gendustry.compat

import java.util
import java.io.{DataInputStream, DataOutputStream}
import java.lang.Iterable
import java.util.Collections

import com.google.common.collect.ImmutableSet
import com.mojang.authlib.GameProfile
import forestry.api.apiculture.{IBee, IBeeGenome, IBeeHousing}
import forestry.api.core.{EnumHumidity, EnumTemperature, ErrorStateRegistry, IErrorState}
import forestry.api.genetics.IIndividual
import forestry.api.apiculture._
import forestry.api.core._
import forestry.api.genetics.{AlleleManager, IIndividual}
import net.bdew.gendustry.api.blocks.IMutatron
import net.minecraft.item.ItemStack
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ChunkCoordinates
import net.minecraft.world.World

class FakeMutatronBeeHousing(tile: TileEntity with IMutatron) extends IBeeHousing {
class FakeMutatronBeeHousing(tile: TileEntity with IMutatron) extends IBeeHousing with IBeeModifier with IBeeListener with IBeeHousingInventory with IErrorLogic {
val beeRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees").asInstanceOf[IBeeRoot]

override def getWorld: World = tile.getWorldObj
override def getXCoord: Int = tile.xCoord
override def getYCoord: Int = tile.yCoord
override def getZCoord: Int = tile.zCoord
override def getCoordinates: ChunkCoordinates = new ChunkCoordinates(tile.xCoord, tile.yCoord, tile.zCoord)

override def getBlockLightValue: Int = getWorld.getBlockLightValue(tile.xCoord, tile.yCoord, tile.zCoord)
override def canBlockSeeTheSky: Boolean = getWorld.canBlockSeeTheSky(tile.xCoord, tile.yCoord, tile.zCoord)

override def getOwnerName: GameProfile = tile.getOwner
override def getBeeListeners: Iterable[IBeeListener] = Collections.singletonList(this)
override def getBeeInventory: IBeeHousingInventory = this
override def getBeeModifiers: Iterable[IBeeModifier] = Collections.singletonList(this)
override def getBeekeepingLogic: IBeekeepingLogic = beeRoot.createBeekeepingLogic(this)
override def getErrorLogic: IErrorLogic = this

override def getOwner: GameProfile = tile.getOwner

override def getDrone: ItemStack = tile.getParent1
override def getQueen: ItemStack = tile.getParent2

override def setQueen(itemStack: ItemStack): Unit = throw new UnsupportedOperationException("Not supported in mutatron")
override def setDrone(itemStack: ItemStack): Unit = throw new UnsupportedOperationException("Not supported in mutatron")
override def canBreed: Boolean = true

override def onQueenDeath(iBee: IBee): Unit = {}
override def onQueenDeath(): Unit = {}
override def wearOutEquipment(i: Int): Unit = {}
override def onPostQueenDeath(iBee: IBee): Unit = {}
override def onQueenChange(itemStack: ItemStack): Unit = {}
override def onEggLaid(iBee: IBee): Boolean = false
override def onPollenRetrieved(iBee: IBee, iIndividual: IIndividual, b: Boolean): Boolean = false
override def onPollenRetrieved(iIndividual: IIndividual): Boolean = false
override def addProduct(product: ItemStack, all: Boolean): Boolean = false

override def isSunlightSimulated: Boolean = false
Expand All @@ -54,10 +62,13 @@ class FakeMutatronBeeHousing(tile: TileEntity with IMutatron) extends IBeeHousin
override def getFloweringModifier(iBeeGenome: IBeeGenome, v: Float): Float = v
override def getTerritoryModifier(iBeeGenome: IBeeGenome, v: Float): Float = v

override def setErrorCondition(b: Boolean, iErrorState: IErrorState): Boolean = false
override def getErrorStates: util.Set[IErrorState] = new util.HashSet
override def setErrorState(state: IErrorState): Unit = {}
override def getErrorState: IErrorState = ErrorStateRegistry.getErrorState("Forestry:ok")
override def setCondition(condition: Boolean, errorState: IErrorState): Boolean = false
override def hasErrors: Boolean = false
override def writeData(data: DataOutputStream): Unit = {}
override def readData(data: DataInputStream): Unit = {}
override def contains(state: IErrorState): Boolean = false
override def clearErrors(): Unit = {}
override def getErrorStates: ImmutableSet[IErrorState] = ImmutableSet.of()

override def getBiome = tile.getWorldObj.getBiomeGenForCoordsBody(tile.xCoord, tile.zCoord)
override def getHumidity: EnumHumidity = EnumHumidity.getFromValue(getBiome.rainfall)
Expand Down
6 changes: 6 additions & 0 deletions src/net/bdew/gendustry/compat/triggers/BaseTrigger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.bdew.gendustry.compat.triggers

import buildcraft.api.statements.{IStatementContainer, IStatementParameter, ITriggerExternal}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.bdew.gendustry.Gendustry
import net.bdew.lib.Misc
import net.minecraft.client.renderer.texture.IIconRegister
Expand All @@ -20,9 +21,14 @@ import net.minecraftforge.common.util.ForgeDirection
abstract class BaseTrigger[T](val id: String, ordering: String, tileClass: Class[T]) extends ITriggerExternal {
var icon: IIcon = null
override def getUniqueTag = "gendustry." + ordering + "." + id

@SideOnly(Side.CLIENT)
override def getIcon = icon

@SideOnly(Side.CLIENT)
override def registerIcons(ir: IIconRegister) =
icon = ir.registerIcon(Misc.iconName(Gendustry.modId, "trigger", id))

override def getDescription = Misc.toLocal("gendustry.trigger." + id)
override def rotateLeft() = this

Expand Down
57 changes: 25 additions & 32 deletions src/net/bdew/gendustry/compat/triggers/ForestryErrorTriggers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,44 @@
package net.bdew.gendustry.compat.triggers

import buildcraft.api.statements.StatementManager
import forestry.api.core.{ErrorStateRegistry, IErrorState}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import forestry.api.core.{ForestryAPI, IErrorLogicSource, IErrorState}
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.api.blocks.IForestryMultiErrorSource
import net.bdew.lib.Misc
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraftforge.common.util.ForgeDirection

case class ForestryErrorTrigger(state: IErrorState) extends BaseTrigger("forestry.error." + state.getID, "y%03d".format(state.getID), classOf[IForestryMultiErrorSource]) {
case class ForestryErrorTrigger(state: IErrorState) extends BaseTrigger("forestry.error." + state.getID, "y%03d".format(state.getID), classOf[IErrorLogicSource]) {
override def getIcon = state.getIcon
override def getDescription = Misc.toLocal("for." + state.getDescription)
override def registerIcons(ir: IIconRegister) {}
override def getState(side: ForgeDirection, tile: IForestryMultiErrorSource) =
if (state.getUniqueName == "Forestry:ok")
tile.getErrorStates.isEmpty
else
tile.getErrorStates.contains(state)
override def getState(side: ForgeDirection, tile: IErrorLogicSource) =
tile.getErrorLogic.contains(state)
}

object ForestryNoErrorTrigger extends BaseTrigger("forestry.noerror", "_", classOf[IErrorLogicSource]) {
override def getDescription = Misc.toLocal("gendustry.errorstate.ok")

@SideOnly(Side.CLIENT)
override def registerIcons(ir: IIconRegister): Unit = {
icon = ir.registerIcon("gendustry:error/ok")
}

override def getState(side: ForgeDirection, tile: IErrorLogicSource) =
!tile.getErrorLogic.hasErrors
}

object ForestryErrorTriggers {

val apiaryTriggerStates = List(
"Forestry:ok",
"Forestry:invalidBiome",
"Forestry:isRaining",
"Forestry:notGloomy",
"Forestry:notLucid",
"Forestry:notDay",
"Forestry:notNight",
"Forestry:noFlower",
"Forestry:noQueen",
"Forestry:noDrone",
"Forestry:noSky",
"Forestry:noSpace",
"Forestry:noPower",
"Forestry:noRedstone",
"Forestry:disabledRedstone"
) map ErrorStateRegistry.getErrorState

val validTriggerStates = apiaryTriggerStates.toSet
val validTriggers = validTriggerStates.map(x => x -> ForestryErrorTrigger(x)).toMap

val apiaryTriggers = apiaryTriggerStates.map(validTriggers)
import scala.collection.JavaConversions._

val errorStateRegistry = ForestryAPI.errorStateRegistry

val triggers = errorStateRegistry.getErrorStates.map(ForestryErrorTrigger) ++ List(ForestryNoErrorTrigger)

def register() {
validTriggers.values.foreach(StatementManager.registerStatement)
Gendustry.logInfo("Created %d BC triggers for Forestry error codes", validTriggers.size)
triggers.foreach(StatementManager.registerStatement)
StatementManager.registerStatement(ForestryNoErrorTrigger)
Gendustry.logInfo("Created %d BC triggers for Forestry error codes", triggers.size)
}
}
6 changes: 3 additions & 3 deletions src/net/bdew/gendustry/compat/triggers/TriggerProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package net.bdew.gendustry.compat.triggers
import java.util

import buildcraft.api.statements._
import net.bdew.gendustry.machines.apiary.TileApiary
import forestry.api.core.IErrorLogicSource
import net.bdew.gendustry.power.TilePowered
import net.bdew.lib.power.TileBaseProcessor
import net.minecraft.tileentity.TileEntity
Expand All @@ -25,8 +25,8 @@ object TriggerProvider extends ITriggerProvider {
import scala.collection.JavaConversions._
val triggers = new util.LinkedList[ITriggerExternal]()

if (tile.isInstanceOf[TileApiary])
triggers.addAll(ForestryErrorTriggers.apiaryTriggers)
if (tile.isInstanceOf[IErrorLogicSource])
triggers.addAll(ForestryErrorTriggers.triggers)

if (tile.isInstanceOf[TilePowered])
triggers.addAll(PowerTriggers.triggers)
Expand Down
29 changes: 14 additions & 15 deletions src/net/bdew/gendustry/custom/BeeMutation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ package net.bdew.gendustry.custom

import forestry.api.apiculture._
import forestry.api.core.{EnumHumidity, EnumTemperature}
import forestry.api.genetics.{AlleleManager, IAllele, IGenome}
import forestry.api.genetics.{AlleleManager, IAllele}
import net.bdew.gendustry.forestry.BeeModifiers
import net.bdew.lib.Misc
import net.minecraft.block.Block
import net.minecraft.item.ItemStack
Expand All @@ -29,25 +30,23 @@ class BeeMutation(parent1: IAlleleBeeSpecies, parent2: IAlleleBeeSpecies, result

// === IBeeMutation ===

def getBlockUnderHousing(h: IBeeHousing) =
if (h.getYCoord > 0)
h.getWorld.getBlock(h.getXCoord, h.getYCoord - 1, h.getZCoord)
def getBlockUnderHousing(h: IBeeHousing) = {
val c = h.getCoordinates
if (c.posY > 0)
h.getWorld.getBlock(c.posX, c.posY - 1, c.posZ)
else null
}

def getBlockMetaUnderHousing(h: IBeeHousing) =
if (h.getYCoord > 0)
h.getWorld.getBlockMetadata(h.getXCoord, h.getYCoord - 1, h.getZCoord)
def getBlockMetaUnderHousing(h: IBeeHousing) = {
val c = h.getCoordinates
if (c.posY > 0)
h.getWorld.getBlockMetadata(c.posX, c.posY - 1, c.posZ)
else -1
}

def testReq[T](req: Option[T], v: T) = req.isEmpty || req.get == v

override def getChance(housing: IBeeHousing, allele0: IAllele, allele1: IAllele, genome0: IGenome, genome1: IGenome) =
getChanceImpl(housing, allele0.asInstanceOf[IAlleleBeeSpecies], allele1.asInstanceOf[IAlleleBeeSpecies], genome0.asInstanceOf[IBeeGenome], genome1.asInstanceOf[IBeeGenome])

override def getChance(housing: IBeeHousing, allele0: IAlleleBeeSpecies, allele1: IAlleleBeeSpecies, genome0: IBeeGenome, genome1: IBeeGenome) =
getChanceImpl(housing, allele0, allele1, genome0, genome1)

def getChanceImpl(housing: IBeeHousing, allele0: IAlleleBeeSpecies, allele1: IAlleleBeeSpecies, genome0: IBeeGenome, genome1: IBeeGenome): Float =
if (!((allele0 == parent1 && allele1 == parent2) || (allele0 == parent2 && allele1 == parent1))) 0
else if (!testReq(reqTemperature, housing.getTemperature)) 0
else if (!testReq(reqHumidity, housing.getHumidity)) 0
Expand All @@ -57,8 +56,8 @@ class BeeMutation(parent1: IAlleleBeeSpecies, parent2: IAlleleBeeSpecies, result
else {
val bkm = getRoot.getBeekeepingMode(housing.getWorld)
var processedChance = chance
processedChance *= housing.getMutationModifier(genome0, genome1, processedChance)
processedChance *= bkm.getMutationModifier(genome0, genome1, processedChance)
processedChance *= BeeModifiers.from(housing).getMutationModifier(genome0, genome1, processedChance)
processedChance *= bkm.getBeeModifier.getMutationModifier(genome0, genome1, processedChance)
processedChance
}

Expand Down
12 changes: 4 additions & 8 deletions src/net/bdew/gendustry/custom/BeeSpecies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.mojang.authlib.GameProfile
import cpw.mods.fml.relauncher.{Side, SideOnly}
import forestry.api.apiculture._
import forestry.api.core.{EnumHumidity, EnumTemperature}
import forestry.api.genetics.{AlleleManager, IAllele, IIndividual}
import forestry.api.genetics.{AlleleManager, IAlleleSpecies, IIndividual}
import net.bdew.gendustry.Gendustry
import net.bdew.gendustry.config.loader.TuningLoader
import net.bdew.gendustry.forestry.ForestryItems
Expand Down Expand Up @@ -85,11 +85,7 @@ class BeeSpecies(cfg: ConfigSection, ident: String) extends IAlleleBeeSpecies {
val specialty = prepareLootList("Specialty")
specialty.foreach(x => Gendustry.logDebug(" [%.1f%%] %s", x._2, x._1))

// Old product/specialty maps - will be removed at some point. Manual boxing because java maps can't hold primitive values.
override val getProducts = products.map(x => x._1 -> Int.box((x._2 * 100).round)).asJava
override val getSpecialty = specialty.map(x => x._1 -> Int.box((x._2 * 100).round)).asJava

// New maps with floats. Ditto about boxing.
// Manual boxing because java maps can't hold primitive values.
override def getProductChances = products.map(x => x._1 -> Float.box(x._2)).asJava
override def getSpecialtyChances = specialty.map(x => x._1 -> Float.box(x._2)).asJava

Expand All @@ -98,9 +94,9 @@ class BeeSpecies(cfg: ConfigSection, ident: String) extends IAlleleBeeSpecies {

// ==== RESEARCH SYSTEM

override lazy val getComplexity: Int = 1 + getMutationPathLength(this, mutable.Set.empty[IAllele])
override lazy val getComplexity: Int = 1 + getMutationPathLength(this, mutable.Set.empty)

private def getMutationPathLength(species: IAllele, excludeSpecies: mutable.Set[IAllele]): Int = {
private def getMutationPathLength(species: IAlleleSpecies, excludeSpecies: mutable.Set[IAlleleSpecies]): Int = {
var highest = 0
excludeSpecies += species
import scala.collection.JavaConversions._
Expand Down
48 changes: 48 additions & 0 deletions src/net/bdew/gendustry/forestry/BeeModifiers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.forestry

import forestry.api.apiculture.{IBeeGenome, IBeeHousing, IBeeModifier}

import scala.collection.JavaConversions._

/**
* Combines multiple IBeeModifier together
* Conceptually based on BeeHousingModifier from Forestry
* @param modifiers collection of modifiers
*/
case class BeeModifiers(modifiers: Traversable[IBeeModifier]) extends IBeeModifier {
override def getTerritoryModifier(genome: IBeeGenome, currentModifier: Float): Float =
modifiers.foldLeft(1F)((v, m) => m.getTerritoryModifier(genome, v * currentModifier))

override def getMutationModifier(genome: IBeeGenome, mate: IBeeGenome, currentModifier: Float): Float =
modifiers.foldLeft(1F)((v, m) => m.getMutationModifier(genome, mate, v * currentModifier))

override def getLifespanModifier(genome: IBeeGenome, mate: IBeeGenome, currentModifier: Float): Float =
modifiers.foldLeft(1F)((v, m) => m.getLifespanModifier(genome, mate, v * currentModifier))

override def getProductionModifier(genome: IBeeGenome, currentModifier: Float): Float =
modifiers.foldLeft(1F)((v, m) => m.getProductionModifier(genome, v * currentModifier))

override def getFloweringModifier(genome: IBeeGenome, currentModifier: Float): Float =
modifiers.foldLeft(1F)((v, m) => m.getFloweringModifier(genome, v * currentModifier))

override def getGeneticDecay(genome: IBeeGenome, currentModifier: Float): Float =
modifiers.foldLeft(1F)((v, m) => m.getGeneticDecay(genome, v * currentModifier))

override def isSealed: Boolean = modifiers.exists(_.isSealed)
override def isSelfLighted: Boolean = modifiers.exists(_.isSelfLighted)
override def isSunlightSimulated: Boolean = modifiers.exists(_.isSunlightSimulated)
override def isHellish: Boolean = modifiers.exists(_.isHellish)
}

object BeeModifiers {
def from(beeHousing: IBeeHousing) = BeeModifiers(beeHousing.getBeeModifiers)
}
Loading

0 comments on commit 9c66c02

Please sign in to comment.