Skip to content

Commit 646c29f

Browse files
committed
Fix block place
1 parent 48b4d98 commit 646c29f

File tree

6 files changed

+35
-48
lines changed

6 files changed

+35
-48
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static boolean isClutchBlock(Level world, BlockPos pos, BlockState state) {
5959

6060
static boolean blockClutch(IBaritone baritone, MovementState state, BlockPos dest, MutableClutchResult result, boolean allowDown) {
6161
state.setTarget(new MovementState.MovementTarget(baritone.getPlayerContext().playerRotations().withPitch(90), true));
62-
if (MovementHelper.attemptToPlaceABlock(state, baritone, dest, allowDown, true, true, result.item.getItem()) == MovementHelper.PlaceResult.READY_TO_PLACE) {
62+
if (MovementHelper.attemptBlockPlace(state, baritone, dest, allowDown, true, true, result.item.getItem()) == MovementHelper.PlaceResult.READY_TO_PLACE) {
6363
state.setInput(Input.CLICK_RIGHT, true);
6464
return true;
6565
} else {

src/main/java/baritone/pathing/movement/MovementHelper.java

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -778,61 +778,48 @@ static boolean isBlockNormalCube(BlockState state) {
778778
return false;
779779
}
780780

781-
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean allowDown, boolean preferDown, boolean wouldSneak, Item customItem) {
781+
static PlaceResult attemptBlockPlace(MovementState state, IBaritone baritone, BlockPos placeAt, boolean allowDown, boolean preferDown, boolean wouldSneak, Item customItem) {
782+
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(false, placeAt.getX(), placeAt.getY(), placeAt.getZ(), customItem)) { // get ready to place a throwaway block
783+
Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
784+
state.setStatus(MovementStatus.UNREACHABLE);
785+
return PlaceResult.NO_OPTION;
786+
}
782787
IPlayerContext ctx = baritone.getPlayerContext();
783-
Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt, wouldSneak); // we assume that if there is a block there, it must be replaceable
784788
boolean found = false;
789+
Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt, wouldSneak); // we assume that if there is a block there, it must be replaceable
785790
if (direct.isPresent()) {
786791
state.setTarget(new MovementTarget(direct.get(), true));
787792
found = true;
788-
}
789-
for (int i = 0; i < (allowDown ? 5 : 4); i++) {
790-
BlockPos against1 = placeAt.relative(HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
791-
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
792-
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(false, placeAt.getX(), placeAt.getY(), placeAt.getZ(), customItem)) { // get ready to place a throwaway block
793-
Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
794-
state.setStatus(MovementStatus.UNREACHABLE);
795-
return PlaceResult.NO_OPTION;
796-
}
797-
double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D;
798-
double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D;
799-
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
800-
Rotation place = RotationUtils.calcRotationFromVec3d(wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.playerHead(), new Vec3(faceX, faceY, faceZ), ctx.playerRotations());
801-
Rotation actual = baritone.getLookBehavior().getAimProcessor().peekRotation(place);
802-
HitResult res = RayTraceUtils.rayTraceTowards(ctx.player(), actual, ctx.playerController().getBlockReachDistance(), wouldSneak);
803-
if (res.getType() == HitResult.Type.BLOCK &&
804-
((BlockHitResult) res).getBlockPos().equals(against1) &&
805-
((BlockHitResult) res).getBlockPos().relative(((BlockHitResult) res).getDirection()).equals(placeAt)) {
806-
state.setTarget(new MovementTarget(place, true));
807-
found = true;
808-
809-
if (!allowDown || !preferDown) {
810-
// if preferDown is true, we want the last option. Otherwise, we want the first.
811-
break;
793+
} else {
794+
for (int i = 0; i < (allowDown ? 5 : 4); i++) {
795+
BlockPos against1 = placeAt.relative(HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
796+
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
797+
double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D;
798+
double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D;
799+
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
800+
Rotation place = RotationUtils.calcRotationFromVec3d(wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.playerHead(), new Vec3(faceX, faceY, faceZ), ctx.playerRotations());
801+
Rotation actual = baritone.getLookBehavior().getAimProcessor().peekRotation(place);
802+
HitResult res = RayTraceUtils.rayTraceTowards(ctx.player(), actual, ctx.playerController().getBlockReachDistance(), wouldSneak);
803+
if (res.getType() == HitResult.Type.BLOCK &&
804+
((BlockHitResult) res).getBlockPos().equals(against1) &&
805+
((BlockHitResult) res).getBlockPos().relative(((BlockHitResult) res).getDirection()).equals(placeAt)) {
806+
state.setTarget(new MovementTarget(place, true));
807+
found = true;
808+
809+
if (!allowDown || !preferDown) {
810+
// if preferDown is true, we want the last option. Otherwise, we want the first.
811+
break;
812+
}
812813
}
813814
}
814815
}
815816
}
816-
if (ctx.getSelectedBlock().isPresent()) {
817-
BlockPos selectedBlock = ctx.getSelectedBlock().get();
818-
Direction side = ((BlockHitResult) ctx.objectMouseOver()).getDirection();
819-
// only way for selectedBlock.equals(placeAt) to be true is if it's replaceable
820-
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.relative(side).equals(placeAt))) {
821-
if (wouldSneak) {
822-
state.setInput(Input.SNEAK, true);
823-
}
824-
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ(), customItem);
825-
return PlaceResult.READY_TO_PLACE;
826-
}
827-
}
828817
if (found) {
829-
if (wouldSneak) {
830-
state.setInput(Input.SNEAK, true);
831-
}
832818
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ(), customItem);
833-
return PlaceResult.ATTEMPTING;
819+
return PlaceResult.READY_TO_PLACE;
820+
} else {
821+
return PlaceResult.NO_OPTION;
834822
}
835-
return PlaceResult.NO_OPTION;
836823
}
837824

838825
enum PlaceResult {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public MovementState updateState(MovementState state) {
176176
BlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
177177
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
178178
ticksWithoutPlacement++;
179-
if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.below(), true, false, true, null) == PlaceResult.READY_TO_PLACE) {
179+
if (MovementHelper.attemptBlockPlace(state, baritone, dest.below(), true, false, true, null) == PlaceResult.READY_TO_PLACE) {
180180
state.setInput(Input.SNEAK, true);
181181
if (ctx.player().isCrouching()) {
182182
state.setInput(Input.CLICK_RIGHT, true);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public MovementState updateState(MovementState state) {
287287
&& ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway()
288288
&& !MovementHelper.canWalkOn(ctx, dest.below())
289289
&& !ctx.player().isOnGround()
290-
&& MovementHelper.attemptToPlaceABlock(state, baritone, dest.below(), true, true, false, null) == PlaceResult.READY_TO_PLACE
290+
&& MovementHelper.attemptBlockPlace(state, baritone, dest.below(), true, true, false, null) == PlaceResult.READY_TO_PLACE
291291
) {
292292
// go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory
293293
state.setInput(Input.CLICK_RIGHT, true);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public MovementState updateState(MovementState state) {
300300
}
301301
}
302302
double dist1 = Math.max(Math.abs(ctx.player().position().x - (dest.getX() + 0.5D)), Math.abs(ctx.player().position().z - (dest.getZ() + 0.5D)));
303-
PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.below(), true, false, !Baritone.settings().assumeSafeWalk.value, null);
303+
PlaceResult p = MovementHelper.attemptBlockPlace(state, baritone, dest.below(), true, false, !Baritone.settings().assumeSafeWalk.value, null);
304304
if ((p == PlaceResult.READY_TO_PLACE || dist1 < 0.6) && !Baritone.settings().assumeSafeWalk.value) {
305305
state.setInput(Input.SNEAK, true);
306306
}

src/main/java/baritone/process/BackfillProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
7373
baritone.getInputOverrideHandler().clearAllKeys();
7474
for (BlockPos toPlace : toFillIn()) {
7575
MovementState fake = new MovementState();
76-
switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, true, false, false, null)) {
76+
switch (MovementHelper.attemptBlockPlace(fake, baritone, toPlace, true, false, false, null)) {
7777
case NO_OPTION:
7878
continue;
7979
case READY_TO_PLACE:

0 commit comments

Comments
 (0)