Search in sources :

Example 6 with IPollinatable

use of forestry.api.genetics.IPollinatable in project ForestryMC by ForestryMC.

the class GeneticsUtil method getCheckPollinatable.

/**
 * Returns an ICheckPollinatable that can be checked but not mated.
 * Used to check for pollination traits without altering the world by changing vanilla leaves to forestry ones.
 */
@Nullable
public static ICheckPollinatable getCheckPollinatable(World world, final BlockPos pos) {
    IPollinatable tile = TileUtil.getTile(world, pos, IPollinatable.class);
    if (tile != null) {
        return tile;
    }
    IIndividual pollen = getPollen(world, pos);
    if (pollen != null) {
        ISpeciesRoot root = pollen.getGenome().getSpeciesRoot();
        if (root instanceof ISpeciesRootPollinatable) {
            return ((ISpeciesRootPollinatable) root).createPollinatable(pollen);
        }
    }
    return null;
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) ISpeciesRootPollinatable(forestry.api.genetics.ISpeciesRootPollinatable) IPollinatable(forestry.api.genetics.IPollinatable) Nullable(javax.annotation.Nullable)

Example 7 with IPollinatable

use of forestry.api.genetics.IPollinatable in project ForestryMC by ForestryMC.

the class Bee method pollinateRandom.

@Override
public boolean pollinateRandom(IBeeHousing housing, IIndividual pollen) {
    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 false;
    }
    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 < 30; 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(pollen)) {
            continue;
        }
        IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwner(), world, posBlock, Config.pollinateVanillaTrees);
        if (realPollinatable != null) {
            realPollinatable.mateWith(pollen);
            return true;
        }
    }
    return false;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) IBeeModifier(forestry.api.apiculture.IBeeModifier) Random(java.util.Random) IPollinatable(forestry.api.genetics.IPollinatable) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

IPollinatable (forestry.api.genetics.IPollinatable)7 ICheckPollinatable (forestry.api.genetics.ICheckPollinatable)3 IIndividual (forestry.api.genetics.IIndividual)2 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)2 ISpeciesRootPollinatable (forestry.api.genetics.ISpeciesRootPollinatable)2 Nullable (javax.annotation.Nullable)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IFlower (binnie.botany.api.genetics.IFlower)1 IBeeModifier (forestry.api.apiculture.IBeeModifier)1 PacketFXSignal (forestry.core.network.packets.PacketFXSignal)1 Random (java.util.Random)1 IBlockState (net.minecraft.block.state.IBlockState)1 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3i (net.minecraft.util.math.Vec3i)1 World (net.minecraft.world.World)1