From 869c206c4fcc8001bd2e1d66f704290331813835 Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Wed, 20 Jan 2016 14:24:34 +1000 Subject: Initial Commit --- .../binnie/core/genetics/BeeBreedingSystem.java | 125 +++++ .../binnie/core/genetics/BeeModifierLogic.java | 47 ++ src/Java/binnie/core/genetics/BreedingSystem.java | 558 +++++++++++++++++++++ .../core/genetics/EnumBeeBooleanModifier.java | 8 + src/Java/binnie/core/genetics/EnumBeeModifier.java | 17 + .../binnie/core/genetics/FlowerBreedingSystem.java | 129 +++++ src/Java/binnie/core/genetics/ForestryAllele.java | 211 ++++++++ src/Java/binnie/core/genetics/Gene.java | 128 +++++ src/Java/binnie/core/genetics/IAlleleProvider.java | 8 + .../binnie/core/genetics/IBreedingMessage.java | 124 +++++ .../core/genetics/IItemStackRepresentitive.java | 8 + src/Java/binnie/core/genetics/ManagerGenetics.java | 298 +++++++++++ .../binnie/core/genetics/MothBreedingSystem.java | 138 +++++ src/Java/binnie/core/genetics/Tolerance.java | 48 ++ .../binnie/core/genetics/TreeBreedingSystem.java | 303 +++++++++++ .../binnie/core/genetics/VirtualBeeHousing.java | 111 ++++ src/Java/binnie/core/genetics/VirtualHousing.java | 98 ++++ .../binnie/core/genetics/VirtualMothHousing.java | 33 ++ 18 files changed, 2392 insertions(+) create mode 100644 src/Java/binnie/core/genetics/BeeBreedingSystem.java create mode 100644 src/Java/binnie/core/genetics/BeeModifierLogic.java create mode 100644 src/Java/binnie/core/genetics/BreedingSystem.java create mode 100644 src/Java/binnie/core/genetics/EnumBeeBooleanModifier.java create mode 100644 src/Java/binnie/core/genetics/EnumBeeModifier.java create mode 100644 src/Java/binnie/core/genetics/FlowerBreedingSystem.java create mode 100644 src/Java/binnie/core/genetics/ForestryAllele.java create mode 100644 src/Java/binnie/core/genetics/Gene.java create mode 100644 src/Java/binnie/core/genetics/IAlleleProvider.java create mode 100644 src/Java/binnie/core/genetics/IBreedingMessage.java create mode 100644 src/Java/binnie/core/genetics/IItemStackRepresentitive.java create mode 100644 src/Java/binnie/core/genetics/ManagerGenetics.java create mode 100644 src/Java/binnie/core/genetics/MothBreedingSystem.java create mode 100644 src/Java/binnie/core/genetics/Tolerance.java create mode 100644 src/Java/binnie/core/genetics/TreeBreedingSystem.java create mode 100644 src/Java/binnie/core/genetics/VirtualBeeHousing.java create mode 100644 src/Java/binnie/core/genetics/VirtualHousing.java create mode 100644 src/Java/binnie/core/genetics/VirtualMothHousing.java (limited to 'src/Java/binnie/core/genetics') diff --git a/src/Java/binnie/core/genetics/BeeBreedingSystem.java b/src/Java/binnie/core/genetics/BeeBreedingSystem.java new file mode 100644 index 0000000000..2c3947b5a0 --- /dev/null +++ b/src/Java/binnie/core/genetics/BeeBreedingSystem.java @@ -0,0 +1,125 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; +import binnie.core.resource.ManagerResource; +import binnie.extrabees.ExtraBees; +import forestry.api.apiculture.EnumBeeChromosome; +import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IApiaristTracker; +import forestry.api.apiculture.IBeeMutation; +import forestry.api.apiculture.IBeeRoot; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IMutation; +import forestry.api.genetics.ISpeciesRoot; +import java.util.TreeSet; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +class BeeBreedingSystem + extends BreedingSystem +{ + public BeeBreedingSystem() + { + this.iconUndiscovered = Binnie.Resource.getItemIcon(ExtraBees.instance, "icon/undiscoveredBee"); + this.iconDiscovered = Binnie.Resource.getItemIcon(ExtraBees.instance, "icon/discoveredBee"); + } + + public float getChance(IMutation mutation, EntityPlayer player, IAllele species1, IAllele species2) + { + return ((IBeeMutation)mutation).getChance(new VirtualBeeHousing(player), species1, species2, getSpeciesRoot().templateAsGenome(getSpeciesRoot().getTemplate(species1.getUID())), getSpeciesRoot().templateAsGenome(getSpeciesRoot().getTemplate(species2.getUID()))); + } + + public ISpeciesRoot getSpeciesRoot() + { + return Binnie.Genetics.getBeeRoot(); + } + + public int getColour() + { + return 16767232; + } + + public Class getTrackerClass() + { + return IApiaristTracker.class; + } + + public String getAlleleName(IChromosomeType chromosome, IAllele allele) + { + if (chromosome == EnumBeeChromosome.FERTILITY) + { + if (allele.getUID().contains("Low")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.low"); + } + if (allele.getUID().contains("Normal")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.normal"); + } + if (allele.getUID().contains("High")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.high"); + } + if (allele.getUID().contains("Maximum")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.maximum"); + } + } + return super.getAlleleName(chromosome, allele); + } + + public boolean isDNAManipulable(ItemStack member) + { + return ((IBeeRoot)getSpeciesRoot()).getType(member) == EnumBeeType.LARVAE; + } + + public int[] getActiveTypes() + { + return new int[] { EnumBeeType.DRONE.ordinal(), EnumBeeType.PRINCESS.ordinal(), EnumBeeType.QUEEN.ordinal(), EnumBeeType.LARVAE.ordinal() }; + } + + public void addExtraAlleles(IChromosomeType chromosome, TreeSet alleles) + { + switch (1.$SwitchMap$forestry$api$apiculture$EnumBeeChromosome[((EnumBeeChromosome)chromosome).ordinal()]) + { + case 1: + for (ForestryAllele.Fertility a : ForestryAllele.Fertility.values()) { + alleles.add(a.getAllele()); + } + break; + case 2: + for (ForestryAllele.Flowering a : ForestryAllele.Flowering.values()) { + alleles.add(a.getAllele()); + } + break; + case 3: + case 4: + for (Tolerance a : Tolerance.values()) { + alleles.add(a.getAllele()); + } + break; + case 5: + for (ForestryAllele.Lifespan a : ForestryAllele.Lifespan.values()) { + alleles.add(a.getAllele()); + } + break; + case 6: + for (ForestryAllele.Speed a : ForestryAllele.Speed.values()) { + alleles.add(a.getAllele()); + } + break; + case 7: + for (ForestryAllele.Territory a : ForestryAllele.Territory.values()) { + alleles.add(a.getAllele()); + } + break; + case 8: + case 9: + case 10: + for (ForestryAllele.Bool a : ForestryAllele.Bool.values()) { + alleles.add(a.getAllele()); + } + break; + } + } +} diff --git a/src/Java/binnie/core/genetics/BeeModifierLogic.java b/src/Java/binnie/core/genetics/BeeModifierLogic.java new file mode 100644 index 0000000000..65a2ab3103 --- /dev/null +++ b/src/Java/binnie/core/genetics/BeeModifierLogic.java @@ -0,0 +1,47 @@ +package binnie.core.genetics; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BeeModifierLogic +{ + private Map modifiers = new HashMap(); + private List booleanModifiers = new ArrayList(); + + public float getModifier(EnumBeeModifier modifier, float currentModifier) + { + if (!this.modifiers.containsKey(modifier)) { + return 1.0F; + } + float mult = ((Float[])this.modifiers.get(modifier))[0].floatValue(); + float max = ((Float[])this.modifiers.get(modifier))[1].floatValue(); + if (max >= 1.0F) + { + if (max <= currentModifier) { + return 1.0F; + } + return Math.min(max / currentModifier, mult); + } + if (max >= currentModifier) { + return 1.0F; + } + return Math.max(max / currentModifier, mult); + } + + public boolean getModifier(EnumBeeBooleanModifier modifier) + { + return this.booleanModifiers.contains(modifier); + } + + public void setModifier(EnumBeeBooleanModifier modifier) + { + this.booleanModifiers.add(modifier); + } + + public void setModifier(EnumBeeModifier modifier, float mult, float max) + { + this.modifiers.put(modifier, new Float[] { Float.valueOf(mult), Float.valueOf(max) }); + } +} diff --git a/src/Java/binnie/core/genetics/BreedingSystem.java b/src/Java/binnie/core/genetics/BreedingSystem.java new file mode 100644 index 0000000000..1bdd5d6376 --- /dev/null +++ b/src/Java/binnie/core/genetics/BreedingSystem.java @@ -0,0 +1,558 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; +import binnie.core.proxy.BinnieProxy; +import binnie.core.resource.BinnieIcon; +import binnie.extrabees.genetics.ExtraBeeMutation; +import com.mojang.authlib.GameProfile; +import cpw.mods.fml.common.eventhandler.EventBus; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import forestry.api.core.ForestryEvent.SyncedBreedingTracker; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleBoolean; +import forestry.api.genetics.IAlleleRegistry; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IClassification; +import forestry.api.genetics.IGenome; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.IMutation; +import forestry.api.genetics.ISpeciesRoot; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; + +public abstract class BreedingSystem + implements IItemStackRepresentitive +{ + protected BinnieIcon iconUndiscovered; + protected BinnieIcon iconDiscovered; + + public BreedingSystem() + { + Binnie.Genetics.registerBreedingSystem(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public String getChromosomeName(IChromosomeType chromo) + { + return BinnieCore.proxy.localise(getSpeciesRoot().getUID() + ".chromosome." + chromo.getName()); + } + + public String getChromosomeShortName(IChromosomeType chromo) + { + return BinnieCore.proxy.localise(getSpeciesRoot().getUID() + ".chromosome." + chromo.getName() + ".short"); + } + + public final String getEpitome(float discoveredPercentage) + { + int i = 0; + if (discoveredPercentage == 1.0F) { + i = 6; + } else if (discoveredPercentage < 0.1F) { + i = 0; + } else if (discoveredPercentage < 0.3F) { + i = 1; + } else if (discoveredPercentage < 0.5F) { + i = 2; + } else if (discoveredPercentage < 0.7F) { + i = 3; + } else if (discoveredPercentage < 0.9F) { + i = 4; + } else if (discoveredPercentage < 1.0F) { + i = 5; + } + return BinnieCore.proxy.localise(getSpeciesRoot().getUID() + ".epitome." + i); + } + + private List allBranches = new ArrayList(); + List allActiveSpecies = new ArrayList(); + private List allSpecies = new ArrayList(); + private List allMutations = new ArrayList(); + private Map> resultantMutations = new HashMap(); + private Map> furtherMutations = new HashMap(); + private Map> allResultantMutations = new HashMap(); + private Map> allFurtherMutations = new HashMap(); + public float discoveredSpeciesPercentage; + public int totalSpeciesCount; + public int discoveredSpeciesCount; + public int totalSecretCount; + public int discoveredSecretCount; + public float discoveredBranchPercentage; + public int totalBranchCount; + public int discoveredBranchCount; + private int totalSecretBranchCount; + private int discoveredSecretBranchCount; + String currentEpithet; + + public abstract ISpeciesRoot getSpeciesRoot(); + + public final List getAllBranches() + { + return this.allBranches; + } + + public final Collection getAllSpecies() + { + return this.allActiveSpecies; + } + + public final Collection getAllMutations() + { + return this.allMutations; + } + + public void calculateArrays() + { + Collection allAlleles = AlleleManager.alleleRegistry.getRegisteredAlleles().values(); + + + this.resultantMutations = new HashMap(); + this.furtherMutations = new HashMap(); + this.allResultantMutations = new HashMap(); + this.allFurtherMutations = new HashMap(); + + this.allActiveSpecies = new ArrayList(); + this.allSpecies = new ArrayList(); + for (IAllele species : allAlleles) { + if (getSpeciesRoot().getTemplate(species.getUID()) != null) + { + this.resultantMutations.put((IAlleleSpecies)species, new ArrayList()); + + this.furtherMutations.put((IAlleleSpecies)species, new ArrayList()); + + this.allResultantMutations.put((IAlleleSpecies)species, new ArrayList()); + + this.allFurtherMutations.put((IAlleleSpecies)species, new ArrayList()); + + this.allSpecies.add((IAlleleSpecies)species); + if ((!isBlacklisted(species)) && (!species.getUID().contains("speciesBotAlfheim"))) { + this.allActiveSpecies.add((IAlleleSpecies)species); + } + } + } + this.allMutations = new ArrayList(); + + Collection allRegBranches = AlleleManager.alleleRegistry.getRegisteredClassifications().values(); + + + this.allBranches = new ArrayList(); + for (IClassification branch : allRegBranches) { + if ((branch.getMemberSpecies().length > 0) && + (getSpeciesRoot().getTemplate(branch.getMemberSpecies()[0].getUID()) != null)) + { + boolean possible = false; + for (IAlleleSpecies species : branch.getMemberSpecies()) { + if (this.allActiveSpecies.contains(species)) { + possible = true; + } + } + if (possible) { + this.allBranches.add(branch); + } + } + } + if (getSpeciesRoot().getMutations(false) != null) + { + Set mutations = new LinkedHashSet(); + mutations.addAll(getSpeciesRoot().getMutations(false)); + if (this == Binnie.Genetics.beeBreedingSystem) { + mutations.addAll(ExtraBeeMutation.mutations); + } + for (IMutation mutation : mutations) + { + this.allMutations.add(mutation); + + Set participatingSpecies = new LinkedHashSet(); + if ((mutation.getAllele0() instanceof IAlleleSpecies)) { + participatingSpecies.add((IAlleleSpecies)mutation.getAllele0()); + } + if ((mutation.getAllele1() instanceof IAlleleSpecies)) { + participatingSpecies.add((IAlleleSpecies)mutation.getAllele1()); + } + for (IAlleleSpecies species : participatingSpecies) + { + ((List)this.allFurtherMutations.get(species)).add(mutation); + if (this.allActiveSpecies.contains(species)) { + ((List)this.furtherMutations.get(species)).add(mutation); + } + } + if (this.resultantMutations.containsKey(mutation.getTemplate()[0])) + { + ((List)this.allResultantMutations.get(mutation.getTemplate()[0])).add(mutation); + ((List)this.resultantMutations.get(mutation.getTemplate()[0])).add(mutation); + } + } + } + } + + public final boolean isBlacklisted(IAllele allele) + { + return AlleleManager.alleleRegistry.isBlacklisted(allele.getUID()); + } + + public final List getResultantMutations(IAlleleSpecies species, boolean includeInactive) + { + if (this.resultantMutations.isEmpty()) { + calculateArrays(); + } + return includeInactive ? (List)this.allResultantMutations.get(species) : (List)this.resultantMutations.get(species); + } + + public final List getResultantMutations(IAlleleSpecies species) + { + if (this.resultantMutations.isEmpty()) { + calculateArrays(); + } + return (List)this.resultantMutations.get(species); + } + + public final List getFurtherMutations(IAlleleSpecies species, boolean includeInactive) + { + if (this.furtherMutations.isEmpty()) { + calculateArrays(); + } + return includeInactive ? (List)this.allFurtherMutations.get(species) : (List)this.furtherMutations.get(species); + } + + public final List getFurtherMutations(IAlleleSpecies species) + { + if (this.furtherMutations.isEmpty()) { + calculateArrays(); + } + return (List)this.furtherMutations.get(species); + } + + public final boolean isMutationDiscovered(IMutation mutation, World world, GameProfile name) + { + return isMutationDiscovered(mutation, getSpeciesRoot().getBreedingTracker(world, name)); + } + + public final boolean isMutationDiscovered(IMutation mutation, IBreedingTracker tracker) + { + if (tracker == null) { + return true; + } + return tracker.isDiscovered(mutation); + } + + public final boolean isSpeciesDiscovered(IAlleleSpecies species, World world, GameProfile name) + { + return isSpeciesDiscovered(species, getSpeciesRoot().getBreedingTracker(world, name)); + } + + public final boolean isSpeciesDiscovered(IAlleleSpecies species, IBreedingTracker tracker) + { + if (tracker == null) { + return true; + } + return tracker.isDiscovered(species); + } + + public final boolean isSecret(IAlleleSpecies species) + { + return !species.isCounted(); + } + + public final boolean isSecret(IClassification branch) + { + for (IAlleleSpecies species : branch.getMemberSpecies()) { + if (!isSecret(species)) { + return false; + } + } + return true; + } + + public final Collection getDiscoveredBranches(World world, GameProfile player) + { + List branches = new ArrayList(); + for (IClassification branch : getAllBranches()) + { + boolean discovered = false; + for (IAlleleSpecies species : branch.getMemberSpecies()) { + if (isSpeciesDiscovered(species, world, player)) { + discovered = true; + } + } + if (discovered) { + branches.add(branch); + } + } + return branches; + } + + public final Collection getDiscoveredBranches(IBreedingTracker tracker) + { + List branches = new ArrayList(); + for (IClassification branch : getAllBranches()) + { + boolean discovered = false; + for (IAlleleSpecies species : branch.getMemberSpecies()) { + if (isSpeciesDiscovered(species, tracker)) { + discovered = true; + } + } + if (discovered) { + branches.add(branch); + } + } + return branches; + } + + public final Collection getDiscoveredSpecies(World world, GameProfile player) + { + List speciesList = new ArrayList(); + for (IAlleleSpecies species : getAllSpecies()) { + if (isSpeciesDiscovered(species, world, player)) { + speciesList.add(species); + } + } + return speciesList; + } + + public final Collection getDiscoveredSpecies(IBreedingTracker tracker) + { + List speciesList = new ArrayList(); + for (IAlleleSpecies species : getAllSpecies()) { + if (isSpeciesDiscovered(species, tracker)) { + speciesList.add(species); + } + } + return speciesList; + } + + public final List getDiscoveredMutations(World world, GameProfile player) + { + List speciesList = new ArrayList(); + for (IMutation species : getAllMutations()) { + if (isMutationDiscovered(species, world, player)) { + speciesList.add(species); + } + } + return speciesList; + } + + public final List getDiscoveredMutations(IBreedingTracker tracker) + { + List speciesList = new ArrayList(); + for (IMutation species : getAllMutations()) { + if (isMutationDiscovered(species, tracker)) { + speciesList.add(species); + } + } + return speciesList; + } + + public final int getDiscoveredBranchMembers(IClassification branch, IBreedingTracker tracker) + { + int discoveredSpecies = 0; + for (IAlleleSpecies species : branch.getMemberSpecies()) { + if (isSpeciesDiscovered(species, tracker)) { + discoveredSpecies++; + } + } + return discoveredSpecies; + } + + public IIcon getUndiscoveredIcon() + { + return this.iconUndiscovered.getIcon(); + } + + public IIcon getDiscoveredIcon() + { + return this.iconDiscovered.getIcon(); + } + + public abstract float getChance(IMutation paramIMutation, EntityPlayer paramEntityPlayer, IAllele paramIAllele1, IAllele paramIAllele2); + + public abstract Class getTrackerClass(); + + @SubscribeEvent + public final void onSyncBreedingTracker(ForestryEvent.SyncedBreedingTracker event) + { + IBreedingTracker tracker = event.tracker; + if (!getTrackerClass().isInstance(tracker)) { + return; + } + syncTracker(tracker); + } + + public final void syncTracker(IBreedingTracker tracker) + { + this.discoveredSpeciesPercentage = 0.0F; + + this.totalSpeciesCount = 0; + this.discoveredSpeciesCount = 0; + + this.totalSecretCount = 0; + this.discoveredSecretCount = 0; + + Collection discoveredSpecies = getDiscoveredSpecies(tracker); + Collection allSpecies = getAllSpecies(); + for (IAlleleSpecies species : allSpecies) { + if (!isSecret(species)) + { + this.totalSpeciesCount += 1; + if (isSpeciesDiscovered(species, tracker)) { + this.discoveredSpeciesCount += 1; + } + } + else + { + this.totalSecretCount += 1; + if (isSpeciesDiscovered(species, tracker)) { + this.discoveredSecretCount += 1; + } + } + } + this.discoveredBranchPercentage = 0.0F; + + this.totalBranchCount = 0; + this.discoveredBranchCount = 0; + + Collection discoveredBranches = getDiscoveredBranches(tracker); + Collection allBranches = getAllBranches(); + for (IClassification branch : allBranches) { + if (!isSecret(branch)) + { + this.totalBranchCount += 1; + if (discoveredBranches.contains(branch)) { + this.discoveredBranchCount += 1; + } + } + else + { + this.totalSecretBranchCount += 1; + if (discoveredBranches.contains(branch)) { + this.discoveredSecretBranchCount += 1; + } + } + } + this.discoveredSpeciesPercentage = (this.discoveredSpeciesCount / this.totalSpeciesCount); + + this.discoveredBranchPercentage = (this.discoveredBranchCount / this.totalBranchCount); + + + String epithet = getEpitome(); + + onSyncBreedingTracker(tracker); + } + + public void onSyncBreedingTracker(IBreedingTracker tracker) {} + + public String getEpitome() + { + return getEpitome(this.discoveredSpeciesPercentage); + } + + public final String getDescriptor() + { + return BinnieCore.proxy.localise(getSpeciesRoot().getUID() + ".descriptor"); + } + + public final String getIdent() + { + return getSpeciesRoot().getUID(); + } + + public final IChromosomeType getChromosome(int i) + { + for (IChromosomeType chromosome : getSpeciesRoot().getKaryotype()) { + if (i == chromosome.ordinal()) { + return chromosome; + } + } + return null; + } + + public abstract int getColour(); + + public String getAlleleName(IChromosomeType chromosome, IAllele allele) + { + if ((allele instanceof IAlleleBoolean)) { + return ((IAlleleBoolean)allele).getValue() ? Binnie.Language.localise(BinnieCore.instance, "allele.true") : Binnie.Language.localise(BinnieCore.instance, "allele.false"); + } + if (allele.getName() == "for.gui.maximum") { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.maximum"); + } + return allele.getName(); + } + + public String getName() + { + return BinnieCore.proxy.localise(getSpeciesRoot().getUID() + ".shortName"); + } + + public ItemStack getItemStackRepresentitive() + { + IIndividual first = (IIndividual)getSpeciesRoot().getIndividualTemplates().get(0); + return getSpeciesRoot().getMemberStack(first, getDefaultType()); + } + + public String toString() + { + return getName(); + } + + public abstract boolean isDNAManipulable(ItemStack paramItemStack); + + public IIndividual getConversion(ItemStack stack) + { + return null; + } + + public final IIndividual getDefaultIndividual() + { + return getSpeciesRoot().templateAsIndividual(getSpeciesRoot().getDefaultTemplate()); + } + + public final int getDefaultType() + { + return getActiveTypes()[0]; + } + + public abstract int[] getActiveTypes(); + + public abstract void addExtraAlleles(IChromosomeType paramIChromosomeType, TreeSet paramTreeSet); + + public ItemStack getConversionStack(ItemStack stack) + { + return getSpeciesRoot().getMemberStack(getConversion(stack), getDefaultType()); + } + + public final Collection getActiveKaryotype() + { + return Binnie.Genetics.getActiveChromosomes(getSpeciesRoot()); + } + + public ItemStack getDefaultMember(String uid) + { + return getSpeciesRoot().getMemberStack(getIndividual(uid), getDefaultType()); + } + + public IIndividual getIndividual(String uid) + { + return getSpeciesRoot().templateAsIndividual(getSpeciesRoot().getTemplate(uid)); + } + + public IGenome getGenome(String uid) + { + return getSpeciesRoot().templateAsGenome(getSpeciesRoot().getTemplate(uid)); + } +} diff --git a/src/Java/binnie/core/genetics/EnumBeeBooleanModifier.java b/src/Java/binnie/core/genetics/EnumBeeBooleanModifier.java new file mode 100644 index 0000000000..58eae12e79 --- /dev/null +++ b/src/Java/binnie/core/genetics/EnumBeeBooleanModifier.java @@ -0,0 +1,8 @@ +package binnie.core.genetics; + +public enum EnumBeeBooleanModifier +{ + Sealed, SelfLighted, SunlightStimulated, Hellish; + + private EnumBeeBooleanModifier() {} +} diff --git a/src/Java/binnie/core/genetics/EnumBeeModifier.java b/src/Java/binnie/core/genetics/EnumBeeModifier.java new file mode 100644 index 0000000000..92fc30bda0 --- /dev/null +++ b/src/Java/binnie/core/genetics/EnumBeeModifier.java @@ -0,0 +1,17 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; + +public enum EnumBeeModifier +{ + Territory, Mutation, Lifespan, Production, Flowering, GeneticDecay; + + private EnumBeeModifier() {} + + public String getName() + { + return Binnie.Language.localise(BinnieCore.instance, "beemodifier." + name().toLowerCase()); + } +} diff --git a/src/Java/binnie/core/genetics/FlowerBreedingSystem.java b/src/Java/binnie/core/genetics/FlowerBreedingSystem.java new file mode 100644 index 0000000000..bc706976c8 --- /dev/null +++ b/src/Java/binnie/core/genetics/FlowerBreedingSystem.java @@ -0,0 +1,129 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.botany.api.EnumFlowerChromosome; +import binnie.botany.api.EnumFlowerStage; +import binnie.botany.api.IBotanistTracker; +import binnie.botany.api.IFlowerMutation; +import binnie.botany.api.IFlowerRoot; +import binnie.botany.core.BotanyCore; +import binnie.botany.genetics.EnumFlowerColor; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; +import binnie.core.resource.ManagerResource; +import binnie.extrabees.ExtraBees; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.IMutation; +import forestry.api.genetics.ISpeciesRoot; +import java.util.TreeSet; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +class FlowerBreedingSystem + extends BreedingSystem +{ + public FlowerBreedingSystem() + { + this.iconUndiscovered = Binnie.Resource.getItemIcon(ExtraBees.instance, "icon/undiscoveredBee"); + this.iconDiscovered = Binnie.Resource.getItemIcon(ExtraBees.instance, "icon/discoveredBee"); + } + + public float getChance(IMutation mutation, EntityPlayer player, IAllele species1, IAllele species2) + { + return ((IFlowerMutation)mutation).getBaseChance(); + } + + public ISpeciesRoot getSpeciesRoot() + { + return Binnie.Genetics.getFlowerRoot(); + } + + public int getColour() + { + return 14563127; + } + + public Class getTrackerClass() + { + return IBotanistTracker.class; + } + + public String getAlleleName(IChromosomeType chromosome, IAllele allele) + { + if (chromosome == EnumFlowerChromosome.FERTILITY) + { + if (allele.getUID().contains("Low")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.low"); + } + if (allele.getUID().contains("Normal")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.normal"); + } + if (allele.getUID().contains("High")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.high"); + } + if (allele.getUID().contains("Maximum")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.fertility.maximum"); + } + } + return super.getAlleleName(chromosome, allele); + } + + public boolean isDNAManipulable(ItemStack member) + { + return ((IFlowerRoot)getSpeciesRoot()).getType(member) == EnumFlowerStage.POLLEN; + } + + public IIndividual getConversion(ItemStack stack) + { + return BotanyCore.getFlowerRoot().getConversion(stack); + } + + public int[] getActiveTypes() + { + return new int[] { EnumFlowerStage.FLOWER.ordinal(), EnumFlowerStage.POLLEN.ordinal(), EnumFlowerStage.SEED.ordinal() }; + } + + public void addExtraAlleles(IChromosomeType chromosome, TreeSet alleles) + { + switch (1.$SwitchMap$binnie$botany$api$EnumFlowerChromosome[((EnumFlowerChromosome)chromosome).ordinal()]) + { + case 1: + for (ForestryAllele.Fertility a : ForestryAllele.Fertility.values()) { + alleles.add(a.getAllele()); + } + break; + case 2: + for (ForestryAllele.Lifespan a : ForestryAllele.Lifespan.values()) { + alleles.add(a.getAllele()); + } + break; + case 3: + case 4: + case 5: + for (Tolerance a : Tolerance.values()) { + alleles.add(a.getAllele()); + } + break; + case 6: + case 7: + case 8: + for (EnumFlowerColor a : EnumFlowerColor.values()) { + alleles.add(a.getAllele()); + } + break; + case 9: + for (ForestryAllele.Sappiness a : ForestryAllele.Sappiness.values()) { + alleles.add(a.getAllele()); + } + break; + case 10: + for (ForestryAllele.Territory a : ForestryAllele.Territory.values()) { + alleles.add(a.getAllele()); + } + break; + } + } +} diff --git a/src/Java/binnie/core/genetics/ForestryAllele.java b/src/Java/binnie/core/genetics/ForestryAllele.java new file mode 100644 index 0000000000..19a3ad8b6f --- /dev/null +++ b/src/Java/binnie/core/genetics/ForestryAllele.java @@ -0,0 +1,211 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import forestry.api.apiculture.IAlleleBeeSpecies; +import forestry.api.apiculture.IBeeRoot; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleRegistry; + +public class ForestryAllele +{ + public static enum Lifespan + { + Shortest, Shorter, Short, Shortened, Normal, Elongated, Long, Longer, Longest; + + private Lifespan() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.lifespan" + toString()); + } + } + + public static enum Speed + { + Slowest, Slower, Slow, Norm, Fast, Faster, Fastest; + + private Speed() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.speed" + toString()); + } + } + + public static enum Fertility + { + Low, Normal, High, Maximum; + + private Fertility() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.fertility" + toString()); + } + } + + public static enum Flowering + { + Slowest, Slower, Slow, Average, Fast, Faster, Fastest, Maximum; + + private Flowering() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.flowering" + toString()); + } + } + + public static enum Territory + { + Default, Large, Larger, Largest; + + private Territory() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.territory" + toString()); + } + } + + public static enum Sappiness + { + Lowest, Lower, Low, Average, High, Higher, Highest; + + private Sappiness() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.sappiness" + toString()); + } + } + + public static enum TreeHeight + { + Smallest, Smaller, Small, Average, Large, Larger, Largest, Gigantic; + + private TreeHeight() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.height" + (this == Average ? "Max10" : toString())); + } + } + + public static enum Size + { + Smallest, Smaller, Small, Average, Large, Larger, Largest; + + private Size() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.size" + toString()); + } + } + + public static enum Saplings + { + Lowest, Lower, Low, Average, High, Higher, Highest; + + private Saplings() {} + + public IAllele getAllele() + { + String s = toString(); + if (this == Average) { + s = "Default"; + } + if (this == High) { + s = "Double"; + } + if (this == Higher) { + s = "Triple"; + } + return AlleleManager.alleleRegistry.getAllele("forestry.saplings" + s); + } + } + + public static enum Yield + { + Lowest, Lower, Low, Average, High, Higher, Highest; + + private Yield() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.yield" + (this == Average ? "Default" : toString())); + } + } + + public static enum Maturation + { + Slowest, Slower, Slow, Average, Fast, Faster, Fastest; + + private Maturation() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.maturation" + toString()); + } + } + + public static enum Bool + { + True, False; + + private Bool() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.bool" + toString()); + } + + public static IAllele get(boolean bool) + { + return (bool ? True : False).getAllele(); + } + } + + public static enum Growth + { + Tropical; + + private Growth() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.growth" + toString()); + } + } + + public static enum Int + { + Int1, Int2, Int3, Int4, Int5, Int6, Int7, Int8, Int9, Int10; + + private Int() {} + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele("forestry.i" + (ordinal() + 1) + "d"); + } + } + + public static enum BeeSpecies + { + Modest, Noble, Forest, Rural, Marshy, Sinister, Tropical, Wintry, Merry, Austere, Imperial, Ended, Meadows, Common, Frugal, Unweary, Diligent, Majestic, Cultivated, Industrious, Valiant, Secluded, Hermitic, Spectral, Exotic, Fiendish, Monastic, Steadfast, Miry, Farmerly, Boggy, Demonic; + + private BeeSpecies() {} + + public IAlleleBeeSpecies getAllele() + { + return (IAlleleBeeSpecies)AlleleManager.alleleRegistry.getAllele("forestry.species" + toString()); + } + + public IAllele[] getTemplate() + { + return Binnie.Genetics.getBeeRoot().getTemplate(getAllele().getUID()); + } + } +} diff --git a/src/Java/binnie/core/genetics/Gene.java b/src/Java/binnie/core/genetics/Gene.java new file mode 100644 index 0000000000..3d071cc1ab --- /dev/null +++ b/src/Java/binnie/core/genetics/Gene.java @@ -0,0 +1,128 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.genetics.api.IGene; +import forestry.api.core.INBTTagable; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleRegistry; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.ISpeciesRoot; +import net.minecraft.nbt.NBTTagCompound; + +public class Gene + implements INBTTagable, IGene +{ + private IAllele allele; + private IChromosomeType chromosome; + private ISpeciesRoot root; + + public ISpeciesRoot getSpeciesRoot() + { + return this.root; + } + + public String toString() + { + return getAlleleName(); + } + + public Gene(IAllele allele, IChromosomeType chromosome, ISpeciesRoot root) + { + this.allele = allele; + this.chromosome = chromosome; + this.root = root; + } + + public Gene(NBTTagCompound nbt) + { + readFromNBT(nbt); + } + + public void readFromNBT(NBTTagCompound nbt) + { + this.allele = AlleleManager.alleleRegistry.getAllele(nbt.getString("allele")); + + this.root = AlleleManager.alleleRegistry.getSpeciesRoot(nbt.getString("root")); + + int chromoID = nbt.getByte("chromo"); + if ((this.root != null) && (chromoID >= 0) && (chromoID < this.root.getKaryotype().length)) { + this.chromosome = this.root.getKaryotype()[chromoID]; + } + } + + public void writeToNBT(NBTTagCompound nbt) + { + nbt.setString("allele", this.allele.getUID()); + nbt.setString("root", this.root.getUID()); + nbt.setByte("chromo", (byte)this.chromosome.ordinal()); + } + + public boolean isCorrupted() + { + return (this.allele == null) || (this.chromosome == null) || (this.root == null); + } + + public static Gene create(NBTTagCompound nbt) + { + Gene gene = new Gene(nbt); + return gene.isCorrupted() ? null : gene; + } + + public static Gene create(IAllele allele, IChromosomeType chromosome, ISpeciesRoot root) + { + Gene gene = new Gene(allele, chromosome, root); + return gene.isCorrupted() ? null : gene; + } + + public NBTTagCompound getNBTTagCompound() + { + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + return nbt; + } + + public String getName() + { + return Binnie.Genetics.getSystem(this.root).getAlleleName(this.chromosome, this.allele); + } + + public BreedingSystem getSystem() + { + return Binnie.Genetics.getSystem(this.root); + } + + public IChromosomeType getChromosome() + { + return this.chromosome; + } + + public IAllele getAllele() + { + return this.allele; + } + + public boolean equals(Object obj) + { + if (!(obj instanceof Gene)) { + return false; + } + Gene g = (Gene)obj; + return (this.allele == g.allele) && (this.chromosome.ordinal() == g.chromosome.ordinal()) && (this.root == g.root); + } + + public String getAlleleName() + { + return getSystem().getAlleleName(this.chromosome, this.allele); + } + + public String getChromosomeName() + { + return getSystem().getChromosomeName(this.chromosome); + } + + public String getShortChromosomeName() + { + return getSystem().getChromosomeShortName(this.chromosome); + } +} diff --git a/src/Java/binnie/core/genetics/IAlleleProvider.java b/src/Java/binnie/core/genetics/IAlleleProvider.java new file mode 100644 index 0000000000..30dc8992e4 --- /dev/null +++ b/src/Java/binnie/core/genetics/IAlleleProvider.java @@ -0,0 +1,8 @@ +package binnie.core.genetics; + +import forestry.api.genetics.IAllele; + +public abstract interface IAlleleProvider +{ + public abstract IAllele getAllele(); +} diff --git a/src/Java/binnie/core/genetics/IBreedingMessage.java b/src/Java/binnie/core/genetics/IBreedingMessage.java new file mode 100644 index 0000000000..fdd815c122 --- /dev/null +++ b/src/Java/binnie/core/genetics/IBreedingMessage.java @@ -0,0 +1,124 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAlleleRegistry; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IClassification; +import forestry.api.genetics.ISpeciesRoot; +import java.util.Map; +import net.minecraft.item.ItemStack; + +abstract interface IBreedingMessage +{ + public abstract String getTitle(); + + public abstract String getBody(); + + public abstract ItemStack getIcon(); + + public static class MessageSpeciesDiscovered + implements IBreedingMessage + { + IAlleleSpecies species; + ItemStack stack; + + public MessageSpeciesDiscovered(IAlleleSpecies species) + { + this.species = species; + ISpeciesRoot root = null; + for (ISpeciesRoot sRoot : AlleleManager.alleleRegistry.getSpeciesRoot().values()) { + if (sRoot.getKaryotype()[0].getAlleleClass().isInstance(species)) { + root = sRoot; + } + } + if (root != null) { + this.stack = root.getMemberStack(root.templateAsIndividual(root.getTemplate(species.getUID())), 0); + } + } + + public String getTitle() + { + return Binnie.Language.localise(BinnieCore.instance, "gui.breedingmessage.species"); + } + + public String getBody() + { + return this.species.getName(); + } + + public ItemStack getIcon() + { + return this.stack; + } + } + + public static class BranchDiscovered + implements IBreedingMessage + { + IAlleleSpecies species; + IClassification classification; + ItemStack stack; + + public BranchDiscovered(IAlleleSpecies species, IClassification classification) + { + this.species = species; + this.classification = classification; + ISpeciesRoot root = null; + for (ISpeciesRoot sRoot : AlleleManager.alleleRegistry.getSpeciesRoot().values()) { + if (sRoot.getKaryotype()[0].getAlleleClass().isInstance(species)) { + root = sRoot; + } + } + if (root != null) { + this.stack = root.getMemberStack(root.templateAsIndividual(root.getTemplate(species.getUID())), 0); + } + } + + public String getTitle() + { + return Binnie.Language.localise(BinnieCore.instance, "gui.breedingmessage.branch"); + } + + public String getBody() + { + return this.classification.getScientific(); + } + + public ItemStack getIcon() + { + return this.stack; + } + } + + public static class EpithetGained + implements IBreedingMessage + { + String epithet; + ItemStack stack; + + public EpithetGained(String epithet, ISpeciesRoot root) + { + this.epithet = epithet; + this.stack = root.getMemberStack(root.templateAsIndividual(root.getDefaultTemplate()), 0); + } + + public String getTitle() + { + return Binnie.Language.localise(BinnieCore.instance, "gui.breedingmessage.epithet"); + } + + public String getBody() + { + return this.epithet; + } + + public ItemStack getIcon() + { + return this.stack; + } + } +} diff --git a/src/Java/binnie/core/genetics/IItemStackRepresentitive.java b/src/Java/binnie/core/genetics/IItemStackRepresentitive.java new file mode 100644 index 0000000000..ccaf2d4ec4 --- /dev/null +++ b/src/Java/binnie/core/genetics/IItemStackRepresentitive.java @@ -0,0 +1,8 @@ +package binnie.core.genetics; + +import net.minecraft.item.ItemStack; + +public abstract interface IItemStackRepresentitive +{ + public abstract ItemStack getItemStackRepresentitive(); +} diff --git a/src/Java/binnie/core/genetics/ManagerGenetics.java b/src/Java/binnie/core/genetics/ManagerGenetics.java new file mode 100644 index 0000000000..4ea18ca7a4 --- /dev/null +++ b/src/Java/binnie/core/genetics/ManagerGenetics.java @@ -0,0 +1,298 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.botany.api.IFlowerRoot; +import binnie.botany.genetics.AlleleColor; +import binnie.core.BinnieCore; +import binnie.core.ManagerBase; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import forestry.api.apiculture.IBeeRoot; +import forestry.api.arboriculture.ITreeRoot; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.EnumTolerance; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleFloat; +import forestry.api.genetics.IAlleleInteger; +import forestry.api.genetics.IAlleleRegistry; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IGenome; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.ISpeciesRoot; +import forestry.api.lepidopterology.IButterflyRoot; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.event.world.WorldEvent.Load; + +public class ManagerGenetics + extends ManagerBase +{ + public BreedingSystem beeBreedingSystem; + public BreedingSystem treeBreedingSystem; + public BreedingSystem mothBreedingSystem; + public BreedingSystem flowerBreedingSystem; + private final Map BREEDING_SYSTEMS; + private List invalidChromosomeTypes; + private Map>> chromosomeArray; + + public void init() + { + if (BinnieCore.isApicultureActive()) { + this.beeBreedingSystem = new BeeBreedingSystem(); + } + if (BinnieCore.isArboricultureActive()) { + this.treeBreedingSystem = new TreeBreedingSystem(); + } + if (BinnieCore.isLepidopteryActive()) { + this.mothBreedingSystem = new MothBreedingSystem(); + } + if (BinnieCore.isBotanyActive()) { + this.flowerBreedingSystem = new FlowerBreedingSystem(); + } + } + + public void postInit() + { + refreshData(); + } + + public boolean isSpeciesDiscovered(IAlleleSpecies species, World world, boolean nei) + { + return true; + } + + public ITreeRoot getTreeRoot() + { + return (ITreeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees"); + } + + public IBeeRoot getBeeRoot() + { + return (IBeeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"); + } + + public IButterflyRoot getButterflyRoot() + { + return (IButterflyRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies"); + } + + public IFlowerRoot getFlowerRoot() + { + return (IFlowerRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootFlowers"); + } + + public BreedingSystem getSystem(String string) + { + for (BreedingSystem system : this.BREEDING_SYSTEMS.values()) { + if (system.getIdent().equals(string)) { + return system; + } + } + return null; + } + + public BreedingSystem getSystem(ISpeciesRoot root) + { + return getSystem(root.getUID()); + } + + public ISpeciesRoot getSpeciesRoot(IAlleleSpecies species) + { + for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) { + if (root.getKaryotype()[0].getAlleleClass().isInstance(species)) { + return root; + } + } + return null; + } + + public IAllele getToleranceAllele(EnumTolerance tol) + { + return AlleleManager.alleleRegistry.getAllele(Tolerance.values()[tol.ordinal()].getUID()); + } + + public int[] getTolerance(EnumTolerance tol) + { + return Tolerance.values()[tol.ordinal()].getBounds(); + } + + public Collection getActiveSystems() + { + return this.BREEDING_SYSTEMS.values(); + } + + public void registerBreedingSystem(BreedingSystem system) + { + this.BREEDING_SYSTEMS.put(system.getSpeciesRoot(), system); + } + + public BreedingSystem getConversionSystem(ItemStack stack) + { + for (BreedingSystem system : getActiveSystems()) { + if (system.getConversion(stack) != null) { + return system; + } + } + return null; + } + + public ItemStack getConversionStack(ItemStack stack) + { + BreedingSystem system = getConversionSystem(stack); + return system == null ? null : system.getConversionStack(stack); + } + + public IIndividual getConversion(ItemStack stack) + { + BreedingSystem system = getConversionSystem(stack); + return system == null ? null : system.getConversion(stack); + } + + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) + { + refreshData(); + } + + private void refreshData() + { + loadAlleles(); + for (BreedingSystem system : Binnie.Genetics.getActiveSystems()) { + system.calculateArrays(); + } + } + + public ManagerGenetics() + { + this.BREEDING_SYSTEMS = new LinkedHashMap(); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + this.invalidChromosomeTypes = new ArrayList(); + + this.chromosomeArray = new LinkedHashMap(); + } + + private void loadAlleles() + { + this.invalidChromosomeTypes.clear(); + for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) + { + BreedingSystem system = getSystem(root); + Map> chromosomeMap = new LinkedHashMap(); + for (IChromosomeType chromosome : root.getKaryotype()) + { + TreeSet alleles = new TreeSet(new ComparatorAllele()); + for (IIndividual individual : root.getIndividualTemplates()) + { + IGenome genome = individual.getGenome(); + try + { + IAllele a1 = genome.getActiveAllele(chromosome); + IAllele a2 = genome.getInactiveAllele(chromosome); + if (chromosome.getAlleleClass().isInstance(a1)) { + alleles.add(a1); + } + if (chromosome.getAlleleClass().isInstance(a2)) { + alleles.add(a2); + } + } + catch (Exception e) {} + } + system.addExtraAlleles(chromosome, alleles); + if (alleles.size() == 0) + { + this.invalidChromosomeTypes.add(chromosome); + } + else + { + List alleleList = new ArrayList(); + alleleList.addAll(alleles); + chromosomeMap.put(chromosome, alleleList); + } + } + this.chromosomeArray.put(root, chromosomeMap); + } + } + + static class ComparatorAllele + implements Comparator + { + public int compare(IAllele o1, IAllele o2) + { + if ((o1 == null) || (o2 == null)) { + throw new NullPointerException("Allele is null!"); + } + if (((o1 instanceof IAlleleFloat)) && ((o2 instanceof IAlleleFloat))) { + return Float.valueOf(((IAlleleFloat)o1).getValue()).compareTo(Float.valueOf(((IAlleleFloat)o2).getValue())); + } + if (((o1 instanceof IAlleleInteger)) && ((o2 instanceof IAlleleInteger)) && (!(o1 instanceof AlleleColor))) { + return Integer.valueOf(((IAlleleInteger)o1).getValue()).compareTo(Integer.valueOf(((IAlleleInteger)o2).getValue())); + } + if ((o1.getName() != null) && (o2.getName() != null)) { + return o1.getName().compareTo(o2.getName()); + } + return o1.getUID().compareTo(o2.getUID()); + } + } + + public Map> getChromosomeMap(ISpeciesRoot root) + { + return (Map)this.chromosomeArray.get(root); + } + + public Collection getActiveChromosomes(ISpeciesRoot root) + { + return getChromosomeMap(root).keySet(); + } + + public boolean isInvalidChromosome(IChromosomeType type) + { + return this.invalidChromosomeTypes.contains(type); + } +} diff --git a/src/Java/binnie/core/genetics/MothBreedingSystem.java b/src/Java/binnie/core/genetics/MothBreedingSystem.java new file mode 100644 index 0000000000..e1a45c9a9c --- /dev/null +++ b/src/Java/binnie/core/genetics/MothBreedingSystem.java @@ -0,0 +1,138 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; +import binnie.core.resource.ManagerResource; +import binnie.extratrees.ExtraTrees; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleInteger; +import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IMutation; +import forestry.api.genetics.ISpeciesRoot; +import forestry.api.lepidopterology.EnumButterflyChromosome; +import forestry.api.lepidopterology.EnumFlutterType; +import forestry.api.lepidopterology.IButterflyRoot; +import forestry.api.lepidopterology.ILepidopteristTracker; +import java.util.TreeSet; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +class MothBreedingSystem + extends BreedingSystem +{ + public MothBreedingSystem() + { + this.iconUndiscovered = Binnie.Resource.getItemIcon(ExtraTrees.instance, "icon/undiscoveredMoth"); + this.iconDiscovered = Binnie.Resource.getItemIcon(ExtraTrees.instance, "icon/discoveredMoth"); + } + + public float getChance(IMutation mutation, EntityPlayer player, IAllele species1, IAllele species2) + { + return 0.0F; + } + + public ISpeciesRoot getSpeciesRoot() + { + return Binnie.Genetics.getButterflyRoot(); + } + + public int getColour() + { + return 62194; + } + + public Class getTrackerClass() + { + return ILepidopteristTracker.class; + } + + public String getAlleleName(IChromosomeType chromosome, IAllele allele) + { + if (chromosome == EnumButterflyChromosome.METABOLISM) + { + int metabolism = ((IAlleleInteger)allele).getValue(); + if (metabolism >= 19) { + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.highest"); + } + if (metabolism >= 16) { + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.higher"); + } + if (metabolism >= 13) { + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.high"); + } + if (metabolism >= 10) { + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.normal"); + } + if (metabolism >= 7) { + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.slow"); + } + if (metabolism >= 4) { + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.slower"); + } + return Binnie.Language.localise(BinnieCore.instance, "allele.metabolism.slowest"); + } + if (chromosome == EnumButterflyChromosome.FERTILITY) + { + int metabolism = ((IAlleleInteger)allele).getValue(); + return metabolism + "x"; + } + return super.getAlleleName(chromosome, allele); + } + + public boolean isDNAManipulable(ItemStack member) + { + return ((IButterflyRoot)getSpeciesRoot()).getType(member) == EnumFlutterType.SERUM; + } + + public int[] getActiveTypes() + { + return new int[] { EnumFlutterType.BUTTERFLY.ordinal(), EnumFlutterType.CATERPILLAR.ordinal(), EnumFlutterType.SERUM.ordinal() }; + } + + public void addExtraAlleles(IChromosomeType chromosome, TreeSet alleles) + { + switch (1.$SwitchMap$forestry$api$lepidopterology$EnumButterflyChromosome[((EnumButterflyChromosome)chromosome).ordinal()]) + { + case 1: + for (ForestryAllele.Int a : ForestryAllele.Int.values()) { + alleles.add(a.getAllele()); + } + break; + case 2: + for (ForestryAllele.Lifespan a : ForestryAllele.Lifespan.values()) { + alleles.add(a.getAllele()); + } + break; + case 3: + for (ForestryAllele.Int a : ForestryAllele.Int.values()) { + alleles.add(a.getAllele()); + } + break; + case 4: + case 5: + case 6: + for (ForestryAllele.Bool a : ForestryAllele.Bool.values()) { + alleles.add(a.getAllele()); + } + break; + case 7: + for (ForestryAllele.Size a : ForestryAllele.Size.values()) { + alleles.add(a.getAllele()); + } + break; + case 8: + for (ForestryAllele.Speed a : ForestryAllele.Speed.values()) { + alleles.add(a.getAllele()); + } + break; + case 9: + case 10: + for (Tolerance a : Tolerance.values()) { + alleles.add(a.getAllele()); + } + break; + } + } +} diff --git a/src/Java/binnie/core/genetics/Tolerance.java b/src/Java/binnie/core/genetics/Tolerance.java new file mode 100644 index 0000000000..7d9f62dfbf --- /dev/null +++ b/src/Java/binnie/core/genetics/Tolerance.java @@ -0,0 +1,48 @@ +package binnie.core.genetics; + +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.EnumTolerance; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleRegistry; + +public enum Tolerance +{ + None(0, 0), Both1(-1, 1), Both2(-2, 2), Both3(-3, 3), Both4(-4, 4), Both5(-5, 5), Up1(0, 1), Up2(0, 2), Up3(0, 3), Up4(0, 4), Up5(0, 5), Down1(-1, 0), Down2(-2, 0), Down3(-3, 0), Down4(-4, 0), Down5(-5, 0); + + private int[] bounds; + + private Tolerance(int a, int b) + { + this.bounds = new int[] { a, b }; + } + + public String getUID() + { + return "forestry.tolerance" + toString(); + } + + public int[] getBounds() + { + return this.bounds; + } + + public static Tolerance get(EnumTolerance tol) + { + return values()[tol.ordinal()]; + } + + public IAllele getAllele() + { + return AlleleManager.alleleRegistry.getAllele(getUID()); + } + + public > boolean canTolerate(T base, T test) + { + return (test.ordinal() <= base.ordinal() + this.bounds[1]) && (test.ordinal() >= base.ordinal() + this.bounds[0]); + } + + public static > boolean canTolerate(T base, T test, EnumTolerance tol) + { + return get(tol).canTolerate(base, test); + } +} diff --git a/src/Java/binnie/core/genetics/TreeBreedingSystem.java b/src/Java/binnie/core/genetics/TreeBreedingSystem.java new file mode 100644 index 0000000000..9793126cb1 --- /dev/null +++ b/src/Java/binnie/core/genetics/TreeBreedingSystem.java @@ -0,0 +1,303 @@ +package binnie.core.genetics; + +import binnie.Binnie; +import binnie.core.BinnieCore; +import binnie.core.language.ManagerLanguage; +import binnie.core.resource.ManagerResource; +import binnie.core.util.UniqueItemStackSet; +import binnie.extratrees.ExtraTrees; +import binnie.extratrees.machines.Lumbermill; +import com.mojang.authlib.GameProfile; +import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.EnumTreeChromosome; +import forestry.api.arboriculture.IAlleleFruit; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.arboriculture.IArboristTracker; +import forestry.api.arboriculture.IFruitProvider; +import forestry.api.arboriculture.ITreeGenome; +import forestry.api.arboriculture.ITreeMutation; +import forestry.api.arboriculture.ITreeRoot; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.genetics.IAlleleInteger; +import forestry.api.genetics.IAllelePlantType; +import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.IBreedingTracker; +import forestry.api.genetics.IChromosomeType; +import forestry.api.genetics.IFruitFamily; +import forestry.api.genetics.IGenome; +import forestry.api.genetics.IIndividual; +import forestry.api.genetics.IMutation; +import forestry.api.genetics.ISpeciesRoot; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeSet; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; + +public class TreeBreedingSystem + extends BreedingSystem +{ + public UniqueItemStackSet allFruits = new UniqueItemStackSet(); + public UniqueItemStackSet allWoods = new UniqueItemStackSet(); + private UniqueItemStackSet discoveredFruits = new UniqueItemStackSet(); + private UniqueItemStackSet discoveredWoods = new UniqueItemStackSet(); + public UniqueItemStackSet discoveredPlanks = new UniqueItemStackSet(); + + public TreeBreedingSystem() + { + this.iconUndiscovered = Binnie.Resource.getItemIcon(ExtraTrees.instance, "icon/undiscoveredTree"); + this.iconDiscovered = Binnie.Resource.getItemIcon(ExtraTrees.instance, "icon/discoveredTree"); + } + + public float getChance(IMutation mutation, EntityPlayer player, IAllele species1, IAllele species2) + { + IGenome genome0 = getSpeciesRoot().templateAsGenome(getSpeciesRoot().getTemplate(species1.getUID())); + IGenome genome1 = getSpeciesRoot().templateAsGenome(getSpeciesRoot().getTemplate(species2.getUID())); + return ((ITreeMutation)mutation).getChance(player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ, species1, species2, genome0, genome1); + } + + public ISpeciesRoot getSpeciesRoot() + { + return Binnie.Genetics.getTreeRoot(); + } + + public int getColour() + { + return 53006; + } + + public Class getTrackerClass() + { + return IArboristTracker.class; + } + + public String getAlleleName(IChromosomeType chromosome, IAllele allele) + { + if (chromosome == EnumTreeChromosome.GIRTH) { + return ((IAlleleInteger)allele).getValue() + "x" + ((IAlleleInteger)allele).getValue(); + } + if (chromosome == EnumTreeChromosome.PLANT) + { + EnumSet types = ((IAllelePlantType)allele).getPlantTypes(); + return types.isEmpty() ? Binnie.Language.localise(BinnieCore.instance, "allele.none") : ((EnumPlantType)types.iterator().next()).toString(); + } + if ((chromosome == EnumTreeChromosome.FRUITS) && (allele.getUID().contains("."))) + { + IFruitProvider provider = ((IAlleleFruit)allele).getProvider(); + return provider.getProducts().length == 0 ? Binnie.Language.localise(BinnieCore.instance, "allele.none") : provider.getProducts()[0].getDisplayName(); + } + if (chromosome == EnumTreeChromosome.GROWTH) + { + if (allele.getUID().contains("Tropical")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.growth.tropical"); + } + if (allele.getUID().contains("Lightlevel")) { + return Binnie.Language.localise(BinnieCore.instance, "allele.growth.lightlevel"); + } + } + return super.getAlleleName(chromosome, allele); + } + + public void onSyncBreedingTracker(IBreedingTracker tracker) + { + this.discoveredFruits.clear(); + this.discoveredWoods.clear(); + for (IAlleleSpecies species : getDiscoveredSpecies(tracker)) + { + IAlleleTreeSpecies tSpecies = (IAlleleTreeSpecies)species; +