Add self-pollination of leaves near bees

This commit is contained in:
temp1011 committed 2018-02-24 18:04:17 +00:00
1 parent e9019fd8c3
commit 7dba583c26
4 files changed
+59

No files matched your search

@@ -114,5 +114,10 @@ public interface IBee extends IIndividualLiving {
IIndividual retrievePollen(IBeeHousing housing);
boolean pollinateRandom(IBeeHousing housing, IIndividual pollen);
//TODO - implement fully in 1.13
default void selfPollinate(IBeeHousing housing) {
return;
}
}
@@ -50,6 +50,7 @@ import forestry.api.core.IErrorLogic;
import forestry.api.core.IErrorState;
import forestry.api.genetics.IEffectData;
import forestry.api.genetics.IIndividual;
import forestry.apiculture.genetics.Bee;
import forestry.apiculture.network.packets.PacketBeeLogicActive;
import forestry.apiculture.network.packets.PacketBeeLogicActiveEntity;
import forestry.core.config.Constants;
@@ -570,6 +571,11 @@ public class BeekeepingLogic implements IBeekeepingLogic {
pollen = null;
}
}
//Other things may implement IBee
if(ModuleApiculture.doSelfPollination) {
queen.selfPollinate(beeHousing);
}
}
}
@@ -156,6 +156,8 @@ public class ModuleApiculture extends BlankForestryModule {
public static boolean hivesDamageOnPeaceful = false;
public static boolean doSelfPollination = true;
public static int maxFlowersSpawnedPerHive = 20;
@Nullable
public static VillagerRegistry.VillagerProfession villagerApiarist;
@@ -278,6 +280,8 @@ public class ModuleApiculture extends BlankForestryModule {
ticksPerBeeWorkCycle = config.getIntLocalized("beekeeping", "ticks.work", 550, 250, 850);
hivesDamageOnPeaceful = config.getBooleanLocalized("beekeeping", "hivedamage.peaceful", false);
doSelfPollination = config.getBooleanLocalized("beekeeping", "self.pollination", false);
config.save();
@@ -729,6 +729,50 @@ public class Bee extends IndividualLiving implements IBee {
return false;
}
public void selfPollinate(IBeeHousing housing) {
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
int chance = (int) (genome.getFlowering() * beeModifier.getFloweringModifier(getGenome(), 1f));
World world = housing.getWorldObj();
Random random = world.rand;
// Correct speed
if (random.nextInt(100) >= chance) {
return;
}
Vec3i area = getArea(genome, beeModifier);
Vec3i offset = new Vec3i(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
BlockPos housingPos = housing.getCoordinates();
for (int i = 0; i < 10; i++) {
BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
BlockPos posBlock = VectUtil.add(housingPos, randomPos, offset);
ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(world, posBlock);
if (checkPollinatable == null) {
continue;
}
if (!genome.getFlowerProvider().isAcceptedPollinatable(world, checkPollinatable)) {
continue;
}
if (!checkPollinatable.canMateWith(checkPollinatable.getPollen())) {
continue;
}
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwner(), world, posBlock, Config.pollinateVanillaTrees);
if (realPollinatable != null) {
realPollinatable.mateWith(realPollinatable.getPollen());
return;
}
}
}
@Override
public void plantFlowerRandom(IBeeHousing housing) {
plantFlowerRandom(housing, null);