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);
}
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();
}
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();
}
}
}
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);
}
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())));
}
Aggregations