Skip to content

Commit a9d3b59

Browse files
committed
Fix hasClutched and removed messy and problematic code.
1 parent 0115ba1 commit a9d3b59

File tree

8 files changed

+48
-25
lines changed

8 files changed

+48
-25
lines changed

src/main/java/baritone/pathing/clutch/Clutch.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public boolean clutch(IBaritone baritone, MovementState state, BlockPos dest, Mu
7272
return ClutchUtils.blockClutch(baritone, state, dest, result, true);
7373
}
7474

75+
public boolean hasClutched(IPlayerContext ctx, BetterBlockPos dest, BlockState destState) {
76+
VoxelShape shape = destState.getCollisionShape(ctx.world(), dest);
77+
if (shape.isEmpty()) {
78+
return ctx.player().getBoundingBox().intersects(dest.x, dest.y, dest.z, dest.x + 1, dest.y + 1, dest.z + 1);
79+
} else {
80+
return ctx.player().getBoundingBox().intersects(
81+
dest.x + shape.bounds().minX, dest.x + shape.bounds().minY, dest.x + shape.bounds().minZ,
82+
dest.x + shape.bounds().maxX, dest.x + shape.bounds().maxY, dest.x + shape.bounds().maxZ);
83+
}
84+
}
85+
7586
public boolean isFinished(IPlayerContext ctx, MovementState state, MutableClutchResult result) {
7687
return true;
7788
}

src/main/java/baritone/pathing/clutch/clutches/LadderClutch.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public boolean isPlaceable(CalculationContext context, int x, int y, int z, Bloc
5959
public boolean clutch(IBaritone baritone, MovementState state, BlockPos dest, MutableClutchResult result) {
6060
return ClutchUtils.blockClutch(baritone, state, dest, result, false);
6161
}
62+
63+
@Override
64+
public boolean hasClutched(IPlayerContext ctx, BetterBlockPos dest, BlockState destState) {
65+
return ctx.player().getBoundingBox().intersects(dest.x, dest.y, dest.z, dest.x + 1, dest.y + 1, dest.z + 1);
66+
}
6267
}

src/main/java/baritone/pathing/clutch/clutches/ScaffoldingClutch.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ public boolean isFinished(IPlayerContext ctx, MovementState state, MutableClutch
4747
state.setInput(Input.SNEAK, true);
4848
return ctx.world().getBlockState(ctx.playerFeet()).is(Blocks.SCAFFOLDING);
4949
}
50+
51+
@Override
52+
public boolean hasClutched(IPlayerContext ctx, BetterBlockPos dest, BlockState destState) {
53+
return ctx.player().getBoundingBox().intersects(dest.x, dest.y, dest.z, dest.x + 1, dest.y + 2, dest.z + 1);
54+
}
5055
}

src/main/java/baritone/pathing/clutch/clutches/SlimeClutch.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
public class SlimeClutch extends Clutch {
3434
public static final SlimeClutch INSTANCE = new SlimeClutch();
3535

36+
private boolean onGround = false;
37+
3638
private SlimeClutch() {}
3739

3840
@Override
@@ -52,21 +54,22 @@ public boolean isSolid(CalculationContext context) {
5254

5355
@Override
5456
public boolean isFinished(IPlayerContext ctx, MovementState state, MutableClutchResult result) {
55-
if (result.phase == 0) {
56-
state.setInput(Input.SNEAK, false);
57-
state.setInput(Input.JUMP, true);
58-
if (ctx.player().isOnGround()) {
59-
result.phase = 1;
60-
}
61-
return false;
62-
} else {
63-
state.setInput(Input.SNEAK, true);
57+
state.setInput(Input.SNEAK, false);
58+
state.setInput(Input.JUMP, true);
59+
if (onGround) {
6460
return true;
6561
}
62+
onGround = ctx.player().isOnGround();
63+
return false;
6664
}
6765

6866
@Override
6967
public double getAdditionalCost() {
7068
return 13.0182684d;
7169
}
70+
71+
@Override
72+
public boolean hasClutched(IPlayerContext ctx, BetterBlockPos dest, BlockState destState) {
73+
return ctx.player().getBoundingBox().intersects(dest.x, dest.y, dest.z, dest.x + 1, dest.y + 2, dest.z + 1);
74+
}
7275
}

src/main/java/baritone/pathing/clutch/clutches/VineClutch.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import net.minecraft.world.level.block.Blocks;
3434
import net.minecraft.world.level.block.VineBlock;
3535
import net.minecraft.world.level.block.state.BlockState;
36+
import net.minecraft.world.phys.shapes.VoxelShape;
3637

3738
public class VineClutch extends Clutch {
3839
public static final VineClutch INSTANCE = new VineClutch();
@@ -77,4 +78,9 @@ public boolean isPlaceable(CalculationContext context, int x, int y, int z, Bloc
7778
public boolean clutch(IBaritone baritone, MovementState state, BlockPos dest, MutableClutchResult result) {
7879
return ClutchUtils.blockClutch(baritone, state, dest, result, false);
7980
}
81+
82+
@Override
83+
public boolean hasClutched(IPlayerContext ctx, BetterBlockPos dest, BlockState destState) {
84+
return ctx.player().getBoundingBox().intersects(dest.x, dest.y, dest.z, dest.x + 1, dest.y + 1, dest.z + 1);
85+
}
8086
}

src/main/java/baritone/pathing/movement/movements/MovementDescend.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ public static void dynamicFallCost(CalculationContext context, int x, int y, int
237237
if (clutchRes != null) {
238238
clutchRes.clutch = clutch;
239239
clutchRes.item = item;
240-
clutchRes.placeBelow = true;
241240
}
242241
}
243242
break;

src/main/java/baritone/pathing/movement/movements/MovementFall.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ public MovementState updateState(MovementState state) {
8282

8383
BlockPos playerFeet = ctx.playerFeet();
8484
Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations());
85-
BetterBlockPos trueDest = clutchResult.placeBelow ? dest.below() : dest;
86-
BlockState destState = ctx.world().getBlockState(trueDest);
85+
BlockState destState = ctx.world().getBlockState(dest);
86+
BetterBlockPos blockDest = dest.below();
87+
BlockState blockDestState = ctx.world().getBlockState(blockDest);
8788
if (ctx.world().getBlockState(dest.below()).is(Blocks.MAGMA_BLOCK) &&
8889
MovementHelper.steppingOnBlocks(ctx).stream().allMatch(block -> MovementHelper.canWalkThrough(ctx, block))) {
8990
state.setInput(Input.SNEAK, true);
@@ -93,15 +94,12 @@ public MovementState updateState(MovementState state) {
9394
return state.setStatus(MovementStatus.UNREACHABLE);
9495
}
9596
if (clutchResult.clutch != null) {
96-
if (clutchResult.clutch.compare(destState) ||
97-
clutchResult.item == null ||
98-
clutchResult.clutch.clutch(baritone, state, trueDest, clutchResult)) {
99-
if (clutchResult.clutch.isFinished(ctx, state, clutchResult) && ctx.player().isOnGround()) {
100-
clutchResult.reset();
101-
return state.setStatus(MovementStatus.SUCCESS);
102-
} else {
103-
return state;
104-
}
97+
if (clutchResult.item != null && !clutchResult.clutch.compare(blockDestState)) {
98+
clutchResult.clutch.clutch(baritone, state, blockDest, clutchResult);
99+
}
100+
if (clutchResult.clutch.hasClutched(ctx, dest, destState) && clutchResult.clutch.isFinished(ctx, state, clutchResult)) {
101+
clutchResult.reset();
102+
return state.setStatus(MovementStatus.SUCCESS);
105103
}
106104
} else if (playerFeet.equals(dest)) {
107105
return state.setStatus(MovementStatus.SUCCESS);

src/main/java/baritone/utils/pathing/MutableClutchResult.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
public final class MutableClutchResult {
2424
public Clutch clutch;
2525
public ItemStack item;
26-
public int phase;
27-
public boolean placeBelow;
2826

2927
public MutableClutchResult() {
3028
reset();
@@ -33,7 +31,5 @@ public MutableClutchResult() {
3331
public void reset() {
3432
clutch = null;
3533
item = null;
36-
phase = 0;
37-
placeBelow = true;
3834
}
3935
}

0 commit comments

Comments
 (0)