Search in sources :

Example 1 with IFlowerProvider

use of forestry.api.genetics.IFlowerProvider in project ForestryMC by ForestryMC.

the class Bee method plantFlowerRandom.

@Override
public BlockPos plantFlowerRandom(IBeeHousing housing, @Nullable List<IBlockState> potentialFlowers) {
    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;
    }
    // Gather required info
    IFlowerProvider provider = genome.getFlowerProvider();
    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 < 10; i++) {
        BlockPos randomPos = VectUtil.getRandomPositionInArea(random, area);
        BlockPos posBlock = VectUtil.add(housingPos, randomPos, offset);
        if (potentialFlowers != null) {
            if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock, potentialFlowers)) {
                return posBlock;
            }
        } else {
            // noinspection deprecation
            if (FlowerManager.flowerRegistry.growFlower(provider.getFlowerType(), world, this, posBlock)) {
                return posBlock;
            }
        }
    }
    return null;
}
Also used : IFlowerProvider(forestry.api.genetics.IFlowerProvider) Vec3i(net.minecraft.util.math.Vec3i) IBeeModifier(forestry.api.apiculture.IBeeModifier) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

IBeeModifier (forestry.api.apiculture.IBeeModifier)1 IFlowerProvider (forestry.api.genetics.IFlowerProvider)1 Random (java.util.Random)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3i (net.minecraft.util.math.Vec3i)1 World (net.minecraft.world.World)1