use of forestry.api.genetics.IPollinatable in project ForestryMC by ForestryMC.
the class GeneticsUtil method getOrCreatePollinatable.
/**
* Returns an IPollinatable that can be mated. This will convert vanilla leaves to Forestry leaves.
*/
@Nullable
public static IPollinatable getOrCreatePollinatable(@Nullable GameProfile owner, World world, final BlockPos pos, boolean convertVanilla) {
IPollinatable pollinatable = TileUtil.getTile(world, pos, IPollinatable.class);
if (pollinatable == null && convertVanilla) {
final IIndividual pollen = getPollen(world, pos);
if (pollen != null) {
ISpeciesRoot root = pollen.getGenome().getSpeciesRoot();
if (root instanceof ISpeciesRootPollinatable) {
ISpeciesRootPollinatable rootPollinatable = (ISpeciesRootPollinatable) root;
pollinatable = rootPollinatable.tryConvertToPollinatable(owner, world, pos, pollen);
}
}
}
return pollinatable;
}
use of forestry.api.genetics.IPollinatable 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.IPollinatable in project Binnie by ForestryMC.
the class ItemFlowerGE method pollinateFlower.
private EnumActionResult pollinateFlower(World world, BlockPos pos, EntityPlayer player, ItemStack stack) {
IFlower flower = BotanyAPI.flowerRoot.getMember(stack);
TileEntity target = world.getTileEntity(pos);
if (!(target instanceof IPollinatable)) {
return EnumActionResult.PASS;
}
IPollinatable pollinatable = (IPollinatable) target;
if (!pollinatable.canMateWith(flower)) {
return EnumActionResult.FAIL;
}
pollinatable.mateWith(flower);
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
use of forestry.api.genetics.IPollinatable in project Binnie by ForestryMC.
the class TileEntityFlower method mateFlower.
private void mateFlower(Random rand, float chancePollinate, float chanceSelfPollinate) {
if (world.rand.nextFloat() < chancePollinate && flower.hasFlowered() && !flower.isWilted()) {
for (int tries = 0; tries < 4; ++tries) {
int x = rand.nextInt(5) - 2;
int z = rand.nextInt(5) - 2;
TileEntity tile = world.getTileEntity(pos.add(x, 0, z));
if (tile instanceof IPollinatable && ((IPollinatable) tile).canMateWith(getFlower())) {
((IPollinatable) tile).mateWith(getFlower());
}
}
}
if (world.rand.nextFloat() < chanceSelfPollinate && flower.hasFlowered() && flower.getMate() == null) {
mateWith(getFlower());
}
}
use of forestry.api.genetics.IPollinatable 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);
}
}
Aggregations