Search in sources :

Example 11 with IBreedingTracker

use of forestry.api.genetics.IBreedingTracker 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)

Example 12 with IBreedingTracker

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

the class BreedingSystem method onSyncBreedingTracker.

@Override
@SubscribeEvent
public final void onSyncBreedingTracker(final ForestryEvent.SyncedBreedingTracker event) {
    final IBreedingTracker tracker = event.tracker;
    if (!this.getTrackerClass().isInstance(tracker)) {
        return;
    }
    this.syncTracker(tracker);
}
Also used : IBreedingTracker(forestry.api.genetics.IBreedingTracker) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 13 with IBreedingTracker

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

the class ManagerGenetics method analyse.

public static ItemStack analyse(ItemStack stack, World world, GameProfile username) {
    if (!stack.isEmpty()) {
        ItemStack conv = Binnie.GENETICS.getConversionStack(stack).copy();
        if (!conv.isEmpty()) {
            conv.setCount(stack.getCount());
            stack = conv;
        }
        ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
        if (root != null) {
            final IIndividual ind = root.getMember(stack);
            ind.analyze();
            IBreedingTracker breedingTracker = ind.getGenome().getSpeciesRoot().getBreedingTracker(world, username);
            breedingTracker.registerBirth(ind);
            final NBTTagCompound nbttagcompound = new NBTTagCompound();
            ind.writeToNBT(nbttagcompound);
            stack.setTagCompound(nbttagcompound);
            return stack;
        }
        if (stack.getItem() instanceof IItemAnalysable) {
            return ((IItemAnalysable) stack.getItem()).analyse(stack);
        }
    }
    return stack;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IBreedingTracker(forestry.api.genetics.IBreedingTracker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IItemAnalysable(binnie.core.api.genetics.IItemAnalysable) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IBreedingTracker (forestry.api.genetics.IBreedingTracker)13 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)7 ItemStack (net.minecraft.item.ItemStack)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 IIndividual (forestry.api.genetics.IIndividual)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)2 IMutation (forestry.api.genetics.IMutation)2 PacketGenomeTrackerSync (forestry.core.network.packets.PacketGenomeTrackerSync)2 ArrayList (java.util.ArrayList)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 FakePlayer (net.minecraftforge.common.util.FakePlayer)2 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)1 IItemAnalysable (binnie.core.api.genetics.IItemAnalysable)1 ITree (forestry.api.arboriculture.ITree)1 IAlleleRegistry (forestry.api.genetics.IAlleleRegistry)1 IGenome (forestry.api.genetics.IGenome)1 WorldGenBase (forestry.core.worldgen.WorldGenBase)1 BufferedWriter (java.io.BufferedWriter)1