Search in sources :

Example 1 with ILeafTickHandler

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());
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IBlockState(net.minecraft.block.state.IBlockState) ITreekeepingMode(forestry.api.arboriculture.ITreekeepingMode) ILeafTickHandler(forestry.api.arboriculture.ILeafTickHandler) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Aggregations

IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)1 ILeafTickHandler (forestry.api.arboriculture.ILeafTickHandler)1 ITree (forestry.api.arboriculture.ITree)1 ITreeGenome (forestry.api.arboriculture.ITreeGenome)1 ITreekeepingMode (forestry.api.arboriculture.ITreekeepingMode)1 IBlockState (net.minecraft.block.state.IBlockState)1