Don't construct new optionals in movement helper
This commit is contained in:
parent
868c023dbd
commit
3e7f9039c4
@ -47,6 +47,8 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S
|
|||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public interface MovementHelper extends ActionCosts, Helper {
|
public interface MovementHelper extends ActionCosts, Helper {
|
||||||
|
static final Optional<Boolean> TRUE = Optional.of(true);
|
||||||
|
static final Optional<Boolean> FALSE = Optional.of(false);
|
||||||
|
|
||||||
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||||
if (!bsi.worldBorder.canPlaceAt(x, y)) {
|
if (!bsi.worldBorder.canPlaceAt(x, y)) {
|
||||||
@ -106,15 +108,15 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
|
|
||||||
if (block == Blocks.AIR) {
|
if (block == Blocks.AIR) {
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block instanceof BlockTrapDoor || block == Blocks.END_ROD) {
|
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block instanceof BlockTrapDoor || block == Blocks.END_ROD) {
|
||||||
return Optional.of(false);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
|
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
|
||||||
return Optional.of(false);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||||
@ -130,7 +132,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
if (block instanceof BlockSnow) {
|
if (block instanceof BlockSnow) {
|
||||||
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
||||||
return Optional.of(false);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -138,14 +140,14 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|
|
||||||
if (block instanceof BlockLiquid) {
|
if (block instanceof BlockLiquid) {
|
||||||
if (state.getValue(BlockLiquid.LEVEL) != 0) {
|
if (state.getValue(BlockLiquid.LEVEL) != 0) {
|
||||||
return Optional.of(false);
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block instanceof BlockCauldron) {
|
if (block instanceof BlockCauldron) {
|
||||||
return Optional.of(false);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information
|
try { // A dodgy catch-all at the end, for most blocks with default behaviour this will work, however where blocks are special this will error out, and we can handle it when we have this information
|
||||||
@ -346,19 +348,19 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
static Optional<Boolean> canWalkOnBlockState(IBlockState state) {
|
static Optional<Boolean> canWalkOnBlockState(IBlockState state) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||||
return Optional.of(false);
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (state.isBlockNormalCube()) {
|
if (state.isBlockNormalCube()) {
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this
|
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) {
|
if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) {
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
|
if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (isWater(block)) {
|
if (isWater(block)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -370,11 +372,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (block instanceof BlockSlab) {
|
if (block instanceof BlockSlab) {
|
||||||
if (!Baritone.settings().allowWalkOnBottomSlab.value) {
|
if (!Baritone.settings().allowWalkOnBottomSlab.value) {
|
||||||
if (((BlockSlab) block).isDouble()) {
|
if (((BlockSlab) block).isDouble()) {
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM);
|
return Optional.of(state.getValue(BlockSlab.HALF) != BlockSlab.EnumBlockHalf.BOTTOM);
|
||||||
}
|
}
|
||||||
return Optional.of(true);
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(block instanceof BlockStairs);
|
return Optional.of(block instanceof BlockStairs);
|
||||||
|
Loading…
Reference in New Issue
Block a user