use of com.ferreusveritas.dynamictrees.trees.Species 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.trees.Species in project DynamicTrees by DynamicTreesTeam.
the class SubstanceMega method apply.
@Override
public Result apply(World world, BlockPos rootPos, BlockPos hitPos) {
IBlockState blockState = world.getBlockState(rootPos);
BlockRooty dirt = TreeHelper.getRooty(blockState);
Species species = dirt.getSpecies(blockState, world, rootPos);
Species megaSpecies = species.getMegaSpecies();
if (megaSpecies.isValid()) {
int life = dirt.getSoilLife(blockState, world, rootPos);
megaSpecies.placeRootyDirtBlock(world, rootPos, life);
blockState = world.getBlockState(rootPos);
dirt = TreeHelper.getRooty(blockState);
if (dirt.getSpecies(blockState, world, rootPos) == megaSpecies) {
TreeHelper.treeParticles(world, rootPos, EnumParticleTypes.DRAGON_BREATH, 8);
WailaOther.invalidateWailaPosition();
return Result.successful();
}
}
return Result.failure("substance.dynamictrees.mega.error.no_mega_species", species.getLocalizedName());
}
use of com.ferreusveritas.dynamictrees.trees.Species 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.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.
the class RedwoodLogic method populateDirectionProbabilityMap.
@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
final Species species = context.species();
final World world = context.world();
final GrowSignal signal = context.signal();
final int[] probMap = context.probMap();
final int radius = context.radius();
final BlockPos pos = context.pos();
Direction originDir = signal.dir.getOpposite();
int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
// Alter probability map for direction change
// Down is always disallowed for spruce
probMap[0] = 0;
probMap[1] = signal.isInTrunk() ? species.getUpProbability() : 0;
boolean branchOut = (signal.numSteps + treeHash) % 5 == 0;
// Only allow turns when we aren't in the trunk(or the branch is not a twig)
int sideTurn = !signal.isInTrunk() || (signal.isInTrunk() && branchOut && radius > 1) ? 2 : 0;
int canopyHeight = species.getLowestBranchHeight() + treeHash % 8 + configuration.get(HEIGHT_OF_CANOPY);
if (signal.delta.getY() < canopyHeight) {
probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
probMap[2 + getHashedVariation(world, pos, 4)] = sideTurn;
} else {
probMap[2] = probMap[3] = probMap[4] = // Only allow turns when we aren't in the trunk(or the branch is not a twig and step is odd)
probMap[5] = !signal.isInTrunk() || (signal.isInTrunk() && signal.numSteps % 4 == 1 && radius > 1) ? 2 : 0;
}
// Disable the direction we came from
probMap[originDir.ordinal()] = 0;
// Favor current travel direction
probMap[signal.dir.ordinal()] += signal.isInTrunk() ? 0 : signal.numTurns == 1 ? 2 : 1;
if (!signal.isInTrunk() && signal.numTurns == 1 && signal.delta.distSqr(0, signal.delta.getY(), 0, false) <= 1.5) {
// disable left and right if we JUST turned out of the trunk, this is to prevent branches from interfering with the other sides
probMap[signal.dir.getClockWise().ordinal()] = probMap[signal.dir.getCounterClockWise().ordinal()] = 0;
}
return probMap;
}
use of com.ferreusveritas.dynamictrees.trees.Species in project DynamicTrees-BYG by DynamicTreesTeam.
the class SmallRedwoodLogic method populateDirectionProbabilityMap.
// *-*-*-*-*-*-*-*- %2 < 1
// **--**--**--**-- %4 < 2
// ****----****---- %8 < 4
// ********-------- %16< 8
@Override
public int[] populateDirectionProbabilityMap(GrowthLogicKitConfiguration configuration, DirectionManipulationContext context) {
final Species species = context.species();
final GrowSignal signal = context.signal();
final int[] probMap = context.probMap();
Direction originDir = signal.dir.getOpposite();
int treeHash = CoordUtils.coordHashCode(signal.rootPos, 2);
// Alter probability map for direction change
// Down is always disallowed for spruce
probMap[0] = 0;
probMap[1] = signal.isInTrunk() ? species.getUpProbability() : 0;
int canopyHeight = species.getLowestBranchHeight() + 4;
if (signal.delta.getY() == species.getLowestBranchHeight()) {
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 if (signal.delta.getY() < canopyHeight) {
probMap[2] = probMap[3] = probMap[4] = probMap[5] = 0;
} else {
probMap[2] = probMap[3] = probMap[4] = // Only allow turns when we aren't in the trunk(or the branch is not a twig and step is odd)
probMap[5] = !signal.isInTrunk() || (signal.isInTrunk() && signal.numSteps % 2 == 1 && context.radius() > 1) ? 2 : 0;
}
// Disable the direction we came from
probMap[originDir.ordinal()] = 0;
// Favor current travel direction
probMap[signal.dir.ordinal()] += signal.isInTrunk() ? 0 : signal.numTurns == 1 ? 2 : 1;
return probMap;
}
Aggregations