Search in sources :

Example 1 with NodeTransform

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));
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) IBlockState(net.minecraft.block.state.IBlockState) NodeTransform(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform) BlockPos(net.minecraft.util.math.BlockPos) CommandException(net.minecraft.command.CommandException) Species(com.ferreusveritas.dynamictrees.trees.Species) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Example 2 with NodeTransform

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();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) NodeTransform(com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform) BlockRooty(com.ferreusveritas.dynamictrees.blocks.BlockRooty) Species(com.ferreusveritas.dynamictrees.trees.Species) MapSignal(com.ferreusveritas.dynamictrees.api.network.MapSignal)

Aggregations

MapSignal (com.ferreusveritas.dynamictrees.api.network.MapSignal)2 BlockRooty (com.ferreusveritas.dynamictrees.blocks.BlockRooty)2 NodeTransform (com.ferreusveritas.dynamictrees.systems.nodemappers.NodeTransform)2 Species (com.ferreusveritas.dynamictrees.trees.Species)2 IBlockState (net.minecraft.block.state.IBlockState)2 CommandException (net.minecraft.command.CommandException)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 BlockPos (net.minecraft.util.math.BlockPos)1