Search in sources :

Example 1 with IPollinatable

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;
}
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 2 with IPollinatable

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;
    }
}
Also used : ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) IPollinatable(forestry.api.genetics.IPollinatable)

Example 3 with IPollinatable

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFlower(binnie.botany.api.genetics.IFlower) IPollinatable(forestry.api.genetics.IPollinatable)

Example 4 with IPollinatable

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());
    }
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IPollinatable(forestry.api.genetics.IPollinatable)

Example 5 with IPollinatable

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);
    }
}
Also used : ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) IBlockState(net.minecraft.block.state.IBlockState) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) IPollinatable(forestry.api.genetics.IPollinatable) PacketFXSignal(forestry.core.network.packets.PacketFXSignal)

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