Search in sources :

Example 6 with Rotation

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

the class BuilderProcess method onTick.

public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel, int recursions) {
    if (recursions > 1000) {
        // onTick calls itself, don't crash
        return new PathingCommand(null, PathingCommandType.SET_GOAL_AND_PATH);
    }
    approxPlaceable = approxPlaceable(36);
    if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
        ticks = 5;
    } else {
        ticks--;
    }
    baritone.getInputOverrideHandler().clearAllKeys();
    if (paused) {
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().buildInLayers.getValue()) {
        if (realSchematic == null) {
            realSchematic = schematic;
        }
        // wrap this properly, dont just have the inner class refer to the builderprocess.this
        ISchematic realSchematic = this.realSchematic;
        int minYInclusive;
        int maxYInclusive;
        // layer = realSchematic.heightY() should be everything
        if (Baritone.settings().layerOrder.getValue()) {
            // top to bottom
            maxYInclusive = realSchematic.heightY() - 1;
            minYInclusive = realSchematic.heightY() - layer;
        } else {
            maxYInclusive = layer - 1;
            minYInclusive = 0;
        }
        schematic = new ISchematic() {

            @Override
            public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
                return realSchematic.desiredState(x, y, z, current, BuilderProcess.this.approxPlaceable);
            }

            @Override
            public boolean inSchematic(int x, int y, int z, IBlockState currentState) {
                return ISchematic.super.inSchematic(x, y, z, currentState) && y >= minYInclusive && y <= maxYInclusive && realSchematic.inSchematic(x, y, z, currentState);
            }

            @Override
            public void reset() {
                realSchematic.reset();
            }

            @Override
            public int widthX() {
                return realSchematic.widthX();
            }

            @Override
            public int heightY() {
                return realSchematic.heightY();
            }

            @Override
            public int lengthZ() {
                return realSchematic.lengthZ();
            }
        };
    }
    BuilderCalculationContext bcc = new BuilderCalculationContext();
    if (!recalc(bcc)) {
        if (Baritone.settings().buildInLayers.getValue() && layer < realSchematic.heightY()) {
            logDirect("Starting layer " + layer);
            layer++;
            return onTick(calcFailed, isSafeToCancel, recursions + 1);
        }
        Vec3i repeat = Baritone.settings().buildRepeat.getValue();
        int max = Baritone.settings().buildRepeatCount.getValue();
        numRepeats++;
        if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
            logDirect("Done building");
            if (Baritone.settings().desktopNotifications.getValue() && Baritone.settings().notificationOnBuildFinished.getValue()) {
                NotificationHelper.notify("Done building", false);
            }
            onLostControl();
            return null;
        }
        // build repeat time
        layer = 0;
        origin = new BlockPos(origin).add(repeat);
        if (!Baritone.settings().buildRepeatSneaky.getValue()) {
            schematic.reset();
        }
        logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
        return onTick(calcFailed, isSafeToCancel, recursions + 1);
    }
    if (Baritone.settings().distanceTrim.getValue()) {
        trim();
    }
    Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
    if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
        // we'd like to pause to break this block
        // only change look direction if it's safe (don't want to fuck up an in progress parkour for example
        Rotation rot = toBreak.get().getSecond();
        BetterBlockPos pos = toBreak.get().getFirst();
        baritone.getLookBehavior().updateTarget(rot, true);
        MovementHelper.switchToBestToolFor(ctx, bcc.get(pos));
        if (ctx.player().isSneaking()) {
            // really horrible bug where a block is visible for breaking while sneaking but not otherwise
            // so you can't see it, it goes to place something else, sneaks, then the next tick it tries to break
            // and is unable since it's unsneaked in the intermediary tick
            baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        }
        if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    List<IBlockState> desirableOnHotbar = new ArrayList<>();
    Optional<Placement> toPlace = searchForPlaceables(bcc, desirableOnHotbar);
    if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
        Rotation rot = toPlace.get().rot;
        baritone.getLookBehavior().updateTarget(rot, true);
        ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
        baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
        if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
            baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
        }
        return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
    }
    if (Baritone.settings().allowInventory.getValue()) {
        ArrayList<Integer> usefulSlots = new ArrayList<>();
        List<IBlockState> noValidHotbarOption = new ArrayList<>();
        outer: for (IBlockState desired : desirableOnHotbar) {
            for (int i = 0; i < 9; i++) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    usefulSlots.add(i);
                    continue outer;
                }
            }
            noValidHotbarOption.add(desired);
        }
        outer: for (int i = 9; i < 36; i++) {
            for (IBlockState desired : noValidHotbarOption) {
                if (valid(approxPlaceable.get(i), desired, true)) {
                    baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
                    break outer;
                }
            }
        }
    }
    Goal goal = assemble(bcc, approxPlaceable.subList(0, 9));
    if (goal == null) {
        // we're far away, so assume that we have our whole inventory to recalculate placeable properly
        goal = assemble(bcc, approxPlaceable, true);
        if (goal == null) {
            if (Baritone.settings().skipFailedLayers.getValue() && Baritone.settings().buildInLayers.getValue() && layer < realSchematic.heightY()) {
                logDirect("Skipping layer that I cannot construct! Layer #" + layer);
                layer++;
                return onTick(calcFailed, isSafeToCancel, recursions + 1);
            }
            logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
            paused = true;
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    }
    return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
}
Also used : ISchematic(baritone.api.schematic.ISchematic) IBlockState(net.minecraft.block.state.IBlockState) Rotation(baritone.api.utils.Rotation) Goal(baritone.api.pathing.goals.Goal) PathingCommand(baritone.api.process.PathingCommand) BetterBlockPos(baritone.api.utils.BetterBlockPos) PathingCommandContext(baritone.utils.PathingCommandContext) BetterBlockPos(baritone.api.utils.BetterBlockPos) Tuple(net.minecraft.util.Tuple)

Example 7 with Rotation

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

the class GetToBlockProcess method rightClick.

private boolean rightClick() {
    for (BlockPos pos : knownLocations) {
        Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
        if (reachable.isPresent()) {
            baritone.getLookBehavior().updateTarget(reachable.get(), true);
            if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) {
                // TODO find some way to right click even if we're in an ESC menu
                baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
                System.out.println(ctx.player().openContainer);
                if (!(ctx.player().openContainer instanceof ContainerPlayer)) {
                    return true;
                }
            }
            if (arrivalTickCount++ > 20) {
                logDirect("Right click timed out");
                return true;
            }
            // trying to right click, will do it next tick or so
            return false;
        }
    }
    logDirect("Arrived but failed to right click open");
    return true;
}
Also used : ContainerPlayer(net.minecraft.inventory.ContainerPlayer) BlockPos(net.minecraft.util.math.BlockPos) Rotation(baritone.api.utils.Rotation)

Example 8 with Rotation

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

the class MovementPillar method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    if (ctx.playerFeet().y < src.y) {
        return state.setStatus(MovementStatus.UNREACHABLE);
    }
    IBlockState fromDown = BlockStateInterface.get(ctx, src);
    if (MovementHelper.isWater(fromDown.getBlock()) && MovementHelper.isWater(ctx, dest)) {
        // stay centered while swimming up a water column
        state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()), false));
        Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
        if (Math.abs(ctx.player().posX - destCenter.x) > 0.2 || Math.abs(ctx.player().posZ - destCenter.z) > 0.2) {
            state.setInput(Input.MOVE_FORWARD, true);
        }
        if (ctx.playerFeet().equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        return state;
    }
    boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE;
    boolean vine = fromDown.getBlock() == Blocks.VINE;
    Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch));
    if (!ladder) {
        state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true));
    }
    boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
    if (ladder) {
        BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
        if (against == null) {
            logDirect("Unable to climb vines. Consider disabling allowVines.");
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        if (ctx.playerFeet().equals(against.up()) || ctx.playerFeet().equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        if (MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) {
            state.setInput(Input.JUMP, true);
        }
        /*
            if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) {
                Baritone.moveTowardsBlock(from);
            }
             */
        MovementHelper.moveTowards(ctx, state, against);
        return state;
    } else {
        // Get ready to place a throwaway block
        if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, src.x, src.y, src.z)) {
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        // delay placement by 1 tick for ncp compatibility
        state.setInput(Input.SNEAK, ctx.player().posY > dest.getY() || ctx.player().posY < src.getY() + 0.2D);
        // since (lower down) we only right click once player.isSneaking, and that happens the tick after we request to sneak
        double diffX = ctx.player().posX - (dest.getX() + 0.5);
        double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
        double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
        double flatMotion = Math.sqrt(ctx.player().motionX * ctx.player().motionX + ctx.player().motionZ * ctx.player().motionZ);
        if (dist > 0.17) {
            // why 0.17? because it seemed like a good number, that's why
            // [explanation added after baritone port lol] also because it needs to be less than 0.2 because of the 0.3 sneak limit
            // and 0.17 is reasonably less than 0.2
            // If it's been more than forty ticks of trying to jump and we aren't done yet, go forward, maybe we are stuck
            state.setInput(Input.MOVE_FORWARD, true);
            // revise our target to both yaw and pitch if we're going to be moving forward
            state.setTarget(new MovementState.MovementTarget(rotation, true));
        } else if (flatMotion < 0.05) {
            // If our Y coordinate is above our goal, stop jumping
            state.setInput(Input.JUMP, ctx.player().posY < dest.getY());
        }
        if (!blockIsThere) {
            IBlockState frState = BlockStateInterface.get(ctx, src);
            Block fr = frState.getBlock();
            // TODO: Evaluate usage of getMaterial().isReplaceable()
            if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) {
                RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance()).map(rot -> new MovementState.MovementTarget(rot, true)).ifPresent(state::setTarget);
                // breaking is like 5x slower when you're jumping
                state.setInput(Input.JUMP, false);
                state.setInput(Input.CLICK_LEFT, true);
                blockIsThere = false;
            } else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos())) && ctx.player().posY > dest.getY() + 0.1) {
                state.setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    // If we are at our goal and the block below us is placed
    if (ctx.playerFeet().equals(dest) && blockIsThere) {
        return state.setStatus(MovementStatus.SUCCESS);
    }
    return state;
}
Also used : Rotation(baritone.api.utils.Rotation) ImmutableSet(com.google.common.collect.ImmutableSet) Blocks(net.minecraft.init.Blocks) VecUtils(baritone.api.utils.VecUtils) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) CalculationContext(baritone.pathing.movement.CalculationContext) MovementHelper(baritone.pathing.movement.MovementHelper) BetterBlockPos(baritone.api.utils.BetterBlockPos) Objects(java.util.Objects) IBlockState(net.minecraft.block.state.IBlockState) IBaritone(baritone.api.IBaritone) MovementStatus(baritone.api.pathing.movement.MovementStatus) Movement(baritone.pathing.movement.Movement) Vec3d(net.minecraft.util.math.Vec3d) net.minecraft.block(net.minecraft.block) Baritone(baritone.Baritone) BlockStateInterface(baritone.utils.BlockStateInterface) RotationUtils(baritone.api.utils.RotationUtils) MovementState(baritone.pathing.movement.MovementState) Input(baritone.api.utils.input.Input) IBlockState(net.minecraft.block.state.IBlockState) CalculationContext(baritone.pathing.movement.CalculationContext) Rotation(baritone.api.utils.Rotation) Vec3d(net.minecraft.util.math.Vec3d) MovementState(baritone.pathing.movement.MovementState) IBaritone(baritone.api.IBaritone) Baritone(baritone.Baritone) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 9 with Rotation

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

the class BuilderProcess method toBreakNearPlayer.

private Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
    BetterBlockPos center = ctx.playerFeet();
    BetterBlockPos pathStart = baritone.getPathingBehavior().pathStart();
    for (int dx = -5; dx <= 5; dx++) {
        for (int dy = Baritone.settings().breakFromAbove.getValue() ? -1 : 0; dy <= 5; dy++) {
            for (int dz = -5; dz <= 5; dz++) {
                int x = center.x + dx;
                int y = center.y + dy;
                int z = center.z + dz;
                if (dy == -1 && x == pathStart.x && z == pathStart.z) {
                    // dont mine what we're supported by, but not directly standing on
                    continue;
                }
                IBlockState desired = bcc.getSchematic(x, y, z, bcc.bsi.get0(x, y, z));
                if (desired == null) {
                    // irrelevant
                    continue;
                }
                IBlockState curr = bcc.bsi.get0(x, y, z);
                if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired, false)) {
                    BetterBlockPos pos = new BetterBlockPos(x, y, z);
                    Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
                    if (rot.isPresent()) {
                        return Optional.of(new Tuple<>(pos, rot.get()));
                    }
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation)

Example 10 with Rotation

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

the class BuilderProcess method possibleToPlace.

private Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
    for (EnumFacing against : EnumFacing.values()) {
        BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
        IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
        if (MovementHelper.isReplaceable(placeAgainstPos.x, placeAgainstPos.y, placeAgainstPos.z, placeAgainstState, bsi)) {
            continue;
        }
        if (!ctx.world().mayPlace(toPlace.getBlock(), new BetterBlockPos(x, y, z), false, against, null)) {
            continue;
        }
        AxisAlignedBB aabb = placeAgainstState.getBoundingBox(ctx.world(), placeAgainstPos);
        for (Vec3d placementMultiplier : aabbSideMultipliers(against)) {
            double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x);
            double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
            double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
            Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations());
            RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true);
            if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) {
                OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
                if (hotbar.isPresent()) {
                    return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
                }
            }
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation)

Aggregations

Rotation (baritone.api.utils.Rotation)18 BetterBlockPos (baritone.api.utils.BetterBlockPos)14 IBlockState (net.minecraft.block.state.IBlockState)12 BlockPos (net.minecraft.util.math.BlockPos)12 Vec3d (net.minecraft.util.math.Vec3d)10 Goal (baritone.api.pathing.goals.Goal)4 PathingCommand (baritone.api.process.PathingCommand)4 CalculationContext (baritone.pathing.movement.CalculationContext)4 MovementState (baritone.pathing.movement.MovementState)4 Baritone (baritone.Baritone)2 IBaritone (baritone.api.IBaritone)2 GoalBlock (baritone.api.pathing.goals.GoalBlock)2 GoalComposite (baritone.api.pathing.goals.GoalComposite)2 MovementStatus (baritone.api.pathing.movement.MovementStatus)2 ISchematic (baritone.api.schematic.ISchematic)2 RotationUtils (baritone.api.utils.RotationUtils)2 VecUtils (baritone.api.utils.VecUtils)2 Input (baritone.api.utils.input.Input)2 Movement (baritone.pathing.movement.Movement)2 MovementHelper (baritone.pathing.movement.MovementHelper)2