Search in sources :

Example 1 with ISpeciesRoot

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

the class GeneticsUtil method getOrCreatePollinatable.

/**
 * Returns an IPollinatable that can be mated. This will convert vanilla leaves to Forestry leaves.
 */
@Nullable
public static IPollinatable getOrCreatePollinatable(@Nullable GameProfile owner, World world, final BlockPos pos, boolean convertVanilla) {
    IPollinatable pollinatable = TileUtil.getTile(world, pos, IPollinatable.class);
    if (pollinatable == null && convertVanilla) {
        final IIndividual pollen = getPollen(world, pos);
        if (pollen != null) {
            ISpeciesRoot root = pollen.getGenome().getSpeciesRoot();
            if (root instanceof ISpeciesRootPollinatable) {
                ISpeciesRootPollinatable rootPollinatable = (ISpeciesRootPollinatable) root;
                pollinatable = rootPollinatable.tryConvertToPollinatable(owner, world, pos, pollen);
            }
        }
    }
    return pollinatable;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) ISpeciesRootPollinatable(forestry.api.genetics.ISpeciesRootPollinatable) IPollinatable(forestry.api.genetics.IPollinatable) Nullable(javax.annotation.Nullable)

Example 2 with ISpeciesRoot

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

the class DatabaseScreenLogic method onItemChange.

public ScreenState onItemChange(ItemStack itemStack) {
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(itemStack);
    // No individual, abort
    if (speciesRoot == null) {
        return ScreenState.NO_INDIVIDUAL;
    }
    IIndividual individual = speciesRoot.getMember(itemStack);
    // Check if a individual is selected and analyzed
    if (individual == null) {
        this.individual = null;
        this.itemStack = ItemStack.EMPTY;
        return ScreenState.NO_INDIVIDUAL;
    } else if (!individual.isAnalyzed()) {
        this.individual = null;
        this.itemStack = ItemStack.EMPTY;
        return ScreenState.NOT_ANALYZED;
    }
    this.individual = individual;
    this.itemStack = itemStack;
    if (speciesRoot != this.speciesRoot) {
        IDatabaseTab[] tabs = getTabs(speciesRoot);
        if (tabs == null) {
            this.tabs = new IDatabaseTab[4];
            return ScreenState.NO_PLUGIN;
        }
        this.tabs = tabs;
        // Select the first tab
        onTabChange(tabs[0]);
    } else {
        // Update the gui
        onTabChange(selectedTab);
    }
    this.speciesRoot = speciesRoot;
    return ScreenState.SUCCESS;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IDatabaseTab(forestry.api.genetics.IDatabaseTab)

Example 3 with ISpeciesRoot

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

the class Chromosome method validateAllele.

private static IAllele validateAllele(@Nullable String speciesUid, IChromosomeType chromosomeType, @Nullable IAllele allele) {
    if (!chromosomeType.getAlleleClass().isInstance(allele)) {
        ISpeciesRoot speciesRoot = chromosomeType.getSpeciesRoot();
        IAllele[] template = null;
        if (speciesUid != null) {
            template = speciesRoot.getTemplate(speciesUid);
        }
        if (template == null) {
            template = speciesRoot.getDefaultTemplate();
        }
        return template[chromosomeType.ordinal()];
    }
    return allele;
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot)

Example 4 with ISpeciesRoot

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

the class InventoryDatabase method canSlotAccept.

@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
    itemStack = GeneticsUtil.convertToGeneticEquivalent(itemStack);
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(itemStack);
    if (speciesRoot == null) {
        return false;
    }
    return true;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot)

Example 5 with ISpeciesRoot

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

the class EntityButterfly method dropFewItems.

/* LOOT */
@Override
protected void dropFewItems(boolean playerKill, int lootLevel) {
    for (ItemStack stack : contained.getLootDrop(this, playerKill, lootLevel)) {
        ItemStackUtil.dropItemStackAsEntity(stack, world, posX, posY, posZ);
    }
    // Drop pollen if any
    IIndividual pollen = getPollen();
    if (pollen != null) {
        ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(pollen);
        ItemStack pollenStack = root.getMemberStack(pollen, EnumGermlingType.POLLEN);
        ItemStackUtil.dropItemStackAsEntity(pollenStack, world, posX, posY, posZ);
    }
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) ItemStack(net.minecraft.item.ItemStack)

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