Search in sources :

Example 11 with ITreePart

use of com.ferreusveritas.dynamictrees.api.treedata.ITreePart in project DynamicTrees by DynamicTreesTeam.

the class TreeHelper method findRootNode.

/**
 * Find the root node of a tree.
 *
 * @param world The world
 * @param pos   The position being analyzed
 * @return The position of the root node of the tree or BlockPos.ORIGIN if nothing was found.
 */
public static BlockPos findRootNode(World world, BlockPos pos) {
    pos = dereferenceTrunkShell(world, pos);
    IBlockState state = world.getBlockState(pos);
    ITreePart treePart = TreeHelper.getTreePart(state);
    switch(treePart.getTreePartType()) {
        case BRANCH:
            // Analyze entire tree network to find root node
            MapSignal signal = treePart.analyse(state, world, pos, null, new MapSignal());
            if (signal.found) {
                return signal.root;
            }
            break;
        case ROOT:
            return pos;
        default:
            return BlockPos.ORIGIN;
    }
    return BlockPos.ORIGIN;
}
Also used : ITreePart(com.ferreusveritas.dynamictrees.api.treedata.ITreePart) IBlockState(net.minecraft.block.state.IBlockState) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Aggregations

ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)11 IBlockState (net.minecraft.block.state.IBlockState)8 BlockPos (net.minecraft.util.math.BlockPos)7 EnumFacing (net.minecraft.util.EnumFacing)5 Species (com.ferreusveritas.dynamictrees.trees.Species)3 ICell (com.ferreusveritas.dynamictrees.api.cells.ICell)1 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)1 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)1 BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)1 TileEntitySpecies (com.ferreusveritas.dynamictrees.tileentity.TileEntitySpecies)1 SimpleVoxmap (com.ferreusveritas.dynamictrees.util.SimpleVoxmap)1 Random (java.util.Random)1 CommandException (net.minecraft.command.CommandException)1 WrongUsageException (net.minecraft.command.WrongUsageException)1