diff --git a/README.md b/README.md index c50caf56a..e2c83ddec 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,9 @@ Baritone is the pathfinding system used in [Impact](https://impactclient.net/) s [Tutorial playlist](https://www.youtube.com/playlist?list=PLnwnJ1qsS7CoQl9Si-RTluuzCo_4Oulpa) -The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.2.15/baritone-api-forge-1.2.15.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. +The easiest way to install Baritone is to install [Impact](https://impactclient.net/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to +install the v1.2.* `api-forge` jar from [releases](https://github.com/cabaletta/baritone/releases). **For 1.12.2 Forge, just click +[here](https://github.com/cabaletta/baritone/releases/download/v1.2.17/baritone-api-forge-1.2.17.jar)**. Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. For 1.16.5, [click here](https://www.youtube.com/watch?v=_4eVJ9Qz2J8) and see description. If you need Forge or Fabric 1.16.5, look [here](https://github.com/cabaletta/baritone/releases/tag/v1.6.3) and get the `api-forge` or `api-fabric` jar. **For 1.16.5 Fabric, just click [here](https://github.com/cabaletta/baritone/releases/download/v1.6.3/baritone-api-fabric-1.6.3.jar)**. diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 5869d4f8e..8155bb3b0 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -107,6 +107,13 @@ public final class Settings { */ public final Setting walkOnWaterOnePenalty = new Setting<>(3D); + /** + * Don't allow breaking blocks next to liquids. + *

+ * Enable if you have mods adding custom fluid physics. + */ + public final Setting strictLiquidCheck = new Setting<>(false); + /** * Allow Baritone to fall arbitrary distances and place a water bucket beneath it. * Reliability: questionable. @@ -116,6 +123,8 @@ public final class Settings { /** * Allow Baritone to assume it can walk on still water just like any other block. * This functionality is assumed to be provided by a separate library that might have imported Baritone. + *

+ * Note: This will prevent some usage of the frostwalker enchantment, like pillaring up from water. */ public final Setting assumeWalkOnWater = new Setting<>(false); diff --git a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java index b8f30a774..3d0f2613f 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java @@ -27,7 +27,7 @@ import java.util.stream.Stream; public enum RelativeCoordinate implements IDatatypePost { INSTANCE; private static String ScalesAliasRegex = "[kKmM]"; - private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)("+ScalesAliasRegex+"?)|)$"); + private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(" + ScalesAliasRegex + "?)|)$"); @Override public Double apply(IDatatypeContext ctx, Double origin) throws CommandException { @@ -43,7 +43,7 @@ public enum RelativeCoordinate implements IDatatypePost { boolean isRelative = !matcher.group(1).isEmpty(); double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2).replaceAll(ScalesAliasRegex, "")); - + if (matcher.group(2).toLowerCase().contains("k")) { offset *= 1000; } diff --git a/src/api/java/baritone/api/command/datatypes/RelativeFile.java b/src/api/java/baritone/api/command/datatypes/RelativeFile.java index 2c7adf98f..0bc3604ab 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeFile.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeFile.java @@ -83,10 +83,10 @@ public enum RelativeFile implements IDatatypePost { boolean useParent = !currentPathStringThing.isEmpty() && !currentPathStringThing.endsWith(File.separator); File currentFile = currentPath.isAbsolute() ? currentPath.toFile() : new File(base, currentPathStringThing); return Stream.of(Objects.requireNonNull(getCanonicalFileUnchecked( - useParent - ? currentFile.getParentFile() - : currentFile - ).listFiles())) + useParent + ? currentFile.getParentFile() + : currentFile + ).listFiles())) .map(f -> (currentPath.isAbsolute() ? f : basePath.relativize(f.toPath()).toString()) + (f.isDirectory() ? File.separator : "")) .filter(s -> s.toLowerCase(Locale.US).startsWith(currentPathStringThing.toLowerCase(Locale.US))) diff --git a/src/api/java/baritone/api/pathing/goals/GoalNear.java b/src/api/java/baritone/api/pathing/goals/GoalNear.java index 6a8226fb4..2252446cd 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalNear.java +++ b/src/api/java/baritone/api/pathing/goals/GoalNear.java @@ -19,8 +19,8 @@ package baritone.api.pathing.goals; import baritone.api.utils.SettingsUtil; import baritone.api.utils.interfaces.IGoalRenderPos; -import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; import it.unimi.dsi.fastutil.doubles.DoubleIterator; +import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; import net.minecraft.util.math.BlockPos; public class GoalNear implements Goal, IGoalRenderPos { diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index 503ae7f43..b704ae4a6 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -18,8 +18,8 @@ package baritone.api.pathing.goals; import baritone.api.utils.SettingsUtil; -import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; import it.unimi.dsi.fastutil.doubles.DoubleIterator; +import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet; import net.minecraft.util.math.BlockPos; import java.util.Arrays; diff --git a/src/api/java/baritone/api/schematic/SubstituteSchematic.java b/src/api/java/baritone/api/schematic/SubstituteSchematic.java index e8fd1fced..b73c4c8f5 100644 --- a/src/api/java/baritone/api/schematic/SubstituteSchematic.java +++ b/src/api/java/baritone/api/schematic/SubstituteSchematic.java @@ -22,6 +22,7 @@ import net.minecraft.block.BlockAir; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.state.IProperty; + import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -33,7 +34,7 @@ public class SubstituteSchematic extends AbstractSchematic { private final Map> substitutions; private final Map> blockStateCache = new HashMap<>(); - public SubstituteSchematic(ISchematic schematic, Map> substitutions) { + public SubstituteSchematic(ISchematic schematic, Map> substitutions) { super(schematic.widthX(), schematic.heightY(), schematic.lengthZ()); this.schematic = schematic; this.substitutions = substitutions; @@ -80,9 +81,10 @@ public class SubstituteSchematic extends AbstractSchematic { } catch (IllegalArgumentException e) { //property does not exist for target block } } - blockStateCache.computeIfAbsent(state, s -> new HashMap()).put(block, newState); + blockStateCache.computeIfAbsent(state, s -> new HashMap()).put(block, newState); return newState; } + private > IBlockState copySingleProp(IBlockState fromState, IBlockState toState, IProperty prop) { return toState.with(prop, fromState.get(prop)); } diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index f3ea93077..e72fb465b 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -301,7 +301,7 @@ public class SettingsUtil { Parser keyParser = Parser.getParser(keyType); Parser valueParser = Parser.getParser(valueType); - return ((Map) value).entrySet().stream() + return ((Map) value).entrySet().stream() .map(o -> keyParser.toString(context, o.getKey()) + "->" + valueParser.toString(context, o.getValue())) .collect(Collectors.joining(",")); } diff --git a/src/main/java/baritone/behavior/InventoryBehavior.java b/src/main/java/baritone/behavior/InventoryBehavior.java index 50544a301..e02ec9a0d 100644 --- a/src/main/java/baritone/behavior/InventoryBehavior.java +++ b/src/main/java/baritone/behavior/InventoryBehavior.java @@ -18,7 +18,6 @@ package baritone.behavior; import baritone.Baritone; -import baritone.api.BaritoneAPI; import baritone.api.event.events.TickEvent; import baritone.utils.ToolSet; import net.minecraft.block.Block; diff --git a/src/main/java/baritone/behavior/WaypointBehavior.java b/src/main/java/baritone/behavior/WaypointBehavior.java index 5eb4ae8ee..f8ab4309f 100644 --- a/src/main/java/baritone/behavior/WaypointBehavior.java +++ b/src/main/java/baritone/behavior/WaypointBehavior.java @@ -72,21 +72,21 @@ public class WaypointBehavior extends Behavior { baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(deathWaypoint); ITextComponent component = new TextComponentString("Death position saved."); component.getStyle() - .setColor(TextFormatting.WHITE) - .setHoverEvent(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, - new TextComponentString("Click to goto death") - )) - .setClickEvent(new ClickEvent( - ClickEvent.Action.RUN_COMMAND, - String.format( - "%s%s goto %s @ %d", - FORCE_COMMAND_PREFIX, - "wp", - deathWaypoint.getTag().getName(), - deathWaypoint.getCreationTimestamp() - ) - )); + .setColor(TextFormatting.WHITE) + .setHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + new TextComponentString("Click to goto death") + )) + .setClickEvent(new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format( + "%s%s goto %s @ %d", + FORCE_COMMAND_PREFIX, + "wp", + deathWaypoint.getTag().getName(), + deathWaypoint.getCreationTimestamp() + ) + )); Helper.HELPER.logDirect(component); } diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index cbdda3687..5a9ab389d 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -22,7 +22,6 @@ import baritone.api.cache.ICachedWorld; import baritone.api.cache.IWaypointCollection; import baritone.api.cache.IWorldData; -import java.io.IOException; import java.nio.file.Path; /** diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 75e319ea6..2d287eaee 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -23,6 +23,7 @@ import baritone.api.utils.Helper; import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IChunkProviderServer; import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.dimension.DimensionType; import org.apache.commons.lang3.SystemUtils; @@ -45,9 +46,11 @@ public class WorldProvider implements IWorldProvider, Helper { private static final Map worldCache = new HashMap<>(); // this is how the bots have the same cached world private WorldData currentWorld; + private World mcWorld; // this let's us detect a broken load/unload hook @Override public final WorldData getCurrentWorld() { + detectAndHandleBrokenLoading(); return this.currentWorld; } @@ -83,7 +86,9 @@ public class WorldProvider implements IWorldProvider, Helper { folderName = mc.getCurrentServerData().serverIP; } else { //replaymod causes null currentServerData and false singleplayer. + System.out.println("World seems to be a replay. Not loading Baritone cache."); currentWorld = null; + mcWorld = mc.world; return; } if (SystemUtils.IS_OS_WINDOWS) { @@ -111,11 +116,13 @@ public class WorldProvider implements IWorldProvider, Helper { synchronized (worldCache) { this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension.getId())); } + this.mcWorld = mc.world; } public final void closeWorld() { WorldData world = this.currentWorld; this.currentWorld = null; + this.mcWorld = null; if (world == null) { return; } @@ -123,8 +130,25 @@ public class WorldProvider implements IWorldProvider, Helper { } public final void ifWorldLoaded(Consumer currentWorldConsumer) { + detectAndHandleBrokenLoading(); if (this.currentWorld != null) { currentWorldConsumer.accept(this.currentWorld); } } + + private final void detectAndHandleBrokenLoading() { + if (this.mcWorld != mc.world) { + if (this.currentWorld != null) { + System.out.println("mc.world unloaded unnoticed! Unloading Baritone cache now."); + closeWorld(); + } + if (mc.world != null) { + System.out.println("mc.world loaded unnoticed! Loading Baritone cache now."); + initWorld(mc.world.getDimension().getType()); + } + } else if (currentWorld == null && mc.world != null && (mc.isSingleplayer() || mc.getCurrentServerData() != null)) { + System.out.println("Retrying to load Baritone cache"); + initWorld(mc.world.getDimension().getType()); + } + } } diff --git a/src/main/java/baritone/command/defaults/ETACommand.java b/src/main/java/baritone/command/defaults/ETACommand.java index 47b6ae9fa..4116d65b0 100644 --- a/src/main/java/baritone/command/defaults/ETACommand.java +++ b/src/main/java/baritone/command/defaults/ETACommand.java @@ -18,17 +18,16 @@ package baritone.command.defaults; import baritone.api.IBaritone; -import baritone.api.pathing.calc.IPathingControlManager; -import baritone.api.process.IBaritoneProcess; import baritone.api.behavior.IPathingBehavior; import baritone.api.command.Command; +import baritone.api.command.argument.IArgConsumer; import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandInvalidStateException; -import baritone.api.command.argument.IArgConsumer; +import baritone.api.pathing.calc.IPathingControlManager; +import baritone.api.process.IBaritoneProcess; import java.util.Arrays; import java.util.List; -import java.util.Optional; import java.util.stream.Stream; public class ETACommand extends Command { diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index 7ca24cf8a..fc1754c0c 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -80,10 +80,10 @@ public class FindCommand extends Command { ITextComponent baseComponent = new TextComponentString(pos.toString()); ITextComponent hoverComponent = new TextComponentString("Click to set goal to this position"); baseComponent.getStyle() - .setColor(TextFormatting.GRAY) - .setInsertion(positionText) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)) - .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)); + .setColor(TextFormatting.GRAY) + .setInsertion(positionText) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)) + .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)); return baseComponent; } @@ -91,9 +91,9 @@ public class FindCommand extends Command { public Stream tabComplete(String label, IArgConsumer args) throws CommandException { return new TabCompleteHelper() .append( - CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.stream() - .map(IRegistry.BLOCK::getKey) - .map(Object::toString) + CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.stream() + .map(IRegistry.BLOCK::getKey) + .map(Object::toString) ) .filterPrefixNamespaced(args.getString()) .sortAlphabetically() diff --git a/src/main/java/baritone/command/defaults/SelCommand.java b/src/main/java/baritone/command/defaults/SelCommand.java index 659a31835..5677eec3c 100644 --- a/src/main/java/baritone/command/defaults/SelCommand.java +++ b/src/main/java/baritone/command/defaults/SelCommand.java @@ -36,8 +36,8 @@ import baritone.api.selection.ISelectionManager; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BlockOptionalMeta; import baritone.api.utils.BlockOptionalMetaLookup; -import baritone.utils.IRenderer; import baritone.utils.BlockStateInterface; +import baritone.utils.IRenderer; import baritone.utils.schematic.StaticSchematic; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -193,7 +193,7 @@ public class SelCommand extends Command { } } } - ISchematic schematic = new StaticSchematic(){{ + ISchematic schematic = new StaticSchematic() {{ states = blockstates; x = size.getX(); y = size.getY(); diff --git a/src/main/java/baritone/command/defaults/WaypointsCommand.java b/src/main/java/baritone/command/defaults/WaypointsCommand.java index 5a45686a3..cf420e90a 100644 --- a/src/main/java/baritone/command/defaults/WaypointsCommand.java +++ b/src/main/java/baritone/command/defaults/WaypointsCommand.java @@ -20,8 +20,8 @@ package baritone.command.defaults; import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.cache.IWaypoint; -import baritone.api.cache.Waypoint; import baritone.api.cache.IWorldData; +import baritone.api.cache.Waypoint; import baritone.api.command.Command; import baritone.api.command.argument.IArgConsumer; import baritone.api.command.datatypes.ForWaypoints; @@ -50,7 +50,7 @@ import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; public class WaypointsCommand extends Command { - private Map> deletedWaypoints = new HashMap<>(); + private Map> deletedWaypoints = new HashMap<>(); public WaypointsCommand(IBaritone baritone) { super(baritone, "waypoints", "waypoint", "wp"); diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index a4a757a97..433101c1e 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -30,6 +30,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.init.Enchantments; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -65,6 +66,7 @@ public class CalculationContext { public final boolean allowJumpAt256; public final boolean allowParkourAscend; public final boolean assumeWalkOnWater; + public final int frostWalker; public final boolean allowDiagonalDescend; public final boolean allowDiagonalAscend; public final boolean allowDownward; @@ -103,6 +105,7 @@ public class CalculationContext { this.allowJumpAt256 = Baritone.settings().allowJumpAt256.value; this.allowParkourAscend = Baritone.settings().allowParkourAscend.value; this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.value; + this.frostWalker = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FROST_WALKER, baritone.getPlayerContext().player()); this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.value; this.allowDiagonalAscend = Baritone.settings().allowDiagonalAscend.value; this.allowDownward = Baritone.settings().allowDownward.value; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 0b7db2015..e8180c0b0 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -29,7 +29,9 @@ import baritone.pathing.precompute.Ternary; import baritone.utils.BlockStateInterface; import baritone.utils.ToolSet; import net.minecraft.block.*; +import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; +import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.fluid.FlowingFluid; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.IFluidState; @@ -38,12 +40,13 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Fluids; import net.minecraft.pathfinding.PathType; import net.minecraft.state.BooleanProperty; +import net.minecraft.state.properties.Half; import net.minecraft.state.properties.SlabType; +import net.minecraft.state.properties.StairsShape; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.IBlockReader; import java.util.Optional; @@ -58,7 +61,7 @@ import static baritone.pathing.precompute.Ternary.*; public interface MovementHelper extends ActionCosts, Helper { static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { - if (!bsi.worldBorder.canPlaceAt(x, y)) { + if (!bsi.worldBorder.canPlaceAt(x, z)) { return true; } Block b = state.getBlock(); @@ -86,6 +89,19 @@ public interface MovementHelper extends ActionCosts, Helper { && BlockFalling.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported) return true; // dont break a block that is adjacent to unsupported gravel because it can cause really weird stuff } + // only pure liquids for now + // waterlogged blocks can have closed bottom sides and such + if (block instanceof BlockFlowingFluid) { + if (directlyAbove || Baritone.settings().strictLiquidCheck.value) { + return true; + } + int level = state.get(BlockFlowingFluid.LEVEL); + if (level == 0) { + return true; // source blocks like to flow horizontally + } + // everything else will prefer flowing down + return !(bsi.get0(x, y - 1, z).getBlock() instanceof BlockFlowingFluid); // assume everything is in a static state + } return !state.getFluidState().isEmpty(); } @@ -210,33 +226,10 @@ public interface MovementHelper extends ActionCosts, Helper { return state.allowsMovement(bsi.access, BlockPos.ORIGIN, PathType.LAND); // workaround for future compatibility =P } - - /** - * canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click), - * not including water, and not including ladders or vines or cobwebs (they slow us down) - * - * @param context Calculation context to provide block state lookup - * @param x The block's x position - * @param y The block's y position - * @param z The block's z position - * @return Whether or not the block at the specified position - */ - static boolean fullyPassable(CalculationContext context, int x, int y, int z) { - return fullyPassable( - context.bsi.access, - context.bsi.isPassableBlockPos.setPos(x, y, z), - context.bsi.get0(x, y, z) - ); - } - - static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) { - return fullyPassable(ctx.world(), pos, ctx.world().getBlockState(pos)); - } - - static boolean fullyPassable(IBlockReader access, BlockPos pos, IBlockState state) { + static Ternary fullyPassableBlockState(IBlockState state) { Block block = state.getBlock(); if (block instanceof BlockAir) { // early return for most common case - return true; + return YES; } // exceptions - blocks that are isPassable true, but we can't actually jump through if (block == Blocks.FIRE @@ -253,10 +246,49 @@ public interface MovementHelper extends ActionCosts, Helper { || block instanceof BlockEndPortal || block instanceof BlockSkull || block instanceof BlockShulkerBox) { - return false; + return NO; } // door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters - return state.allowsMovement(access, pos, PathType.LAND); + // at least in 1.12.2 vanilla, that is..... + 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 + if (state.allowsMovement(null, null, PathType.LAND)) { + return YES; + } else { + return NO; + } + } catch (Throwable exception) { + // see PR #1087 for why + System.out.println("The block " + state.getBlock().getNameTextComponent().getString() + " requires a special case due to the exception " + exception.getMessage()); + return MAYBE; + } + } + + /** + * canWalkThrough but also won't impede movement at all. so not including doors or fence gates (we'd have to right click), + * not including water, and not including ladders or vines or cobwebs (they slow us down) + */ + static boolean fullyPassable(CalculationContext context, int x, int y, int z) { + return fullyPassable(context, x, y, z, context.get(x, y, z)); + } + + static boolean fullyPassable(CalculationContext context, int x, int y, int z, IBlockState state) { + return context.precomputedData.fullyPassable(context.bsi, x, y, z, state); + } + + static boolean fullyPassable(IPlayerContext ctx, BlockPos pos) { + IBlockState state = ctx.world().getBlockState(pos); + Ternary fullyPassable = fullyPassableBlockState(state); + if (fullyPassable == YES) { + return true; + } + if (fullyPassable == NO) { + return false; + } + return fullyPassablePosition(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ(), state); // meh + } + + static boolean fullyPassablePosition(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + return state.allowsMovement(bsi.access, bsi.isPassableBlockPos.setPos(x, y, z), PathType.LAND); } static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) { @@ -463,6 +495,58 @@ public interface MovementHelper extends ActionCosts, Helper { return canWalkOn(bsi, x, y, z, bsi.get0(x, y, z)); } + static boolean canUseFrostWalker(CalculationContext context, IBlockState state) { + return context.frostWalker != 0 + && state.getMaterial() == Material.WATER + && ((Integer) state.get(BlockFlowingFluid.LEVEL)) == 0; + } + + static boolean canUseFrostWalker(IPlayerContext ctx, BlockPos pos) { + IBlockState state = BlockStateInterface.get(ctx, pos); + return EnchantmentHelper.hasFrostWalker(ctx.player()) + && state.getMaterial() == Material.WATER + && ((Integer) state.get(BlockFlowingFluid.LEVEL)) == 0; + } + + /** + * If movements make us stand/walk on this block, will it have a top to walk on? + */ + static boolean mustBeSolidToWalkOn(CalculationContext context, int x, int y, int z, IBlockState state) { + Block block = state.getBlock(); + if (block == Blocks.LADDER || block == Blocks.VINE) { + return false; + } + if (!state.getFluidState().isEmpty()) { + // used for frostwalker so only includes blocks where we are still on ground when leaving them to any side + if (state.isTopSolid()) { + // TODO 1.19+ : add leaves, add dripleaf? + // TODO 1.14+ : add scaffolding + return true; + } + if (block instanceof BlockStairs) { + if (state.get(BlockStairs.HALF) == Half.TOP) { + return true; + } + StairsShape shape = state.get(BlockStairs.SHAPE); + if (shape == StairsShape.INNER_LEFT || shape == StairsShape.INNER_RIGHT) { + return true; + } + } else if (block instanceof BlockTrapDoor) { + if (!state.get(BlockTrapDoor.OPEN) && state.get(BlockTrapDoor.HALF) == Half.TOP) { + return true; + } + } + if (context.assumeWalkOnWater) { + return false; + } + Block blockAbove = context.getBlock(x, y + 1, z); + if (blockAbove instanceof BlockFlowingFluid) { + return false; + } + } + return true; + } + static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) { return canPlaceAgainst(bsi, x, y, z, bsi.get0(x, y, z)); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 3f88b3ff0..4a43df52d 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -43,6 +43,7 @@ import java.util.Set; public class MovementDescend extends Movement { private int numTicks = 0; + public boolean forceSafeMode = false; public MovementDescend(IBaritone baritone, BetterBlockPos start, BetterBlockPos end) { super(baritone, start, end, new BetterBlockPos[]{end.up(2), end.up(), end}, end.down()); @@ -52,6 +53,14 @@ public class MovementDescend extends Movement { public void reset() { super.reset(); numTicks = 0; + forceSafeMode = false; + } + + /** + * Called by PathExecutor if needing safeMode can only be detected with knowledge about the next movement + */ + public void forceSafeMode() { + forceSafeMode = true; } @Override @@ -109,6 +118,9 @@ public class MovementDescend extends Movement { if (destDown.getBlock() == Blocks.LADDER || destDown.getBlock() == Blocks.VINE) { return; } + if (MovementHelper.canUseFrostWalker(context, destDown)) { // no need to check assumeWalkOnWater + return; // the water will freeze when we try to walk into it + } // we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel) double walk = WALK_OFF_BLOCK_COST; @@ -248,6 +260,9 @@ public class MovementDescend extends Movement { } public boolean safeMode() { + if (forceSafeMode) { + return true; + } // (dest - src) + dest is offset 1 more in the same direction // so it's the block we'd need to worry about running into if we decide to sprint straight through this descend BlockPos into = dest.subtract(src.down()).add(dest); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index d7ba88468..893107d04 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -114,36 +114,45 @@ public class MovementDiagonal extends Movement { return; } IBlockState destInto = context.get(destX, y, destZ); + IBlockState fromDown; boolean ascend = false; IBlockState destWalkOn; boolean descend = false; + boolean frostWalker = false; if (!MovementHelper.canWalkThrough(context, destX, y, destZ, destInto)) { ascend = true; if (!context.allowDiagonalAscend || !MovementHelper.canWalkThrough(context, x, y + 2, z) || !MovementHelper.canWalkOn(context, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context, destX, y + 2, destZ)) { return; } destWalkOn = destInto; + fromDown = context.get(x, y - 1, z); } else { destWalkOn = context.get(destX, y - 1, destZ); - if (!MovementHelper.canWalkOn(context, destX, y - 1, destZ, destWalkOn)) { + fromDown = context.get(x, y - 1, z); + boolean standingOnABlock = MovementHelper.mustBeSolidToWalkOn(context, x, y - 1, z, fromDown); + frostWalker = standingOnABlock && MovementHelper.canUseFrostWalker(context, destWalkOn); + if (!frostWalker && !MovementHelper.canWalkOn(context, destX, y - 1, destZ, destWalkOn)) { descend = true; if (!context.allowDiagonalDescend || !MovementHelper.canWalkOn(context, destX, y - 2, destZ) || !MovementHelper.canWalkThrough(context, destX, y - 1, destZ, destWalkOn)) { return; } } + frostWalker &= !context.assumeWalkOnWater; // do this after checking for descends because jesus can't prevent the water from freezing, it just prevents us from relying on the water freezing } double multiplier = WALK_ONE_BLOCK_COST; // For either possible soul sand, that affects half of our walking if (destWalkOn.getBlock() == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; + } else if (frostWalker) { + // frostwalker lets us walk on water without the penalty } else if (destWalkOn.getBlock() == Blocks.WATER) { multiplier += context.walkOnWaterOnePenalty * SQRT_2; } - Block fromDown = context.get(x, y - 1, z).getBlock(); - if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { + Block fromDownBlock = fromDown.getBlock(); + if (fromDownBlock == Blocks.LADDER || fromDownBlock == Blocks.VINE) { return; } - if (fromDown == Blocks.SOUL_SAND) { + if (fromDownBlock == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } IBlockState cuttingOver1 = context.get(x, y - 1, destZ); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 51066951e..83fcaa79f 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -17,6 +17,7 @@ package baritone.pathing.movement.movements; +import baritone.Baritone; import baritone.api.IBaritone; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; @@ -32,7 +33,6 @@ import net.minecraft.block.BlockStairs; import net.minecraft.block.state.IBlockState; import net.minecraft.fluid.WaterFluid; import net.minecraft.init.Blocks; -import net.minecraft.init.Fluids; import net.minecraft.util.EnumFacing; import java.util.HashSet; @@ -92,9 +92,16 @@ public class MovementParkour extends Movement { return; } IBlockState standingOn = context.get(x, y - 1, z); - if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn) || standingOn.getFluidState().getFluid() != Fluids.EMPTY) { + if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn)) { return; } + // we can't jump from (frozen) water with assumeWalkOnWater because we can't be sure it will be frozen + if (context.assumeWalkOnWater && !standingOn.getFluidState().isEmpty()) { + return; + } + if (!context.get(x, y, z).getFluidState().isEmpty()) { + return; // can't jump out of water + } int maxJump; if (standingOn.getBlock() == Blocks.SOUL_SAND) { maxJump = 2; // 1 block gap @@ -105,13 +112,13 @@ public class MovementParkour extends Movement { maxJump = 3; } } - + // check parkour jumps from smallest to largest for obstacles/walls and landing positions int verifiedMaxJump = 1; // i - 1 (when i = 2) for (int i = 2; i <= maxJump; i++) { int destX = x + xDiff * i; int destZ = z + zDiff * i; - + // check head/feet if (!MovementHelper.fullyPassable(context, destX, y + 1, destZ)) { break; @@ -119,10 +126,10 @@ public class MovementParkour extends Movement { if (!MovementHelper.fullyPassable(context, destX, y + 2, destZ)) { break; } - + // check for ascend landing position IBlockState destInto = context.bsi.get0(destX, y, destZ); - if (!MovementHelper.fullyPassable(context.bsi.access, context.bsi.isPassableBlockPos.setPos(destX, y, destZ), destInto)) { + if (!MovementHelper.fullyPassable(context, destX, y, destZ, destInto)) { if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) { res.x = destX; res.y = y + 1; @@ -132,11 +139,14 @@ public class MovementParkour extends Movement { } break; } - + // check for flat landing position IBlockState landingOn = context.bsi.get0(destX, y - 1, destZ); // farmland needs to be canWalkOn otherwise farm can never work at all, but we want to specifically disallow ending a jump on farmland haha - if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context, destX, y - 1, destZ, landingOn)) { + // frostwalker works here because we can't jump from possibly unfrozen water + if ((landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context, destX, y - 1, destZ, landingOn)) + || (Math.min(16, context.frostWalker + 2) >= i && MovementHelper.canUseFrostWalker(context, landingOn)) + ) { if (checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) { res.x = destX; res.y = y; @@ -146,14 +156,14 @@ public class MovementParkour extends Movement { } break; } - + if (!MovementHelper.fullyPassable(context, destX, y + 3, destZ)) { break; } - + verifiedMaxJump = i; } - + // parkour place starts here if (!context.allowParkourPlace) { return; @@ -266,7 +276,12 @@ public class MovementParkour extends Movement { } } else if (!ctx.playerFeet().equals(src)) { if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - src.y > 0.0001) { - if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true, false) == PlaceResult.READY_TO_PLACE) { + if (Baritone.settings().allowPlace.value // see PR #3775 + && ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway() + && !MovementHelper.canWalkOn(ctx, dest.down()) + && !ctx.player().onGround + && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true, false) == PlaceResult.READY_TO_PLACE + ) { // go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory state.setInput(Input.CLICK_RIGHT, true); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 62c4f2082..333875fde 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -101,6 +101,10 @@ public class MovementPillar extends Movement { // if we're standing on water and assumeWalkOnWater is false, we must have ascended to here, or sneak backplaced, so it is possible to pillar again return COST_INF; } + if ((from == Blocks.LILY_PAD || from instanceof BlockCarpet) && !fromDown.getFluidState().isEmpty()) { + // to ascend here we'd have to break the block we are standing on + return COST_INF; + } double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true); if (hardness >= COST_INF) { return COST_INF; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 7d00eff41..4f84c0048 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -33,7 +33,6 @@ import baritone.utils.BlockStateInterface; import com.google.common.collect.ImmutableSet; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; -import net.minecraft.fluid.WaterFluid; import net.minecraft.init.Blocks; import net.minecraft.state.properties.SlabType; import net.minecraft.util.math.BlockPos; @@ -73,9 +72,11 @@ public class MovementTraverse extends Movement { IBlockState pb0 = context.get(destX, y + 1, destZ); IBlockState pb1 = context.get(destX, y, destZ); IBlockState destOn = context.get(destX, y - 1, destZ); - IBlockState down = context.get(x, y - 1, z); - Block srcDown = down.getBlock(); - if (MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge + IBlockState srcDown = context.get(x, y - 1, z); + Block srcDownBlock = srcDown.getBlock(); + boolean standingOnABlock = MovementHelper.mustBeSolidToWalkOn(context, x, y - 1, z, srcDown); + boolean frostWalker = standingOnABlock && !context.assumeWalkOnWater && MovementHelper.canUseFrostWalker(context, destOn); + if (frostWalker || MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) { //this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (MovementHelper.isWater(pb0) || MovementHelper.isWater(pb1)) { @@ -84,10 +85,12 @@ public class MovementTraverse extends Movement { } else { if (destOn.getBlock() == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; + } else if (frostWalker) { + // with frostwalker we can walk on water without the penalty, if we are sure we won't be using jesus } else if (destOn.getBlock() == Blocks.WATER) { WC += context.walkOnWaterOnePenalty; } - if (srcDown == Blocks.SOUL_SAND) { + if (srcDownBlock == Blocks.SOUL_SAND) { WC += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } } @@ -105,13 +108,13 @@ public class MovementTraverse extends Movement { } return WC; } - if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { + if (srcDownBlock == Blocks.LADDER || srcDownBlock == Blocks.VINE) { hardness1 *= 5; hardness2 *= 5; } return WC + hardness1 + hardness2; } else {//this is a bridge, so we need to place a block - if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) { + if (srcDownBlock == Blocks.LADDER || srcDownBlock == Blocks.VINE) { return COST_INF; } if (MovementHelper.isReplaceable(destX, y - 1, destZ, destOn, context.bsi)) { @@ -142,12 +145,16 @@ public class MovementTraverse extends Movement { } } // now that we've checked all possible directions to side place, we actually need to backplace - if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && down.get(BlockSlab.TYPE) != SlabType.DOUBLE)) { + if (srcDownBlock == Blocks.SOUL_SAND || (srcDownBlock instanceof BlockSlab && srcDown.get(BlockSlab.TYPE) != SlabType.DOUBLE)) { return COST_INF; // can't sneak and backplace against soul sand or half slabs (regardless of whether it's top half or bottom half) =/ } - if (down.getFluidState() instanceof WaterFluid) { + if (!standingOnABlock) { // standing on water / swimming return COST_INF; // this is obviously impossible } + Block blockSrc = context.getBlock(x, y, z); + if ((blockSrc == Blocks.LILY_PAD || blockSrc instanceof BlockCarpet) && !srcDown.getFluidState().isEmpty()) { + return COST_INF; // we can stand on these but can't place against them + } WC = WC * (SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST);//since we are sneak backplacing, we are sneaking lol return WC + placeCost + hardness1 + hardness2; } @@ -229,7 +236,7 @@ public class MovementTraverse extends Movement { } } - boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder; + boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder || MovementHelper.canUseFrostWalker(ctx, positionToPlace); BlockPos feet = ctx.playerFeet(); if (feet.getY() != dest.getY() && !ladder) { logDebug("Wrong Y coordinate"); diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 880274054..a91a84636 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -379,6 +379,26 @@ public class PathExecutor implements IPathExecutor, Helper { // however, descend and ascend don't request sprinting, because they don't know the context of what movement comes after it if (current instanceof MovementDescend) { + if (pathPosition < path.length() - 2) { + // keep this out of onTick, even if that means a tick of delay before it has an effect + IMovement next = path.movements().get(pathPosition + 1); + if (MovementHelper.canUseFrostWalker(ctx, next.getDest().down())) { + // frostwalker only works if you cross the edge of the block on ground so in some cases we may not overshoot + // Since MovementDescend can't know the next movement we have to tell it + if (next instanceof MovementTraverse || next instanceof MovementParkour) { + boolean couldPlaceInstead = Baritone.settings().allowPlace.value && behavior.baritone.getInventoryBehavior().hasGenericThrowaway() && next instanceof MovementParkour; // traverse doesn't react fast enough + // this is true if the next movement does not ascend or descends and goes into the same cardinal direction (N-NE-E-SE-S-SW-W-NW) as the descend + // in that case current.getDirection() is e.g. (0, -1, 1) and next.getDirection() is e.g. (0, 0, 3) so the cross product of (0, 0, 1) and (0, 0, 3) is taken, which is (0, 0, 0) because the vectors are colinear (don't form a plane) + // since movements in exactly the opposite direction (e.g. descend (0, -1, 1) and traverse (0, 0, -1)) would also pass this check we also have to rule out that case + // we can do that by adding the directions because traverse is always 1 long like descend and parkour can't jump through current.getSrc().down() + boolean sameFlatDirection = !current.getDirection().up().add(next.getDirection()).equals(BlockPos.ORIGIN) + && current.getDirection().up().crossProduct(next.getDirection()).equals(BlockPos.ORIGIN); // here's why you learn maths in school + if (sameFlatDirection && !couldPlaceInstead) { + ((MovementDescend) current).forceSafeMode(); + } + } + } + } if (((MovementDescend) current).safeMode() && !((MovementDescend) current).skipToAscend()) { logDebug("Sprinting would be unsafe"); return false; diff --git a/src/main/java/baritone/pathing/precompute/PrecomputedData.java b/src/main/java/baritone/pathing/precompute/PrecomputedData.java index 72eb575b3..bf00ee087 100644 --- a/src/main/java/baritone/pathing/precompute/PrecomputedData.java +++ b/src/main/java/baritone/pathing/precompute/PrecomputedData.java @@ -25,7 +25,7 @@ import net.minecraft.block.state.IBlockState; import static baritone.pathing.precompute.Ternary.MAYBE; import static baritone.pathing.precompute.Ternary.YES; -public class PrecomputedData { // TODO add isFullyPassable +public class PrecomputedData { private final int[] data = new int[Block.BLOCK_STATE_IDS.size()]; @@ -34,6 +34,8 @@ public class PrecomputedData { // TODO add isFullyPassable private static final int CAN_WALK_ON_SPECIAL_MASK = 1 << 2; private static final int CAN_WALK_THROUGH_MASK = 1 << 3; private static final int CAN_WALK_THROUGH_SPECIAL_MASK = 1 << 4; + private static final int FULLY_PASSABLE_MASK = 1 << 5; + private static final int FULLY_PASSABLE_SPECIAL_MASK = 1 << 6; private int fillData(int id, IBlockState state) { int blockData = 0; @@ -50,10 +52,18 @@ public class PrecomputedData { // TODO add isFullyPassable if (canWalkThroughState == YES) { blockData |= CAN_WALK_THROUGH_MASK; } - if (canWalkOnState == MAYBE) { + if (canWalkThroughState == MAYBE) { blockData |= CAN_WALK_THROUGH_SPECIAL_MASK; } + Ternary fullyPassableState = MovementHelper.fullyPassableBlockState(state); + if (fullyPassableState == YES) { + blockData |= FULLY_PASSABLE_MASK; + } + if (fullyPassableState == MAYBE) { + blockData |= FULLY_PASSABLE_SPECIAL_MASK; + } + blockData |= COMPLETED_MASK; data[id] = blockData; // in theory, this is thread "safe" because every thread should compute the exact same int to write? @@ -89,4 +99,19 @@ public class PrecomputedData { // TODO add isFullyPassable return (blockData & CAN_WALK_THROUGH_MASK) != 0; } } + + public boolean fullyPassable(BlockStateInterface bsi, int x, int y, int z, IBlockState state) { + int id = Block.BLOCK_STATE_IDS.get(state); + int blockData = data[id]; + + if ((blockData & COMPLETED_MASK) == 0) { // we need to fill in the data + blockData = fillData(id, state); + } + + if ((blockData & FULLY_PASSABLE_SPECIAL_MASK) != 0) { + return MovementHelper.fullyPassablePosition(bsi, x, y, z, state); + } else { + return (blockData & FULLY_PASSABLE_MASK) != 0; + } + } } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 2a3f19c55..a0682b1ca 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -71,6 +71,7 @@ import java.io.IOException; import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; import static baritone.api.pathing.movement.ActionCosts.COST_INF; @@ -87,6 +88,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil private int layer; private int numRepeats; private List approxPlaceable; + public int stopAtHeight = 0; public BuilderProcess(Baritone baritone) { super(baritone); @@ -97,6 +99,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil this.name = name; this.schematic = schematic; this.realSchematic = null; + boolean buildingSelectionSchematic = schematic instanceof SelectionSchematic; if (!Baritone.settings().buildSubstitutes.value.isEmpty()) { this.schematic = new SubstituteSchematic(this.schematic, Baritone.settings().buildSubstitutes.value); } @@ -115,6 +118,25 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil this.origin = new Vec3i(x, y, z); this.paused = false; this.layer = Baritone.settings().startAtLayer.value; + this.stopAtHeight = schematic.heightY(); + if (Baritone.settings().buildOnlySelection.value && buildingSelectionSchematic) { // currently redundant but safer maybe + if (baritone.getSelectionManager().getSelections().length == 0) { + logDirect("Poor little kitten forgot to set a selection while BuildOnlySelection is true"); + this.stopAtHeight = 0; + } else if (Baritone.settings().buildInLayers.value) { + OptionalInt minim = Stream.of(baritone.getSelectionManager().getSelections()).mapToInt(sel -> sel.min().y).min(); + OptionalInt maxim = Stream.of(baritone.getSelectionManager().getSelections()).mapToInt(sel -> sel.max().y).max(); + if (minim.isPresent() && maxim.isPresent()) { + int startAtHeight = Baritone.settings().layerOrder.value ? y + schematic.heightY() - maxim.getAsInt() : minim.getAsInt() - y; + this.stopAtHeight = (Baritone.settings().layerOrder.value ? y + schematic.heightY() - minim.getAsInt() : maxim.getAsInt() - y) + 1; + this.layer = Math.max(this.layer, startAtHeight / Baritone.settings().layerHeight.value); // startAtLayer or startAtHeight, whichever is highest + logDebug(String.format("Schematic starts at y=%s with height %s", y, schematic.heightY())); + logDebug(String.format("Selection starts at y=%s and ends at y=%s", minim.getAsInt(), maxim.getAsInt())); + logDebug(String.format("Considering relevant height %s - %s", startAtHeight, this.stopAtHeight)); + } + } + } + this.numRepeats = 0; this.observedCompleted = new LongOpenHashSet(); this.incorrectPositions = null; @@ -477,7 +499,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } BuilderCalculationContext bcc = new BuilderCalculationContext(); if (!recalc(bcc)) { - if (Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < realSchematic.heightY()) { + if (Baritone.settings().buildInLayers.value && layer * Baritone.settings().layerHeight.value < stopAtHeight) { logDirect("Starting layer " + layer); layer++; return onTick(calcFailed, isSafeToCancel, recursions + 1); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index e79cb815b..34f5c4c35 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -28,7 +28,6 @@ import baritone.cache.CachedChunk; import baritone.cache.WorldScanner; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; -import baritone.pathing.precompute.PrecomputedData; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; @@ -215,6 +214,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro public boolean isInGoal(int x, int y, int z) { return false; } + @Override public double heuristic() { return Double.NEGATIVE_INFINITY; @@ -500,9 +500,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } if (!Baritone.settings().allowBreak.value) { BlockOptionalMetaLookup f = new BlockOptionalMetaLookup(this.filter.blocks() - .stream() - .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) - .toArray(BlockOptionalMeta[]::new)); + .stream() + .filter(e -> Baritone.settings().allowBreakAnyway.value.contains(e.getBlock())) + .toArray(BlockOptionalMeta[]::new)); if (f.blocks().isEmpty()) { logDirect("Unable to mine when allowBreak is false and target block is not in allowBreakAnyway!"); return null; diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index f09f99939..691c66502 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -211,8 +211,7 @@ public final class PathRenderer implements IRenderer { if (!settings.renderGoalAnimated.value) { // y = 1 causes rendering issues when the player is at the same y as the top of a block for some reason y = 0.999F; - } - else { + } else { y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); } if (goal instanceof IGoalRenderPos) { diff --git a/src/main/java/baritone/utils/ToolSet.java b/src/main/java/baritone/utils/ToolSet.java index a86f7e637..bdd6eb181 100644 --- a/src/main/java/baritone/utils/ToolSet.java +++ b/src/main/java/baritone/utils/ToolSet.java @@ -128,7 +128,7 @@ public class ToolSet { if (!Baritone.settings().useSwordToMine.value && itemStack.getItem() instanceof ItemSword) { continue; } - + if (Baritone.settings().itemSaver.value && (itemStack.getDamage() + Baritone.settings().itemSaverThreshold.value) >= itemStack.getMaxDamage() && itemStack.getMaxDamage() > 1) { continue; } diff --git a/src/main/java/baritone/utils/schematic/SelectionSchematic.java b/src/main/java/baritone/utils/schematic/SelectionSchematic.java index 243a3d4d0..156a80918 100644 --- a/src/main/java/baritone/utils/schematic/SelectionSchematic.java +++ b/src/main/java/baritone/utils/schematic/SelectionSchematic.java @@ -33,10 +33,10 @@ public class SelectionSchematic extends MaskSchematic { public SelectionSchematic(ISchematic schematic, Vec3i origin, ISelection[] selections) { super(schematic); this.selections = Stream.of(selections).map( - sel -> sel - .shift(EnumFacing.WEST, origin.getX()) - .shift(EnumFacing.DOWN, origin.getY()) - .shift(EnumFacing.NORTH, origin.getZ())) + sel -> sel + .shift(EnumFacing.WEST, origin.getX()) + .shift(EnumFacing.DOWN, origin.getY()) + .shift(EnumFacing.NORTH, origin.getZ())) .toArray(ISelection[]::new); } @@ -44,7 +44,7 @@ public class SelectionSchematic extends MaskSchematic { protected boolean partOfMask(int x, int y, int z, IBlockState currentState) { for (ISelection selection : selections) { if (x >= selection.min().x && y >= selection.min().y && z >= selection.min().z - && x <= selection.max().x && y <= selection.max().y && z <= selection.max().z) { + && x <= selection.max().x && y <= selection.max().y && z <= selection.max().z) { return true; } } diff --git a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java index ce82d41eb..03c85643a 100644 --- a/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java +++ b/src/main/java/baritone/utils/schematic/format/defaults/LitematicaSchematic.java @@ -136,7 +136,7 @@ public final class LitematicaSchematic extends StaticSchematic { * @return amount of bits used to encode a block. */ private static int getBitsPerBlock(int amountOfBlockTypes) { - return (int) Math.max(2,Math.ceil(Math.log(amountOfBlockTypes) / Math.log(2))); + return (int) Math.max(2, Math.ceil(Math.log(amountOfBlockTypes) / Math.log(2))); } /**