Search in sources :

Example 16 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class IsolatorLogic method onFinishTask.

@Override
protected void onFinishTask() {
    super.onFinishTask();
    final Random rand = this.getMachine().getWorld().rand;
    MachineUtil util = this.getUtil();
    final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(util.getStack(Isolator.SLOT_TARGET));
    if (root == null) {
        return;
    }
    final IIndividual individual = root.getMember(util.getStack(Isolator.SLOT_TARGET));
    if (individual == null) {
        return;
    }
    IChromosomeType[] karyotype = root.getKaryotype();
    IChromosomeType chromosome = karyotype[rand.nextInt(karyotype.length)];
    IGenome genome = individual.getGenome();
    IAllele allele = rand.nextBoolean() ? genome.getActiveAllele(chromosome) : genome.getInactiveAllele(chromosome);
    Gene gene = Gene.create(allele, chromosome, root);
    final ItemStack serum = ItemSequence.create(gene);
    util.setStack(Isolator.SLOT_RESULUT, serum);
    util.decreaseStack(Isolator.SLOT_SEQUENCER_VIAL, 1);
    if (rand.nextFloat() < TARGET_LOSS_CHANCE) {
        util.decreaseStack(Isolator.SLOT_TARGET, 1);
    }
    util.drainTank(Isolator.TANK_ETHANOL, ETHANOL_PER_PROCESS);
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack)

Example 17 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class InoculatorRecipeMaker method create.

public static List<InoculatorRecipeWrapper> create() {
    List<InoculatorRecipeWrapper> recipes = new ArrayList<>();
    for (IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
        ISpeciesRoot root = system.getSpeciesRoot();
        IChromosomeType speciesChromosomeType = root.getSpeciesChromosomeType();
        IAllele[] defaultTemplate = root.getDefaultTemplate();
        IIndividual individual = root.templateAsIndividual(defaultTemplate);
        for (ISpeciesType speciesType : system.getActiveTypes()) {
            if (system.isDNAManipulable(speciesType)) {
                ItemStack memberStack = root.getMemberStack(individual, speciesType);
                memberStack.setItemDamage(OreDictionary.WILDCARD_VALUE);
                IAllele species = defaultTemplate[speciesChromosomeType.ordinal()];
                ItemStack serum = ItemSerum.create(new Gene(species, speciesChromosomeType, root));
                // set fully charged
                serum.setItemDamage(0);
                recipes.add(new InoculatorRecipeWrapper(serum, memberStack));
                recipes.add(new SplicerRecipeWrapper(serum, memberStack));
                ItemStack serumArray = ItemSerumArray.create(new Gene(species, speciesChromosomeType, root));
                // set fully charged
                serumArray.setItemDamage(0);
                for (IChromosomeType chromosomeType : root.getKaryotype()) {
                    if (chromosomeType != speciesChromosomeType) {
                        IAllele allele = defaultTemplate[chromosomeType.ordinal()];
                        Engineering.addGene(serumArray, new Gene(allele, chromosomeType, root));
                    }
                }
                recipes.add(new InoculatorRecipeWrapper(serumArray, memberStack));
                recipes.add(new SplicerRecipeWrapper(serumArray, memberStack));
            }
        }
    }
    return recipes;
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ISpeciesType(forestry.api.genetics.ISpeciesType) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Gene(binnie.core.genetics.Gene) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack)

Example 18 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class IsolatorRecipeMaker method create.

public static List<IsolatorRecipeWrapper> create() {
    List<IsolatorRecipeWrapper> recipes = new ArrayList<>();
    Collection<ISpeciesRoot> roots = AlleleManager.alleleRegistry.getSpeciesRoot().values();
    for (ISpeciesRoot root : roots) {
        ISpeciesType[] speciesTypes = root.getIconType().getClass().getEnumConstants();
        IChromosomeType speciesChromosomeType = root.getSpeciesChromosomeType();
        IAllele[] defaultTemplate = root.getDefaultTemplate();
        IIndividual individual = root.templateAsIndividual(defaultTemplate);
        for (ISpeciesType speciesType : speciesTypes) {
            ItemStack memberStack = root.getMemberStack(individual, speciesType);
            memberStack.setItemDamage(OreDictionary.WILDCARD_VALUE);
            IAllele species = defaultTemplate[speciesChromosomeType.ordinal()];
            ItemStack filledSequence = ItemSequence.create(new Gene(species, speciesChromosomeType, root), false);
            IsolatorRecipeWrapper recipeWrapper = new IsolatorRecipeWrapper(memberStack, filledSequence);
            recipes.add(recipeWrapper);
        }
    }
    return recipes;
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ISpeciesType(forestry.api.genetics.ISpeciesType) ArrayList(java.util.ArrayList) IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Gene(binnie.core.genetics.Gene) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack)

Example 19 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class GeneTracker method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
        NBTTagCompound nbtRoot = new NBTTagCompound();
        for (IChromosomeType chromo : root.getKaryotype()) {
            NBTTagList nbtChromo = new NBTTagList();
            for (IGene gene : discoveredGenes) {
                if (gene.getSpeciesRoot() == root && gene.getChromosome() == chromo) {
                    nbtChromo.appendTag(new NBTTagString(gene.getAllele().getUID()));
                }
            }
            nbtRoot.setTag(String.valueOf(chromo.ordinal()), nbtChromo);
        }
        nbt.setTag(root.getUID(), nbtRoot);
    }
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IGene(binnie.core.api.genetics.IGene) NBTTagString(net.minecraft.nbt.NBTTagString) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 20 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class GeneTracker method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
        if (!nbt.hasKey(root.getUID())) {
            continue;
        }
        NBTTagCompound nbtRoot = nbt.getCompoundTag(root.getUID());
        for (IChromosomeType chromo : root.getKaryotype()) {
            if (!nbtRoot.hasKey(String.valueOf(chromo.ordinal()))) {
                continue;
            }
            NBTTagList nbtChromo = nbtRoot.getTagList(String.valueOf(chromo.ordinal()), 8);
            for (int i = 0; i < nbtChromo.tagCount(); ++i) {
                String uid = nbtChromo.getStringTagAt(i);
                IAllele allele = AlleleManager.alleleRegistry.getAllele(uid);
                if (allele == null) {
                    continue;
                }
                Gene gene = new Gene(allele, chromo, root);
                if (!discoveredGenes.contains(gene)) {
                    discoveredGenes.add(gene);
                }
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Gene(binnie.core.genetics.Gene) IGene(binnie.core.api.genetics.IGene) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosomeType(forestry.api.genetics.IChromosomeType) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

IChromosomeType (forestry.api.genetics.IChromosomeType)20 IAllele (forestry.api.genetics.IAllele)14 Gene (binnie.core.genetics.Gene)11 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)11 ArrayList (java.util.ArrayList)8 ItemStack (net.minecraft.item.ItemStack)7 IIndividual (forestry.api.genetics.IIndividual)6 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)5 List (java.util.List)5 IGene (binnie.core.api.genetics.IGene)4 Point (binnie.core.gui.geometry.Point)4 IChromosome (forestry.api.genetics.IChromosome)4 Map (java.util.Map)4 ControlText (binnie.core.gui.controls.ControlText)3 ControlPlayerInventory (binnie.core.gui.minecraft.control.ControlPlayerInventory)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 BreedingSystem (binnie.core.genetics.BreedingSystem)2 Area (binnie.core.gui.geometry.Area)2