Search in sources :

Example 36 with IIndividual

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

the class EscritoireGame method probe.

public void probe(ItemStack specimen, IInventory inventory, int startSlot, int slotCount) {
    if (status != Status.PLAYING) {
        return;
    }
    IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
    if (individual == null) {
        return;
    }
    if (bountyLevel > 1) {
        bountyLevel--;
    }
    IAlleleSpecies species = individual.getGenome().getPrimary();
    gameBoard.hideProbedTokens();
    int revealCount = getSampleSize(slotCount);
    for (int i = 0; i < revealCount; i++) {
        ItemStack sample = inventory.decrStackSize(startSlot + i, 1);
        if (!sample.isEmpty()) {
            if (rand.nextFloat() < species.getResearchSuitability(sample)) {
                gameBoard.probe();
            }
        }
    }
    lastUpdate = System.currentTimeMillis();
}
Also used : IIndividual(forestry.api.genetics.IIndividual) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ItemStack(net.minecraft.item.ItemStack)

Example 37 with IIndividual

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

the class Bee method retrievePollen.

/* FLOWERS */
@Override
@Nullable
public IIndividual retrievePollen(IBeeHousing housing) {
    IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
    int chance = Math.round(genome.getFlowering() * beeModifier.getFloweringModifier(getGenome(), 1f));
    World world = housing.getWorldObj();
    Random random = world.rand;
    // Correct speed
    if (random.nextInt(100) >= chance) {
        return null;
    }
    Vec3i area = getArea(genome, beeModifier);
    Vec3i offset = new Vec3i(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
    BlockPos housingPos = housing.getCoordinates();
    IIndividual pollen = null;
    for (int i = 0; i < 20; i++) {
        BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
        BlockPos blockPos = VectUtil.add(housingPos, randomPos, offset);
        ICheckPollinatable pitcher = TileUtil.getTile(world, blockPos, ICheckPollinatable.class);
        if (pitcher != null) {
            if (genome.getFlowerProvider().isAcceptedPollinatable(world, pitcher)) {
                pollen = pitcher.getPollen();
            }
        } else {
            pollen = GeneticsUtil.getPollen(world, blockPos);
        }
        if (pollen != null) {
            return pollen;
        }
    }
    return null;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) IBeeModifier(forestry.api.apiculture.IBeeModifier) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Example 38 with IIndividual

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

the class InventoryEscritoire method canSlotAccept.

@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
    if (slotIndex >= SLOT_INPUT_1 && slotIndex < SLOT_INPUT_1 + tile.getGame().getSampleSize(SLOTS_INPUT_COUNT)) {
        ItemStack specimen = getStackInSlot(SLOT_ANALYZE);
        if (specimen.isEmpty()) {
            return false;
        }
        IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
        return individual != null && individual.getGenome().getPrimary().getResearchSuitability(itemStack) > 0;
    }
    return slotIndex == SLOT_ANALYZE && (AlleleManager.alleleRegistry.isIndividual(itemStack) || GeneticsUtil.getGeneticEquivalent(itemStack) != null);
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ItemStack(net.minecraft.item.ItemStack)

Example 39 with IIndividual

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

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

IIndividual (forestry.api.genetics.IIndividual)49 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)30 ItemStack (net.minecraft.item.ItemStack)29 IAllele (forestry.api.genetics.IAllele)14 IGenome (forestry.api.genetics.IGenome)10 ISpeciesType (forestry.api.genetics.ISpeciesType)8 Nullable (javax.annotation.Nullable)7 Gene (binnie.core.genetics.Gene)6 IChromosomeType (forestry.api.genetics.IChromosomeType)6 ArrayList (java.util.ArrayList)6 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)5 Random (java.util.Random)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 IGene (binnie.core.api.genetics.IGene)4 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)4 IBreedingTracker (forestry.api.genetics.IBreedingTracker)3 IFilterData (forestry.api.genetics.IFilterData)3 Tolerance (binnie.core.genetics.Tolerance)2 Point (binnie.core.gui.geometry.Point)2 ControlItemDisplay (binnie.core.gui.minecraft.control.ControlItemDisplay)2