Search in sources :

Example 1 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees-BYG by DynamicTreesTeam.

the class BranchSproutsGenFeature method placeSprouts.

private void placeSprouts(int count, GenFeatureConfiguration configuration, IWorld world, BlockPos rootPos) {
    WeightedList<Pair<BlockPos, Direction>> validSpots = new WeightedList<>();
    final FindSidedBlockNode sproutPlacer = new FindSidedBlockNode(validSpots, configuration.get(MIN_RADIUS));
    TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(sproutPlacer));
    if (!validSpots.isEmpty()) {
        for (int i = 0; i < count; i++) {
            Pair<BlockPos, Direction> selection = validSpots.getOne(world.getRandom());
            BlockPos pos = selection.getFirst();
            Block block = configuration.get(SPROUT_BLOCK);
            if (world.getBlockState(pos.below()).getBlock() == block)
                return;
            world.setBlock(pos, block.defaultBlockState().setValue(HorizontalBlock.FACING, selection.getSecond()), 3);
        }
    }
}
Also used : WeightedList(net.minecraft.util.WeightedList) BranchBlock(com.ferreusveritas.dynamictrees.blocks.branches.BranchBlock) TrunkShellBlock(com.ferreusveritas.dynamictrees.blocks.branches.TrunkShellBlock) Block(net.minecraft.block.Block) HorizontalBlock(net.minecraft.block.HorizontalBlock) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) Pair(com.mojang.datafixers.util.Pair) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 2 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal 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 3 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.

the class SubstanceFreeze method apply.

@Override
public Result apply(World world, BlockPos rootPos, BlockPos hitPos) {
    IBlockState rootyState = world.getBlockState(rootPos);
    BlockRooty dirt = TreeHelper.getRooty(rootyState);
    Species species = dirt.getSpecies(rootyState, world, rootPos);
    if (species != Species.NULLSPECIES && dirt != null) {
        if (world.isRemote) {
            TreeHelper.treeParticles(world, rootPos, EnumParticleTypes.FIREWORKS_SPARK, 8);
        } else {
            dirt.startAnalysis(world, rootPos, new MapSignal(new NodeFreezer(species)));
            // destroy the soil life so it can no longer grow
            dirt.fertilize(world, rootPos, -15);
        }
        return Result.successful();
    }
    return Result.failure();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) Species(com.ferreusveritas.dynamictrees.trees.Species) NodeFreezer(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFreezer) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 4 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal 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 5 with MapSignal

use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.

the class ChunkTreeHelper method removeOrphanedBranchNodes.

/**
 * Removes floating little bits of tree that have somehow lost
 * connection with their parent root system.
 *
 * @param world The world
 * @param cPos The chunk position where the effect is intended
 * @param radius Radius of effect in chunk width units
 */
public static void removeOrphanedBranchNodes(World world, ChunkPos cPos, int radius) {
    if (cPos == null) {
        // Who would be so unkind?
        throw new NullPointerException("Null Chunk Position");
    }
    // This is used to track branches that are already proven
    Set<BlockPos> found = new HashSet<>();
    BlockBounds bounds = getEffectiveBlockBounds(world, cPos, radius);
    for (MutableBlockPos pos : bounds.iterate()) {
        if (found.contains(pos)) {
            // Block was already proven to be part of a valid tree structure
            continue;
        }
        // Test if there's a branch block at this position
        IBlockState state = world.getBlockState(pos);
        Optional<BlockBranch> branchBlock = TreeHelper.getBranchOpt(state);
        if (!branchBlock.isPresent()) {
            // No branch block found at this position.  Move on
            continue;
        }
        // Test if the branch has a root node attached to it
        BlockPos rootPos = TreeHelper.findRootNode(world, pos);
        if (rootPos == BlockPos.ORIGIN) {
            // If the root position is the ORIGIN object it means that no root block was found
            // If the root node isn't found then all nodes are orphan.  Destroy the entire network.
            doTreeDestroy(world, branchBlock, rootPos);
            continue;
        }
        // There is at least one root block in the network
        IBlockState rootyState = world.getBlockState(rootPos);
        Optional<BlockRooty> rootyBlock = TreeHelper.getRootyOpt(rootyState);
        if (!rootyBlock.isPresent()) {
            // This theoretically shouldn't ever happen
            continue;
        }
        // Rooty block confirmed, build details about the trunk coming out of it
        EnumFacing trunkDir = rootyBlock.get().getTrunkDirection(world, rootPos);
        BlockPos trunkPos = rootPos.offset(trunkDir);
        IBlockState trunkState = world.getBlockState(trunkPos);
        Optional<BlockBranch> trunk = TreeHelper.getBranchOpt(trunkState);
        if (!trunk.isPresent()) {
            // This theoretically shouldn't ever happen
            continue;
        }
        // There's a trunk coming out of the rooty block, that's kinda expected.  But is it the only rooty block in the network?
        MapSignal signal = new MapSignal();
        signal.destroyLoopedNodes = false;
        trunk.get().analyse(trunkState, world, trunkPos, null, signal);
        if (signal.multiroot || signal.overflow) {
            // We found multiple root nodes.  This can't be resolved. Destroy the entire network
            doTreeDestroy(world, branchBlock, pos);
            continue;
        } else {
            // Tree appears healthy with only a single attached root block
            trunk.get().analyse(trunkState, world, trunkPos, null, new MapSignal(new NodeCollector(found)));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) BlockBranch(com.ferreusveritas.dynamictrees.blocks.BlockBranch) NodeCollector(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) HashSet(java.util.HashSet) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Aggregations

MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)15 IBlockState (net.minecraft.block.state.IBlockState)10 BlockPos (net.minecraft.util.math.BlockPos)9 BlockBranch (com.ferreusveritas.dynamictrees.blocks.BlockBranch)6 Species (com.ferreusveritas.dynamictrees.trees.Species)5 BlockRooty (com.ferreusveritas.dynamictrees.blocks.BlockRooty)4 NodeFindEnds (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeFindEnds)4 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)4 Block (net.minecraft.block.Block)3 ILeavesProperties (com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties)2 NodeCollector (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeCollector)2 NodeNetVolume (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume)2 NodeTransform (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform)2 SimpleVoxmap (com.ferreusveritas.dynamictrees.util.SimpleVoxmap)2 Cell (com.ferreusveritas.dynamictrees.util.SimpleVoxmap.Cell)2 EnumFacing (net.minecraft.util.EnumFacing)2 WeightedList (net.minecraft.util.WeightedList)2 INodeInspector (com.ferreusveritas.dynamictrees.api.network.INodeInspector)1 ITreePart (com.ferreusveritas.dynamictrees.api.treedata.ITreePart)1 BlockDynamicLeaves (com.ferreusveritas.dynamictrees.blocks.BlockDynamicLeaves)1