Search in sources :

Example 21 with ISpeciesRoot

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

the class InoculatorRecipeCategory method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, InoculatorRecipeWrapper recipeWrapper, IIngredients ingredients) {
    if (!splicer) {
        IDrawable tank = GeneticsJeiPlugin.drawables.getTank();
        IDrawable tankOverlay = GeneticsJeiPlugin.drawables.getTankOverlay();
        IGuiFluidStackGroup fluidStacks = recipeLayout.getFluidStacks();
        fluidStacks.init(Inoculator.TANK_VEKTOR, true, 1, 1, 16, 58, 100, false, tankOverlay);
        fluidStacks.setBackground(Inoculator.TANK_VEKTOR, tank);
        fluidStacks.set(ingredients);
    }
    IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
    itemStacks.init(0, true, 22, 0);
    itemStacks.init(1, true, 42, 21);
    itemStacks.init(2, false, 92, 21);
    IDrawable slot = GeneticsJeiPlugin.guiHelper.getSlotDrawable();
    for (int i = 0; i <= 2; i++) {
        itemStacks.setBackground(i, slot);
    }
    recipeWrapper.setCurrentIngredients(itemStacks.getGuiIngredients());
    IFocus<?> focus = recipeLayout.getFocus();
    if (focus != null) {
        Object focusValue = focus.getValue();
        if (focusValue instanceof ItemStack) {
            ItemStack focusStack = (ItemStack) focusValue;
            if (AlleleManager.alleleRegistry.isIndividual(focusStack)) {
                if (focus.getMode() == IFocus.Mode.INPUT) {
                    ItemStack serum = recipeWrapper.getInputSerum();
                    ItemStack output = InoculatorLogic.applySerum(focusStack, serum);
                    itemStacks.set(0, serum);
                    itemStacks.set(1, focusStack);
                    itemStacks.set(2, output);
                    return;
                } else if (focus.getMode() == IFocus.Mode.OUTPUT) {
                    IIndividual individual = AlleleManager.alleleRegistry.getIndividual(focusStack);
                    if (individual != null) {
                        ISpeciesRoot speciesRoot = individual.getGenome().getSpeciesRoot();
                        IAlleleSpecies species = individual.getGenome().getPrimary();
                        ItemStack serum = ItemSerum.create(new Gene(species, speciesRoot.getSpeciesChromosomeType(), speciesRoot));
                        // set fully charged
                        serum.setItemDamage(0);
                        itemStacks.set(0, serum);
                        itemStacks.set(1, recipeWrapper.getWildcardTarget());
                        itemStacks.set(2, focusStack);
                        return;
                    }
                }
            } else if (focusStack.getItem() instanceof ItemSerum) {
                ItemStack input = recipeWrapper.getWildcardTarget();
                ItemStack output = InoculatorLogic.applySerum(input, focusStack);
                itemStacks.set(0, focusStack);
                itemStacks.set(1, input);
                itemStacks.set(2, output);
                return;
            }
        }
    }
    itemStacks.set(ingredients);
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IGuiFluidStackGroup(mezz.jei.api.gui.IGuiFluidStackGroup) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ItemSerum(binnie.genetics.item.ItemSerum) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) ItemStack(net.minecraft.item.ItemStack) IDrawable(mezz.jei.api.gui.IDrawable)

Example 22 with ISpeciesRoot

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

the class BreedingSystem method calculateArrays.

@Override
public void calculateArrays() {
    ISpeciesRoot speciesRoot = getSpeciesRoot();
    calculateAlleles(speciesRoot);
    calculateBranches(speciesRoot);
    calculateMutations(speciesRoot);
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot)

Example 23 with ISpeciesRoot

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

the class Gene method readFromNBT.

@Override
public void readFromNBT(final NBTTagCompound nbt) {
    this.allele = AlleleManager.alleleRegistry.getAllele(nbt.getString("allele"));
    String rootKey = nbt.getString("root");
    ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(rootKey);
    Preconditions.checkArgument(root != null, "Could not find root: %s", rootKey);
    this.root = root;
    final int chromoID = nbt.getByte("chromo");
    Preconditions.checkArgument(chromoID >= 0 && chromoID < this.root.getKaryotype().length, "Invalid chromosomeId: %s", chromoID);
    this.chromosome = this.root.getKaryotype()[chromoID];
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot)

Example 24 with ISpeciesRoot

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

the class ManagerGenetics method loadAlleles.

private void loadAlleles() {
    this.invalidChromosomeTypes.clear();
    for (IBreedingSystem system : BREEDING_SYSTEMS.values()) {
        ISpeciesRoot root = system.getSpeciesRoot();
        Map<IChromosomeType, List<IAllele>> chromosomeMap = new LinkedHashMap<>();
        for (IChromosomeType chromosome : root.getKaryotype()) {
            TreeSet<IAllele> alleles = new TreeSet<>(new ComparatorAllele());
            for (IIndividual individual : root.getIndividualTemplates()) {
                IGenome genome = individual.getGenome();
                IAllele activeAllele = genome.getActiveAllele(chromosome);
                IAllele inactiveAllele = genome.getInactiveAllele(chromosome);
                if (chromosome.getAlleleClass().isInstance(activeAllele)) {
                    alleles.add(activeAllele);
                }
                if (!chromosome.getAlleleClass().isInstance(inactiveAllele)) {
                    continue;
                }
                alleles.add(inactiveAllele);
            }
            system.addExtraAlleles(chromosome, alleles);
            if (alleles.size() == 0) {
                this.invalidChromosomeTypes.add(chromosome);
            } else {
                final List<IAllele> alleleList = new ArrayList<>(alleles);
                chromosomeMap.put(chromosome, alleleList);
            }
        }
        this.chromosomeArray.put(root, chromosomeMap);
    }
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) LinkedHashMap(java.util.LinkedHashMap) IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 25 with ISpeciesRoot

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

the class Splicer method setGene.

public static void setGene(IGene gene, ItemStack target, boolean setPrimary, boolean setSecondary) {
    int chromosomeID = gene.getChromosome().ordinal();
    Class<? extends IAllele> cls = gene.getChromosome().getAlleleClass();
    if (!cls.isInstance(gene.getAllele())) {
        return;
    }
    NBTTagCompound targetTag = target.getTagCompound();
    NBTTagCompound mate = null;
    if (targetTag != null && targetTag.hasKey("Mate")) {
        mate = targetTag.getCompoundTag("Mate").copy();
    }
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(target);
    Preconditions.checkNotNull(speciesRoot);
    IIndividual original = speciesRoot.getMember(target);
    Preconditions.checkNotNull(original);
    IChromosome[] chromosomes = original.getGenome().getChromosomes();
    IAllele[] primaryAlleles = new IAllele[chromosomes.length];
    IAllele[] secondaryAlleles = new IAllele[chromosomes.length];
    for (int i = 0; i < chromosomes.length; i++) {
        IChromosome chromosome = chromosomes[i];
        if (i == chromosomeID && setPrimary) {
            primaryAlleles[i] = gene.getAllele();
        } else {
            primaryAlleles[i] = chromosome.getPrimaryAllele();
        }
        if (i == chromosomeID && setSecondary) {
            secondaryAlleles[i] = gene.getAllele();
        } else {
            secondaryAlleles[i] = chromosome.getSecondaryAllele();
        }
    }
    IIndividual individual = speciesRoot.templateAsIndividual(primaryAlleles, secondaryAlleles);
    if (original.isAnalyzed()) {
        individual.analyze();
    }
    if (original instanceof IBee) {
        IBee individualBee = (IBee) individual;
        IBee originalBee = (IBee) original;
        individualBee.setIsNatural(originalBee.isNatural());
    }
    NBTTagCompound nbt = new NBTTagCompound();
    individual.writeToNBT(nbt);
    if (mate != null) {
        nbt.setTag("Mate", mate);
    }
    target.setTagCompound(nbt);
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome) IBee(forestry.api.apiculture.IBee)

Aggregations

ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)49 IIndividual (forestry.api.genetics.IIndividual)30 ItemStack (net.minecraft.item.ItemStack)20 IAllele (forestry.api.genetics.IAllele)17 IChromosomeType (forestry.api.genetics.IChromosomeType)11 Gene (binnie.core.genetics.Gene)10 IBreedingTracker (forestry.api.genetics.IBreedingTracker)7 IGenome (forestry.api.genetics.IGenome)7 ArrayList (java.util.ArrayList)7 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)6 ISpeciesType (forestry.api.genetics.ISpeciesType)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 IGene (binnie.core.api.genetics.IGene)4 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)4 IFilterData (forestry.api.genetics.IFilterData)3 List (java.util.List)3 Random (java.util.Random)3 Nullable (javax.annotation.Nullable)3 IGeneItem (binnie.genetics.genetics.IGeneItem)2 ForestryEvent (forestry.api.core.ForestryEvent)2