Search in sources :

Example 11 with IGenome

use of forestry.api.genetics.IGenome 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 12 with IGenome

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

the class InoculatorLogic method isValidSerum.

@Nullable
public ErrorState isValidSerum() {
    final ItemStack serum = this.getUtil().getStack(Inoculator.SLOT_SERUM_VIAL);
    final ItemStack target = this.getUtil().getStack(Inoculator.SLOT_TARGET);
    final IGene[] genes = Engineering.getGenes(serum);
    if (genes.length == 0) {
        return new ErrorState(GeneticsErrorCode.INVALID_SERUM_NO);
    }
    if (!genes[0].getSpeciesRoot().isMember(target)) {
        return new ErrorState(GeneticsErrorCode.INVALID_SERUM_MISMATCH);
    }
    final IIndividual individual = genes[0].getSpeciesRoot().getMember(target);
    if (individual != null) {
        final IGenome genome = individual.getGenome();
        for (final IGene gene : genes) {
            final IAllele a = genome.getActiveAllele(gene.getChromosome());
            final IAllele b = genome.getInactiveAllele(gene.getChromosome());
            if (!a.getUID().equals(gene.getAllele().getUID()) || !b.getUID().equals(gene.getAllele().getUID())) {
                return null;
            }
        }
    }
    return new ErrorState(GeneticsErrorCode.DEFUNCT_SERUM);
}
Also used : IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) IIndividual(forestry.api.genetics.IIndividual) ErrorState(binnie.core.machines.errors.ErrorState) IGene(binnie.core.api.genetics.IGene) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 13 with IGenome

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

Aggregations

IGenome (forestry.api.genetics.IGenome)13 IIndividual (forestry.api.genetics.IIndividual)10 IAllele (forestry.api.genetics.IAllele)7 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)7 ItemStack (net.minecraft.item.ItemStack)5 Gene (binnie.core.genetics.Gene)2 Tolerance (binnie.core.genetics.Tolerance)2 IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)2 IChromosome (forestry.api.genetics.IChromosome)2 IChromosomeType (forestry.api.genetics.IChromosomeType)2 Random (java.util.Random)2 Nullable (javax.annotation.Nullable)2 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)1 IGene (binnie.core.api.genetics.IGene)1 MachineUtil (binnie.core.machines.MachineUtil)1 ErrorState (binnie.core.machines.errors.ErrorState)1 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)1 IBreedingTracker (forestry.api.genetics.IBreedingTracker)1 IFilterRuleType (forestry.api.genetics.IFilterRuleType)1 IMutation (forestry.api.genetics.IMutation)1