@Override public List<ITree> getSaplings(World world, @Nullable GameProfile playerProfile, BlockPos pos, float modifier) { List<ITree> prod = new ArrayList<>(); float chance = genome.getFertility() * modifier; if (world.rand.nextFloat() <= chance) { if (mate == null) { prod.add(TreeManager.treeRoot.getTree(world, new TreeGenome(genome.getChromosomes()))); } else { prod.add(createOffspring(world, mate, playerProfile, pos)); } } return prod; }
@Override public void mate(ITree other) { mate = new TreeGenome(other.getGenome().getChromosomes()); }
private ITree createOffspring(World world, ITreeGenome mate, @Nullable GameProfile playerProfile, BlockPos pos) { IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length]; IChromosome[] parent1 = genome.getChromosomes(); IChromosome[] parent2 = mate.getChromosomes(); // Check for mutation. Replace one of the parents with the mutation // template if mutation occured. IChromosome[] mutated = mutateSpecies(world, playerProfile, pos, genome, mate); if (mutated == null) { mutated = mutateSpecies(world, playerProfile, pos, mate, genome); } if (mutated != null) { return new Tree(new TreeGenome(mutated)); } for (int i = 0; i < parent1.length; i++) { if (parent1[i] != null && parent2[i] != null) { chromosomes[i] = Chromosome.inheritChromosome(world.rand, parent1[i], parent2[i]); } } return new Tree(new TreeGenome(chromosomes)); }
@Nullable private static IChromosome[] mutateSpecies(World world, @Nullable GameProfile playerProfile, BlockPos pos, ITreeGenome genomeOne, ITreeGenome genomeTwo) { IChromosome[] parent1 = genomeOne.getChromosomes(); IChromosome[] parent2 = genomeTwo.getChromosomes();