Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ public final class Settings {
public final Setting<Boolean> elytraFreeLook = new Setting<>(true);

/**
* Forces the client-sided yaw rotation to an average of the last {@link #smoothLookTicks} of server-sided rotations.
* Forces the client-sided yaw rotation to an average of the last
* {@link #smoothLookTicks} server-sided rotations.
*/
public final Setting<Boolean> smoothLook = new Setting<>(false);

Expand All @@ -789,6 +790,21 @@ public final class Settings {
*/
public final Setting<Integer> smoothLookTicks = new Setting<>(5);

/**
* Interpolates player rotation from the current look direction to the target direction.
* <p>
* This uses {@link #interpolatedLookLength} as a maximum angular speed, so larger
* turns take more ticks than smaller turns.
*/
public final Setting<Boolean> interpolatedLook = new Setting<>(false);

/**
* Maximum angular speed, in degrees per tick, for {@link #interpolatedLook}.
* The historical name is retained for config compatibility.
*/
public final Setting<Integer> interpolatedLookLength = new Setting<>(10);


/**
* When true, the player will remain with its existing look direction as often as possible.
* Although, in some cases this can get it stuck, hence this setting to disable that behavior.
Expand Down
36 changes: 36 additions & 0 deletions src/api/java/baritone/api/behavior/ILookBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,42 @@ public interface ILookBehavior extends IBehavior {
*/
void updateTarget(Rotation rotation, boolean blockInteract);

/**
* Updates the current {@link ILookBehavior} target and optionally restarts
* any active interpolation.
*
* @param rotation The target rotations
* @param blockInteract Whether the target rotations are needed for a block interaction
* @param restartInterpolation Whether active interpolation should restart
* from its current sample
* @see #updateTarget(Rotation, boolean)
*/
default void updateTarget(
Rotation rotation,
boolean blockInteract,
boolean restartInterpolation) {
updateTarget(rotation, blockInteract);
}

/**
* Updates the current {@link ILookBehavior} target and optionally uses it
* without aim processing.
*
* @param rotation The target rotations
* @param blockInteract Whether the target rotations are needed for a block interaction
* @param restartInterpolation Whether active interpolation should restart
* from its current sample
* @param exactRotation Whether the target rotation should skip aim processing
* @see #updateTarget(Rotation, boolean, boolean)
*/
default void updateTarget(
Rotation rotation,
boolean blockInteract,
boolean restartInterpolation,
boolean exactRotation) {
updateTarget(rotation, blockInteract, restartInterpolation);
}

/**
* The aim processor instance for this {@link ILookBehavior}, which is responsible for applying additional,
* deterministic transformations to the target rotation set by {@link #updateTarget}.
Expand Down
14 changes: 14 additions & 0 deletions src/api/java/baritone/api/utils/IInputOverrideHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import baritone.api.behavior.IBehavior;
import baritone.api.utils.input.Input;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;

/**
* @author Brady
Expand All @@ -31,4 +33,16 @@ public interface IInputOverrideHandler extends IBehavior {
void setInputForceState(Input input, boolean forced);

void clearAllKeys();

default boolean isBreakingBlock(BlockPos pos) {
return false;
}

default void setBlockBreakTarget(BlockPos pos) {
// Optional hook for handlers that support targeted block breaking.
}

default void setBlockPlaceTarget(BlockPos pos, Direction side) {
// Optional hook for handlers that support targeted block placing.
}
}
16 changes: 14 additions & 2 deletions src/api/java/baritone/api/utils/IPlayerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SlabBlock;
Expand Down Expand Up @@ -116,15 +117,26 @@ static double eyeHeight(boolean ifSneaking) {
*
* @return The position of the highlighted block
*/
default Optional<BlockPos> getSelectedBlock() {
default Optional<BlockHitResult> getSelectedBlockHitResult() {
HitResult result = objectMouseOver();
if (result != null && result.getType() == HitResult.Type.BLOCK) {
return Optional.of(((BlockHitResult) result).getBlockPos());
return Optional.of((BlockHitResult) result);
}
return Optional.empty();
}

default Optional<BlockPos> getSelectedBlock() {
return getSelectedBlockHitResult().map(BlockHitResult::getBlockPos);
}

default boolean isLookingAt(BlockPos pos) {
return getSelectedBlock().equals(Optional.of(pos));
}

default boolean isLookingAt(BlockPos pos, Direction side) {
return getSelectedBlockHitResult()
.filter(hit -> hit.getBlockPos().equals(pos))
.filter(hit -> hit.getDirection() == side)
.isPresent();
}
}
Loading