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