use of com.ferreusveritas.dynamictrees.systems.GrowSignal in project DynamicTrees-BYG by DynamicTreesTeam.
the class TaperedWitheredOakLogic method selectNewDirection.
@Override
public Direction selectNewDirection(GrowthLogicKitConfiguration configuration, DirectionSelectionContext context) {
final Species species = context.species();
final GrowSignal signal = context.signal();
Direction newDir = super.selectNewDirection(configuration, context);
if (signal.delta.getY() == species.getLowestBranchHeight() && signal.isInTrunk() && // Turned out of trunk
newDir != Direction.UP)
signal.energy = 5;
return newDir;
}
use of com.ferreusveritas.dynamictrees.systems.GrowSignal in project DynamicTrees-BYG by DynamicTreesTeam.
the class DiagonalPalmFamily method createBranchBlock.
@Override
protected BranchBlock createBranchBlock() {
final BasicBranchBlock branch = new BasicBranchBlock(this.getProperties()) {
@Override
public GrowSignal growIntoAir(World world, BlockPos pos, GrowSignal signal, int fromRadius) {
final Species species = signal.getSpecies();
final DynamicLeavesBlock leaves = species.getLeavesBlock().orElse(null);
if (leaves != null) {
if (fromRadius == getFamily().getPrimaryThickness()) {
// If we came from a twig (and we're not a stripped branch) then just make some leaves
if (isNextToBranch(world, pos, signal.dir.getOpposite())) {
signal.success = false;
return signal;
}
signal.success = leaves.growLeavesIfLocationIsSuitable(world, species.getLeavesProperties(), pos.above(), 0);
if (signal.success)
return leaves.branchOut(world, pos, signal);
} else {
// Otherwise make a proper branch
return leaves.branchOut(world, pos, signal);
}
} else {
// If the leaves block is null, the branch grows directly without checking for leaves requirements
if (isNextToBranch(world, pos, signal.dir.getOpposite())) {
signal.success = false;
return signal;
}
setRadius(world, pos, getFamily().getPrimaryThickness(), null);
signal.radius = getFamily().getSecondaryThickness();
signal.success = true;
}
return signal;
}
};
if (this.isFireProof())
branch.setFireSpreadSpeed(0).setFlammability(0);
return branch;
}
use of com.ferreusveritas.dynamictrees.systems.GrowSignal 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.systems.GrowSignal in project DynamicTrees-BYG by DynamicTreesTeam.
the class AncientLogic method populateDirectionProbabilityMap.
@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
final GrowSignal signal = context.signal();
final int[] probMap = context.probMap();
final World world = context.world();
final BlockPos pos = context.pos();
final Species species = context.species();
Direction originDir = signal.dir.getOpposite();
int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
// Down is always disallowed
probMap[0] = 0;
if (signal.energy > configuration.get(CANOPY_ENERGY)) {
// not canopy
// Alter probability map for direction change
probMap[1] = species.getUpProbability();
// Start by disabling probability on the sides
probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
if (signal.isInTrunk()) {
if (signal.delta.getY() <= configuration.getLowestBranchHeight(context) + 1) {
// midway
int sideHash = treeHash % 16;
probMap[2] = sideHash % 2 < 1 ? 1 : 0;
probMap[3] = sideHash % 4 < 2 ? 1 : 0;
probMap[4] = sideHash % 8 < 4 ? 1 : 0;
probMap[5] = sideHash < 8 ? 1 : 0;
}
} else {
branchTwisting(world, pos, signal, probMap);
}
} else
// it is canopy so dark oak logic is used
darkOakCanopy(signal, probMap);
// Disable the direction we came from
probMap[originDir.ordinal()] = 0;
return probMap;
}
use of com.ferreusveritas.dynamictrees.systems.GrowSignal in project DynamicTrees-BYG by DynamicTreesTeam.
the class AncientLogic method selectNewDirection.
@Override
public Direction selectNewDirection(GrowthLogicKitConfiguration configuration, DirectionSelectionContext context) {
final Direction newDir = super.selectNewDirection(configuration, context);
final GrowSignal signal = context.signal();
if (signal.isInTrunk() && newDir != Direction.UP) {
signal.energy = Math.min(signal.energy, configuration.get(CANOPY_ENERGY) + 3.5f);
}
return newDir;
}
Aggregations