Search in sources :

Example 1 with Rotation

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

the class MovementFall method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    BlockPos playerFeet = ctx.playerFeet();
    Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations());
    Rotation targetRotation = null;
    Block destBlock = ctx.world().getBlockState(dest).getBlock();
    boolean isWater = destBlock == Blocks.WATER || destBlock == Blocks.FLOWING_WATER;
    if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
        if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().provider.isNether()) {
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        if (ctx.player().posY - dest.getY() < ctx.playerController().getBlockReachDistance() && !ctx.player().onGround) {
            ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER);
            targetRotation = new Rotation(toDest.getYaw(), 90.0F);
            if (ctx.isLookingAt(dest) || ctx.isLookingAt(dest.down())) {
                state.setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    if (targetRotation != null) {
        state.setTarget(new MovementTarget(targetRotation, true));
    } else {
        state.setTarget(new MovementTarget(toDest, false));
    }
    if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || isWater)) {
        // 0.094 because lilypads
        if (isWater) {
            // only match water, not flowing water (which we cannot pick up with a bucket)
            if (InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
                ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
                if (ctx.player().motionY >= 0) {
                    return state.setInput(Input.CLICK_RIGHT, true);
                } else {
                    return state;
                }
            } else {
                if (ctx.player().motionY >= 0) {
                    return state.setStatus(MovementStatus.SUCCESS);
                }
            // don't else return state; we need to stay centered because this water might be flowing under the surface
            }
        } else {
            return state.setStatus(MovementStatus.SUCCESS);
        }
    }
    // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
    Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
    if (Math.abs(ctx.player().posX + ctx.player().motionX - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().motionZ - destCenter.z) > 0.1) {
        if (!ctx.player().onGround && Math.abs(ctx.player().motionY) > 0.4) {
            state.setInput(Input.SNEAK, true);
        }
        state.setInput(Input.MOVE_FORWARD, true);
    }
    Vec3i avoid = Optional.ofNullable(avoid()).map(EnumFacing::getDirectionVec).orElse(null);
    if (avoid == null) {
        avoid = src.subtract(dest);
    } else {
        double dist = Math.abs(avoid.getX() * (destCenter.x - avoid.getX() / 2.0 - ctx.player().posX)) + Math.abs(avoid.getZ() * (destCenter.z - avoid.getZ() / 2.0 - ctx.player().posZ));
        if (dist < 0.6) {
            state.setInput(Input.MOVE_FORWARD, true);
        } else if (!ctx.player().onGround) {
            state.setInput(Input.SNEAK, false);
        }
    }
    if (targetRotation == null) {
        Vec3d destCenterOffset = new Vec3d(destCenter.x + 0.125 * avoid.getX(), destCenter.y, destCenter.z + 0.125 * avoid.getZ());
        state.setTarget(new MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), destCenterOffset, ctx.playerRotations()), false));
    }
    return state;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation) MovementTarget(baritone.pathing.movement.MovementState.MovementTarget) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with Rotation

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

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 3 with Rotation

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

the class MovementTraverse method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
    IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
    if (state.getStatus() != MovementStatus.RUNNING) {
        // if the setting is enabled
        if (!Baritone.settings().walkWhileBreaking.getValue()) {
            return state;
        }
        // and if we're prepping (aka mining the block in front)
        if (state.getStatus() != MovementStatus.PREPPING) {
            return state;
        }
        // and if it's fine to walk into the blocks in front
        if (MovementHelper.avoidWalkingInto(pb0.getBlock())) {
            return state;
        }
        if (MovementHelper.avoidWalkingInto(pb1.getBlock())) {
            return state;
        }
        // and we aren't already pressed up against the block
        double dist = Math.max(Math.abs(ctx.player().posX - (dest.getX() + 0.5D)), Math.abs(ctx.player().posZ - (dest.getZ() + 0.5D)));
        if (dist < 0.83) {
            return state;
        }
        if (!state.getTarget().getRotation().isPresent()) {
            // this can happen rarely when the server lags and doesn't send the falling sand entity until you've already walked through the block and are now mining the next one
            return state;
        }
        // combine the yaw to the center of the destination, and the pitch to the specific block we're trying to break
        // it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
        float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();
        float pitchToBreak = state.getTarget().getRotation().get().getPitch();
        if ((pb0.isFullCube() || pb0.getBlock() instanceof BlockAir && (pb1.isFullCube() || pb1.getBlock() instanceof BlockAir))) {
            // in the meantime, before we're right up against the block, we can break efficiently at this angle
            pitchToBreak = 26;
        }
        return state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true)).setInput(Input.MOVE_FORWARD, true).setInput(Input.SPRINT, true);
    }
    // sneak may have been set to true in the PREPPING state while mining an adjacent block
    state.setInput(Input.SNEAK, false);
    Block fd = BlockStateInterface.get(ctx, src.down()).getBlock();
    boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
    if (pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor) {
        boolean notPassable = pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, src, dest) || pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, dest, src);
        boolean canOpen = !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()));
        if (notPassable && canOpen) {
            return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), positionsToBreak[0]), ctx.playerRotations()), true)).setInput(Input.CLICK_RIGHT, true);
        }
    }
    if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
        BlockPos blocked = !MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up()) ? positionsToBreak[0] : !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1] : null;
        if (blocked != null) {
            Optional<Rotation> rotation = RotationUtils.reachable(ctx, blocked);
            if (rotation.isPresent()) {
                return state.setTarget(new MovementState.MovementTarget(rotation.get(), true)).setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder;
    BlockPos feet = ctx.playerFeet();
    if (feet.getY() != dest.getY() && !ladder) {
        logDebug("Wrong Y coordinate");
        if (feet.getY() < dest.getY()) {
            return state.setInput(Input.JUMP, true);
        }
        return state;
    }
    if (isTheBridgeBlockThere) {
        if (feet.equals(dest)) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        if (Baritone.settings().overshootTraverse.getValue() && (feet.equals(dest.add(getDirection())) || feet.equals(dest.add(getDirection()).add(getDirection())))) {
            return state.setStatus(MovementStatus.SUCCESS);
        }
        Block low = BlockStateInterface.get(ctx, src).getBlock();
        Block high = BlockStateInterface.get(ctx, src.up()).getBlock();
        if (ctx.player().posY > src.y + 0.1D && !ctx.player().onGround && (low == Blocks.VINE || low == Blocks.LADDER || high == Blocks.VINE || high == Blocks.LADDER)) {
            // wait until we're on the ground
            return state;
        }
        BlockPos into = dest.subtract(src).add(dest);
        Block intoBelow = BlockStateInterface.get(ctx, into).getBlock();
        Block intoAbove = BlockStateInterface.get(ctx, into.up()).getBlock();
        if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, feet) || Baritone.settings().sprintInWater.getValue()) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
            state.setInput(Input.SPRINT, true);
        }
        IBlockState destDown = BlockStateInterface.get(ctx, dest.down());
        BlockPos against = positionsToBreak[0];
        if (feet.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) {
            against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.getValue(BlockLadder.FACING).getOpposite());
            if (against == null) {
                logDirect("Unable to climb vines. Consider disabling allowVines.");
                return state.setStatus(MovementStatus.UNREACHABLE);
            }
        }
        MovementHelper.moveTowards(ctx, state, against);
        return state;
    } else {
        wasTheBridgeBlockAlwaysThere = false;
        Block standingOn = BlockStateInterface.get(ctx, feet.down()).getBlock();
        if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) {
            // see issue #118
            double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().posX), Math.abs(dest.getZ() + 0.5 - ctx.player().posZ));
            if (dist < 0.85) {
                // 0.5 + 0.3 + epsilon
                MovementHelper.moveTowards(ctx, state, dest);
                return state.setInput(Input.MOVE_FORWARD, false).setInput(Input.MOVE_BACK, true);
            }
        }
        double dist1 = Math.max(Math.abs(ctx.player().posX - (dest.getX() + 0.5D)), Math.abs(ctx.player().posZ - (dest.getZ() + 0.5D)));
        PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false, true);
        if ((p == PlaceResult.READY_TO_PLACE || dist1 < 0.6) && !Baritone.settings().assumeSafeWalk.getValue()) {
            state.setInput(Input.SNEAK, true);
        }
        switch(p) {
            case READY_TO_PLACE:
                {
                    if (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.getValue()) {
                        state.setInput(Input.CLICK_RIGHT, true);
                    }
                    return state;
                }
            case ATTEMPTING:
                {
                    if (dist1 > 0.83) {
                        // might need to go forward a bit
                        float yaw = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()).getYaw();
                        if (Math.abs(state.getTarget().rotation.getYaw() - yaw) < 0.1) {
                            // but only if our attempted place is straight ahead
                            return state.setInput(Input.MOVE_FORWARD, true);
                        }
                    } else if (ctx.playerRotations().isReallyCloseTo(state.getTarget().rotation)) {
                        // well i guess theres something in the way
                        return state.setInput(Input.CLICK_LEFT, true);
                    }
                    return state;
                }
            default:
                break;
        }
        if (feet.equals(dest)) {
            // If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
            // Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
            double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D;
            double faceY = (dest.getY() + src.getY() - 1.0D) * 0.5D;
            double faceZ = (dest.getZ() + src.getZ() + 1.0D) * 0.5D;
            // faceX, faceY, faceZ is the middle of the face between from and to
            // this is the block we were just standing on, and the one we want to place against
            BlockPos goalLook = src.down();
            Rotation backToFace = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
            float pitch = backToFace.getPitch();
            double dist2 = Math.max(Math.abs(ctx.player().posX - faceX), Math.abs(ctx.player().posZ - faceZ));
            if (dist2 < 0.29) {
                // see issue #208
                float yaw = RotationUtils.calcRotationFromVec3d(VecUtils.getBlockPosCenter(dest), ctx.playerHead(), ctx.playerRotations()).getYaw();
                state.setTarget(new MovementState.MovementTarget(new Rotation(yaw, pitch), true));
                state.setInput(Input.MOVE_BACK, true);
            } else {
                state.setTarget(new MovementState.MovementTarget(backToFace, true));
            }
            if (ctx.isLookingAt(goalLook)) {
                // wait to right click until we are able to place
                return state.setInput(Input.CLICK_RIGHT, true);
            }
            // Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
            if (ctx.playerRotations().isReallyCloseTo(state.getTarget().rotation)) {
                state.setInput(Input.CLICK_LEFT, true);
            }
            return state;
        }
        MovementHelper.moveTowards(ctx, state, positionsToBreak[0]);
        return state;
    // TODO MovementManager.moveTowardsBlock(to); // move towards not look at because if we are bridging for a couple blocks in a row, it is faster if we dont spin around and walk forwards then spin around and place backwards for every block
    }
}
Also used : 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) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 4 with Rotation

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

the class MovementDescend method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    BlockPos playerFeet = ctx.playerFeet();
    BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ());
    if ((playerFeet.equals(dest) || playerFeet.equals(fakeDest)) && (MovementHelper.isLiquid(ctx, dest) || ctx.player().posY - dest.getY() < 0.5)) {
        // Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
        return state.setStatus(MovementStatus.SUCCESS);
    /* else {
                // System.out.println(player().posY + " " + playerFeet.getY() + " " + (player().posY - playerFeet.getY()));
            }*/
    }
    if (safeMode()) {
        double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83;
        double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83;
        EntityPlayerSP player = ctx.player();
        state.setTarget(new MovementState.MovementTarget(new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(destX, dest.getY(), destZ), new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch), false)).setInput(Input.MOVE_FORWARD, true);
        return state;
    }
    double diffX = ctx.player().posX - (dest.getX() + 0.5);
    double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
    double ab = Math.sqrt(diffX * diffX + diffZ * diffZ);
    double x = ctx.player().posX - (src.getX() + 0.5);
    double z = ctx.player().posZ - (src.getZ() + 0.5);
    double fromStart = Math.sqrt(x * x + z * z);
    if (!playerFeet.equals(dest) || ab > 0.25) {
        if (numTicks++ < 20 && fromStart < 1.25) {
            MovementHelper.moveTowards(ctx, state, fakeDest);
        } else {
            MovementHelper.moveTowards(ctx, state, dest);
        }
    }
    return state;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Rotation(baritone.api.utils.Rotation) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with Rotation

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

the class MovementFall method updateState.

@Override
public MovementState updateState(MovementState state) {
    super.updateState(state);
    if (state.getStatus() != MovementStatus.RUNNING) {
        return state;
    }
    BlockPos playerFeet = ctx.playerFeet();
    Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations());
    Rotation targetRotation = null;
    Block destBlock = ctx.world().getBlockState(dest).getBlock();
    boolean isWater = destBlock == Blocks.WATER || destBlock == Blocks.FLOWING_WATER;
    if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
        if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().provider.isNether()) {
            return state.setStatus(MovementStatus.UNREACHABLE);
        }
        if (ctx.player().posY - dest.getY() < ctx.playerController().getBlockReachDistance() && !ctx.player().onGround) {
            ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER);
            targetRotation = new Rotation(toDest.getYaw(), 90.0F);
            if (ctx.isLookingAt(dest) || ctx.isLookingAt(dest.down())) {
                state.setInput(Input.CLICK_RIGHT, true);
            }
        }
    }
    if (targetRotation != null) {
        state.setTarget(new MovementTarget(targetRotation, true));
    } else {
        state.setTarget(new MovementTarget(toDest, false));
    }
    if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || isWater)) {
        // 0.094 because lilypads
        if (isWater) {
            // only match water, not flowing water (which we cannot pick up with a bucket)
            if (InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
                ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
                if (ctx.player().motionY >= 0) {
                    return state.setInput(Input.CLICK_RIGHT, true);
                } else {
                    return state;
                }
            } else {
                if (ctx.player().motionY >= 0) {
                    return state.setStatus(MovementStatus.SUCCESS);
                }
            // don't else return state; we need to stay centered because this water might be flowing under the surface
            }
        } else {
            return state.setStatus(MovementStatus.SUCCESS);
        }
    }
    // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
    Vec3d destCenter = VecUtils.getBlockPosCenter(dest);
    if (Math.abs(ctx.player().posX + ctx.player().motionX - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().motionZ - destCenter.z) > 0.1) {
        if (!ctx.player().onGround && Math.abs(ctx.player().motionY) > 0.4) {
            state.setInput(Input.SNEAK, true);
        }
        state.setInput(Input.MOVE_FORWARD, true);
    }
    Vec3i avoid = Optional.ofNullable(avoid()).map(EnumFacing::getDirectionVec).orElse(null);
    if (avoid == null) {
        avoid = src.subtract(dest);
    } else {
        double dist = Math.abs(avoid.getX() * (destCenter.x - avoid.getX() / 2.0 - ctx.player().posX)) + Math.abs(avoid.getZ() * (destCenter.z - avoid.getZ() / 2.0 - ctx.player().posZ));
        if (dist < 0.6) {
            state.setInput(Input.MOVE_FORWARD, true);
        } else if (!ctx.player().onGround) {
            state.setInput(Input.SNEAK, false);
        }
    }
    if (targetRotation == null) {
        Vec3d destCenterOffset = new Vec3d(destCenter.x + 0.125 * avoid.getX(), destCenter.y, destCenter.z + 0.125 * avoid.getZ());
        state.setTarget(new MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), destCenterOffset, ctx.playerRotations()), false));
    }
    return state;
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) Rotation(baritone.api.utils.Rotation) MovementTarget(baritone.pathing.movement.MovementState.MovementTarget) Vec3d(net.minecraft.util.math.Vec3d)

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