better protection logic, fix placing outside worldborder
This commit is contained in:
parent
c5f5445f4b
commit
6b7a8e2bd3
@ -21,6 +21,7 @@ import baritone.Baritone;
|
|||||||
import baritone.api.pathing.movement.ActionCosts;
|
import baritone.api.pathing.movement.ActionCosts;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.ToolSet;
|
import baritone.utils.ToolSet;
|
||||||
|
import baritone.utils.pathing.BetterWorldBorder;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
@ -44,6 +45,7 @@ public class CalculationContext implements Helper {
|
|||||||
private final int maxFallHeightBucket;
|
private final int maxFallHeightBucket;
|
||||||
private final double waterWalkSpeed;
|
private final double waterWalkSpeed;
|
||||||
private final double breakBlockAdditionalCost;
|
private final double breakBlockAdditionalCost;
|
||||||
|
private final BetterWorldBorder worldBorder;
|
||||||
|
|
||||||
public CalculationContext() {
|
public CalculationContext() {
|
||||||
this(new ToolSet());
|
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?
|
// 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,
|
// 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.
|
// 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() {
|
public ToolSet getToolSet() {
|
||||||
|
@ -343,15 +343,6 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return state.isBlockNormalCube();
|
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) {
|
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);
|
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) {
|
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (!canWalkThrough(x, y, z, state)) {
|
if (!canWalkThrough(x, y, z, state)) {
|
||||||
if (!context.allowBreak()) {
|
if (!context.canBreakAt(x, y, z)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (avoidBreaking(x, y, z, state)) {
|
if (avoidBreaking(x, y, z, state)) {
|
||||||
|
@ -72,7 +72,7 @@ public class MovementAscend extends Movement {
|
|||||||
}
|
}
|
||||||
boolean hasToPlace = false;
|
boolean hasToPlace = false;
|
||||||
if (!MovementHelper.canWalkOn(destX, y, destZ, toPlace)) {
|
if (!MovementHelper.canWalkOn(destX, y, destZ, toPlace)) {
|
||||||
if (!context.hasThrowaway()) {
|
if (!context.canPlaceThrowawayAt(destX, y, destZ)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y, destZ, toPlace)) {
|
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y, destZ, toPlace)) {
|
||||||
|
@ -118,7 +118,7 @@ public class MovementParkour extends Movement {
|
|||||||
int destX = x + 4 * xDiff;
|
int destX = x + 4 * xDiff;
|
||||||
int destZ = z + 4 * zDiff;
|
int destZ = z + 4 * zDiff;
|
||||||
IBlockState toPlace = BlockStateInterface.get(destX, y - 1, destZ);
|
IBlockState toPlace = BlockStateInterface.get(destX, y - 1, destZ);
|
||||||
if (!context.hasThrowaway()) {
|
if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (toPlace.getBlock() != Blocks.AIR && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(destX, y - 1, destZ, toPlace)) {
|
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);
|
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);
|
state.setInput(InputOverrideHandler.Input.SPRINT, false);
|
||||||
if (playerFeet().equals(src.offset(direction, -1))) {
|
if (playerFeet().equals(src.offset(direction, -1))) {
|
||||||
MovementHelper.moveTowards(state, src);
|
MovementHelper.moveTowards(state, src);
|
||||||
|
@ -76,7 +76,7 @@ public class MovementPillar extends Movement {
|
|||||||
return LADDER_UP_ONE_COST;
|
return LADDER_UP_ONE_COST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!context.hasThrowaway() && !ladder) {
|
if (!ladder && !context.canPlaceThrowawayAt(x, y, z)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true);
|
double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true);
|
||||||
|
@ -108,7 +108,7 @@ public class MovementTraverse extends Movement {
|
|||||||
if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) {
|
if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (!context.hasThrowaway()) {
|
if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb0, false);
|
double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb0, false);
|
||||||
|
@ -36,4 +36,11 @@ public class BetterWorldBorder implements Helper {
|
|||||||
public boolean entirelyContains(int x, int z) {
|
public boolean entirelyContains(int x, int z) {
|
||||||
return x + 1 > minX && x < maxX && z + 1 > minZ && z < maxZ;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user