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