use of forestry.api.genetics.ICheckPollinatable in project ForestryMC by ForestryMC.
the class AIButterflyPollinate method updateTask.
@Override
public void updateTask() {
if (shouldContinueExecuting() && rest != null) {
ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(entity.world, rest);
if (checkPollinatable != null) {
if (entity.getPollen() == null) {
entity.setPollen(checkPollinatable.getPollen());
// 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.world, rest, false);
if (realPollinatable != null) {
realPollinatable.mateWith(entity.getPollen());
// 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.api.genetics.ICheckPollinatable in project ForestryMC by ForestryMC.
the class ItemGermlingGE method onItemRightClickPollen.
private static ActionResult<ItemStack> onItemRightClickPollen(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, BlockPos pos, ITree tree) {
ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(worldIn, pos);
if (checkPollinatable == null || !checkPollinatable.canMateWith(tree)) {
return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
}
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(playerIn.getGameProfile(), worldIn, pos, true);
if (pollinatable == null || !pollinatable.canMateWith(tree)) {
return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
}
if (worldIn.isRemote) {
return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
} else {
pollinatable.mateWith(tree);
IBlockState blockState = worldIn.getBlockState(pos);
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
NetworkUtil.sendNetworkPacket(packet, pos, worldIn);
if (!playerIn.capabilities.isCreativeMode) {
itemStackIn.shrink(1);
}
return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
}
}
use of forestry.api.genetics.ICheckPollinatable in project ForestryMC by ForestryMC.
the class GeneticsUtil method getPollen.
/**
* Gets pollen from a location. Does not affect the pollen source.
*/
@Nullable
public static IIndividual getPollen(World world, final BlockPos pos) {
if (!world.isBlockLoaded(pos)) {
return null;
}
ICheckPollinatable checkPollinatable = TileUtil.getTile(world, pos, ICheckPollinatable.class);
if (checkPollinatable != null) {
return checkPollinatable.getPollen();
}
IBlockState blockState = world.getBlockState(pos);
for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
IIndividual individual = root.translateMember(blockState);
if (individual != null) {
return individual;
}
}
return null;
}
use of forestry.api.genetics.ICheckPollinatable 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;
}
use of forestry.api.genetics.ICheckPollinatable in project ForestryMC by ForestryMC.
the class Bee method retrievePollen.
/* FLOWERS */
@Override
@Nullable
public IIndividual retrievePollen(IBeeHousing housing) {
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
int chance = Math.round(genome.getFlowering() * beeModifier.getFloweringModifier(getGenome(), 1f));
World world = housing.getWorldObj();
Random random = world.rand;
// Correct speed
if (random.nextInt(100) >= chance) {
return null;
}
Vec3i area = getArea(genome, beeModifier);
Vec3i offset = new Vec3i(-area.getX() / 2, -area.getY() / 4, -area.getZ() / 2);
BlockPos housingPos = housing.getCoordinates();
IIndividual pollen = null;
for (int i = 0; i < 20; i++) {
BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
BlockPos blockPos = VectUtil.add(housingPos, randomPos, offset);
ICheckPollinatable pitcher = TileUtil.getTile(world, blockPos, ICheckPollinatable.class);
if (pitcher != null) {
if (genome.getFlowerProvider().isAcceptedPollinatable(world, pitcher)) {
pollen = pitcher.getPollen();
}
} else {
pollen = GeneticsUtil.getPollen(world, blockPos);
}
if (pollen != null) {
return pollen;
}
}
return null;
}
Aggregations