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