Search in sources :

Example 1 with NodeNetVolume

use of com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume in project DynamicTrees by DynamicTreesTeam.

the class WailaBranchHandler method getTreeVolume.

private float getTreeVolume(World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    // Dereference proxy trunk shell block
    if (block instanceof BlockTrunkShell) {
        ShellMuse muse = ((BlockTrunkShell) block).getMuse(world, pos);
        if (muse != null) {
            state = muse.state;
            block = state.getBlock();
            pos = muse.pos;
        }
    }
    if (block instanceof BlockBranch) {
        BlockBranch branch = (BlockBranch) block;
        // Analyze only part of the tree beyond the break point and calculate it's volume, then destroy the branches
        NodeNetVolume volumeSum = new NodeNetVolume();
        branch.analyse(state, world, pos, null, new MapSignal(volumeSum));
        return volumeSum.getVolume() * ModConfigs.treeHarvestMultiplier;
    }
    return 0;
}
Also used : NodeNetVolume(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume) IBlockState(net.minecraft.block.state.IBlockState) BlockTrunkShell(com.ferreusveritas.dynamictrees.blocks.BlockTrunkShell) Block(net.minecraft.block.Block) ShellMuse(com.ferreusveritas.dynamictrees.blocks.BlockTrunkShell.ShellMuse) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 2 with NodeNetVolume

use of com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume 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);
}
Also used : NodeSpecies(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies) NodeNetVolume(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume) NodeExtState(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeExtState) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BranchDestructionData(com.ferreusveritas.dynamictrees.util.BranchDestructionData) NodeDestroyer(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeDestroyer) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) NodeSpecies(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies) Species(com.ferreusveritas.dynamictrees.trees.Species) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Aggregations

MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)2 NodeNetVolume (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)1 BlockTrunkShell (com.ferreusveritas.dynamictrees.blocks.BlockTrunkShell)1 ShellMuse (com.ferreusveritas.dynamictrees.blocks.BlockTrunkShell.ShellMuse)1 NodeDestroyer (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeDestroyer)1 NodeExtState (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeExtState)1 NodeSpecies (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeSpecies)1 Species (com.ferreusveritas.dynamictrees.trees.Species)1 BranchDestructionData (com.ferreusveritas.dynamictrees.util.BranchDestructionData)1 Block (net.minecraft.block.Block)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)1