Search in sources :

Example 1 with MovementTarget

use of baritone.pathing.movement.MovementState.MovementTarget 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 MovementTarget

use of baritone.pathing.movement.MovementState.MovementTarget 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

BetterBlockPos (baritone.api.utils.BetterBlockPos)2 Rotation (baritone.api.utils.Rotation)2 MovementTarget (baritone.pathing.movement.MovementState.MovementTarget)2 Block (net.minecraft.block.Block)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3d (net.minecraft.util.math.Vec3d)2 Vec3i (net.minecraft.util.math.Vec3i)2