Search in sources :

Example 1 with BlockOptionalMeta

use of baritone.api.utils.BlockOptionalMeta in project baritone by cabaletta.

the class SelCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    Action action = Action.getByName(args.getString());
    if (action == null) {
        throw new CommandInvalidTypeException(args.consumed(), "an action");
    }
    if (action == Action.POS1 || action == Action.POS2) {
        if (action == Action.POS2 && pos1 == null) {
            throw new CommandInvalidStateException("Set pos1 first before using pos2");
        }
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (action == Action.POS1) {
            pos1 = pos;
            logDirect("Position 1 has been set");
        } else {
            manager.addSelection(pos1, pos);
            pos1 = null;
            logDirect("Selection added");
        }
    } else if (action == Action.CLEAR) {
        args.requireMax(0);
        pos1 = null;
        logDirect(String.format("Removed %d selections", manager.removeAllSelections().length));
    } else if (action == Action.UNDO) {
        args.requireMax(0);
        if (pos1 != null) {
            pos1 = null;
            logDirect("Undid pos1");
        } else {
            ISelection[] selections = manager.getSelections();
            if (selections.length < 1) {
                throw new CommandInvalidStateException("Nothing to undo!");
            } else {
                pos1 = manager.removeSelection(selections[selections.length - 1]).pos1();
                logDirect("Undid pos2");
            }
        }
    } else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
        BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
        BlockOptionalMetaLookup replaces = null;
        if (action == Action.REPLACE) {
            args.requireMin(1);
            List<BlockOptionalMeta> replacesList = new ArrayList<>();
            replacesList.add(type);
            while (args.has(2)) {
                replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
            }
            type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
            replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
        } else {
            args.requireMax(0);
        }
        ISelection[] selections = manager.getSelections();
        if (selections.length == 0) {
            throw new CommandInvalidStateException("No selections");
        }
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
            if (action == Action.WALLS) {
                schematic = new WallsSchematic(schematic);
            } else if (action == Action.SHELL) {
                schematic = new ShellSchematic(schematic);
            } else if (action == Action.REPLACE) {
                schematic = new ReplaceSchematic(schematic, replaces);
            }
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        baritone.getBuilderProcess().build("Fill", composite, origin);
        logDirect("Filling now");
    } else if (action == Action.COPY) {
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections");
        }
        BlockStateInterface bsi = new BlockStateInterface(ctx);
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            IBlockState[][][] blockstates = new IBlockState[size.getX()][size.getZ()][size.getY()];
            for (int x = 0; x < size.getX(); x++) {
                for (int y = 0; y < size.getY(); y++) {
                    for (int z = 0; z < size.getZ(); z++) {
                        blockstates[x][z][y] = bsi.get0(min.x + x, min.y + y, min.z + z);
                    }
                }
            }
            ISchematic schematic = new StaticSchematic() {

                {
                    states = blockstates;
                    x = size.getX();
                    y = size.getY();
                    z = size.getZ();
                }
            };
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        clipboard = composite;
        clipboardOffset = origin.subtract(pos);
        logDirect("Selection copied");
    } else if (action == Action.PASTE) {
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (clipboard == null) {
            throw new CommandInvalidStateException("You need to copy a selection first");
        }
        baritone.getBuilderProcess().build("Fill", clipboard, pos.add(clipboardOffset));
        logDirect("Building now");
    } else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
        args.requireExactly(3);
        TransformTarget transformTarget = TransformTarget.getByName(args.getString());
        if (transformTarget == null) {
            throw new CommandInvalidStateException("Invalid transform type");
        }
        EnumFacing direction = args.getDatatypeFor(ForEnumFacing.INSTANCE);
        int blocks = args.getAs(Integer.class);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections found");
        }
        selections = transformTarget.transform(selections);
        for (ISelection selection : selections) {
            if (action == Action.EXPAND) {
                manager.expand(selection, direction, blocks);
            } else if (action == Action.CONTRACT) {
                manager.contract(selection, direction, blocks);
            } else {
                manager.shift(selection, direction, blocks);
            }
        }
        logDirect(String.format("Transformed %d selections", selections.length));
    }
}
Also used : CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) EnumFacing(net.minecraft.util.EnumFacing) ForEnumFacing(baritone.api.command.datatypes.ForEnumFacing) StaticSchematic(baritone.utils.schematic.StaticSchematic) BetterBlockPos(baritone.api.utils.BetterBlockPos) ISelection(baritone.api.selection.ISelection) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) RelativeBlockPos(baritone.api.command.datatypes.RelativeBlockPos) List(java.util.List) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) Vec3i(net.minecraft.util.math.Vec3i) BlockStateInterface(baritone.utils.BlockStateInterface) IBlockState(net.minecraft.block.state.IBlockState) BlockOptionalMetaLookup(baritone.api.utils.BlockOptionalMetaLookup) ForBlockOptionalMeta(baritone.api.command.datatypes.ForBlockOptionalMeta) BlockOptionalMeta(baritone.api.utils.BlockOptionalMeta)

Example 2 with BlockOptionalMeta

use of baritone.api.utils.BlockOptionalMeta in project baritone by cabaletta.

the class GotoCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    // is no need to handle the case of empty arguments.
    if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
        args.requireMax(3);
        BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
        Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
        logDirect(String.format("Going to: %s", goal.toString()));
        baritone.getCustomGoalProcess().setGoalAndPath(goal);
        return;
    }
    args.requireMax(1);
    BlockOptionalMeta destination = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
    baritone.getGetToBlockProcess().getToBlock(destination);
}
Also used : RelativeGoal(baritone.api.command.datatypes.RelativeGoal) Goal(baritone.api.pathing.goals.Goal) ForBlockOptionalMeta(baritone.api.command.datatypes.ForBlockOptionalMeta) BlockOptionalMeta(baritone.api.utils.BlockOptionalMeta) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 3 with BlockOptionalMeta

use of baritone.api.utils.BlockOptionalMeta in project Spark-Client by Spark-Client-Development.

the class SelCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    Action action = Action.getByName(args.getString());
    if (action == null) {
        throw new CommandInvalidTypeException(args.consumed(), "an action");
    }
    if (action == Action.POS1 || action == Action.POS2) {
        if (action == Action.POS2 && pos1 == null) {
            throw new CommandInvalidStateException("Set pos1 first before using pos2");
        }
        BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
        BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
        args.requireMax(0);
        if (action == Action.POS1) {
            pos1 = pos;
            logDirect("Position 1 has been set");
        } else {
            manager.addSelection(pos1, pos);
            pos1 = null;
            logDirect("Selection added");
        }
    } else if (action == Action.CLEAR) {
        args.requireMax(0);
        pos1 = null;
        logDirect(String.format("Removed %d selections", manager.removeAllSelections().length));
    } else if (action == Action.UNDO) {
        args.requireMax(0);
        if (pos1 != null) {
            pos1 = null;
            logDirect("Undid pos1");
        } else {
            ISelection[] selections = manager.getSelections();
            if (selections.length < 1) {
                throw new CommandInvalidStateException("Nothing to undo!");
            } else {
                pos1 = manager.removeSelection(selections[selections.length - 1]).pos1();
                logDirect("Undid pos2");
            }
        }
    } else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
        BlockOptionalMeta type = action == Action.CLEARAREA ? new BlockOptionalMeta(Blocks.AIR) : args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
        BlockOptionalMetaLookup replaces = null;
        if (action == Action.REPLACE) {
            args.requireMin(1);
            List<BlockOptionalMeta> replacesList = new ArrayList<>();
            replacesList.add(type);
            while (args.has(2)) {
                replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
            }
            type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
            replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
        } else {
            args.requireMax(0);
        }
        ISelection[] selections = manager.getSelections();
        if (selections.length == 0) {
            throw new CommandInvalidStateException("No selections");
        }
        BetterBlockPos origin = selections[0].min();
        CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
        for (ISelection selection : selections) {
            BetterBlockPos min = selection.min();
            origin = new BetterBlockPos(Math.min(origin.x, min.x), Math.min(origin.y, min.y), Math.min(origin.z, min.z));
        }
        for (ISelection selection : selections) {
            Vec3i size = selection.size();
            BetterBlockPos min = selection.min();
            ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
            if (action == Action.WALLS) {
                schematic = new WallsSchematic(schematic);
            } else if (action == Action.SHELL) {
                schematic = new ShellSchematic(schematic);
            } else if (action == Action.REPLACE) {
                schematic = new ReplaceSchematic(schematic, replaces);
            }
            composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
        }
        baritone.getBuilderProcess().build("Fill", composite, origin);
        logDirect("Filling now");
    } else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
        args.requireExactly(3);
        TransformTarget transformTarget = TransformTarget.getByName(args.getString());
        if (transformTarget == null) {
            throw new CommandInvalidStateException("Invalid transform type");
        }
        EnumFacing direction = args.getDatatypeFor(ForEnumFacing.INSTANCE);
        int blocks = args.getAs(Integer.class);
        ISelection[] selections = manager.getSelections();
        if (selections.length < 1) {
            throw new CommandInvalidStateException("No selections found");
        }
        selections = transformTarget.transform(selections);
        for (ISelection selection : selections) {
            if (action == Action.EXPAND) {
                manager.expand(selection, direction, blocks);
            } else if (action == Action.CONTRACT) {
                manager.contract(selection, direction, blocks);
            } else {
                manager.shift(selection, direction, blocks);
            }
        }
        logDirect(String.format("Transformed %d selections", selections.length));
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) CommandInvalidTypeException(baritone.api.command.exception.CommandInvalidTypeException) EnumFacing(net.minecraft.util.EnumFacing) ForEnumFacing(baritone.api.command.datatypes.ForEnumFacing) BlockOptionalMetaLookup(baritone.api.utils.BlockOptionalMetaLookup) ForBlockOptionalMeta(baritone.api.command.datatypes.ForBlockOptionalMeta) BlockOptionalMeta(baritone.api.utils.BlockOptionalMeta) BetterBlockPos(baritone.api.utils.BetterBlockPos) ISelection(baritone.api.selection.ISelection) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) RelativeBlockPos(baritone.api.command.datatypes.RelativeBlockPos) List(java.util.List) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException)

Example 4 with BlockOptionalMeta

use of baritone.api.utils.BlockOptionalMeta in project Spark-Client by Spark-Client-Development.

the class GotoCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    // is no need to handle the case of empty arguments.
    if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
        args.requireMax(3);
        BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
        Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
        logDirect(String.format("Going to: %s", goal.toString()));
        baritone.getCustomGoalProcess().setGoalAndPath(goal);
        return;
    }
    args.requireMax(1);
    BlockOptionalMeta destination = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
    baritone.getGetToBlockProcess().getToBlock(destination);
}
Also used : RelativeGoal(baritone.api.command.datatypes.RelativeGoal) Goal(baritone.api.pathing.goals.Goal) ForBlockOptionalMeta(baritone.api.command.datatypes.ForBlockOptionalMeta) BlockOptionalMeta(baritone.api.utils.BlockOptionalMeta) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Aggregations

ForBlockOptionalMeta (baritone.api.command.datatypes.ForBlockOptionalMeta)4 BetterBlockPos (baritone.api.utils.BetterBlockPos)4 BlockOptionalMeta (baritone.api.utils.BlockOptionalMeta)4 ForEnumFacing (baritone.api.command.datatypes.ForEnumFacing)2 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)2 RelativeGoal (baritone.api.command.datatypes.RelativeGoal)2 CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)2 CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)2 Goal (baritone.api.pathing.goals.Goal)2 ISelection (baritone.api.selection.ISelection)2 BlockOptionalMetaLookup (baritone.api.utils.BlockOptionalMetaLookup)2 List (java.util.List)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3i (net.minecraft.util.math.Vec3i)2 BlockStateInterface (baritone.utils.BlockStateInterface)1 StaticSchematic (baritone.utils.schematic.StaticSchematic)1 IBlockState (net.minecraft.block.state.IBlockState)1