Search in sources :

Example 1 with IBeeGenome

use of forestry.api.apiculture.IBeeGenome in project ForestryMC by ForestryMC.

the class ItemInventoryImprinter method getSelectedBee.

public IBee getSelectedBee() {
    IBeeRoot beeRoot = BeeManager.beeRoot;
    List<IBee> individualTemplates = beeRoot.getIndividualTemplates();
    Map<String, IAllele[]> genomeTemplates = beeRoot.getGenomeTemplates();
    IAllele[] templateActive = genomeTemplates.get(individualTemplates.get(primaryIndex).getIdent());
    IAllele[] templateInactive = genomeTemplates.get(individualTemplates.get(secondaryIndex).getIdent());
    IBeeGenome genome = beeRoot.templateAsGenome(templateActive, templateInactive);
    return new Bee(genome);
}
Also used : IAllele(forestry.api.genetics.IAllele) IBee(forestry.api.apiculture.IBee) Bee(forestry.apiculture.genetics.Bee) IBeeRoot(forestry.api.apiculture.IBeeRoot) IBee(forestry.api.apiculture.IBee) IBeeGenome(forestry.api.apiculture.IBeeGenome)

Example 2 with IBeeGenome

use of forestry.api.apiculture.IBeeGenome in project ForestryMC by ForestryMC.

the class BeekeepingLogic method queenWorkTick.

private void queenWorkTick(@Nullable IBee queen, ItemStack queenStack) {
    if (queen == null) {
        beeProgress = 0;
        beeProgressMax = 0;
        return;
    }
    // Effects only fire when queen can work.
    effectData = queen.doEffect(effectData, housing);
    // Work cycles are throttled, rather than occurring every game tick.
    queenWorkCycleThrottle++;
    if (queenWorkCycleThrottle >= ModuleApiculture.ticksPerBeeWorkCycle) {
        queenWorkCycleThrottle = 0;
        doProduction(queen, housing, beeListener);
        World world = housing.getWorldObj();
        List<IBlockState> flowers = hasFlowersCache.getFlowers(world);
        if (flowers.size() < ModuleApiculture.maxFlowersSpawnedPerHive) {
            BlockPos blockPos = queen.plantFlowerRandom(housing, flowers);
            if (blockPos != null) {
                hasFlowersCache.addFlowerPos(blockPos);
            }
        }
        pollenHandler.doPollination(queen, housing, beeListener);
        // Age the queen
        IBeeGenome mate = queen.getMate();
        Preconditions.checkState(mate != null);
        float lifespanModifier = beeModifier.getLifespanModifier(queen.getGenome(), mate, 1.0f);
        queen.age(world, lifespanModifier);
        // Write the changed queen back into the item stack.
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        queen.writeToNBT(nbttagcompound);
        queenStack.setTagCompound(nbttagcompound);
        housing.getBeeInventory().setQueen(queenStack);
    }
    beeProgress = queen.getHealth();
    beeProgressMax = queen.getMaxHealth();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) IBeeGenome(forestry.api.apiculture.IBeeGenome)

Example 3 with IBeeGenome

use of forestry.api.apiculture.IBeeGenome in project ForestryMC by ForestryMC.

the class HasFlowersCache method onNewQueen.

public void onNewQueen(IBee queen, IBeeHousing housing) {
    if (this.flowerData != null) {
        IBeeGenome genome = queen.getGenome();
        String flowerType = genome.getFlowerProvider().getFlowerType();
        if (!this.flowerData.flowerType.equals(flowerType) || !this.flowerData.territory.equals(genome.getTerritory())) {
            flowerData = new FlowerData(queen, housing);
            flowerCoords.clear();
            flowers.clear();
        }
    }
}
Also used : IBeeGenome(forestry.api.apiculture.IBeeGenome)

Example 4 with IBeeGenome

use of forestry.api.apiculture.IBeeGenome in project ForestryMC by ForestryMC.

the class Bee method createOffspring.

private IBee createOffspring(IBeeHousing housing, IBeeGenome mate, int generation) {
    World world = housing.getWorldObj();
    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 occurred.
    IChromosome[] mutated1 = mutateSpecies(housing, genome, mate);
    if (mutated1 != null) {
        parent1 = mutated1;
    }
    IChromosome[] mutated2 = mutateSpecies(housing, mate, genome);
    if (mutated2 != null) {
        parent2 = mutated2;
    }
    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]);
        }
    }
    IBeekeepingMode mode = BeeManager.beeRoot.getBeekeepingMode(world);
    return new Bee(new BeeGenome(chromosomes), mode.isNaturalOffspring(this), generation);
}
Also used : IBeeGenome(forestry.api.apiculture.IBeeGenome) IBee(forestry.api.apiculture.IBee) IChromosome(forestry.api.genetics.IChromosome) IBeekeepingMode(forestry.api.apiculture.IBeekeepingMode) World(net.minecraft.world.World)

Example 5 with IBeeGenome

use of forestry.api.apiculture.IBeeGenome in project ForestryMC by ForestryMC.

the class VillageApiaristHouse method getRandomVillageBee.

private static IBee getRandomVillageBee(World world, BlockPos pos) {
    // Get current biome
    Biome biome = world.getBiome(pos);
    List<IBeeGenome> candidates;
    if (BeeManager.uncommonVillageBees != null && !BeeManager.uncommonVillageBees.isEmpty() && world.rand.nextDouble() < 0.2) {
        candidates = BeeManager.uncommonVillageBees;
    } else {
        candidates = BeeManager.commonVillageBees;
    }
    EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome, world, pos);
    EnumHumidity biomeHumidity = EnumHumidity.getFromValue(biome.getRainfall());
    // Add bees that can live in this environment
    List<IBeeGenome> valid = new ArrayList<>();
    for (IBeeGenome genome : candidates) {
        if (checkBiomeHazard(genome, biomeTemperature, biomeHumidity)) {
            valid.add(genome);
        }
    }
    // No valid ones found, return any of the common ones.
    if (valid.isEmpty()) {
        int index = world.rand.nextInt(BeeManager.commonVillageBees.size());
        IBeeGenome genome = BeeManager.commonVillageBees.get(index);
        return BeeManager.beeRoot.getBee(genome);
    }
    return BeeManager.beeRoot.getBee(valid.get(world.rand.nextInt(valid.size())));
}
Also used : Biome(net.minecraft.world.biome.Biome) ArrayList(java.util.ArrayList) EnumHumidity(forestry.api.core.EnumHumidity) IBeeGenome(forestry.api.apiculture.IBeeGenome) EnumTemperature(forestry.api.core.EnumTemperature)

Aggregations

IBeeGenome (forestry.api.apiculture.IBeeGenome)13 IBee (forestry.api.apiculture.IBee)7 IAllele (forestry.api.genetics.IAllele)4 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 IChromosome (forestry.api.genetics.IChromosome)2 ArrayList (java.util.ArrayList)2 GameProfile (com.mojang.authlib.GameProfile)1 EnumBeeType (forestry.api.apiculture.EnumBeeType)1 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IApiaristTracker (forestry.api.apiculture.IApiaristTracker)1 IBeeMutation (forestry.api.apiculture.IBeeMutation)1 IBeeRoot (forestry.api.apiculture.IBeeRoot)1 IBeekeepingMode (forestry.api.apiculture.IBeekeepingMode)1 EnumHumidity (forestry.api.core.EnumHumidity)1 EnumTemperature (forestry.api.core.EnumTemperature)1 EnumTolerance (forestry.api.genetics.EnumTolerance)1 IMutation (forestry.api.genetics.IMutation)1 Bee (forestry.apiculture.genetics.Bee)1 Map (java.util.Map)1