Search in sources :

Example 16 with BetterBlockPos

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

the class PathingBehavior method pathStart.

/**
 * See issue #209
 *
 * @return The starting {@link BlockPos} for a new path
 */
public BetterBlockPos pathStart() {
    // TODO move to a helper or util class
    BetterBlockPos feet = ctx.playerFeet();
    if (!MovementHelper.canWalkOn(ctx, feet.down())) {
        if (ctx.player().onGround) {
            double playerX = ctx.player().posX;
            double playerZ = ctx.player().posZ;
            ArrayList<BetterBlockPos> closest = new ArrayList<>();
            for (int dx = -1; dx <= 1; dx++) {
                for (int dz = -1; dz <= 1; dz++) {
                    closest.add(new BetterBlockPos(feet.x + dx, feet.y, feet.z + dz));
                }
            }
            closest.sort(Comparator.comparingDouble(pos -> ((pos.x + 0.5D) - playerX) * ((pos.x + 0.5D) - playerX) + ((pos.z + 0.5D) - playerZ) * ((pos.z + 0.5D) - playerZ)));
            for (int i = 0; i < 4; i++) {
                BetterBlockPos possibleSupport = closest.get(i);
                double xDist = Math.abs((possibleSupport.x + 0.5D) - playerX);
                double zDist = Math.abs((possibleSupport.z + 0.5D) - playerZ);
                if (xDist > 0.8 && zDist > 0.8) {
                    // can't possibly be sneaking off of this one, we're too far away
                    continue;
                }
                if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) {
                    // logDebug("Faking path start assuming player is standing off the edge of a block");
                    return possibleSupport;
                }
            }
        } else {
            // we're in the middle of a jump
            if (MovementHelper.canWalkOn(ctx, feet.down().down())) {
                // logDebug("Faking path start assuming player is midair and falling");
                return feet.down();
            }
        }
    }
    return feet;
}
Also used : IPathingBehavior(baritone.api.behavior.IPathingBehavior) Helper(baritone.api.utils.Helper) PathCalculationResult(baritone.api.utils.PathCalculationResult) IGoalRenderPos(baritone.api.utils.interfaces.IGoalRenderPos) MovementHelper(baritone.pathing.movement.MovementHelper) ArrayList(java.util.ArrayList) GoalXZ(baritone.api.pathing.goals.GoalXZ) AStarPathFinder(baritone.pathing.calc.AStarPathFinder) Favoring(baritone.utils.pathing.Favoring) AbstractNodeCostSearch(baritone.pathing.calc.AbstractNodeCostSearch) baritone.api.event.events(baritone.api.event.events) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Goal(baritone.api.pathing.goals.Goal) BetterBlockPos(baritone.api.utils.BetterBlockPos) Objects(java.util.Objects) PathingCommand(baritone.api.process.PathingCommand) PathingCommandContext(baritone.utils.PathingCommandContext) IPath(baritone.api.pathing.calc.IPath) PathRenderer(baritone.utils.PathRenderer) Baritone(baritone.Baritone) Optional(java.util.Optional) PathExecutor(baritone.pathing.path.PathExecutor) Comparator(java.util.Comparator) BetterBlockPos(baritone.api.utils.BetterBlockPos) ArrayList(java.util.ArrayList)

Example 17 with BetterBlockPos

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

the class PathingBehavior method estimatedTicksToGoal.

public Optional<Double> estimatedTicksToGoal() {
    BetterBlockPos currentPos = ctx.playerFeet();
    if (goal == null || currentPos == null || startPosition == null) {
        return Optional.empty();
    }
    if (goal.isInGoal(ctx.playerFeet())) {
        resetEstimatedTicksToGoal();
        return Optional.of(0.0);
    }
    if (ticksElapsedSoFar == 0) {
        return Optional.empty();
    }
    double current = goal.heuristic(currentPos.x, currentPos.y, currentPos.z);
    double start = goal.heuristic(startPosition.x, startPosition.y, startPosition.z);
    if (current == start) {
        // can't check above because current and start can be equal even if currentPos and startPosition are not
        return Optional.empty();
    }
    double eta = Math.abs(current - goal.heuristic()) * ticksElapsedSoFar / Math.abs(start - current);
    return Optional.of(eta);
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 18 with BetterBlockPos

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

the class WaypointCollection method load.

private synchronized void load(Waypoint.Tag tag) {
    this.waypoints.put(tag, new HashSet<>());
    Path fileName = this.directory.resolve(tag.name().toLowerCase() + ".mp4");
    if (!Files.exists(fileName)) {
        return;
    }
    try (FileInputStream fileIn = new FileInputStream(fileName.toFile());
        BufferedInputStream bufIn = new BufferedInputStream(fileIn);
        DataInputStream in = new DataInputStream(bufIn)) {
        long magic = in.readLong();
        if (magic != WAYPOINT_MAGIC_VALUE) {
            throw new IOException("Bad magic value " + magic);
        }
        // Yes I want 9,223,372,036,854,775,807 waypoints, do you not?
        long length = in.readLong();
        while (length-- > 0) {
            String name = in.readUTF();
            long creationTimestamp = in.readLong();
            int x = in.readInt();
            int y = in.readInt();
            int z = in.readInt();
            this.waypoints.get(tag).add(new Waypoint(name, tag, new BetterBlockPos(x, y, z), creationTimestamp));
        }
    } catch (IOException ignored) {
    }
}
Also used : Path(java.nio.file.Path) BetterBlockPos(baritone.api.utils.BetterBlockPos) IWaypoint(baritone.api.cache.IWaypoint) Waypoint(baritone.api.cache.Waypoint) IWaypoint(baritone.api.cache.IWaypoint) Waypoint(baritone.api.cache.Waypoint)

Example 19 with BetterBlockPos

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

the class ChestsCommand method execute.

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
    args.requireMax(0);
    Set<Map.Entry<BlockPos, IRememberedInventory>> entries = ctx.worldData().getContainerMemory().getRememberedInventories().entrySet();
    if (entries.isEmpty()) {
        throw new CommandInvalidStateException("No remembered inventories");
    }
    for (Map.Entry<BlockPos, IRememberedInventory> entry : entries) {
        // betterblockpos has censoring
        BetterBlockPos pos = new BetterBlockPos(entry.getKey());
        IRememberedInventory inv = entry.getValue();
        logDirect(pos.toString());
        for (ItemStack item : inv.getContents()) {
            ITextComponent component = item.getTextComponent();
            component.appendText(String.format(" x %d", item.getCount()));
            logDirect(component);
        }
    }
}
Also used : IRememberedInventory(baritone.api.cache.IRememberedInventory) BetterBlockPos(baritone.api.utils.BetterBlockPos) ITextComponent(net.minecraft.util.text.ITextComponent) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) CommandInvalidStateException(baritone.api.command.exception.CommandInvalidStateException) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map)

Example 20 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos 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)

Aggregations

BetterBlockPos (baritone.api.utils.BetterBlockPos)57 IBlockState (net.minecraft.block.state.IBlockState)15 Goal (baritone.api.pathing.goals.Goal)14 BlockPos (net.minecraft.util.math.BlockPos)10 CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)9 IWaypoint (baritone.api.cache.IWaypoint)6 GoalBlock (baritone.api.pathing.goals.GoalBlock)6 Waypoint (baritone.api.cache.Waypoint)5 Rotation (baritone.api.utils.Rotation)5 EnumFacing (net.minecraft.util.EnumFacing)5 IBaritone (baritone.api.IBaritone)4 Command (baritone.api.command.Command)4 IArgConsumer (baritone.api.command.argument.IArgConsumer)4 ForBlockOptionalMeta (baritone.api.command.datatypes.ForBlockOptionalMeta)4 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)4 RelativeGoal (baritone.api.command.datatypes.RelativeGoal)4 CommandException (baritone.api.command.exception.CommandException)4 CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)4 IPath (baritone.api.pathing.calc.IPath)4 PathingCommand (baritone.api.process.PathingCommand)4