Search in sources :

Example 41 with ISpeciesRoot

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

the class FilterLogic method getValidDirections.

public Collection<EnumFacing> getValidDirections(ItemStack itemStack, EnumFacing from) {
    ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(itemStack);
    IIndividual individual = null;
    ISpeciesType type = null;
    if (root != null) {
        individual = root.getMember(itemStack);
        type = root.getType(itemStack);
    }
    IFilterData filterData = new FilterData(root, individual, type);
    List<EnumFacing> validFacings = new LinkedList<>();
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (facing == from) {
            continue;
        }
        if (isValid(facing, itemStack, filterData)) {
            validFacings.add(facing);
        }
    }
    return validFacings;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IFilterData(forestry.api.genetics.IFilterData) ISpeciesType(forestry.api.genetics.ISpeciesType) EnumFacing(net.minecraft.util.EnumFacing) IFilterData(forestry.api.genetics.IFilterData) LinkedList(java.util.LinkedList)

Example 42 with ISpeciesRoot

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

the class IsolatorLogic method onFinishTask.

@Override
protected void onFinishTask() {
    super.onFinishTask();
    final Random rand = this.getMachine().getWorld().rand;
    MachineUtil util = this.getUtil();
    final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(util.getStack(Isolator.SLOT_TARGET));
    if (root == null) {
        return;
    }
    final IIndividual individual = root.getMember(util.getStack(Isolator.SLOT_TARGET));
    if (individual == null) {
        return;
    }
    IChromosomeType[] karyotype = root.getKaryotype();
    IChromosomeType chromosome = karyotype[rand.nextInt(karyotype.length)];
    IGenome genome = individual.getGenome();
    IAllele allele = rand.nextBoolean() ? genome.getActiveAllele(chromosome) : genome.getInactiveAllele(chromosome);
    Gene gene = Gene.create(allele, chromosome, root);
    final ItemStack serum = ItemSequence.create(gene);
    util.setStack(Isolator.SLOT_RESULUT, serum);
    util.decreaseStack(Isolator.SLOT_SEQUENCER_VIAL, 1);
    if (rand.nextFloat() < TARGET_LOSS_CHANCE) {
        util.decreaseStack(Isolator.SLOT_TARGET, 1);
    }
    util.drainTank(Isolator.TANK_ETHANOL, ETHANOL_PER_PROCESS);
}
Also used : MachineUtil(binnie.core.machines.MachineUtil) IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack)

Example 43 with ISpeciesRoot

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

the class ToleranceSystem method alter.

public ItemStack alter(final ItemStack stack, final ItemStack acc) {
    final Random rand = new Random();
    final float effect = this.type.getEffect(acc);
    if (rand.nextFloat() > Math.abs(effect)) {
        return stack;
    }
    final IIndividual member = AlleleManager.alleleRegistry.getIndividual(stack);
    final IGenome genome = member.getGenome();
    final IAlleleTolerance tolAllele = (IAlleleTolerance) genome.getActiveAllele(this.chromosomeType);
    final Tolerance tol = Tolerance.get(tolAllele.getValue());
    final Tolerance newTol = Acclimatiser.alterTolerance(tol, effect);
    if (rand.nextFloat() > 1.0f / (-newTol.getBounds()[0] + newTol.getBounds()[1])) {
        return stack;
    }
    final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
    boolean setPrimary = rand.nextBoolean();
    boolean setSecondary = !setPrimary;
    Gene gene = new Gene(newTol.getAllele(), this.chromosomeType, root);
    Splicer.setGene(gene, stack, setPrimary, setSecondary);
    return stack;
}
Also used : IGenome(forestry.api.genetics.IGenome) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) Tolerance(binnie.core.genetics.Tolerance) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance)

Example 44 with ISpeciesRoot

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

the class ControlIndividualDisplay method setSpecies.

public void setSpecies(final IAlleleSpecies species, EnumDiscoveryState state) {
    final ISpeciesRoot speciesRoot = Binnie.GENETICS.getSpeciesRoot(species);
    final IBreedingSystem system = Binnie.GENETICS.getSystem(speciesRoot);
    final IAllele[] template = system.getSpeciesRoot().getTemplate(species);
    final IIndividual ind = system.getSpeciesRoot().templateAsIndividual(template);
    super.setItemStack(system.getSpeciesRoot().getMemberStack(ind, system.getDefaultType()));
    this.species = species;
    final GameProfile username = Window.get(this).getUsername();
    if (state == EnumDiscoveryState.UNDETERMINED) {
        state = (system.isSpeciesDiscovered(species, Window.get(this).getWorld(), username) ? EnumDiscoveryState.DISCOVERED : EnumDiscoveryState.UNDISCOVERED);
    }
    if (Window.get(this) instanceof WindowAbstractDatabase && ((WindowAbstractDatabase) Window.get(this)).isMaster()) {
        state = EnumDiscoveryState.SHOW;
    }
    this.discovered = state;
    this.addAttribute(Attribute.MOUSE_OVER);
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) GameProfile(com.mojang.authlib.GameProfile) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem)

Example 45 with ISpeciesRoot

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

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