use of com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform 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.systems.nodemappers.NodeTransform 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();
}
Aggregations