Merge pull request #2825 from Zephreo/parkour-place

ParkourPlace for shorter parkour jumps
This commit is contained in:
Leijurv 2021-07-16 20:50:23 -07:00 committed by GitHub
commit ce2ec8047e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 34 deletions

6
.gitignore vendored
View File

@ -18,6 +18,12 @@ classes/
*.iws *.iws
/logs/ /logs/
# Eclipse Files
.classpath
.project
.settings/
baritone_Client.launch
# Copyright Files # Copyright Files
!/.idea/copyright/Baritone.xml !/.idea/copyright/Baritone.xml
!/.idea/copyright/profiles_settings.xml !/.idea/copyright/profiles_settings.xml

View File

@ -104,15 +104,22 @@ public class MovementParkour extends Movement {
maxJump = 3; maxJump = 3;
} }
} }
// check parkour jumps from smallest to largest for obstacles/walls and landing positions
int verifiedMaxJump = 1; // i - 1 (when i = 2)
for (int i = 2; i <= maxJump; i++) { for (int i = 2; i <= maxJump; i++) {
int destX = x + xDiff * i; int destX = x + xDiff * i;
int destZ = z + zDiff * i; int destZ = z + zDiff * i;
// check head/feet
if (!MovementHelper.fullyPassable(context, destX, y + 1, destZ)) { if (!MovementHelper.fullyPassable(context, destX, y + 1, destZ)) {
return; break;
} }
if (!MovementHelper.fullyPassable(context, destX, y + 2, destZ)) { if (!MovementHelper.fullyPassable(context, destX, y + 2, destZ)) {
return; break;
} }
// check for ascend landing position
IBlockState destInto = context.bsi.get0(destX, y, destZ); IBlockState destInto = context.bsi.get0(destX, y, destZ);
if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) { if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) {
if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) {
@ -120,57 +127,65 @@ public class MovementParkour extends Movement {
res.y = y + 1; res.y = y + 1;
res.z = destZ; res.z = destZ;
res.cost = i * SPRINT_ONE_BLOCK_COST + context.jumpPenalty; res.cost = i * SPRINT_ONE_BLOCK_COST + context.jumpPenalty;
return;
} }
return; break;
} }
// check for flat landing position
IBlockState landingOn = context.bsi.get0(destX, y - 1, destZ); IBlockState landingOn = context.bsi.get0(destX, y - 1, destZ);
// farmland needs to be canwalkon otherwise farm can never work at all, but we want to specifically disallow ending a jumy on farmland haha // farmland needs to be canWalkOn otherwise farm can never work at all, but we want to specifically disallow ending a jump on farmland haha
if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn)) { if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn)) {
if (checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) { if (checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) {
res.x = destX; res.x = destX;
res.y = y; res.y = y;
res.z = destZ; res.z = destZ;
res.cost = costFromJumpDistance(i) + context.jumpPenalty; res.cost = costFromJumpDistance(i) + context.jumpPenalty;
return;
} }
return; break;
} }
if (!MovementHelper.fullyPassable(context, destX, y + 3, destZ)) { if (!MovementHelper.fullyPassable(context, destX, y + 3, destZ)) {
return; break;
} }
verifiedMaxJump = i;
} }
if (maxJump != 4) {
return; // parkour place starts here
}
if (!context.allowParkourPlace) { if (!context.allowParkourPlace) {
return; return;
} }
// time 2 pop off with that dank skynet parkour place // check parkour jumps from largest to smallest for positions to place blocks
int destX = x + 4 * xDiff; for (int i = verifiedMaxJump; i > 1; i--) {
int destZ = z + 4 * zDiff; int destX = x + i * xDiff;
IBlockState toReplace = context.get(destX, y - 1, destZ); int destZ = z + i * zDiff;
double placeCost = context.costOfPlacingAt(destX, y - 1, destZ, toReplace); IBlockState toReplace = context.get(destX, y - 1, destZ);
if (placeCost >= COST_INF) { double placeCost = context.costOfPlacingAt(destX, y - 1, destZ, toReplace);
return; if (placeCost >= COST_INF) {
}
if (!MovementHelper.isReplaceable(destX, y - 1, destZ, toReplace, context.bsi)) {
return;
}
if (!checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) {
return;
}
for (int i = 0; i < 5; i++) {
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast
continue; continue;
} }
if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) { if (!MovementHelper.isReplaceable(destX, y - 1, destZ, toReplace, context.bsi)) {
res.x = destX; continue;
res.y = y; }
res.z = destZ; if (!checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) {
res.cost = costFromJumpDistance(4) + placeCost + context.jumpPenalty; continue;
return; }
for (int j = 0; j < 5; j++) {
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[j].getXOffset();
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[j].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[j].getZOffset();
if (againstX == destX - xDiff && againstZ == destZ - zDiff) { // we can't turn around that fast
continue;
}
if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) {
res.x = destX;
res.y = y;
res.z = destZ;
res.cost = costFromJumpDistance(i) + placeCost + context.jumpPenalty;
return;
}
} }
} }
} }