Search in sources :

Example 1 with BlockDynamicLeaves

use of com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves in project DynamicTrees by DynamicTreesTeam.

the class JoCode method cleanupFrankentree.

/**
 * Attempt to clean up fused trees that have multiple root blocks by simply destroying them both messily
 */
protected void cleanupFrankentree(World world, BlockPos treePos, IBlockState treeState, List<BlockPos> endPoints, SafeChunkBounds safeBounds) {
    Set<BlockPos> blocksToDestroy = new HashSet<>();
    BlockBranch branch = TreeHelper.getBranch(treeState);
    MapSignal signal = new MapSignal(new NodeCollector(blocksToDestroy));
    signal.destroyLoopedNodes = false;
    signal.trackVisited = true;
    branch.analyse(treeState, world, treePos, null, signal);
    BlockBranch.destroyMode = EnumDestroyMode.IGNORE;
    for (BlockPos pos : blocksToDestroy) {
        if (safeBounds.inBounds(pos, false)) {
            IBlockState branchState = world.getBlockState(pos);
            Optional<BlockBranch> branchBlock = TreeHelper.getBranchOpt(branchState);
            if (branchBlock.isPresent()) {
                int radius = branchBlock.get().getRadius(branchState);
                TreeFamily family = branchBlock.get().getFamily();
                Species species = family.getCommonSpecies();
                if (family.getPrimaryThickness() == radius) {
                    ILeavesProperties leavesProperties = species.getLeavesProperties();
                    if (leavesProperties != LeavesProperties.NULLPROPERTIES) {
                        SimpleVoxmap leafCluster = leavesProperties.getCellKit().getLeafCluster();
                        if (leafCluster != LeafClusters.NULLMAP) {
                            for (Cell cell : leafCluster.getAllNonZeroCells()) {
                                BlockPos delPos = pos.add(cell.getPos());
                                if (safeBounds.inBounds(delPos, false)) {
                                    IBlockState leavesState = world.getBlockState(delPos);
                                    if (TreeHelper.isLeaves(leavesState)) {
                                        BlockDynamicLeaves leavesBlock = (BlockDynamicLeaves) leavesState.getBlock();
                                        if (leavesProperties.getTree() == leavesBlock.getProperties(leavesState).getTree()) {
                                            world.setBlockState(delPos, ModBlocks.blockStates.air, 2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                world.setBlockState(pos, ModBlocks.blockStates.air, 2);
            }
        }
    }
    BlockBranch.destroyMode = EnumDestroyMode.HARVEST;
// Now wreck out all surrounding leaves.  Let them grow back naturally.
/*if(!endPoints.isEmpty()) {
			BlockBounds bounds = new BlockBounds(endPoints);
			bounds.expand(3);
			for(BlockPos pos : bounds.iterate()) {
				if(safeBounds.inBounds(pos, false)) {
					if(TreeHelper.isLeaves(world.getBlockState(pos))) {
						world.setBlockState(pos, ModBlocks.blockStates.air, 2);
					}
				}
			}
		}*/
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) SimpleVoxmap(com.ferreusveritas.dynamictrees.util.SimpleVoxmap) BlockDynamicLeaves(com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) NodeCollector(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector) ILeavesProperties(com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties) TreeFamily(com.ferreusveritas.dynamictrees.trees.TreeFamily) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Species(com.ferreusveritas.dynamictrees.trees.Species) Cell(com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 2 with BlockDynamicLeaves

use of com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves in project DynamicTrees by DynamicTreesTeam.

the class BranchDestructionData method convertLeavesToIntArray.

// /////////////////////////////////////////////////////////
// Leaves
// /////////////////////////////////////////////////////////
private int[][] convertLeavesToIntArray(Map<BlockPos, IBlockState> leavesList) {
    int[] posData = new int[leavesList.size()];
    int[] blockIndexData = new int[leavesList.size()];
    int index = 0;
    // Encode the remaining blocks
    for (Entry<BlockPos, IBlockState> set : leavesList.entrySet()) {
        BlockPos relPos = set.getKey();
        IBlockState state = set.getValue();
        Block block = state.getBlock();
        if (block instanceof BlockDynamicLeaves && bounds.inBounds(relPos)) {
            // Place comfortable limits on the system
            posData[index] = encodeLeaves(relPos, (BlockDynamicLeaves) block, state);
            blockIndexData[index++] = encodeLeavesBlocks(state, this.species);
        }
    }
    // Shrink down the array
    posData = Arrays.copyOf(posData, index);
    blockIndexData = Arrays.copyOf(blockIndexData, index);
    return new int[][] { posData, blockIndexData };
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockDynamicLeaves(com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves)

Example 3 with BlockDynamicLeaves

use of com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves in project DynamicTrees by DynamicTreesTeam.

the class NodeTransform method transformSurroundingLeaves.

public void transformSurroundingLeaves(World world, BlockPos twigPos) {
    if (!world.isRemote) {
        for (BlockPos leavesPos : BlockPos.getAllInBox(twigPos.add(-3, -3, -3), twigPos.add(3, 3, 3))) {
            if (fromSpecies.getLeavesProperties().getCellKit().getLeafCluster().getVoxel(twigPos, leavesPos) != 0) {
                // We're only interested in where leaves could possibly be
                IBlockState state = world.getBlockState(leavesPos);
                if (fromSpecies.getFamily().isCompatibleGenericLeaves(state, world, leavesPos)) {
                    int hydro = state.getBlock() instanceof BlockDynamicLeaves ? state.getValue(BlockDynamicLeaves.HYDRO) : 2;
                    world.setBlockState(leavesPos, toSpeciesLeaves == null ? Blocks.AIR.getDefaultState() : toSpeciesLeaves.withProperty(BlockDynamicLeaves.HYDRO, hydro));
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockDynamicLeaves(com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves)

Aggregations

BlockDynamicLeaves (com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves)3 IBlockState (net.minecraft.block.state.IBlockState)3 BlockPos (net.minecraft.util.math.BlockPos)3 MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)1 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)1 BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)1 NodeCollector (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector)1 Species (com.ferreusveritas.dynamictrees.trees.Species)1 TreeFamily (com.ferreusveritas.dynamictrees.trees.TreeFamily)1 SimpleVoxmap (com.ferreusveritas.dynamictrees.util.SimpleVoxmap)1 Cell (com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell)1 Block (net.minecraft.block.Block)1 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)1