use of forestry.api.arboriculture.ILeafTickHandler in project ForestryMC by ForestryMC.
the class TileLeaves method onBlockTick.
@Override
public void onBlockTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
ITree tree = getTree();
if (tree == null) {
return;
}
ITreeGenome genome = tree.getGenome();
IAlleleTreeSpecies primary = genome.getPrimary();
if (!checkedForConversionToDefaultLeaves) {
if (shouldConvertToDefaultLeaves()) {
IBlockState defaultLeaves = ModuleArboriculture.getBlocks().getDefaultLeaves(primary.getUID());
worldIn.setBlockState(getPos(), defaultLeaves);
return;
}
checkedForConversionToDefaultLeaves = true;
}
boolean isDestroyed = isDestroyed(tree, damage);
for (ILeafTickHandler tickHandler : primary.getRoot().getLeafTickHandlers()) {
if (tickHandler.onRandomLeafTick(tree, world, rand, getPos(), isDestroyed)) {
return;
}
}
if (isDestroyed) {
return;
}
if (damage > 0) {
damage--;
}
if (hasFruit() && getRipeningTime() < ripeningPeriod) {
ITreekeepingMode treekeepingMode = TreeManager.treeRoot.getTreekeepingMode(world);
float sappinessModifier = treekeepingMode.getSappinessModifier(genome, 1f);
float sappiness = genome.getSappiness() * sappinessModifier;
if (rand.nextFloat() < sappiness) {
ripeningTime++;
sendNetworkUpdateRipening();
}
}
if (caterpillar != null) {
matureCaterpillar();
}
effectData = tree.doEffect(effectData, world, getPos());
}
Aggregations