Search in sources :

Example 6 with IAlleleTolerance

use of forestry.api.genetics.IAlleleTolerance in project ForestryMC by ForestryMC.

the class AlleleHelper method createAllele.

private static <K extends IAlleleValue<V>, V> IAllele createAllele(String category, K enumValue, IChromosomeType... types) {
    V value = enumValue.getValue();
    boolean isDominant = enumValue.isDominant();
    String name = enumValue.toString().toLowerCase(Locale.ENGLISH);
    Class<?> valueClass = value.getClass();
    if (Float.class.isAssignableFrom(valueClass)) {
        return AlleleManager.alleleFactory.createFloat(modId, category, name, (Float) value, isDominant, types);
    } else if (Integer.class.isAssignableFrom(valueClass)) {
        return AlleleManager.alleleFactory.createInteger(modId, category, name, (Integer) value, isDominant, types);
    } else if (Vec3i.class.isAssignableFrom(valueClass)) {
        Vec3i area = (Vec3i) value;
        return AlleleManager.alleleFactory.createArea(modId, category, name, area, isDominant, types);
    } else if (Boolean.class.isAssignableFrom(valueClass)) {
        return AlleleManager.alleleFactory.createBoolean(modId, category, (Boolean) value, isDominant, types);
    } else if (EnumTolerance.class.isAssignableFrom(valueClass)) {
        IAlleleTolerance alleleTolerance = new AlleleTolerance(modId, category, name, (EnumTolerance) value, isDominant);
        AlleleManager.alleleRegistry.registerAllele(alleleTolerance, types);
        return alleleTolerance;
    } else if (FlowerProvider.class.isAssignableFrom(valueClass)) {
        return AlleleManager.alleleFactory.createFlowers(modId, category, name, (FlowerProvider) value, isDominant, types);
    }
    throw new RuntimeException("could not create allele for category: " + category + " and value " + valueClass);
}
Also used : IAlleleInteger(forestry.api.genetics.IAlleleInteger) Vec3i(net.minecraft.util.math.Vec3i) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) IAlleleBoolean(forestry.api.genetics.IAlleleBoolean) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) FlowerProvider(forestry.apiculture.flowers.FlowerProvider)

Example 7 with IAlleleTolerance

use of forestry.api.genetics.IAlleleTolerance in project ForestryMC by ForestryMC.

the class Bee 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!
    IAlleleBeeSpecies primary = genome.getPrimary();
    IAlleleBeeSpecies secondary = genome.getSecondary();
    if (!isPureBred(EnumBeeChromosome.SPECIES)) {
        list.add(TextFormatting.BLUE + Translator.translateToLocal("for.bees.hybrid").replaceAll("%PRIMARY", primary.getAlleleName()).replaceAll("%SECONDARY", secondary.getAlleleName()));
    }
    if (generation > 0) {
        EnumRarity rarity;
        if (generation >= 1000) {
            rarity = EnumRarity.EPIC;
        } else if (generation >= 100) {
            rarity = EnumRarity.RARE;
        } else if (generation >= 10) {
            rarity = EnumRarity.UNCOMMON;
        } else {
            rarity = EnumRarity.COMMON;
        }
        String generationString = rarity.rarityColor + Translator.translateToLocalFormatted("for.gui.beealyzer.generations", generation);
        list.add(generationString);
    }
    IAllele speedAllele = genome.getActiveAllele(EnumBeeChromosome.SPEED);
    IAlleleTolerance tempToleranceAllele = (IAlleleTolerance) getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE);
    IAlleleTolerance humidToleranceAllele = (IAlleleTolerance) getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE);
    String unlocalizedCustomSpeed = "for.tooltip.worker." + speedAllele.getUnlocalizedName().replaceAll("(.*)\\.", "");
    String speed;
    if (Translator.canTranslateToLocal(unlocalizedCustomSpeed)) {
        speed = Translator.translateToLocal(unlocalizedCustomSpeed);
    } else {
        speed = speedAllele.getAlleleName() + ' ' + Translator.translateToLocal("for.gui.worker");
    }
    String lifespan = genome.getActiveAllele(EnumBeeChromosome.LIFESPAN).getAlleleName() + ' ' + Translator.translateToLocal("for.gui.life");
    String tempTolerance = TextFormatting.GREEN + "T: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempToleranceAllele.getAlleleName();
    String humidTolerance = TextFormatting.GREEN + "H: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidToleranceAllele.getAlleleName();
    String flowers = genome.getFlowerProvider().getDescription();
    list.add(lifespan);
    list.add(speed);
    list.add(tempTolerance);
    list.add(humidTolerance);
    list.add(flowers);
    if (genome.getNeverSleeps()) {
        list.add(TextFormatting.RED + GenericRatings.rateActivityTime(genome.getNeverSleeps(), false));
    }
    if (genome.getToleratesRain()) {
        list.add(TextFormatting.WHITE + Translator.translateToLocal("for.gui.flyer.tooltip"));
    }
}
Also used : IAlleleBeeSpecies(forestry.api.apiculture.IAlleleBeeSpecies) IAllele(forestry.api.genetics.IAllele) EnumRarity(net.minecraft.item.EnumRarity) IAlleleTolerance(forestry.api.genetics.IAlleleTolerance)

Example 8 with IAlleleTolerance

use of forestry.api.genetics.IAlleleTolerance in project ForestryMC by ForestryMC.

the class BeeDatabaseTab method createElements.

@Override
public void createElements(IGuiElementHelper elementHelper, IBee bee, ItemStack itemStack) {
    EnumBeeType type = BeeManager.beeRoot.getType(itemStack);
    if (type == null) {
        return;
    }
    IAlleleSpecies primarySpecies = bee.getGenome().getPrimary();
    boolean active = tab == EnumDatabaseTab.ACTIVE_SPECIES;
    elementHelper.addText(Translator.translateToLocal("for.gui.database.tab." + tab.name().toLowerCase() + ".name"), GuiElementAlignment.CENTER, 0xcfb53b);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.species"), bee, EnumBeeChromosome.SPECIES, active);
    IAlleleTolerance tempTolerance = (IAlleleTolerance) (active ? bee.getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE) : bee.getGenome().getInactiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.climate"), GuiElementAlignment.CENTER);
    elementHelper.addToleranceInfo(tempTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getTemperature()));
    IAlleleTolerance humidTolerance = (IAlleleTolerance) (active ? bee.getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE) : bee.getGenome().getInactiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.humidity"), GuiElementAlignment.CENTER);
    elementHelper.addToleranceInfo(humidTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getHumidity()));
    elementHelper.addAllele(Translator.translateToLocal("for.gui.lifespan"), bee, EnumBeeChromosome.LIFESPAN, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.speed"), bee, EnumBeeChromosome.SPEED, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.pollination"), bee, EnumBeeChromosome.FLOWERING, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.flowers"), bee, EnumBeeChromosome.FLOWER_PROVIDER, active);
    IAlleleInteger primaryFertility = (IAlleleInteger) (active ? bee.getGenome().getActiveAllele(EnumBeeChromosome.FERTILITY) : bee.getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.fertility"), GuiElementAlignment.CENTER);
    elementHelper.addFertilityInfo(primaryFertility, 0, 0);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.area"), bee, EnumBeeChromosome.TERRITORY, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.effect"), bee, EnumBeeChromosome.EFFECT, active);
    String yes = Translator.translateToLocal("for.yes");
    String no = Translator.translateToLocal("for.no");
    String diurnal, nocturnal;
    if (active) {
        if (bee.getGenome().getNeverSleeps()) {
            nocturnal = diurnal = yes;
        } else {
            nocturnal = bee.getGenome().getPrimary().isNocturnal() ? yes : no;
            diurnal = !bee.getGenome().getPrimary().isNocturnal() ? yes : no;
        }
    } else {
        if (((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumButterflyChromosome.NOCTURNAL)).getValue()) {
            nocturnal = diurnal = yes;
        } else {
            nocturnal = bee.getGenome().getSecondary().isNocturnal() ? yes : no;
            diurnal = !bee.getGenome().getSecondary().isNocturnal() ? yes : no;
        }
    }
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.diurnal"), GuiElementAlignment.CENTER);
    elementHelper.addText(diurnal, GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(false));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.nocturnal"), GuiElementAlignment.CENTER);
    elementHelper.addText(nocturnal, GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(false));
    String flyer = StringUtil.readableBoolean(active ? bee.getGenome().getToleratesRain() : ((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TOLERATES_RAIN)).getValue(), yes, no);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.flyer"), (a) -> flyer, bee, EnumButterflyChromosome.TOLERANT_FLYER, active);
    String cave = StringUtil.readableBoolean(active ? bee.getGenome().getCaveDwelling() : ((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.CAVE_DWELLING)).getValue(), yes, no);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.fireresist"), (a) -> cave, bee, EnumButterflyChromosome.FIRE_RESIST, active);
    String displayText;
    if (type == EnumBeeType.PRINCESS || type == EnumBeeType.QUEEN) {
        String displayTextKey = "for.bees.stock.pristine";
        if (!bee.isNatural()) {
            displayTextKey = "for.bees.stock.ignoble";
        }
        displayText = Translator.translateToLocal(displayTextKey);
        elementHelper.addText(displayText, GuiElementAlignment.CENTER, ColourProperties.INSTANCE.get("gui.beealyzer.binomial"));
    }
}
Also used : IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) IAlleleInteger(forestry.api.genetics.IAlleleInteger) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) EnumBeeType(forestry.api.apiculture.EnumBeeType) AlleleBoolean(forestry.core.genetics.alleles.AlleleBoolean)

Example 9 with IAlleleTolerance

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

IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)9 AlleleBoolean (forestry.core.genetics.alleles.AlleleBoolean)4 IAlleleInteger (forestry.api.genetics.IAlleleInteger)3 Tolerance (binnie.core.genetics.Tolerance)2 EnumBeeType (forestry.api.apiculture.EnumBeeType)2 IGenome (forestry.api.genetics.IGenome)2 IIndividual (forestry.api.genetics.IIndividual)2 IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)2 GuiAlyzer (forestry.core.gui.GuiAlyzer)2 TextLayoutHelper (forestry.core.gui.TextLayoutHelper)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 Gene (binnie.core.genetics.Gene)1 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IBee (forestry.api.apiculture.IBee)1 IAllele (forestry.api.genetics.IAllele)1 IAlleleBoolean (forestry.api.genetics.IAlleleBoolean)1 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)1 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 IButterfly (forestry.api.lepidopterology.IButterfly)1 FlowerProvider (forestry.apiculture.flowers.FlowerProvider)1