use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class Tree method mutateSpecies.
@Nullable
private static IChromosome[] mutateSpecies(World world, @Nullable GameProfile playerProfile, BlockPos pos, ITreeGenome genomeOne, ITreeGenome genomeTwo) {
IChromosome[] parent1 = genomeOne.getChromosomes();
IChromosome[] parent2 = genomeTwo.getChromosomes();
ITreeGenome genome0;
ITreeGenome genome1;
IAlleleTreeSpecies allele0;
IAlleleTreeSpecies allele1;
if (world.rand.nextBoolean()) {
allele0 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
allele1 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
genome0 = genomeOne;
genome1 = genomeTwo;
} else {
allele0 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
allele1 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
genome0 = genomeTwo;
genome1 = genomeOne;
}
IArboristTracker breedingTracker = null;
if (playerProfile != null) {
breedingTracker = TreeManager.treeRoot.getBreedingTracker(world, playerProfile);
}
List<IMutation> combinations = TreeManager.treeRoot.getCombinations(allele0, allele1, true);
for (IMutation mutation : combinations) {
ITreeMutation treeMutation = (ITreeMutation) mutation;
// Stop blacklisted species.
// if (BeeManager.breedingManager.isBlacklisted(mutation.getTemplate()[0].getUID())) {
// continue;
// }
float chance = treeMutation.getChance(world, pos, allele0, allele1, genome0, genome1);
if (chance <= 0) {
continue;
}
// boost chance for researched mutations
if (breedingTracker != null && breedingTracker.isResearched(treeMutation)) {
float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
chance += mutationBoost;
}
if (chance > world.rand.nextFloat() * 100) {
return TreeManager.treeRoot.templateAsChromosomes(treeMutation.getTemplate());
}
}
return null;
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class Tree method addTooltip.
@Override
public void addTooltip(List<String> list) {
// No info 4 u!
if (!isAnalyzed) {
list.add("<" + Translator.translateToLocal("for.gui.unknown") + ">");
return;
}
// You analyzed it? Juicy tooltip coming up!
IAlleleTreeSpecies primary = genome.getPrimary();
IAlleleTreeSpecies secondary = genome.getSecondary();
if (!isPureBred(EnumTreeChromosome.SPECIES)) {
list.add(TextFormatting.BLUE + Translator.translateToLocal("for.trees.hybrid").replaceAll("%PRIMARY", primary.getAlleleName()).replaceAll("%SECONDARY", secondary.getAlleleName()));
}
String sappiness = TextFormatting.GOLD + "S: " + genome.getActiveAllele(EnumTreeChromosome.SAPPINESS).getAlleleName();
String maturation = TextFormatting.RED + "M: " + genome.getActiveAllele(EnumTreeChromosome.MATURATION).getAlleleName();
String height = TextFormatting.LIGHT_PURPLE + "H: " + genome.getActiveAllele(EnumTreeChromosome.HEIGHT).getAlleleName();
String girth = TextFormatting.AQUA + "G: " + String.format("%sx%s", genome.getGirth(), genome.getGirth());
String saplings = TextFormatting.YELLOW + "S: " + genome.getActiveAllele(EnumTreeChromosome.FERTILITY).getAlleleName();
String yield = TextFormatting.WHITE + "Y: " + genome.getActiveAllele(EnumTreeChromosome.YIELD).getAlleleName();
String carbonization = TextFormatting.GRAY + "CA: " + secondary.getWoodProvider().getCarbonization();
list.add(String.format("%s, %s", saplings, maturation));
list.add(String.format("%s, %s", height, girth));
list.add(String.format("%s, %s", yield, sappiness));
list.add(String.format("%s", carbonization));
IAlleleBoolean primaryFireproof = (IAlleleBoolean) genome.getActiveAllele(EnumTreeChromosome.FIREPROOF);
if (primaryFireproof.getValue()) {
list.add(TextFormatting.RED + Translator.translateToLocal("for.gui.fireresist"));
}
IAllele fruit = getGenome().getActiveAllele(EnumTreeChromosome.FRUITS);
if (fruit != AlleleFruits.fruitNone) {
String strike = "";
if (!canBearFruit()) {
strike = TextFormatting.STRIKETHROUGH.toString();
}
list.add(strike + TextFormatting.GREEN + "F: " + genome.getFruitProvider().getDescription());
}
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class TreeGenHelper method getTreeGenome.
private static ITreeGenome getTreeGenome(String speciesName) throws SpeciesNotFoundException, TemplateNotFoundException {
IAlleleTreeSpecies species = null;
for (String uid : AlleleManager.alleleRegistry.getRegisteredAlleles().keySet()) {
if (!uid.equals(speciesName)) {
continue;
}
IAllele allele = AlleleManager.alleleRegistry.getAllele(uid);
if (allele instanceof IAlleleTreeSpecies) {
species = (IAlleleTreeSpecies) allele;
break;
}
}
if (species == null) {
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
if (allele instanceof IAlleleTreeSpecies && allele.getAlleleName().replaceAll("\\s", "").equals(speciesName)) {
species = (IAlleleTreeSpecies) allele;
break;
}
}
}
if (species == null) {
throw new SpeciesNotFoundException(speciesName);
}
IAllele[] template = TreeManager.treeRoot.getTemplate(species);
return TreeManager.treeRoot.templateAsGenome(template);
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class PropertyTree method parseValue.
@Override
public Optional<IAlleleTreeSpecies> parseValue(String value) {
if (namesMap.isEmpty()) {
List<IAlleleTreeSpecies> allowedValues = getAllowedValues();
for (IAlleleTreeSpecies allowedValue : allowedValues) {
String propertyName = getName(allowedValue);
namesMap.put(propertyName, allowedValue);
}
}
return Optional.fromNullable(namesMap.get(value));
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project Binnie by ForestryMC.
the class PagePlanksTrees method getTreesThatMakePlanks.
private static Collection<IAlleleSpecies> getTreesThatMakePlanks(ItemStack fruit, boolean master, World world, GameProfile player) {
if (fruit == null) {
return new ArrayList<>();
}
ITreeRoot treeRoot = TreeManager.treeRoot;
IBreedingSystem system = Binnie.GENETICS.getSystem(treeRoot);
final Collection<IAlleleSpecies> set = master ? system.getAllSpecies() : system.getDiscoveredSpecies(world, player);
final List<IAlleleSpecies> found = new ArrayList<>();
for (final IAlleleSpecies species : set) {
final IAlleleTreeSpecies tSpecies = (IAlleleTreeSpecies) species;
ITreeGenome genome = treeRoot.templateAsGenome(treeRoot.getTemplate(tSpecies));
IAlleleTreeSpecies treeSpecies = genome.getPrimary();
final ItemStack woodStack = treeSpecies.getWoodProvider().getWoodStack();
ItemStack plankProduct = LumbermillRecipeManager.getPlankProduct(woodStack, world);
if (!plankProduct.isEmpty() && fruit.isItemEqual(plankProduct)) {
found.add(species);
}
}
return found;
}
Aggregations