vastly increase cuteness by removing the optional boolean
This commit is contained in:
parent
0bd16fb81a
commit
2d1b81dc20
@ -25,6 +25,7 @@ import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.pathing.precompute.Ternary;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.ToolSet;
|
||||
import net.minecraft.block.*;
|
||||
@ -40,6 +41,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import java.util.Optional;
|
||||
|
||||
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
|
||||
import static baritone.pathing.precompute.Ternary.*;
|
||||
|
||||
/**
|
||||
* Static helpers for cost calculation
|
||||
@ -48,10 +50,6 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____S
|
||||
*/
|
||||
public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
Optional<Boolean> YES = Optional.of(true);
|
||||
Optional<Boolean> NO = Optional.of(false);
|
||||
Optional<Boolean> MAYBE = Optional.empty();
|
||||
|
||||
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
if (!bsi.worldBorder.canPlaceAt(x, y)) {
|
||||
return true;
|
||||
@ -101,14 +99,17 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
}
|
||||
|
||||
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
Optional<Boolean> canWalkThrough = canWalkThroughBlockState(state);
|
||||
if (canWalkThrough.isPresent()) { // note: don't replace this with the functional style, because the lambda is impure (it captures local variables as context), meaning it allocates
|
||||
return canWalkThrough.get();
|
||||
Ternary canWalkThrough = canWalkThroughBlockState(state);
|
||||
if (canWalkThrough == YES) {
|
||||
return true;
|
||||
}
|
||||
if (canWalkThrough == NO) {
|
||||
return false;
|
||||
}
|
||||
return canWalkThroughPosition(bsi, x, y, z, state);
|
||||
}
|
||||
|
||||
static Optional<Boolean> canWalkThroughBlockState(IBlockState state) {
|
||||
static Ternary canWalkThroughBlockState(IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block == Blocks.AIR) {
|
||||
@ -156,7 +157,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
}
|
||||
|
||||
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
|
||||
return Optional.of(block.isPassable(null, null));
|
||||
if (block.isPassable(null, null)) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
} catch (Throwable exception) {
|
||||
System.out.println("The block " + state.getBlock().getLocalizedName() + " requires a special case due to the exception " + exception.getMessage());
|
||||
return MAYBE;
|
||||
@ -346,14 +351,17 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
* @return Whether or not the specified block can be walked on
|
||||
*/
|
||||
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||
Optional<Boolean> canWalkOn = canWalkOnBlockState(state);
|
||||
if (canWalkOn.isPresent()) {
|
||||
return canWalkOn.get();
|
||||
Ternary canWalkOn = canWalkOnBlockState(state);
|
||||
if (canWalkOn == YES) {
|
||||
return true;
|
||||
}
|
||||
if (canWalkOn == NO) {
|
||||
return false;
|
||||
}
|
||||
return canWalkOnPosition(bsi, x, y, z, state);
|
||||
}
|
||||
|
||||
static Optional<Boolean> canWalkOnBlockState(IBlockState state) {
|
||||
static Ternary canWalkOnBlockState(IBlockState state) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.AIR || block == Blocks.MAGMA) {
|
||||
return NO;
|
||||
|
@ -22,7 +22,8 @@ import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
||||
import java.util.Optional;
|
||||
import static baritone.pathing.precompute.Ternary.MAYBE;
|
||||
import static baritone.pathing.precompute.Ternary.YES;
|
||||
|
||||
public class PrecomputedData { // TODO add isFullyPassable
|
||||
|
||||
@ -37,21 +38,19 @@ public class PrecomputedData { // TODO add isFullyPassable
|
||||
private int fillData(int id, IBlockState state) {
|
||||
int blockData = 0;
|
||||
|
||||
Optional<Boolean> canWalkOnState = MovementHelper.canWalkOnBlockState(state);
|
||||
if (canWalkOnState.isPresent()) {
|
||||
if (canWalkOnState.get()) {
|
||||
Ternary canWalkOnState = MovementHelper.canWalkOnBlockState(state);
|
||||
if (canWalkOnState == YES) {
|
||||
blockData |= canWalkOnMask;
|
||||
}
|
||||
} else {
|
||||
if (canWalkOnState == MAYBE) {
|
||||
blockData |= canWalkOnSpecialMask;
|
||||
}
|
||||
|
||||
Optional<Boolean> canWalkThroughState = MovementHelper.canWalkThroughBlockState(state);
|
||||
if (canWalkThroughState.isPresent()) {
|
||||
if (canWalkThroughState.get()) {
|
||||
Ternary canWalkThroughState = MovementHelper.canWalkThroughBlockState(state);
|
||||
if (canWalkThroughState == YES) {
|
||||
blockData |= canWalkThroughMask;
|
||||
}
|
||||
} else {
|
||||
if (canWalkOnState == MAYBE) {
|
||||
blockData |= canWalkThroughSpecialMask;
|
||||
}
|
||||
|
||||
|
22
src/main/java/baritone/pathing/precompute/Ternary.java
Normal file
22
src/main/java/baritone/pathing/precompute/Ternary.java
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.pathing.precompute;
|
||||
|
||||
public enum Ternary {
|
||||
YES, MAYBE, NO
|
||||
}
|
Loading…
Reference in New Issue
Block a user