Search in sources :

Example 1 with IBaritone

use of baritone.api.IBaritone in project baritone by cabaletta.

the class RotationUtils method reachable.

public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
    IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
    if (baritone.getPlayerContext().isLookingAt(pos)) {
        /*
             * why add 0.0001?
             * to indicate that we actually have a desired pitch
             * the way we indicate that the pitch can be whatever and we only care about the yaw
             * is by setting the desired pitch to the current pitch
             * setting the desired pitch to the current pitch + 0.0001 means that we do have a desired pitch, it's
             * just what it currently is
             *
             * or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level
             */
        Rotation hypothetical = new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F);
        if (wouldSneak) {
            // the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are
            RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true);
            if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(pos)) {
                // yes, if we sneaked we would still be looking at the block
                return Optional.of(hypothetical);
            }
        } else {
            return Optional.of(hypothetical);
        }
    }
    Optional<Rotation> possibleRotation = reachableCenter(entity, pos, blockReachDistance, wouldSneak);
    // System.out.println("center: " + possibleRotation);
    if (possibleRotation.isPresent()) {
        return possibleRotation;
    }
    IBlockState state = entity.world.getBlockState(pos);
    AxisAlignedBB aabb = state.getBoundingBox(entity.world, pos);
    for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
        double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x);
        double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
        double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
        possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak);
        if (possibleRotation.isPresent()) {
            return possibleRotation;
        }
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBaritone(baritone.api.IBaritone)

Example 2 with IBaritone

use of baritone.api.IBaritone in project baritone by cabaletta.

the class MixinEntityPlayerSP method isKeyDown.

@Redirect(method = "onLivingUpdate", at = @At(value = "INVOKE", target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z"))
private boolean isKeyDown(KeyBinding keyBinding) {
    IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
    if (baritone == null) {
        return keyBinding.isKeyDown();
    }
    SprintStateEvent event = new SprintStateEvent();
    baritone.getGameEventHandler().onPlayerSprintState(event);
    if (event.getState() != null) {
        return event.getState();
    }
    if (baritone != BaritoneAPI.getProvider().getPrimaryBaritone()) {
        // hitting control shouldn't make all bots sprint
        return false;
    }
    return keyBinding.isKeyDown();
}
Also used : IBaritone(baritone.api.IBaritone) SprintStateEvent(baritone.api.event.events.SprintStateEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 with IBaritone

use of baritone.api.IBaritone in project baritone by cabaletta.

the class MixinEntityPlayerSP method sendChatMessage.

@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void sendChatMessage(String msg, CallbackInfo ci) {
    ChatEvent event = new ChatEvent(msg);
    IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
    if (baritone == null) {
        return;
    }
    baritone.getGameEventHandler().onSendChatMessage(event);
    if (event.isCancelled()) {
        ci.cancel();
    }
}
Also used : IBaritone(baritone.api.IBaritone) ChatEvent(baritone.api.event.events.ChatEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with IBaritone

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

the class MovementHelper method attemptToPlaceABlock.

static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown, boolean wouldSneak) {
    IPlayerContext ctx = baritone.getPlayerContext();
    // we assume that if there is a block there, it must be replacable
    Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt, wouldSneak);
    boolean found = false;
    if (direct.isPresent()) {
        state.setTarget(new MovementState.MovementTarget(direct.get(), true));
        found = true;
    }
    for (int i = 0; i < 5; i++) {
        BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
        if (MovementHelper.canPlaceAgainst(ctx, against1)) {
            if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(false, placeAt.getX(), placeAt.getY(), placeAt.getZ())) {
                // get ready to place a throwaway block
                Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
                state.setStatus(MovementStatus.UNREACHABLE);
                return PlaceResult.NO_OPTION;
            }
            double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D;
            double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D;
            double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
            Rotation place = RotationUtils.calcRotationFromVec3d(wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
            RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance(), wouldSneak);
            if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) {
                state.setTarget(new MovementState.MovementTarget(place, true));
                found = true;
                if (!preferDown) {
                    // if preferDown is false, we want the first
                    break;
                }
            }
        }
    }
    if (ctx.getSelectedBlock().isPresent()) {
        BlockPos selectedBlock = ctx.getSelectedBlock().get();
        EnumFacing side = ctx.objectMouseOver().sideHit;
        // only way for selectedBlock.equals(placeAt) to be true is if it's replacable
        if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
            if (wouldSneak) {
                state.setInput(Input.SNEAK, true);
            }
            ((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
            return PlaceResult.READY_TO_PLACE;
        }
    }
    if (found) {
        if (wouldSneak) {
            state.setInput(Input.SNEAK, true);
        }
        ((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
        return PlaceResult.ATTEMPTING;
    }
    return PlaceResult.NO_OPTION;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) MovementTarget(baritone.pathing.movement.MovementState.MovementTarget) Vec3d(net.minecraft.util.math.Vec3d) IBaritone(baritone.api.IBaritone) Baritone(baritone.Baritone) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with IBaritone

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

the class MixinEntityPlayerSP method sendChatMessage.

@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void sendChatMessage(String msg, CallbackInfo ci) {
    ChatEvent event = new ChatEvent(msg);
    IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
    if (baritone == null) {
        return;
    }
    baritone.getGameEventHandler().onSendChatMessage(event);
    if (event.isCancelled()) {
        ci.cancel();
    }
}
Also used : IBaritone(baritone.api.IBaritone) ChatEvent(baritone.api.event.events.ChatEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

IBaritone (baritone.api.IBaritone)14 Inject (org.spongepowered.asm.mixin.injection.Inject)8 Baritone (baritone.Baritone)2 ChatEvent (baritone.api.event.events.ChatEvent)2 RotationMoveEvent (baritone.api.event.events.RotationMoveEvent)2 SprintStateEvent (baritone.api.event.events.SprintStateEvent)2 TabCompleteEvent (baritone.api.event.events.TabCompleteEvent)2 TickEvent (baritone.api.event.events.TickEvent)2 EventState (baritone.api.event.events.type.EventState)2 MovementTarget (baritone.pathing.movement.MovementState.MovementTarget)2 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2