Search in sources :

Example 1 with Tolerance

use of binnie.core.genetics.Tolerance in project Binnie by ForestryMC.

the class ControlToleranceBar method setValues.

public void setValues(T value, forestry.api.genetics.EnumTolerance enumTol) {
    tolerated.clear();
    Tolerance tol = Tolerance.get(enumTol);
    for (T full : fullSet) {
        if (full.ordinal() > value.ordinal() + tol.getBounds()[1]) {
            continue;
        }
        if (full.ordinal() < value.ordinal() + tol.getBounds()[0]) {
            continue;
        }
        tolerated.add(full);
    }
}
Also used : Tolerance(binnie.core.genetics.Tolerance)

Example 2 with Tolerance

use of binnie.core.genetics.Tolerance in project Binnie by ForestryMC.

the class ToleranceSystem method canAlter.

public boolean canAlter(final ItemStack stack, final ItemStack acclim) {
    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 float effect = this.type.getEffect(acclim);
    return (effect > 0.0f && tol.getBounds()[1] < 5) || (effect < 0.0f && tol.getBounds()[0] > -5);
}
Also used : IGenome(forestry.api.genetics.IGenome) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) IIndividual(forestry.api.genetics.IIndividual) Tolerance(binnie.core.genetics.Tolerance) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance)

Example 3 with Tolerance

use of binnie.core.genetics.Tolerance 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

Tolerance (binnie.core.genetics.Tolerance)3 IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)2 IGenome (forestry.api.genetics.IGenome)2 IIndividual (forestry.api.genetics.IIndividual)2 Gene (binnie.core.genetics.Gene)1 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 Random (java.util.Random)1