Search in sources :

Example 21 with IFlower

use of binnie.botany.api.genetics.IFlower in project Binnie by ForestryMC.

the class TileEntityFlower method plantOffspring.

private void plantOffspring(Random rand, float chanceDispersal) {
    if (world.rand.nextFloat() < chanceDispersal && flower.hasFlowered() && !flower.isWilted()) {
        IFlowerGenome mate = flower.getMate();
        if (mate != null) {
            boolean dispersed = false;
            for (int tries = 0; tries < 5 && !dispersed; ++tries) {
                int x = rand.nextInt(3) - 1;
                int z = rand.nextInt(3) - 1;
                Block b2 = world.getBlockState(pos.add(x, -1, z)).getBlock();
                if (world.isAirBlock(pos.add(x, 0, z)) && BotanyCore.getGardening().isSoil(b2)) {
                    IFlower offspring = flower.getOffspring(world, pos);
                    if (offspring != null) {
                        BotanyCore.getFlowerRoot().plant(world, pos.add(x, 0, z), offspring, getOwner());
                        flower.removeMate();
                        dispersed = true;
                    }
                }
            }
        }
    }
}
Also used : IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) IFlower(binnie.botany.api.genetics.IFlower) Block(net.minecraft.block.Block)

Example 22 with IFlower

use of binnie.botany.api.genetics.IFlower in project Binnie by ForestryMC.

the class TileEntityFlower method checkIfDead.

public boolean checkIfDead(boolean wasCut) {
    if (getSection() != 0) {
        return getRoot().checkIfDead(wasCut);
    }
    EnumSoilType soil = BotanyCore.getGardening().getSoilType(world, pos);
    int maxAge = (int) (flower.getMaxAge() * (1.0f + soil.ordinal() * 0.25f));
    if (flower.getAge() > maxAge) {
        if (!wasCut && flower.getMate() != null) {
            world.setBlockToAir(pos);
            IFlower offspring = flower.getOffspring(world, pos.down());
            TileEntity above = world.getTileEntity(pos.up());
            if (above instanceof TileEntityFlower) {
                world.setBlockToAir(pos.up());
            }
            BotanyCore.getFlowerRoot().plant(world, pos, offspring, getOwner());
        } else {
            kill();
        }
        return true;
    }
    return false;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IFlower(binnie.botany.api.genetics.IFlower) EnumSoilType(binnie.botany.api.gardening.EnumSoilType)

Example 23 with IFlower

use of binnie.botany.api.genetics.IFlower in project Binnie by ForestryMC.

the class TileEntityFlower method create.

public void create(ItemStack stack, @Nullable GameProfile owner) {
    IFlower flower = BotanyCore.getFlowerRoot().getMember(stack);
    create(flower, owner);
}
Also used : IFlower(binnie.botany.api.genetics.IFlower)

Example 24 with IFlower

use of binnie.botany.api.genetics.IFlower in project Binnie by ForestryMC.

the class TileEntityFlower method onShear.

public void onShear() {
    if (getRoot() != null) {
        getRoot().onShear();
    }
    if (getFlower() == null || getFlower().getAge() <= 1) {
        return;
    }
    Random rand = new Random();
    IFlower cutting = (IFlower) getFlower().copy();
    cutting.setAge(0);
    ItemStack cuttingStack = BotanyCore.getFlowerRoot().getMemberStack(cutting, EnumFlowerStage.SEED);
    float f = 0.7f;
    double xPos = rand.nextFloat() * f + (1.0f - f) * 0.5;
    double yPos = rand.nextFloat() * f + (1.0f - f) * 0.5;
    double zPos = rand.nextFloat() * f + (1.0f - f) * 0.5;
    EntityItem entityItem = new EntityItem(world, pos.getX() + xPos, pos.getY() + yPos, pos.getZ() + zPos, cuttingStack);
    entityItem.setPickupDelay(10);
    world.spawnEntity(entityItem);
    for (int maxAge = getFlower().getMaxAge(), i = 0; i < maxAge; ++i) {
        if (rand.nextBoolean()) {
            getFlower().age();
            if (checkIfDead(true)) {
                return;
            }
        }
    }
}
Also used : Random(java.util.Random) IFlower(binnie.botany.api.genetics.IFlower) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IFlower (binnie.botany.api.genetics.IFlower)24 ItemStack (net.minecraft.item.ItemStack)10 IFlowerRoot (binnie.botany.api.genetics.IFlowerRoot)6 TileEntity (net.minecraft.tileentity.TileEntity)6 IFlowerGenome (binnie.botany.api.genetics.IFlowerGenome)5 TileEntityFlower (binnie.botany.tile.TileEntityFlower)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 Block (net.minecraft.block.Block)3 BlockPos (net.minecraft.util.math.BlockPos)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 EnumFlowerChromosome (binnie.botany.api.genetics.EnumFlowerChromosome)2 IAlleleFlowerSpecies (binnie.botany.api.genetics.IAlleleFlowerSpecies)2 Area (binnie.core.gui.geometry.Area)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EnumSoilType (binnie.botany.api.gardening.EnumSoilType)1 IBlockSoil (binnie.botany.api.gardening.IBlockSoil)1 FlowerRenderInfo (binnie.botany.tile.FlowerRenderInfo)1 ControlText (binnie.core.gui.controls.ControlText)1