Search in sources :

Example 1 with ICheckPollinatable

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

Example 2 with ICheckPollinatable

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

Example 3 with ICheckPollinatable

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;
}
Also used : ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IBlockState(net.minecraft.block.state.IBlockState) IIndividual(forestry.api.genetics.IIndividual) Nullable(javax.annotation.Nullable)

Example 4 with ICheckPollinatable

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;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) IBeeModifier(forestry.api.apiculture.IBeeModifier) Random(java.util.Random) IPollinatable(forestry.api.genetics.IPollinatable) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 5 with ICheckPollinatable

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;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) ICheckPollinatable(forestry.api.genetics.ICheckPollinatable) IBeeModifier(forestry.api.apiculture.IBeeModifier) Random(java.util.Random) IIndividual(forestry.api.genetics.IIndividual) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Aggregations

ICheckPollinatable (forestry.api.genetics.ICheckPollinatable)5 IPollinatable (forestry.api.genetics.IPollinatable)3 IBeeModifier (forestry.api.apiculture.IBeeModifier)2 IIndividual (forestry.api.genetics.IIndividual)2 Random (java.util.Random)2 Nullable (javax.annotation.Nullable)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3i (net.minecraft.util.math.Vec3i)2 World (net.minecraft.world.World)2 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 PacketFXSignal (forestry.core.network.packets.PacketFXSignal)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1