Search in sources :

Example 1 with IFlowerGenome

use of binnie.botany.api.genetics.IFlowerGenome in project Binnie by ForestryMC.

the class Flower method mutateSpecies.

private IChromosome[] mutateSpecies(World world, BlockPos pos, IFlowerGenome genomeFirst, IFlowerGenome genomeSecond) {
    IChromosome[] parentFirst = genomeFirst.getChromosomes();
    IChromosome[] parentSecond = genomeSecond.getChromosomes();
    IAlleleFlowerSpecies alleleFirst;
    IAlleleFlowerSpecies alleleSecond;
    IFlowerGenome genome0;
    IFlowerGenome genome2;
    if (world.rand.nextBoolean()) {
        alleleFirst = (IAlleleFlowerSpecies) parentFirst[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        alleleSecond = (IAlleleFlowerSpecies) parentSecond[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeFirst;
        genome2 = genomeSecond;
    } else {
        alleleFirst = (IAlleleFlowerSpecies) parentSecond[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        alleleSecond = (IAlleleFlowerSpecies) parentFirst[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeSecond;
        genome2 = genomeFirst;
    }
    IFlowerColor colorFirst = genome0.getPrimaryColor();
    IFlowerColor colorSecond = genome2.getPrimaryColor();
    if (colorFirst != colorSecond) {
        for (IColorMix mutation : BotanyCore.getFlowerRoot().getColorMixes(true)) {
            if (mutation.isMutation(colorFirst, colorSecond) && world.rand.nextFloat() * 100.0f < mutation.getChance()) {
                parentFirst[EnumFlowerChromosome.PRIMARY.ordinal()] = new Chromosome(mutation.getResult().getAllele());
            }
        }
    }
    colorFirst = genome0.getSecondaryColor();
    colorSecond = genome2.getSecondaryColor();
    if (colorFirst != colorSecond) {
        for (IColorMix mutation : BotanyCore.getFlowerRoot().getColorMixes(true)) {
            if (mutation.isMutation(colorFirst, colorSecond) && world.rand.nextFloat() * 100.0f < mutation.getChance()) {
                parentFirst[EnumFlowerChromosome.SECONDARY.ordinal()] = new Chromosome(mutation.getResult().getAllele());
            }
        }
    }
    colorFirst = genome0.getStemColor();
    colorSecond = genome2.getStemColor();
    if (colorFirst != colorSecond) {
        for (IColorMix mutation : BotanyCore.getFlowerRoot().getColorMixes(true)) {
            if (mutation.isMutation(colorFirst, colorSecond) && world.rand.nextFloat() * 100.0f < mutation.getChance()) {
                parentFirst[EnumFlowerChromosome.STEM.ordinal()] = new Chromosome(mutation.getResult().getAllele());
            }
        }
    }
    IChromosome[] template = null;
    for (IFlowerMutation mutation2 : BotanyCore.getFlowerRoot().getMutations(true)) {
        float chance = mutation2.getChance(world, pos, alleleFirst, alleleSecond, genome0, genome2);
        if (chance > 0.0f && world.rand.nextFloat() * 100.0f < chance && template == null) {
            template = BotanyCore.getFlowerRoot().templateAsChromosomes(mutation2.getTemplate());
        }
    }
    if (template != null) {
        parentFirst = template;
    }
    return parentFirst;
}
Also used : IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) IColorMix(binnie.botany.api.genetics.IColorMix) IFlowerMutation(binnie.botany.api.genetics.IFlowerMutation) IChromosome(forestry.api.genetics.IChromosome) IFlowerColor(binnie.botany.api.genetics.IFlowerColor) Chromosome(forestry.core.genetics.Chromosome) IChromosome(forestry.api.genetics.IChromosome) EnumTreeChromosome(forestry.api.arboriculture.EnumTreeChromosome) EnumFlowerChromosome(binnie.botany.api.genetics.EnumFlowerChromosome) IAlleleFlowerSpecies(binnie.botany.api.genetics.IAlleleFlowerSpecies)

Example 2 with IFlowerGenome

use of binnie.botany.api.genetics.IFlowerGenome in project Binnie by ForestryMC.

the class PageSpeciesFlowerGenome method onValueChanged.

@Override
public void onValueChanged(IAlleleSpecies species) {
    deleteAllChildren();
    IAllele[] template = BotanyAPI.flowerRoot.getTemplate(species.getUID());
    if (template == null) {
        return;
    }
    IFlower flower = BotanyAPI.flowerRoot.templateAsIndividual(template);
    IFlowerGenome genome = flower.getGenome();
    IAlleleFlowerSpecies flowerSpecies = genome.getPrimary();
    int w = 144;
    int h = 176;
    new ControlText(this, new Area(0, 4, w, 16), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".title"), TextJustification.MIDDLE_CENTER);
    ControlScrollableContent scrollable = new ControlScrollableContent(this, 4, 20, w - 8, h - 8 - 16, 12);
    Control contents = new Control(scrollable, 0, 0, w - 8 - 12, h - 8 - 16);
    int tw = w - 8 - 12;
    int w2 = 55;
    int w3 = tw - 50;
    int y = 0;
    int th = 14;
    int th2 = 18;
    new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".temp"), TextJustification.MIDDLE_RIGHT);
    new ControlText(contents, new Area(w2, y, w3, th), flowerSpecies.getTemperature().getName(), TextJustification.MIDDLE_LEFT);
    y += th;
    new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".moist"), TextJustification.MIDDLE_RIGHT);
    new ControlText(contents, new Area(w2, y, w3, th), EnumHelper.getLocalisedName(flowerSpecies.getMoisture(), false), TextJustification.MIDDLE_LEFT);
    y += th;
    new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".ph"), TextJustification.MIDDLE_RIGHT);
    new ControlText(contents, new Area(w2, y, w3, th), EnumHelper.getLocalisedName(flowerSpecies.getPH(), false), TextJustification.MIDDLE_LEFT);
    y += th;
    new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".fertility"), TextJustification.MIDDLE_RIGHT);
    new ControlText(contents, new Area(w2, y, w3, th), genome.getFertility() + "x", TextJustification.MIDDLE_LEFT);
    y += th;
    float lifespan = genome.getLifespan() * 68.27f / genome.getAgeChance() / 24000.0f;
    String lifespanValue = String.format("%.2f", lifespan);
    new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".lifespan"), TextJustification.MIDDLE_RIGHT);
    new ControlText(contents, new Area(w2, y, w3, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".lifespan.value", lifespanValue), TextJustification.MIDDLE_LEFT);
    y += th;
    new ControlText(contents, new Area(0, y, w2, th), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".nectar"), TextJustification.MIDDLE_RIGHT);
    new ControlText(contents, new Area(w2, y, w3, th), genome.getActiveAllele(EnumFlowerChromosome.SAPPINESS).getAlleleName(), TextJustification.MIDDLE_LEFT);
    y += th;
    int x = w2;
    int tot = 0;
    for (IIndividual vid : BotanyCore.getFlowerRoot().getIndividualTemplates()) {
        if (vid.getGenome().getPrimary() == flowerSpecies) {
            if (tot > 0 && tot % 3 == 0) {
                x -= 54;
                y += 18;
            }
            ItemStack stack = BotanyCore.getFlowerRoot().getMemberStack(vid, EnumFlowerStage.FLOWER);
            ControlItemDisplay display = new ControlItemDisplay(contents, x, y);
            display.setItemStack(stack);
            ++tot;
            x += 18;
        }
    }
    int numOfLines = 1 + (tot - 1) / 3;
    new ControlText(contents, new Area(0, y - (numOfLines - 1) * 18, w2, 4 + 18 * numOfLines), I18N.localise(DatabaseConstants.BOTANY_GENOME_KEY + ".varieties"), TextJustification.MIDDLE_RIGHT);
    y += th;
    contents.setSize(new Point(contents.getSize().xPos(), y));
    scrollable.setScrollableContent(contents);
}
Also used : IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) ControlItemDisplay(binnie.core.gui.minecraft.control.ControlItemDisplay) IFlower(binnie.botany.api.genetics.IFlower) IIndividual(forestry.api.genetics.IIndividual) ControlText(binnie.core.gui.controls.ControlText) Point(binnie.core.gui.geometry.Point) IAlleleFlowerSpecies(binnie.botany.api.genetics.IAlleleFlowerSpecies) Point(binnie.core.gui.geometry.Point) IAllele(forestry.api.genetics.IAllele) Area(binnie.core.gui.geometry.Area) Control(binnie.core.gui.controls.core.Control) ItemStack(net.minecraft.item.ItemStack) ControlScrollableContent(binnie.core.gui.controls.scroll.ControlScrollableContent)

Example 3 with IFlowerGenome

use of binnie.botany.api.genetics.IFlowerGenome in project Binnie by ForestryMC.

the class ItemFlowerGE method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemStack, @Nullable World worldIn, List<String> list, ITooltipFlag flagIn) {
    IFlower individual = (IFlower) getIndividual(itemStack);
    if (individual == null) {
        list.add(TextFormatting.DARK_RED + I18N.localise("item.botany.flower.destroy"));
        return;
    }
    IFlowerGenome genome = individual.getGenome();
    // Colors
    String primaryColor = genome.getPrimaryColor().getColorName();
    String secondaryColor = genome.getSecondaryColor().getColorName();
    String stemColor = genome.getStemColor().getColorName();
    String colorInfo;
    if (!primaryColor.equals(secondaryColor)) {
        colorInfo = I18N.localise("item.botany.grammar.flower.secondary", primaryColor, secondaryColor, stemColor);
    } else {
        colorInfo = I18N.localise("item.botany.grammar.flower", primaryColor, stemColor);
    }
    list.add(TextFormatting.YELLOW + colorInfo);
    if (individual.isAnalyzed()) {
        if (GuiScreen.isShiftKeyDown()) {
            individual.addTooltip(list);
        } else {
            list.add(TextFormatting.ITALIC + "<" + I18N.localise("for.gui.tooltip.tmi") + '>');
        }
    } else {
        list.add('<' + I18N.localise("for.gui.unknown") + '>');
    }
}
Also used : IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) IFlower(binnie.botany.api.genetics.IFlower) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with IFlowerGenome

use of binnie.botany.api.genetics.IFlowerGenome in project Binnie by ForestryMC.

the class BlockFlower method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItemMainhand();
    if (heldItem.isEmpty() || heldItem.getItem() != BinnieCore.getFieldKit() || !player.isSneaking()) {
        return false;
    }
    if (world.isRemote) {
        return true;
    }
    TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntityFlower)) {
        return true;
    }
    TileEntityFlower tileFlower = (TileEntityFlower) tile;
    IFlower flower = tileFlower.getFlower();
    if (flower == null) {
        return true;
    }
    IFlowerGenome flowerGenome = flower.getGenome();
    NBTTagCompound info = new NBTTagCompound();
    info.setString("Species", flowerGenome.getPrimary().getUID());
    info.setString("Species2", flowerGenome.getSecondary().getUID());
    info.setFloat("Age", flower.getAge() / flowerGenome.getLifespan());
    info.setShort("Colour", (short) flowerGenome.getPrimaryColor().getID());
    info.setShort("Colour2", (short) flowerGenome.getSecondaryColor().getID());
    info.setBoolean("Wilting", flower.isWilted());
    info.setBoolean("Flowered", flower.hasFlowered());
    Botany.proxy.sendToPlayer(new MessageNBT(PacketID.FIELDKIT.ordinal(), info), player);
    heldItem.damageItem(1, player);
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) MessageNBT(binnie.core.network.packet.MessageNBT) IFlower(binnie.botany.api.genetics.IFlower) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TileEntityFlower(binnie.botany.tile.TileEntityFlower)

Example 5 with IFlowerGenome

use of binnie.botany.api.genetics.IFlowerGenome in project Binnie by ForestryMC.

the class TileEntityFlower method plantOffspring.

private void plantOffspring(Random rand, float chanceDispersal) {
    if (world.rand.nextFloat() < chanceDispersal && flower.hasFlowered() && !flower.isWilted()) {
        IFlowerGenome mate = flower.getMate();
        if (mate != null) {
            boolean dispersed = false;
            for (int tries = 0; tries < 5 && !dispersed; ++tries) {
                int x = rand.nextInt(3) - 1;
                int z = rand.nextInt(3) - 1;
                Block b2 = world.getBlockState(pos.add(x, -1, z)).getBlock();
                if (world.isAirBlock(pos.add(x, 0, z)) && BotanyCore.getGardening().isSoil(b2)) {
                    IFlower offspring = flower.getOffspring(world, pos);
                    if (offspring != null) {
                        BotanyCore.getFlowerRoot().plant(world, pos.add(x, 0, z), offspring, getOwner());
                        flower.removeMate();
                        dispersed = true;
                    }
                }
            }
        }
    }
}
Also used : IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) IFlower(binnie.botany.api.genetics.IFlower) Block(net.minecraft.block.Block)

Aggregations

IFlowerGenome (binnie.botany.api.genetics.IFlowerGenome)5 IFlower (binnie.botany.api.genetics.IFlower)4 IAlleleFlowerSpecies (binnie.botany.api.genetics.IAlleleFlowerSpecies)2 ItemStack (net.minecraft.item.ItemStack)2 EnumFlowerChromosome (binnie.botany.api.genetics.EnumFlowerChromosome)1 IColorMix (binnie.botany.api.genetics.IColorMix)1 IFlowerColor (binnie.botany.api.genetics.IFlowerColor)1 IFlowerMutation (binnie.botany.api.genetics.IFlowerMutation)1 TileEntityFlower (binnie.botany.tile.TileEntityFlower)1 ControlText (binnie.core.gui.controls.ControlText)1 Control (binnie.core.gui.controls.core.Control)1 ControlScrollableContent (binnie.core.gui.controls.scroll.ControlScrollableContent)1 Area (binnie.core.gui.geometry.Area)1 Point (binnie.core.gui.geometry.Point)1 ControlItemDisplay (binnie.core.gui.minecraft.control.ControlItemDisplay)1 MessageNBT (binnie.core.network.packet.MessageNBT)1 EnumTreeChromosome (forestry.api.arboriculture.EnumTreeChromosome)1 IAllele (forestry.api.genetics.IAllele)1 IChromosome (forestry.api.genetics.IChromosome)1 IIndividual (forestry.api.genetics.IIndividual)1