use of com.ferreusveritas.dynamictrees.systems.nodemappers.NodeDestroyer in project DynamicTrees by DynamicTreesTeam.
the class BlockBranch method destroyBranchFromNode.
/**
* Destroys all branches recursively not facing the branching direction with the root node
*
* @param world The world
* @param cutPos The position of the branch being lobbed
* @param toolDir The face that was pounded on when breaking the block at cutPos
* @param wholeTree Indicates if the whole tree should be destroyed or just the branch
* @return The volume of the portion of the tree that was destroyed
*/
public BranchDestructionData destroyBranchFromNode(World world, BlockPos cutPos, EnumFacing toolDir, boolean wholeTree) {
IBlockState blockState = world.getBlockState(cutPos);
NodeSpecies nodeSpecies = new NodeSpecies();
// Analyze entire tree network to find root node and species
MapSignal signal = analyse(blockState, world, cutPos, null, new MapSignal(nodeSpecies));
// Get the species from the root node
Species species = nodeSpecies.getSpecies();
// Analyze only part of the tree beyond the break point and map out the extended block states
// We can't destroy the branches during this step since we need accurate extended block states that include connections
NodeExtState extStateMapper = new NodeExtState(cutPos);
analyse(blockState, world, cutPos, wholeTree ? null : signal.localRootDir, new MapSignal(extStateMapper));
// Analyze only part of the tree beyond the break point and calculate it's volume, then destroy the branches
NodeNetVolume volumeSum = new NodeNetVolume();
NodeDestroyer destroyer = new NodeDestroyer(species);
destroyMode = EnumDestroyMode.HARVEST;
analyse(blockState, world, cutPos, wholeTree ? null : signal.localRootDir, new MapSignal(volumeSum, destroyer));
destroyMode = EnumDestroyMode.SLOPPY;
// Destroy all the leaves on the branch, store them in a map and convert endpoint coordinates from absolute to relative
List<BlockPos> endPoints = destroyer.getEnds();
Map<BlockPos, IBlockState> destroyedLeaves = new HashMap<>();
List<BlockItemStack> leavesDropsList = new ArrayList<>();
destroyLeaves(world, cutPos, species, endPoints, destroyedLeaves, leavesDropsList);
endPoints = endPoints.stream().map(p -> p.subtract(cutPos)).collect(Collectors.toList());
// Calculate main trunk height
int trunkHeight = 1;
for (BlockPos iter = new BlockPos(0, 1, 0); extStateMapper.getExtStateMap().containsKey(iter); iter = iter.up()) {
trunkHeight++;
}
EnumFacing cutDir = signal.localRootDir;
if (cutDir == null) {
cutDir = EnumFacing.DOWN;
}
return new BranchDestructionData(species, extStateMapper.getExtStateMap(), destroyedLeaves, leavesDropsList, endPoints, volumeSum.getVolume(), cutPos, cutDir, toolDir, trunkHeight);
}
Aggregations