better protection logic, fix placing outside worldborder

This commit is contained in:
Leijurv 2018-10-12 14:34:33 -07:00
parent c5f5445f4b
commit 6b7a8e2bd3
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 41 additions and 15 deletions

View File

@ -21,6 +21,7 @@ import baritone.Baritone;
import baritone.api.pathing.movement.ActionCosts;
import baritone.utils.Helper;
import baritone.utils.ToolSet;
import baritone.utils.pathing.BetterWorldBorder;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
@ -44,6 +45,7 @@ public class CalculationContext implements Helper {
private final int maxFallHeightBucket;
private final double waterWalkSpeed;
private final double breakBlockAdditionalCost;
private final BetterWorldBorder worldBorder;
public CalculationContext() {
this(new ToolSet());
@ -68,6 +70,32 @@ public class CalculationContext implements Helper {
// why cache these things here, why not let the movements just get directly from settings?
// because if some movements are calculated one way and others are calculated another way,
// then you get a wildly inconsistent path that isn't optimal for either scenario.
this.worldBorder = new BetterWorldBorder(world().getWorldBorder());
}
public boolean canPlaceThrowawayAt(int x, int y, int z) {
if (!hasThrowaway()) { // only true if allowPlace is true, see constructor
return false;
}
if (isPossiblyProtected(x, y, z)) {
return false;
}
return worldBorder.canPlaceAt(x, z); // TODO perhaps MovementHelper.canPlaceAgainst could also use this?
}
public boolean canBreakAt(int x, int y, int z) {
if (!allowBreak()) {
return false;
}
if (isPossiblyProtected(x, y, z)) {
return false;
}
return true;
}
public boolean isPossiblyProtected(int x, int y, int z) {
// TODO more protection logic here; see #220
return false;
}
public ToolSet getToolSet() {

View File

@ -343,15 +343,6 @@ public interface MovementHelper extends ActionCosts, Helper {
return state.isBlockNormalCube();
}
static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, boolean includeFalling) {
IBlockState state = BlockStateInterface.get(position);
return getMiningDurationTicks(context, position.x, position.y, position.z, state, includeFalling);
}
static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, IBlockState state, boolean includeFalling) {
return getMiningDurationTicks(context, position.x, position.y, position.z, state, includeFalling);
}
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) {
return getMiningDurationTicks(context, x, y, z, BlockStateInterface.get(x, y, z), includeFalling);
}
@ -359,7 +350,7 @@ public interface MovementHelper extends ActionCosts, Helper {
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
Block block = state.getBlock();
if (!canWalkThrough(x, y, z, state)) {
if (!context.allowBreak()) {
if (!context.canBreakAt(x, y, z)) {
return COST_INF;
}
if (avoidBreaking(x, y, z, state)) {

View File

@ -72,7 +72,7 @@ public class MovementAscend extends Movement {
}
boolean hasToPlace = false;
if (!MovementHelper.canWalkOn(destX, y, destZ, toPlace)) {
if (!context.hasThrowaway()) {
if (!context.canPlaceThrowawayAt(destX, y, destZ)) {
return COST_INF;
}
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y, destZ, toPlace)) {

View File

@ -118,7 +118,7 @@ public class MovementParkour extends Movement {
int destX = x + 4 * xDiff;
int destZ = z + 4 * zDiff;
IBlockState toPlace = BlockStateInterface.get(destX, y - 1, destZ);
if (!context.hasThrowaway()) {
if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) {
return;
}
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y - 1, destZ, toPlace)) {
@ -225,7 +225,7 @@ public class MovementParkour extends Movement {
}
state.setInput(InputOverrideHandler.Input.JUMP, true);
} else if(!playerFeet().equals(dest.offset(direction, -1))) {
} else if (!playerFeet().equals(dest.offset(direction, -1))) {
state.setInput(InputOverrideHandler.Input.SPRINT, false);
if (playerFeet().equals(src.offset(direction, -1))) {
MovementHelper.moveTowards(state, src);

View File

@ -76,7 +76,7 @@ public class MovementPillar extends Movement {
return LADDER_UP_ONE_COST;
}
}
if (!context.hasThrowaway() && !ladder) {
if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) {
return COST_INF;
}
double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true);

View File

@ -108,7 +108,7 @@ public class MovementTraverse extends Movement {
if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) {
return COST_INF;
}
if (!context.hasThrowaway()) {
if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) {
return COST_INF;
}
double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb0, false);

View File

@ -36,4 +36,11 @@ public class BetterWorldBorder implements Helper {
public boolean entirelyContains(int x, int z) {
return x + 1 > minX && x < maxX && z + 1 > minZ && z < maxZ;
}
public boolean canPlaceAt(int x, int z) {
// move it in 1 block on all sides
// because we can't place a block at the very edge against a block outside the border
// it won't let us right click it
return x > minX && x + 1 < maxX && z > minZ && z + 1 < maxZ;
}
}