Search in sources :

Example 36 with ISpeciesRoot

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

the class EventHandlerCore method syncBreedingTrackers.

private static void syncBreedingTrackers(EntityPlayer player) {
    IAlleleRegistry alleleRegistry = AlleleManager.alleleRegistry;
    Collection<ISpeciesRoot> speciesRoots = alleleRegistry.getSpeciesRoot().values();
    for (ISpeciesRoot speciesRoot : speciesRoots) {
        IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.getEntityWorld(), player.getGameProfile());
        breedingTracker.synchToPlayer(player);
    }
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IAlleleRegistry(forestry.api.genetics.IAlleleRegistry) IBreedingTracker(forestry.api.genetics.IBreedingTracker)

Example 37 with ISpeciesRoot

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

the class GuiAlyzer method drawAnalyticsPageMutations.

public void drawAnalyticsPageMutations(IIndividual individual) {
    textLayout.startPage(COLUMN_0, COLUMN_1, COLUMN_2);
    textLayout.drawLine(Translator.translateToLocal("for.gui.beealyzer.mutations") + ":", COLUMN_0);
    textLayout.newLine();
    RenderHelper.enableGUIStandardItemLighting();
    IGenome genome = individual.getGenome();
    ISpeciesRoot speciesRoot = genome.getSpeciesRoot();
    IAlleleSpecies species = genome.getPrimary();
    int columnWidth = 50;
    int x = 0;
    EntityPlayer player = Minecraft.getMinecraft().player;
    IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
    for (IMutation mutation : speciesRoot.getCombinations(species)) {
        if (breedingTracker.isDiscovered(mutation)) {
            drawMutationInfo(mutation, species, COLUMN_0 + x, breedingTracker);
        } else {
            // Do not display secret undiscovered mutations.
            if (mutation.isSecret()) {
                continue;
            }
            drawUnknownMutation(mutation, COLUMN_0 + x, breedingTracker);
        }
        x += columnWidth;
        if (x >= columnWidth * 4) {
            x = 0;
            textLayout.newLine(16);
        }
    }
    textLayout.endPage();
}
Also used : IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IMutation(forestry.api.genetics.IMutation) IBreedingTracker(forestry.api.genetics.IBreedingTracker) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 38 with ISpeciesRoot

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

the class GuiElementFactory method createMutation.

public IGuiElementLayout createMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker) {
    if (breedingTracker.isDiscovered(mutation)) {
        GuiElementPanel element = new GuiElementPanel(x, y, width, height);
        ISpeciesRoot speciesRoot = mutation.getRoot();
        int speciesIndex = speciesRoot.getSpeciesChromosomeType().ordinal();
        ISpeciesPlugin plugin = mutation.getRoot().getSpeciesPlugin();
        Map<String, ItemStack> iconStacks = plugin.getIndividualStacks();
        ItemStack partner = iconStacks.get(mutation.getPartner(species).getUID());
        IAllele resultAllele = mutation.getTemplate()[speciesIndex];
        ItemStack result = iconStacks.get(resultAllele.getUID());
        element.addElements(new GuiElementItemStack(0, 0, partner), new GuiElementItemStack(33, 0, result));
        element.addElements(createProbabilityArrow(mutation, 18, 4, breedingTracker));
        return element;
    }
    // Do not display secret undiscovered mutations.
    if (mutation.isSecret()) {
        return null;
    }
    return createUnknownMutationGroup(x, y, width, height, mutation, breedingTracker);
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) ISpeciesPlugin(forestry.api.genetics.ISpeciesPlugin) ItemStack(net.minecraft.item.ItemStack)

Example 39 with ISpeciesRoot

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

the class ItemInventoryAlyzer method analyzeSpecimen.

private void analyzeSpecimen(ItemStack specimen) {
    if (specimen.isEmpty()) {
        return;
    }
    ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
    if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
        setInventorySlotContents(SLOT_SPECIMEN, convertedSpecimen);
        specimen = convertedSpecimen;
    }
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
    // No individual, abort
    if (speciesRoot == null) {
        return;
    }
    IIndividual individual = speciesRoot.getMember(specimen);
    // Analyze if necessary
    if (individual != null && !individual.isAnalyzed()) {
        final boolean requiresEnergy = ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.APICULTURE));
        if (requiresEnergy) {
            // Requires energy
            if (!isAlyzingFuel(getStackInSlot(SLOT_ENERGY))) {
                return;
            }
        }
        if (individual.analyze()) {
            IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
            breedingTracker.registerSpecies(individual.getGenome().getPrimary());
            breedingTracker.registerSpecies(individual.getGenome().getSecondary());
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            individual.writeToNBT(nbttagcompound);
            specimen.setTagCompound(nbttagcompound);
            if (requiresEnergy) {
                // Decrease energy
                decrStackSize(SLOT_ENERGY, 1);
            }
        }
    }
    setInventorySlotContents(SLOT_ANALYZE_1, specimen);
    setInventorySlotContents(SLOT_SPECIMEN, ItemStack.EMPTY);
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IBreedingTracker(forestry.api.genetics.IBreedingTracker) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 40 with ISpeciesRoot

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

the class TileDatabase method analyzeSpecimen.

// Called by the container on the server side
public ItemStack analyzeSpecimen(int selectedDatabaseSlot) {
    if (selectedDatabaseSlot < 0) {
        return ItemStack.EMPTY;
    }
    ItemStack specimen = getStackInSlot(selectedDatabaseSlot);
    if (specimen.isEmpty()) {
        return ItemStack.EMPTY;
    }
    ItemStack convertedSpecimen = GeneticsUtil.convertToGeneticEquivalent(specimen);
    if (!ItemStack.areItemStacksEqual(specimen, convertedSpecimen)) {
        setInventorySlotContents(selectedDatabaseSlot, convertedSpecimen);
        specimen = convertedSpecimen;
    }
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(specimen);
    // No individual, abort
    if (speciesRoot == null) {
        return specimen;
    }
    IIndividual individual = speciesRoot.getMember(specimen);
    // Analyze if necessary
    if (individual != null && !individual.isAnalyzed()) {
        final boolean requiresEnergy = ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.APICULTURE));
        if (requiresEnergy) {
            // Requires energy
            if (!analyzerInventory.isAlyzingFuel(analyzerInventory.getStackInSlot(InventoryDatabaseAnalyzer.SLOT_ENERGY))) {
                return specimen;
            }
        }
        if (individual.analyze()) {
            IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(world, ownerHandler.getOwner());
            breedingTracker.registerSpecies(individual.getGenome().getPrimary());
            breedingTracker.registerSpecies(individual.getGenome().getSecondary());
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            individual.writeToNBT(nbttagcompound);
            specimen.setTagCompound(nbttagcompound);
            if (requiresEnergy) {
                // Decrease energy
                analyzerInventory.decrStackSize(InventoryDatabaseAnalyzer.SLOT_ENERGY, 1);
            }
        }
        setInventorySlotContents(selectedDatabaseSlot, specimen);
    }
    return specimen;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IBreedingTracker(forestry.api.genetics.IBreedingTracker) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) 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