diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..176a458f9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/README.md b/README.md index 08aac2b99..c9f68ea8a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) [![Code of Conduct](https://img.shields.io/badge/%E2%9D%A4-code%20of%20conduct-blue.svg?style=flat)](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md) [![Known Vulnerabilities](https://snyk.io/test/github/cabaletta/baritone/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle) -[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) +[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) [![Issues](https://img.shields.io/github/issues/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/issues/) [![GitHub issues-closed](https://img.shields.io/github/issues-closed/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed) [![Pull Requests](https://img.shields.io/github/issues-pr/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/pulls/) @@ -51,7 +51,7 @@ Here are some links to help to get started: # API -The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/). +The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com). Please note that usage of anything located outside of the ``baritone.api`` package is not supported by the API release jar. diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 4e0dd3a1d..373fd08eb 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -23,7 +23,7 @@ import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.item.Item; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.Vec3i; import net.minecraft.util.text.ITextComponent; import java.awt.*; @@ -214,6 +214,13 @@ public final class Settings { */ public final Setting sprintAscends = new Setting<>(true); + /** + * If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway. + *

+ * This helps with speed at >=20m/s + */ + public final Setting overshootTraverse = new Setting<>(true); + /** * When breaking blocks for a movement, wait until all falling blocks have settled before continuing */ @@ -537,6 +544,8 @@ public final class Settings { /** * Exclusively use cached chunks for pathing + *

+ * Never turn this on */ public final Setting pathThroughCachedOnly = new Setting<>(false); @@ -567,7 +576,7 @@ public final class Settings { public final Setting renderCachedChunks = new Setting<>(false); /** - * 0.0f = not visible, fully transparent + * 0.0f = not visible, fully transparent (instead of setting this to 0, turn off renderCachedChunks) * 1.0f = fully opaque */ public final Setting cachedChunksOpacity = new Setting<>(0.5f); @@ -638,7 +647,7 @@ public final class Settings { public final Setting exploreMaintainY = new Setting<>(64); /** - * Replant nether wart + * Replant nether wart while farming */ public final Setting replantNetherWart = new Setting<>(false); @@ -655,14 +664,16 @@ public final class Settings { public final Setting buildInLayers = new Setting<>(false); /** - * How far to move before repeating the build. -1 for the size of the build in that axis. 0 to disable + * false = build from bottom to top + *

+ * true = build from top to bottom */ - public final Setting buildRepeatDistance = new Setting<>(0); + public final Setting layerOrder = new Setting<>(false); /** - * What direction to repeat the build in + * How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely */ - public final Setting buildRepeatDirection = new Setting<>(EnumFacing.NORTH); + public final Setting buildRepeat = new Setting<>(new Vec3i(0, 0, 0)); /** * Allow standing above a block while mining it, in BuilderProcess @@ -798,6 +809,11 @@ public final class Settings { */ public final Setting> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage); + /** + * The size of the box that is rendered when the current goal is a GoalYLevel + */ + public final Setting yLevelBoxSize = new Setting<>(15D); + /** * The color of the current path */ diff --git a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java index ce54eebb7..9add7176a 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java +++ b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java @@ -29,7 +29,7 @@ public class GoalYLevel implements Goal, ActionCosts { /** * The target Y level */ - private final int level; + public final int level; public GoalYLevel(int level) { this.level = level; diff --git a/src/api/java/baritone/api/utils/BetterBlockPos.java b/src/api/java/baritone/api/utils/BetterBlockPos.java index a1a3cb320..3b94a8339 100644 --- a/src/api/java/baritone/api/utils/BetterBlockPos.java +++ b/src/api/java/baritone/api/utils/BetterBlockPos.java @@ -61,6 +61,8 @@ public final class BetterBlockPos extends BlockPos { } public static long longHash(int x, int y, int z) { + // TODO use the same thing as BlockPos.fromLong(); + // invertibility would be incredibly useful /* * This is the hashcode implementation of Vec3i (the superclass of the class which I shall not name) * diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java index 47dcde32d..7a7cf9b37 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -688,18 +688,20 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener private Goal parseGoal(String[] params) { Goal goal; try { + BetterBlockPos playerFeet = ctx.playerFeet(); switch (params.length) { case 0: - goal = new GoalBlock(ctx.playerFeet()); + goal = new GoalBlock(playerFeet); break; case 1: - goal = new GoalYLevel(Integer.parseInt(params[0])); + + goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y)); break; case 2: - goal = new GoalXZ(Integer.parseInt(params[0]), Integer.parseInt(params[1])); + goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.z)); break; case 3: - goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2]))); + goal = new GoalBlock(new BlockPos(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.y), parseOrDefault(params[2], playerFeet.z))); break; default: logDirect("unable to understand lol"); diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index cfb102130..e42bb073f 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -24,6 +24,7 @@ import net.minecraft.item.Item; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.IRegistry; +import net.minecraft.util.math.Vec3i; import java.awt.*; import java.io.BufferedReader; @@ -181,6 +182,11 @@ public class SettingsUtil { str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])), color -> color.getRed() + "," + color.getGreen() + "," + color.getBlue() ), + VEC3I( + Vec3i.class, + str -> new Vec3i(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])), + vec -> vec.getX() + "," + vec.getY() + "," + vec.getZ() + ), BLOCK( Block.class, str -> BlockUtils.stringToBlockRequired(str.trim()), diff --git a/src/main/java/baritone/cache/ContainerMemory.java b/src/main/java/baritone/cache/ContainerMemory.java index c1cb7b34d..e79435e3a 100644 --- a/src/main/java/baritone/cache/ContainerMemory.java +++ b/src/main/java/baritone/cache/ContainerMemory.java @@ -29,6 +29,7 @@ import net.minecraft.util.math.BlockPos; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.util.*; @@ -45,6 +46,8 @@ public class ContainerMemory implements IContainerMemory { this.saveTo = saveTo; try { read(Files.readAllBytes(saveTo)); + } catch (NoSuchFileException ignored) { + inventories.clear(); } catch (Exception ex) { ex.printStackTrace(); inventories.clear(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 62ebd41f1..cdd3484b7 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -231,7 +231,11 @@ public class MovementTraverse extends Movement { } if (isTheBridgeBlockThere) { - if (ctx.playerFeet().equals(dest)) { + BetterBlockPos feet = ctx.playerFeet(); + if (feet.equals(dest)) { + return state.setStatus(MovementStatus.SUCCESS); + } + if (Baritone.settings().overshootTraverse.value && (feet.equals(dest.add(getDirection())) || feet.equals(dest.add(getDirection()).add(getDirection())))) { return state.setStatus(MovementStatus.SUCCESS); } Block low = BlockStateInterface.get(ctx, src).getBlock(); diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index ffebaacca..e3257ce13 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -318,12 +318,29 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro if (realSchematic == null) { realSchematic = schematic; } + ISchematic realSchematic = this.realSchematic; // wrap this properly, dont just have the inner class refer to the builderprocess.this + int minYInclusive; + int maxYInclusive; + // layer = 0 should be nothing + // layer = realSchematic.heightY() should be everything + if (Baritone.settings().layerOrder.value) { // top to bottom + maxYInclusive = realSchematic.heightY() - 1; + minYInclusive = realSchematic.heightY() - layer; + } else { + maxYInclusive = layer - 1; + minYInclusive = 0; + } schematic = new ISchematic() { @Override public IBlockState desiredState(int x, int y, int z) { return realSchematic.desiredState(x, y, z); } + @Override + public boolean inSchematic(int x, int y, int z) { + return ISchematic.super.inSchematic(x, y, z) && y >= minYInclusive && y <= maxYInclusive; + } + @Override public int widthX() { return realSchematic.widthX(); @@ -331,7 +348,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro @Override public int heightY() { - return layer; + return realSchematic.heightY(); } @Override @@ -347,20 +364,16 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro layer++; return onTick(calcFailed, isSafeToCancel); } - int distance = Baritone.settings().buildRepeatDistance.value; - EnumFacing direction = Baritone.settings().buildRepeatDirection.value; - if (distance == 0) { + Vec3i repeat = Baritone.settings().buildRepeat.value; + if (repeat.equals(new Vec3i(0, 0, 0))) { logDirect("Done building"); onLostControl(); return null; } // build repeat time - if (distance == -1) { - distance = schematic.size(direction.getAxis()); - } layer = 0; - origin = new BlockPos(origin).offset(direction, distance); - logDirect("Repeating build " + distance + " blocks to the " + direction + ", new origin is " + origin); + origin = new BlockPos(origin).add(repeat); + logDirect("Repeating build in vector " + repeat + ", new origin is " + origin); return onTick(calcFailed, isSafeToCancel); } trim(bcc); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index daada33ed..c5a7c8efc 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -88,17 +88,16 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } } - boolean shouldCancel = calcFailed; - if (calcFailed && !knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { - logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance..."); - knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add); - knownOreLocations.removeIf(blacklist::contains); - shouldCancel = false; // 😎 - } - if (shouldCancel) { - logDirect("Unable to find any path to " + mining + ", canceling Mine"); - cancel(); - return null; + if (calcFailed) { + if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { + logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance..."); + knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add); + knownOreLocations.removeIf(blacklist::contains); + } else { + logDirect("Unable to find any path to " + mining + ", canceling Mine"); + cancel(); + return null; + } } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 98ad3f9b9..1d313ed1e 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -276,13 +276,13 @@ public final class PathRenderer implements Helper { double maxY; double y1; double y2; + double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); if (goal instanceof IGoalRenderPos) { BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos(); minX = goalPos.getX() + 0.002 - renderPosX; maxX = goalPos.getX() + 1 - 0.002 - renderPosX; minZ = goalPos.getZ() + 0.002 - renderPosZ; maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ; - double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2)); if (goal instanceof GoalGetToBlock || goal instanceof GoalTwoBlocks) { y /= 2; } @@ -345,6 +345,16 @@ public final class PathRenderer implements Helper { drawDankLitGoalBox(player, g, partialTicks, color); } return; + } else if (goal instanceof GoalYLevel) { + GoalYLevel goalpos = (GoalYLevel) goal; + minX = player.posX - Baritone.settings().yLevelBoxSize.value - renderPosX; + minZ = player.posZ - Baritone.settings().yLevelBoxSize.value - renderPosZ; + maxX = player.posX + Baritone.settings().yLevelBoxSize.value - renderPosX; + maxZ = player.posZ + Baritone.settings().yLevelBoxSize.value - renderPosZ; + minY = ((GoalYLevel) goal).level - renderPosY; + maxY = minY + 2; + y1 = 1 + y + goalpos.level - renderPosY; + y2 = 1 - y + goalpos.level - renderPosY; } else { return; }