Search in sources :

Example 1 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class Butterfly method getCanGrow.

@Override
public Set<IErrorState> getCanGrow(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
    World world = nursery.getWorldObj();
    Set<IErrorState> errorStates = new HashSet<>();
    // / And finally climate check
    IAlleleButterflySpecies species = genome.getPrimary();
    EnumTemperature actualTemperature = nursery.getTemperature();
    EnumTemperature baseTemperature = species.getTemperature();
    EnumTolerance toleranceTemperature = genome.getToleranceTemp();
    EnumHumidity actualHumidity = nursery.getHumidity();
    EnumHumidity baseHumidity = species.getHumidity();
    EnumTolerance toleranceHumidity = genome.getToleranceHumid();
    ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
    return errorStates;
}
Also used : IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies) EnumTemperature(forestry.api.core.EnumTemperature)

Example 2 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class Butterfly method addTooltip.

@Override
public void addTooltip(List<String> list) {
    IAlleleButterflySpecies primary = genome.getPrimary();
    IAlleleButterflySpecies secondary = genome.getSecondary();
    if (!isPureBred(EnumButterflyChromosome.SPECIES)) {
        list.add(TextFormatting.BLUE + Translator.translateToLocal("for.butterflies.hybrid").replaceAll("%PRIMARY", primary.getAlleleName()).replaceAll("%SECONDARY", secondary.getAlleleName()));
    }
    if (getMate() != null) {
        list.add(TextFormatting.RED + Translator.translateToLocal("for.gui.fecundated").toUpperCase(Locale.ENGLISH));
    }
    list.add(TextFormatting.YELLOW + genome.getActiveAllele(EnumButterflyChromosome.SIZE).getAlleleName());
    list.add(TextFormatting.DARK_GREEN + genome.getActiveAllele(EnumButterflyChromosome.SPEED).getAlleleName());
    list.add(genome.getActiveAllele(EnumButterflyChromosome.LIFESPAN).getAlleleName() + ' ' + Translator.translateToLocal("for.gui.life"));
    IAlleleTolerance tempTolerance = (IAlleleTolerance) getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE);
    list.add(TextFormatting.GREEN + "T: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / " + tempTolerance.getAlleleName());
    IAlleleTolerance humidTolerance = (IAlleleTolerance) getGenome().getActiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE);
    list.add(TextFormatting.GREEN + "H: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / " + humidTolerance.getAlleleName());
    list.add(TextFormatting.RED + GenericRatings.rateActivityTime(genome.getNocturnal(), genome.getPrimary().isNocturnal()));
    if (genome.getTolerantFlyer()) {
        list.add(TextFormatting.WHITE + Translator.translateToLocal("for.gui.flyer.tooltip"));
    }
}
Also used : IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies)

Example 3 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class Butterfly method getCanSpawn.

@Override
public Set<IErrorState> getCanSpawn(IButterflyNursery nursery, @Nullable IButterflyCocoon cocoon) {
    World world = nursery.getWorldObj();
    Set<IErrorState> errorStates = new HashSet<>();
    // / Night or darkness requires nocturnal species
    boolean isDaytime = world.isDaytime();
    if (!isActiveThisTime(isDaytime)) {
        if (isDaytime) {
            errorStates.add(EnumErrorCode.NOT_NIGHT);
        } else {
            errorStates.add(EnumErrorCode.NOT_DAY);
        }
    }
    // / And finally climate check
    IAlleleButterflySpecies species = genome.getPrimary();
    EnumTemperature actualTemperature = nursery.getTemperature();
    EnumTemperature baseTemperature = species.getTemperature();
    EnumTolerance toleranceTemperature = genome.getToleranceTemp();
    EnumHumidity actualHumidity = nursery.getHumidity();
    EnumHumidity baseHumidity = species.getHumidity();
    EnumTolerance toleranceHumidity = genome.getToleranceHumid();
    ClimateUtil.addClimateErrorStates(actualTemperature, actualHumidity, baseTemperature, toleranceTemperature, baseHumidity, toleranceHumidity, errorStates);
    return errorStates;
}
Also used : IErrorState(forestry.api.core.IErrorState) EnumTolerance(forestry.api.genetics.EnumTolerance) EnumHumidity(forestry.api.core.EnumHumidity) World(net.minecraft.world.World) HashSet(java.util.HashSet) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies) EnumTemperature(forestry.api.core.EnumTemperature)

Example 4 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class ButterflyDatabaseTab method createElements.

@Override
public void createElements(IGuiElementHelper elementHelper, IButterfly butterfly, ItemStack itemStack) {
    boolean active = tab == EnumDatabaseTab.ACTIVE_SPECIES;
    IAlleleButterflySpecies primarySpecies = butterfly.getGenome().getPrimary();
    elementHelper.addText(Translator.translateToLocal("for.gui.database.tab." + tab.name().toLowerCase() + ".name"), GuiElementAlignment.CENTER, 0xcfb53b);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.species"), butterfly, EnumButterflyChromosome.SPECIES, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.size"), butterfly, EnumButterflyChromosome.SIZE, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.lifespan"), butterfly, EnumButterflyChromosome.LIFESPAN, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.speed"), butterfly, EnumButterflyChromosome.SPEED, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.metabolism"), (IAlleleInteger a) -> GenericRatings.rateMetabolism(a.getValue()), butterfly, EnumButterflyChromosome.METABOLISM, active);
    IAlleleInteger fertility = (IAlleleInteger) (active ? butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.FERTILITY) : butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FERTILITY));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.fertility"), GuiElementAlignment.CENTER);
    elementHelper.addFertilityInfo(fertility, 0, 8);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.flowers"), butterfly, EnumButterflyChromosome.FLOWER_PROVIDER, active);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.effect"), butterfly, EnumButterflyChromosome.EFFECT, active);
    IAlleleTolerance tempTolerance = (IAlleleTolerance) (active ? butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.TEMPERATURE_TOLERANCE) : butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.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 ? butterfly.getGenome().getActiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE) : butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.HUMIDITY_TOLERANCE));
    elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.humidity"), GuiElementAlignment.CENTER);
    elementHelper.addToleranceInfo(humidTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getHumidity()));
    String yes = Translator.translateToLocal("for.yes");
    String no = Translator.translateToLocal("for.no");
    String diurnal, nocturnal;
    if (active) {
        if (butterfly.getGenome().getNocturnal()) {
            nocturnal = diurnal = yes;
        } else {
            nocturnal = butterfly.getGenome().getPrimary().isNocturnal() ? yes : no;
            diurnal = !butterfly.getGenome().getPrimary().isNocturnal() ? yes : no;
        }
    } else {
        if (((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.NOCTURNAL)).getValue()) {
            nocturnal = diurnal = yes;
        } else {
            nocturnal = butterfly.getGenome().getSecondary().isNocturnal() ? yes : no;
            diurnal = !butterfly.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 ? butterfly.getGenome().getTolerantFlyer() : ((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.TOLERANT_FLYER)).getValue(), yes, no);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.flyer"), (a) -> flyer, butterfly, EnumButterflyChromosome.TOLERANT_FLYER, active);
    String fireresist = StringUtil.readableBoolean(active ? butterfly.getGenome().getFireResist() : ((AlleleBoolean) butterfly.getGenome().getInactiveAllele(EnumButterflyChromosome.FIRE_RESIST)).getValue(), yes, no);
    elementHelper.addAllele(Translator.translateToLocal("for.gui.fireresist"), (a) -> fireresist, butterfly, EnumButterflyChromosome.FIRE_RESIST, active);
}
Also used : IAlleleTolerance(forestry.api.genetics.IAlleleTolerance) IAlleleInteger(forestry.api.genetics.IAlleleInteger) AlleleBoolean(forestry.core.genetics.alleles.AlleleBoolean) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies)

Example 5 with IAlleleButterflySpecies

use of forestry.api.lepidopterology.IAlleleButterflySpecies in project ForestryMC by ForestryMC.

the class ButterflyGenome method getSpecies.

// NBT RETRIEVAL
public static IAlleleButterflySpecies getSpecies(ItemStack itemStack) {
    Preconditions.checkArgument(ButterflyManager.butterflyRoot.isMember(itemStack), "Must be a butterfly");
    IAlleleSpecies species = getSpeciesDirectly(ButterflyManager.butterflyRoot, itemStack);
    if (species instanceof IAlleleButterflySpecies) {
        return (IAlleleButterflySpecies) species;
    }
    return (IAlleleButterflySpecies) getActiveAllele(itemStack, EnumButterflyChromosome.SPECIES, ButterflyManager.butterflyRoot);
}
Also used : IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) IAlleleButterflySpecies(forestry.api.lepidopterology.IAlleleButterflySpecies)

Aggregations

IAlleleButterflySpecies (forestry.api.lepidopterology.IAlleleButterflySpecies)7 EnumHumidity (forestry.api.core.EnumHumidity)2 EnumTemperature (forestry.api.core.EnumTemperature)2 IErrorState (forestry.api.core.IErrorState)2 EnumTolerance (forestry.api.genetics.EnumTolerance)2 IAllele (forestry.api.genetics.IAllele)2 IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)2 HashSet (java.util.HashSet)2 World (net.minecraft.world.World)2 IAlleleInteger (forestry.api.genetics.IAlleleInteger)1 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)1 AlleleBoolean (forestry.core.genetics.alleles.AlleleBoolean)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Property (net.minecraftforge.common.config.Property)1