Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swimming #3988

Open
wants to merge 1 commit into
base: 1.19.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
import java.util.List;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

Expand Down Expand Up @@ -730,6 +731,11 @@ public final class Settings {
*/
public final Setting<Boolean> sprintInWater = new Setting<>(true);

/**
* Attempt to enter the underwater swimming state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aka California after the big earthquake hits

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so true

*/
public final Setting<Boolean> swimInWater = new Setting<>(true);

/**
* When GetToBlockProcess or MineProcess fails to calculate a path, instead of just giving up, mark the closest instance
* of that block as "unreachable" and go towards the next closest. GetToBlock expands this search to the whole "vein"; MineProcess does not.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/baritone/pathing/movement/Movement.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
import baritone.api.utils.*;
import baritone.api.utils.input.Input;
import baritone.behavior.PathingBehavior;
import baritone.pathing.movement.movements.MovementTraverse;
import baritone.utils.BlockStateInterface;
import java.util.*;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.phys.AABB;

import java.util.*;

public abstract class Movement implements IMovement, MovementHelper {

public static final Direction[] HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.DOWN};
Expand Down Expand Up @@ -123,7 +125,7 @@ protected boolean playerInValidPosition() {
public MovementStatus update() {
ctx.player().getAbilities().flying = false;
currentState = updateState(currentState);
if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && ctx.player().position().y < dest.y + 0.6) {
if ((MovementHelper.isLiquid(ctx, ctx.playerFeet()) && ctx.player().position().y < dest.y + 0.6) && !(Baritone.settings().swimInWater.value && this instanceof MovementTraverse)) {
currentState.setInput(Input.JUMP, true);
}
if (ctx.player().isInWall()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import baritone.api.IBaritone;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Rotation;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
Expand All @@ -29,16 +30,17 @@
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class MovementDiagonal extends Movement {

private static final double SQRT_2 = Math.sqrt(2);
Expand Down Expand Up @@ -271,6 +273,10 @@ public MovementState updateState(MovementState state) {
state.setInput(Input.SPRINT, true);
}
MovementHelper.moveTowards(ctx, state, dest);
if (ctx.player().isSwimming() && Baritone.settings().swimInWater.value) {
state.setInput(Input.SPRINT, true);
state.setTarget(new MovementState.MovementTarget(new Rotation(state.getTarget().getRotation().get().getYaw(), -30), true));
}
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@
import baritone.utils.BlockStateInterface;
import com.google.common.collect.ImmutableSet;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CarpetBlock;
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.LadderBlock;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -240,10 +233,16 @@ public MovementState updateState(MovementState state) {
}
}
}

boolean swim = Baritone.settings().swimInWater.value &&
MovementHelper.isLiquid(ctx, src) &&
MovementHelper.isLiquid(ctx, dest) &&
(ctx.player().isSwimming() || (ctx.world().getBlockState(dest.below()).equals(pb1) &&
ctx.world().getBlockState(src.below()).equals(pb1))) &&
ctx.playerFeetAsVec().y >= src.y - 1;
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder || MovementHelper.canUseFrostWalker(ctx, positionToPlace);
BlockPos feet = ctx.playerFeet();
if (feet.getY() != dest.getY() && !ladder) {
state.setInput(Input.JUMP, false);
if (feet.getY() != dest.getY() && !ladder && !swim) {
logDebug("Wrong Y coordinate");
if (feet.getY() < dest.getY()) {
System.out.println("In movement traverse");
Expand Down Expand Up @@ -283,6 +282,9 @@ public MovementState updateState(MovementState state) {
}
}
MovementHelper.moveTowards(ctx, state, against);
if (swim) {
state.setTarget(new MovementState.MovementTarget(new Rotation(state.getTarget().getRotation().get().getYaw(), -30), true));
}
return state;
} else {
wasTheBridgeBlockAlwaysThere = false;
Expand Down