introduce MAYBE and fix more allocation cases

This commit is contained in:
Leijurv 2022-07-14 21:42:38 -07:00
parent 5b7bee977b
commit 93fa6cf875
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
1 changed files with 11 additions and 7 deletions

View File

@ -50,6 +50,7 @@ public interface MovementHelper extends ActionCosts, Helper {
Optional<Boolean> TRUE = Optional.of(true); Optional<Boolean> TRUE = Optional.of(true);
Optional<Boolean> FALSE = Optional.of(false); Optional<Boolean> FALSE = Optional.of(false);
Optional<Boolean> MAYBE = Optional.empty();
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)) {
@ -126,11 +127,14 @@ public interface MovementHelper extends ActionCosts, Helper {
// Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume // Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume
// that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't // that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't
// be opened by just interacting. // be opened by just interacting.
return Optional.of(block != Blocks.IRON_DOOR); if (block == Blocks.IRON_DOOR) {
return FALSE;
}
return TRUE;
} }
if (block == Blocks.CARPET) { if (block == Blocks.CARPET) {
return Optional.empty(); return MAYBE;
} }
if (block instanceof BlockSnow) { if (block instanceof BlockSnow) {
@ -138,14 +142,14 @@ public interface MovementHelper extends ActionCosts, Helper {
return FALSE; return FALSE;
} }
return Optional.empty(); return MAYBE;
} }
if (block instanceof BlockLiquid) { if (block instanceof BlockLiquid) {
if (state.getValue(BlockLiquid.LEVEL) != 0) { if (state.getValue(BlockLiquid.LEVEL) != 0) {
return FALSE; return FALSE;
} else { } else {
return Optional.empty(); return MAYBE;
} }
} }
@ -157,7 +161,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return Optional.of(block.isPassable(null, null)); return Optional.of(block.isPassable(null, null));
} catch (Throwable exception) { } catch (Throwable exception) {
System.out.println("The block " + state.getBlock().getLocalizedName() + " requires a special case due to the exception " + exception.getMessage()); System.out.println("The block " + state.getBlock().getLocalizedName() + " requires a special case due to the exception " + exception.getMessage());
return Optional.empty(); return MAYBE;
} }
} }
@ -369,10 +373,10 @@ public interface MovementHelper extends ActionCosts, Helper {
return TRUE; return TRUE;
} }
if (isWater(block)) { if (isWater(block)) {
return Optional.empty(); return MAYBE;
} }
if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) { if (Baritone.settings().assumeWalkOnLava.value && MovementHelper.isLava(block)) {
return Optional.empty(); return MAYBE;
} }
if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) { if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) {