Search in sources :

Example 1 with ICheckPollinatable

use of forestry.arboriculture.genetics.ICheckPollinatable in project ForestryMC by ForestryMC.

the class AIButterflyPollinate method updateTask.

@Override
public void updateTask() {
    if (continueExecuting()) {
        ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(entity.worldObj, rest.posX, rest.posY, rest.posZ);
        if (checkPollinatable != null) {
            if (entity.getPollen() == null) {
                entity.setPollen(checkPollinatable.getPollen());
            // Proxies.log.finest("A butterfly '%s' grabbed a pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ);
            } else if (checkPollinatable.canMateWith(entity.getPollen())) {
                IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
                if (realPollinatable != null) {
                    realPollinatable.mateWith(entity.getPollen());
                    // Proxies.log.finest("A butterfly '%s' unloaded pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ);
                    entity.setPollen(null);
                }
            }
        }
        setHasInteracted();
        entity.cooldownPollination = EntityButterfly.COOLDOWNS;
    }
}
Also used : ICheckPollinatable(forestry.arboriculture.genetics.ICheckPollinatable) IPollinatable(forestry.api.genetics.IPollinatable)

Example 2 with ICheckPollinatable

use of forestry.arboriculture.genetics.ICheckPollinatable 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.
 */
public static ICheckPollinatable getCheckPollinatable(World world, final int x, final int y, final int z) {
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile instanceof IPollinatable) {
        return new CheckPollinatable((IPollinatable) tile);
    }
    ITree pollen = getErsatzPollen(world, x, y, z);
    if (pollen != null) {
        return new CheckPollinatableTree(pollen);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPollinatable(forestry.api.genetics.IPollinatable) ITree(forestry.api.arboriculture.ITree) ICheckPollinatable(forestry.arboriculture.genetics.ICheckPollinatable) CheckPollinatable(forestry.arboriculture.genetics.CheckPollinatable) CheckPollinatableTree(forestry.arboriculture.genetics.CheckPollinatableTree)

Example 3 with ICheckPollinatable

use of forestry.arboriculture.genetics.ICheckPollinatable in project ForestryMC by ForestryMC.

the class Bee method pollinateRandom.

@Override
public boolean pollinateRandom(IBeeHousing housing, IIndividual pollen) {
    int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f));
    World world = housing.getWorld();
    Random random = world.rand;
    // Correct speed
    if (random.nextInt(100) >= chance) {
        return false;
    }
    Vect area = getArea(genome, housing);
    Vect offset = new Vect(-area.x / 2, -area.y / 4, -area.z / 2);
    Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
    for (int i = 0; i < 30; i++) {
        Vect randomPos = Vect.getRandomPositionInArea(random, area);
        Vect posBlock = Vect.add(housingPos, randomPos, offset);
        ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(world, posBlock.x, posBlock.y, posBlock.z);
        if (checkPollinatable == null) {
            continue;
        }
        if (!genome.getFlowerProvider().isAcceptedPollinatable(world, new FakePollinatable(checkPollinatable))) {
            continue;
        }
        if (!checkPollinatable.canMateWith(pollen)) {
            continue;
        }
        IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), world, posBlock.x, posBlock.y, posBlock.z);
        if (realPollinatable != null) {
            realPollinatable.mateWith(pollen);
            return true;
        }
    }
    return false;
}
Also used : ICheckPollinatable(forestry.arboriculture.genetics.ICheckPollinatable) Random(java.util.Random) FakePollinatable(forestry.arboriculture.genetics.FakePollinatable) Vect(forestry.core.vect.Vect) MutableVect(forestry.core.vect.MutableVect) IPollinatable(forestry.api.genetics.IPollinatable) World(net.minecraft.world.World)

Aggregations

IPollinatable (forestry.api.genetics.IPollinatable)3 ICheckPollinatable (forestry.arboriculture.genetics.ICheckPollinatable)3 ITree (forestry.api.arboriculture.ITree)1 CheckPollinatable (forestry.arboriculture.genetics.CheckPollinatable)1 CheckPollinatableTree (forestry.arboriculture.genetics.CheckPollinatableTree)1 FakePollinatable (forestry.arboriculture.genetics.FakePollinatable)1 MutableVect (forestry.core.vect.MutableVect)1 Vect (forestry.core.vect.Vect)1 Random (java.util.Random)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1