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);
}
}
}
}*/
}
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 };
}
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));
}
}
}
}
}
Aggregations