use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.
the class Species method grow.
/**
* The grow handler.
*
* @param world The world
* @param rootyDirt The {@link BlockRooty} that is supporting this tree
* @param rootPos The {@link BlockPos} of the {@link BlockRooty} type in the world
* @param soilLife The life of the soil. 0: Depleted -> 15: Full
* @param treePos The {@link BlockPos} of the {@link TreeFamily} trunk base.
* @param random A random number generator
* @param natural If true then this member is being used to grow the tree naturally(create drops or fruit). If
* false then this member is being used to grow a tree with a growth accelerant like bonemeal or
* the potion of burgeoning
* @return true if network is viable. false if network is not viable(will destroy the {@link BlockRooty} this tree
* is on)
*/
public boolean grow(World world, BlockRooty rootyDirt, BlockPos rootPos, int soilLife, ITreePart treeBase, BlockPos treePos, Random random, boolean natural) {
float growthRate = getGrowthRate(world, rootPos) * ModConfigs.treeGrowthMultiplier * ModConfigs.treeGrowthFolding;
do {
if (soilLife > 0) {
if (growthRate > random.nextFloat()) {
GrowSignal signal = new GrowSignal(this, rootPos, getEnergy(world, rootPos));
boolean success = treeBase.growSignal(world, treePos, signal).success;
int soilLongevity = getSoilLongevity(world, rootPos) * // Don't deplete the soil as much if the grow operation failed
(success ? 1 : 16);
if (soilLongevity <= 0 || random.nextInt(soilLongevity) == 0) {
// 1 in X(soilLongevity) chance to draw nutrients from soil
// decrement soil life
rootyDirt.setSoilLife(world, rootPos, soilLife - 1);
}
if (signal.choked) {
soilLife = 0;
rootyDirt.setSoilLife(world, rootPos, soilLife);
TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(new NodeShrinker(signal.getSpecies())));
}
}
}
} while (--growthRate > 0.0f);
return postGrow(world, rootPos, treePos, soilLife, natural);
}
use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees-BYG by DynamicTreesTeam.
the class AlternativeBranchGenFeature method placeAltBranches.
private void placeAltBranches(boolean isWorldgen, GenFeatureConfiguration configuration, IWorld world, BlockPos rootPos, Family family) {
WeightedList<BlockPos> validSpots = new WeightedList<>();
final FindValidBranchesNode altBranchPlacer = new FindValidBranchesNode(validSpots, configuration.get(MIN_RADIUS), family);
TreeHelper.startAnalysisFromRoot(world, rootPos, new MapSignal(altBranchPlacer));
if (!validSpots.isEmpty()) {
if (isWorldgen) {
for (BlockPos listPos : validSpots.stream().collect(Collectors.toSet())) if (world.getRandom().nextFloat() < configuration.get(WORLDGEN_PLACE_CHANCE))
placeBranch(configuration, world, listPos);
} else
placeBranch(configuration, world, validSpots.getOne(world.getRandom()));
}
}
use of com.ferreusveritas.dynamictrees.api.network.MapSignal 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));
}
}
use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.
the class SubstanceTransform method apply.
@Override
public Result apply(World world, BlockPos rootPos, BlockPos hitPos) {
IBlockState rootyState = world.getBlockState(rootPos);
BlockRooty dirt = TreeHelper.getRooty(rootyState);
if (this.toSpecies == null) {
return Result.failure("substance.dynamictrees.transform.error.not_brewed");
}
if (dirt == null) {
return Result.failure();
}
final Species fromSpecies = dirt.getSpecies(rootyState, world, rootPos);
if (!fromSpecies.isTransformable()) {
return Result.failure("substance.dynamictrees.transform.error.not_transformable", fromSpecies.getLocalizedName());
}
if (fromSpecies == toSpecies) {
return Result.failure("substance.dynamictrees.transform.error.already_transformed", fromSpecies.getLocalizedName());
}
if (world.isRemote) {
TreeHelper.treeParticles(world, rootPos, EnumParticleTypes.FIREWORKS_SPARK, 8);
WailaOther.invalidateWailaPosition();
} else {
dirt.startAnalysis(world, rootPos, new MapSignal(new NodeTransform(fromSpecies, toSpecies)));
if (dirt.getSpecies(rootyState, world, rootPos) != toSpecies) {
toSpecies.placeRootyDirtBlock(world, rootPos, dirt.getSoilLife(rootyState, world, rootPos));
}
}
return Result.successful();
}
use of com.ferreusveritas.dynamictrees.api.network.MapSignal in project DynamicTrees by DynamicTreesTeam.
the class Species method getEnds.
/**
* A little internal convenience function for getting branch endpoints
*
* @param world The world
* @param treePos The {@link BlockPos} of the base of the {@link TreeFamily} trunk
* @param treeBase The tree part that is the base of the {@link TreeFamily} trunk. Provided for easy analysis.
* @return A list of all branch endpoints for the {@link TreeFamily}
*/
protected final List<BlockPos> getEnds(World world, BlockPos treePos, ITreePart treeBase) {
NodeFindEnds endFinder = new NodeFindEnds();
treeBase.analyse(world.getBlockState(treePos), world, treePos, null, new MapSignal(endFinder));
return endFinder.getEnds();
}
Aggregations