use of forestry.api.genetics.IGenome in project ForestryMC by ForestryMC.
the class Butterfly method mutateSpecies.
@Nullable
private static IChromosome[] mutateSpecies(World world, IButterflyNursery nursery, IGenome genomeOne, IGenome genomeTwo) {
IChromosome[] parent1 = genomeOne.getChromosomes();
IChromosome[] parent2 = genomeTwo.getChromosomes();
IGenome genome0;
IGenome genome1;
IAllele allele0;
IAllele allele1;
if (rand.nextBoolean()) {
allele0 = parent1[EnumButterflyChromosome.SPECIES.ordinal()].getPrimaryAllele();
allele1 = parent2[EnumButterflyChromosome.SPECIES.ordinal()].getSecondaryAllele();
genome0 = genomeOne;
genome1 = genomeTwo;
} else {
allele0 = parent2[EnumButterflyChromosome.SPECIES.ordinal()].getPrimaryAllele();
allele1 = parent1[EnumButterflyChromosome.SPECIES.ordinal()].getSecondaryAllele();
genome0 = genomeTwo;
genome1 = genomeOne;
}
for (IButterflyMutation mutation : ButterflyManager.butterflyRoot.getMutations(true)) {
float chance = mutation.getChance(world, nursery, allele0, allele1, genome0, genome1);
if (chance > rand.nextFloat() * 100) {
return ButterflyManager.butterflyRoot.templateAsChromosomes(mutation.getTemplate());
}
}
return null;
}
use of forestry.api.genetics.IGenome in project ForestryMC by ForestryMC.
the class FilterLogic method isValid.
public boolean isValid(EnumFacing facing, ItemStack itemStack, IFilterData filterData) {
IFilterRuleType rule = getRule(facing);
if (rule == DefaultFilterRuleType.CLOSED) {
return false;
}
if (rule == DefaultFilterRuleType.ITEM && !filterData.isPresent()) {
return true;
}
String requiredRoot = rule.getRootUID();
if (requiredRoot != null && (!filterData.isPresent() || !filterData.getRoot().getUID().equals(requiredRoot))) {
return false;
}
if (rule == DefaultFilterRuleType.ANYTHING || rule.isValid(itemStack, filterData)) {
if (filterData.isPresent()) {
IIndividual ind = filterData.getIndividual();
IGenome genome = ind.getGenome();
IAllele active = genome.getPrimary();
IAllele inactive = genome.getSecondary();
if (!isValidAllelePair(facing, active.getUID(), inactive.getUID())) {
return false;
}
}
return true;
}
return false;
}
use of forestry.api.genetics.IGenome in project ForestryMC by ForestryMC.
the class EscritoireGameBoard method initialize.
public boolean initialize(ItemStack specimen) {
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
if (individual == null) {
return false;
}
IGenome genome = individual.getGenome();
ISpeciesRoot root = genome.getPrimary().getRoot();
tokenCount = getTokenCount(genome);
for (int i = 0; i < tokenCount / 2; i++) {
IAllele[] randomTemplate = root.getRandomTemplate(rand);
String speciesUid = randomTemplate[root.getSpeciesChromosomeType().ordinal()].getUID();
gameTokens.add(new EscritoireGameToken(speciesUid));
gameTokens.add(new EscritoireGameToken(speciesUid));
}
Collections.shuffle(gameTokens);
return true;
}
use of forestry.api.genetics.IGenome in project EnderIO by SleepyTrousers.
the class SpeciesItemFilter method itemMatched.
private boolean itemMatched(@Nonnull ItemStack item) {
if (Prep.isInvalid(item)) {
return false;
}
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(item);
if (speciesRoot == null) {
return false;
}
IIndividual member = speciesRoot.getMember(item);
if (member == null) {
return false;
}
IGenome genome = member.getGenome();
String primarySpeciesUid = genome.getPrimary().getUID();
String secondarySpeciesUid = genome.getSecondary().getUID();
for (int slot = 0; slot < items.size(); slot++) {
ItemStack slotItem = items.get(slot);
if (slotItem.getItem() == item.getItem()) {
switch(speciesMode) {
case BOTH:
if (primarySpeciesUids[slot].equals(primarySpeciesUid) && secondarySpeciesUids[slot].equals(secondarySpeciesUid)) {
return true;
}
break;
case PRIMARY:
if (primarySpeciesUids[slot].equals(primarySpeciesUid)) {
return true;
}
break;
case SECONDARY:
if (secondarySpeciesUids[slot].equals(secondarySpeciesUid)) {
return true;
}
break;
}
}
}
return false;
}
use of forestry.api.genetics.IGenome in project Binnie by ForestryMC.
the class ManagerGenetics method loadAlleles.
private void loadAlleles() {
this.invalidChromosomeTypes.clear();
for (IBreedingSystem system : BREEDING_SYSTEMS.values()) {
ISpeciesRoot root = system.getSpeciesRoot();
Map<IChromosomeType, List<IAllele>> chromosomeMap = new LinkedHashMap<>();
for (IChromosomeType chromosome : root.getKaryotype()) {
TreeSet<IAllele> alleles = new TreeSet<>(new ComparatorAllele());
for (IIndividual individual : root.getIndividualTemplates()) {
IGenome genome = individual.getGenome();
IAllele activeAllele = genome.getActiveAllele(chromosome);
IAllele inactiveAllele = genome.getInactiveAllele(chromosome);
if (chromosome.getAlleleClass().isInstance(activeAllele)) {
alleles.add(activeAllele);
}
if (!chromosome.getAlleleClass().isInstance(inactiveAllele)) {
continue;
}
alleles.add(inactiveAllele);
}
system.addExtraAlleles(chromosome, alleles);
if (alleles.size() == 0) {
this.invalidChromosomeTypes.add(chromosome);
} else {
final List<IAllele> alleleList = new ArrayList<>(alleles);
chromosomeMap.put(chromosome, alleleList);
}
}
this.chromosomeArray.put(root, chromosomeMap);
}
}
Aggregations