use of com.ferreusveritas.dynamictrees.blocks.BlockRooty in project DynamicTrees by DynamicTreesTeam.
the class WailaRootyHandler method getWailaBody.
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
IBlockState state = accessor.getWorld().getBlockState(accessor.getPosition());
if (state.getBlock() instanceof BlockRooty) {
BlockRooty rooty = (BlockRooty) state.getBlock();
int life = rooty.getSoilLife(state, accessor.getWorld(), accessor.getPosition());
tooltip.add("Soil Life: " + MathHelper.floor(life * 100f / 15) + "%");
}
return tooltip;
}
use of com.ferreusveritas.dynamictrees.blocks.BlockRooty 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.blocks.BlockRooty 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)));
}
}
}
use of com.ferreusveritas.dynamictrees.blocks.BlockRooty in project DynamicTrees by DynamicTreesTeam.
the class EntityFallingTree method cleanupRootyDirt.
public void cleanupRootyDirt() {
// Force the Rooty Dirt to update if it's there. Turning it back to dirt.
if (!world.isRemote) {
BlockPos rootPos = getDestroyData().cutPos.down();
IBlockState belowState = world.getBlockState(rootPos);
if (TreeHelper.isRooty(belowState)) {
BlockRooty rootyBlock = (BlockRooty) belowState.getBlock();
rootyBlock.doDecay(world, rootPos, belowState, getDestroyData().species);
}
}
}
use of com.ferreusveritas.dynamictrees.blocks.BlockRooty in project DynamicTrees by DynamicTreesTeam.
the class CommandTransform method execute.
@Override
public void execute(World world, ICommandSender sender, String[] args) throws CommandException {
BlockPos pos = BlockPos.ORIGIN;
Species toSpecies = null;
if (args.length < 5) {
throw new WrongUsageException("commands.dynamictrees.transform.usage");
}
for (int arg = 0; arg < args.length; arg++) {
switch(arg) {
case 3:
pos = CommandBase.parseBlockPos(sender, args, 1, false);
break;
case 4:
toSpecies = TreeRegistry.findSpeciesSloppy(args[4]);
if (toSpecies == Species.NULLSPECIES) {
throw new CommandException("commands.dynamictrees.setree.specieserror", args[4]);
}
break;
}
}
BlockPos rootPos = TreeHelper.findRootNode(world, pos);
Species fromSpecies = TreeHelper.getExactSpecies(world, rootPos);
if (rootPos == BlockPos.ORIGIN) {
throw new CommandException("commands.dynamictrees.soillife.notreeerror", pos.getX() + " " + pos.getY() + " " + pos.getZ());
}
if (!toSpecies.isTransformable() || !fromSpecies.isTransformable()) {
throw new CommandException("commands.dynamictrees.transform.nottransformableerror", !toSpecies.isTransformable() ? args[4] : fromSpecies.getRegistryName());
}
IBlockState rootyState = world.getBlockState(rootPos);
BlockRooty rootyBlock = TreeHelper.getRooty(rootyState);
rootyBlock.startAnalysis(world, rootPos, new MapSignal(new NodeTransform(fromSpecies, toSpecies)));
if (rootyBlock.getSpecies(rootyState, world, rootPos) != toSpecies) {
// Place new rooty dirt block in case we're transforming to species that requires tile entity.
toSpecies.placeRootyDirtBlock(world, rootPos, rootyBlock.getSoilLife(rootyState, world, rootPos));
}
}
Aggregations