diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 55e5ad06f..e2b8874c6 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -14,12 +14,19 @@ Baritone version: Forge mods (if used): ## Exception, error or logs -You can find your logs in `%appdata%/.minecraft/logs/` (Windows) or `/Library/Application\ Support/minecraft/logs` (Mac). +Please find your `latest.log` or `debug.log` in this folder and attach it to the issue + +Linux: `~/.minecraft/logs/` + +Windows: `%appdata%/.minecraft/logs/` + +Mac: `/Library/Application\ Support/minecraft/logs/` ## How to reproduce Add your steps to reproduce the issue/bug experienced here. ## Final checklist +- [x] I know how to properly use check boxes - [ ] I have included the version of Minecraft I'm running, baritone's version and forge mods (if used). - [ ] I have included logs, exceptions and / or steps to reproduce the issue. -- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file +- [ ] I have not used any OwO's or UwU's in this issue. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 2482fd4c3..b5de2dfd3 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -10,4 +10,5 @@ assignees: '' With as much detail as possible, describe your question and what you may need help with. ## Final checklist -- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file +- [x] I know how to properly use check boxes +- [ ] I have not used any OwO's or UwU's in this issue. diff --git a/.github/ISSUE_TEMPLATE/suggestion.md b/.github/ISSUE_TEMPLATE/suggestion.md index da61c638d..9f7a30bf7 100644 --- a/.github/ISSUE_TEMPLATE/suggestion.md +++ b/.github/ISSUE_TEMPLATE/suggestion.md @@ -16,4 +16,5 @@ If applicable, what settings/customizability should be offered to tweak the func Describe how your suggestion would improve Baritone, or the reason behind it being added. ## Final checklist -- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file +- [x] I know how to properly use check boxes +- [ ] I have not used any OwO's or UwU's in this issue. diff --git a/README.md b/README.md index 043aed085..9bc29c667 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [![Minecraft](https://img.shields.io/badge/MC-1.12.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/master/) [![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.13.2/) [![Minecraft](https://img.shields.io/badge/MC-1.14.4-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.14.4/) +[![Minecraft](https://img.shields.io/badge/MC-1.15.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.15.2/) [![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/) @@ -22,6 +23,7 @@ [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) +[![rootNET integration](https://img.shields.io/badge/rootNET%20integration-v1.2.11-green.svg)](https://rootnet.dev/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) [![Future integration](https://img.shields.io/badge/Future%20integration-Soon™%3F%3F%3F-red.svg)](https://futureclient.net/) [![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/) @@ -29,14 +31,14 @@ A Minecraft pathfinder bot. -Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://www.youtube.com/watch?v=yI8hgW_m6dQ) made by @Adovin#3153 on Baritone's integration into Impact. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do. +Baritone is the pathfinding system used in [Impact](https://impactclient.net/) since 4.4. There's a [showcase video](https://youtu.be/CZkLXWo4Fg4) made by @Adovin#0730 on Baritone which I recommend. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a (very old!) video I made showing off what it can do. 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.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. -For 1.14.4, [click here](https://www.dropbox.com/s/rkml3hjokd3qv0m/1.14.4-Baritone.zip?dl=1). Or [with optifine](https://github.com/cabaletta/baritone/issues/797). +For 1.15.2, [click here](https://www.youtube.com/watch?v=j1qKtCZFURM) and see description. This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), -the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 and 1.13.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). +the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 through 1.15.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). Have committed at least once a day from Aug 1 2018 to Aug 1 2019. @@ -56,6 +58,10 @@ Here are some links to help to get started: - [Usage (chat control)](USAGE.md) +## Stars over time + +[![Stargazers over time](https://starchart.cc/cabaletta/baritone.svg)](https://starchart.cc/cabaletta/baritone) + # API The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/). diff --git a/SETUP.md b/SETUP.md index 1fcaf1d2b..7efab34ff 100644 --- a/SETUP.md +++ b/SETUP.md @@ -47,6 +47,8 @@ You can verify whether or not it worked by running `.b version` in chat (only va ## Command Line On Mac OSX and Linux, use `./gradlew` instead of `gradlew`. +If you have errors with a package missing please make sure you have setup your environment, and are using Oracle JDK 8. + Setting up the Environment: ``` @@ -54,6 +56,12 @@ $ gradlew setupDecompWorkspace $ gradlew --refresh-dependencies ``` +Building Baritone: + +``` +$ gradlew build +``` + Running Baritone: ``` @@ -87,16 +95,6 @@ For information on how to build baritone, see [Building Baritone](#building-bari ![Image](https://i.imgur.com/hrLhG9u.png) -# Building - -Make sure that you have properly [setup](#setup) the environment before trying to build it. - -## Command Line - -``` -$ gradlew build -``` - ## IntelliJ - Navigate to the gradle tasks on the right tab as follows diff --git a/USAGE.md b/USAGE.md index 0f911efaa..681298b01 100644 --- a/USAGE.md +++ b/USAGE.md @@ -20,6 +20,8 @@ Try `#help` I promise it won't just send you back here =) just look at `#help` lmao +Watch this [showcase video](https://youtu.be/CZkLXWo4Fg4)! + # Commands **All** of these commands may need a prefix before them, as above ^. @@ -42,7 +44,7 @@ Some common examples: - `save waypointName` to save a waypoint. `goto waypointName` to go to it. - `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). - `schematica` to build the schematic that is currently open in schematica -- `tunnel` to dig just straight ahead and make a tunnel +- `tunnel height width depth` to dig and make a tunnel. If you don't supply numbers then it just digs a 1x2 tunnel. - `farm` to automatically harvest, replant, or bone meal crops - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load. @@ -71,6 +73,8 @@ There are about a hundred settings, but here are some fun / interesting / import - `worldExploringChunkOffset` - `acceptableThrowawayItems` - `blocksToAvoidBreaking` +- `mineScanDroppedItems` +- `allowDiagonalAscend` diff --git a/build.gradle b/build.gradle index 117f1d63d..9912a92a1 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.2.10' +version '1.2.11' buildscript { repositories { diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 4ac0f7233..52b843ddf 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -181,19 +181,19 @@ -assumenosideeffects public class java.lang.* extends java.lang.Number { public static java.lang.String toString(byte); public static java.lang.Byte valueOf(byte); - public static byte parseByte(java.lang.String); - public static byte parseByte(java.lang.String,int); - public static java.lang.Byte valueOf(java.lang.String,int); - public static java.lang.Byte valueOf(java.lang.String); - public static java.lang.Byte decode(java.lang.String); +# public static byte parseByte(java.lang.String); +# public static byte parseByte(java.lang.String,int); +# public static java.lang.Byte valueOf(java.lang.String,int); +# public static java.lang.Byte valueOf(java.lang.String); +# public static java.lang.Byte decode(java.lang.String); public int compareTo(java.lang.Byte); public static java.lang.String toString(short); - public static short parseShort(java.lang.String); - public static short parseShort(java.lang.String,int); - public static java.lang.Short valueOf(java.lang.String,int); - public static java.lang.Short valueOf(java.lang.String); +# public static short parseShort(java.lang.String); +# public static short parseShort(java.lang.String,int); +# public static java.lang.Short valueOf(java.lang.String,int); +# public static java.lang.Short valueOf(java.lang.String); public static java.lang.Short valueOf(short); - public static java.lang.Short decode(java.lang.String); +# public static java.lang.Short decode(java.lang.String); public static short reverseBytes(short); public int compareTo(java.lang.Short); public static java.lang.String toString(int,int); @@ -201,10 +201,10 @@ public static java.lang.String toOctalString(int); public static java.lang.String toBinaryString(int); public static java.lang.String toString(int); - public static int parseInt(java.lang.String,int); - public static int parseInt(java.lang.String); - public static java.lang.Integer valueOf(java.lang.String,int); - public static java.lang.Integer valueOf(java.lang.String); +# public static int parseInt(java.lang.String,int); +# public static int parseInt(java.lang.String); +# public static java.lang.Integer valueOf(java.lang.String,int); +# public static java.lang.Integer valueOf(java.lang.String); public static java.lang.Integer valueOf(int); public static java.lang.Integer getInteger(java.lang.String); public static java.lang.Integer getInteger(java.lang.String,int); @@ -226,12 +226,12 @@ public static java.lang.String toOctalString(long); public static java.lang.String toBinaryString(long); public static java.lang.String toString(long); - public static long parseLong(java.lang.String,int); - public static long parseLong(java.lang.String); - public static java.lang.Long valueOf(java.lang.String,int); - public static java.lang.Long valueOf(java.lang.String); +# public static long parseLong(java.lang.String,int); +# public static long parseLong(java.lang.String); +# public static java.lang.Long valueOf(java.lang.String,int); +# public static java.lang.Long valueOf(java.lang.String); public static java.lang.Long valueOf(long); - public static java.lang.Long decode(java.lang.String); +# public static java.lang.Long decode(java.lang.String); public static java.lang.Long getLong(java.lang.String); public static java.lang.Long getLong(java.lang.String,long); public static java.lang.Long getLong(java.lang.String,java.lang.Long); @@ -248,9 +248,9 @@ public int compareTo(java.lang.Long); public static java.lang.String toString(float); public static java.lang.String toHexString(float); - public static java.lang.Float valueOf(java.lang.String); +# public static java.lang.Float valueOf(java.lang.String); public static java.lang.Float valueOf(float); - public static float parseFloat(java.lang.String); +# public static float parseFloat(java.lang.String); public static boolean isNaN(float); public static boolean isInfinite(float); public static int floatToIntBits(float); @@ -262,9 +262,9 @@ public int compareTo(java.lang.Float); public static java.lang.String toString(double); public static java.lang.String toHexString(double); - public static java.lang.Double valueOf(java.lang.String); - public static java.lang.Double valueOf(double); - public static double parseDouble(java.lang.String); +# public static java.lang.Double valueOf(java.lang.String); +# public static java.lang.Double valueOf(double); +# public static double parseDouble(java.lang.String); public static boolean isNaN(double); public static boolean isInfinite(double); public static long doubleToLongBits(double); diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 69bcabcb6..1bbde3b2b 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1046,6 +1046,10 @@ public final class Settings { */ public final Setting renderSelectionCorners = new Setting<>(true); + /** + * Desktop Notifications + */ + public final Setting desktopNotifications = new Setting<>(false); /** * A map of lowercase setting field names to their respective setting diff --git a/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java index cd3977b6f..c50aab015 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeGoalXZ.java @@ -37,7 +37,7 @@ public enum RelativeGoalXZ implements IDatatypePost { final IArgConsumer consumer = ctx.getConsumer(); return new GoalXZ( MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.x)), - MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.y)) + MathHelper.floor(consumer.getDatatypePost(RelativeCoordinate.INSTANCE, (double) origin.z)) ); } diff --git a/src/api/java/baritone/api/utils/Helper.java b/src/api/java/baritone/api/utils/Helper.java index 994d8c7b5..3cda18343 100755 --- a/src/api/java/baritone/api/utils/Helper.java +++ b/src/api/java/baritone/api/utils/Helper.java @@ -24,6 +24,7 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import java.util.Arrays; +import java.util.Calendar; import java.util.stream.Stream; /** @@ -47,7 +48,9 @@ public interface Helper { static ITextComponent getPrefix() { // Inner text component - ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone"); + final Calendar now = Calendar.getInstance(); + final boolean xd = now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) <= 3; + ITextComponent baritone = new TextComponentString(xd ? "Baritoe" : BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone"); baritone.getStyle().setColor(TextFormatting.LIGHT_PURPLE); // Outer brackets diff --git a/src/api/java/baritone/api/utils/IPlayerContext.java b/src/api/java/baritone/api/utils/IPlayerContext.java index b461c3891..8ce3271b2 100644 --- a/src/api/java/baritone/api/utils/IPlayerContext.java +++ b/src/api/java/baritone/api/utils/IPlayerContext.java @@ -77,6 +77,10 @@ public interface IPlayerContext { return new Rotation(player().rotationYaw, player().rotationPitch); } + static double eyeHeight(boolean ifSneaking) { + return ifSneaking ? 1.54 : 1.62; + } + /** * Returns the block that the crosshair is currently placed over. Updated once per tick. * diff --git a/src/api/java/baritone/api/utils/RayTraceUtils.java b/src/api/java/baritone/api/utils/RayTraceUtils.java index 0fd1e4e01..4f763e392 100644 --- a/src/api/java/baritone/api/utils/RayTraceUtils.java +++ b/src/api/java/baritone/api/utils/RayTraceUtils.java @@ -40,7 +40,16 @@ public final class RayTraceUtils { * @return The calculated raytrace result */ public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) { - Vec3d start = entity.getPositionEyes(1.0F); + return rayTraceTowards(entity, rotation, blockReachDistance, false); + } + + public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance, boolean wouldSneak) { + Vec3d start; + if (wouldSneak) { + start = inferSneakingEyePosition(entity); + } else { + start = entity.getPositionEyes(1.0F); // do whatever is correct + } Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation); Vec3d end = start.add( direction.x * blockReachDistance, @@ -49,4 +58,8 @@ public final class RayTraceUtils { ); return entity.world.rayTraceBlocks(start, end, false, false, true); } + + public static Vec3d inferSneakingEyePosition(Entity entity) { + return new Vec3d(entity.posX, entity.posY + IPlayerContext.eyeHeight(true), entity.posZ); + } } diff --git a/src/api/java/baritone/api/utils/RotationUtils.java b/src/api/java/baritone/api/utils/RotationUtils.java index e19f531df..39e68fd4f 100644 --- a/src/api/java/baritone/api/utils/RotationUtils.java +++ b/src/api/java/baritone/api/utils/RotationUtils.java @@ -140,6 +140,10 @@ public final class RotationUtils { return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); } + public static Optional reachable(IPlayerContext ctx, BlockPos pos, boolean wouldSneak) { + return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance(), wouldSneak); + } + /** * Determines if the specified entity is able to reach the center of any of the sides * of the specified block. It first checks if the block center is reachable, and if so, @@ -153,6 +157,10 @@ public final class RotationUtils { * @return The optional rotation */ public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) { + return reachable(entity, pos, blockReachDistance, false); + } + + public static Optional reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity); if (baritone.getPlayerContext().isLookingAt(pos)) { /* @@ -165,9 +173,18 @@ public final class RotationUtils { * * or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level */ - return Optional.of(new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F)); + Rotation hypothetical = new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F); + if (wouldSneak) { + // the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are + RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true); + if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(pos)) { + return Optional.of(hypothetical); // yes, if we sneaked we would still be looking at the block + } + } else { + return Optional.of(hypothetical); + } } - Optional possibleRotation = reachableCenter(entity, pos, blockReachDistance); + Optional possibleRotation = reachableCenter(entity, pos, blockReachDistance, wouldSneak); //System.out.println("center: " + possibleRotation); if (possibleRotation.isPresent()) { return possibleRotation; @@ -179,7 +196,7 @@ public final class RotationUtils { double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x); double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z); - possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance); + possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance, wouldSneak); if (possibleRotation.isPresent()) { return possibleRotation; } @@ -198,9 +215,10 @@ public final class RotationUtils { * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) { - Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); - RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance); + public static Optional reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) { + Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F); + Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); + RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak); //System.out.println(result); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { if (result.getBlockPos().equals(pos)) { @@ -222,7 +240,7 @@ public final class RotationUtils { * @param blockReachDistance The block reach distance of the entity * @return The optional rotation */ - public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance) { - return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance); + public static Optional reachableCenter(Entity entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) { + return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(entity.world, pos), blockReachDistance, wouldSneak); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 3de4a0f54..51e9959f3 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -145,7 +145,7 @@ public class MixinMinecraft { ) private boolean isAllowUserInput(GuiScreen screen) { // allow user input is only the primary baritone - return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.allowUserInput; + return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing() && player != null) || screen.allowUserInput; } @Inject( diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 86fd95055..50ca7425f 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -103,7 +103,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, @Override public void onPlayerSprintState(SprintStateEvent event) { - if (current != null) { + if (isPathing()) { event.setState(current.isSprinting()); } } diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index e74053901..23d7ca8c8 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -184,7 +184,9 @@ public final class CachedWorld implements ICachedWorld, Helper { int distZ = ((region.getZ() << 9) + 256) - pruneCenter.getZ(); double dist = Math.sqrt(distX * distX + distZ * distZ); if (dist > 1024) { - logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram"); + if (!Baritone.settings().censorCoordinates.value) { + logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram"); + } cachedRegions.remove(getRegionID(region.getX(), region.getZ())); } } diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 991a7ff81..6f7304a6a 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -18,11 +18,13 @@ package baritone.command.defaults; import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.argument.IArgConsumer; +import baritone.api.command.exception.CommandException; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalStrictDirection; -import baritone.api.command.Command; -import baritone.api.command.exception.CommandException; -import baritone.api.command.argument.IArgConsumer; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; import java.util.Arrays; import java.util.List; @@ -36,13 +38,56 @@ public class TunnelCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - args.requireMax(0); - Goal goal = new GoalStrictDirection( - ctx.playerFeet(), - ctx.player().getHorizontalFacing() - ); - baritone.getCustomGoalProcess().setGoalAndPath(goal); - logDirect(String.format("Goal: %s", goal.toString())); + args.requireMax(3); + if (args.hasExactly(3)) { + boolean cont = true; + int height = Integer.parseInt(args.getArgs().get(0).getValue()); + int width = Integer.parseInt(args.getArgs().get(1).getValue()); + int depth = Integer.parseInt(args.getArgs().get(2).getValue()); + + if (width < 1 || height < 2 || depth < 1 || height > 255) { + logDirect("Width and depth must at least be 1 block; Height must at least be 2 blocks, and cannot be greater than the build limit."); + cont = false; + } + + if (cont) { + height--; + width--; + BlockPos corner1; + BlockPos corner2; + EnumFacing enumFacing = ctx.player().getHorizontalFacing(); + int addition = ((width % 2 == 0) ? 0 : 1); + switch (enumFacing) { + case EAST: + corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z - width / 2); + corner2 = new BlockPos(ctx.playerFeet().x + depth, ctx.playerFeet().y + height, ctx.playerFeet().z + width / 2 + addition); + break; + case WEST: + corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z + width / 2 + addition); + corner2 = new BlockPos(ctx.playerFeet().x - depth, ctx.playerFeet().y + height, ctx.playerFeet().z - width / 2); + break; + case NORTH: + corner1 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y, ctx.playerFeet().z); + corner2 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y + height, ctx.playerFeet().z - depth); + break; + case SOUTH: + corner1 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y, ctx.playerFeet().z); + corner2 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y + height, ctx.playerFeet().z + depth); + break; + default: + throw new IllegalStateException("Unexpected value: " + enumFacing); + } + logDirect(String.format("Creating a tunnel %s block(s) high, %s block(s) wide, and %s block(s) deep", height+1, width+1, depth)); + baritone.getBuilderProcess().clearArea(corner1, corner2); + } + } else { + Goal goal = new GoalStrictDirection( + ctx.playerFeet(), + ctx.player().getHorizontalFacing() + ); + baritone.getCustomGoalProcess().setGoalAndPath(goal); + logDirect(String.format("Goal: %s", goal.toString())); + } } @Override @@ -61,7 +106,8 @@ public class TunnelCommand extends Command { "The tunnel command sets a goal that tells Baritone to mine completely straight in the direction that you're facing.", "", "Usage:", - "> tunnel" + "> tunnel - No arguments, mines in a 1x2 radius.", + "> tunnel - Tunnels in a user defined height, width and depth." ); } } diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index a67384acc..eea23905e 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -26,6 +26,7 @@ import baritone.api.utils.Helper; import baritone.api.utils.PathCalculationResult; import baritone.pathing.movement.CalculationContext; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import baritone.utils.NotificationHelper; import java.util.Optional; @@ -216,6 +217,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper { if (logInfo) { logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); logDebug("No path found =("); + if (Baritone.settings().desktopNotifications.value) { + NotificationHelper.notify("No path found =(", true); + } } return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index ca4abe9e3..c46b24dea 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -177,7 +177,7 @@ public abstract class Movement implements IMovement, MovementHelper { //i'm doing it anyway //i dont care if theres snow in the way!!!!!!! //you dont own me!!!! - state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), + state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(blockPos), ctx.playerRotations()), true) ); // don't check selectedblock on this one, this is a fallback when we can't see any face directly, it's intended to be breaking the "incorrect" block diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 31a1de7a6..7e1c567a3 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -502,9 +502,9 @@ public interface MovementHelper extends ActionCosts, Helper { } - static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) { + static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown, boolean wouldSneak) { IPlayerContext ctx = baritone.getPlayerContext(); - Optional direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable + Optional direct = RotationUtils.reachable(ctx, placeAt, wouldSneak); // we assume that if there is a block there, it must be replacable boolean found = false; if (direct.isPresent()) { state.setTarget(new MovementState.MovementTarget(direct.get(), true)); @@ -522,7 +522,7 @@ public interface MovementHelper extends ActionCosts, Helper { double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D; double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D; Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()); - RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance()); + RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance(), wouldSneak); if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) { state.setTarget(new MovementState.MovementTarget(place, true)); found = true; @@ -540,11 +540,17 @@ public interface MovementHelper extends ActionCosts, Helper { EnumFacing side = ctx.objectMouseOver().sideHit; // only way for selectedBlock.equals(placeAt) to be true is if it's replacable if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) { + if (wouldSneak) { + state.setInput(Input.SNEAK, true); + } ((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ()); return PlaceResult.READY_TO_PLACE; } } if (found) { + if (wouldSneak) { + state.setInput(Input.SNEAK, true); + } ((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ()); return PlaceResult.ATTEMPTING; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 4f35ef8eb..161ffdacd 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -175,7 +175,7 @@ public class MovementAscend extends Movement { IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace); if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) { ticksWithoutPlacement++; - if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false) == PlaceResult.READY_TO_PLACE) { + if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false, true) == PlaceResult.READY_TO_PLACE) { state.setInput(Input.SNEAK, true); if (ctx.player().isSneaking()) { state.setInput(Input.CLICK_RIGHT, true); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 67b7cd95a..128d1bf99 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -224,7 +224,7 @@ public class MovementDescend extends Movement { double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83; EntityPlayerSP player = ctx.player(); state.setTarget(new MovementState.MovementTarget( - new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F), + new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(destX, dest.getY(), destZ), new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch), false diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 3d3426da2..b9a0fd446 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -250,7 +250,7 @@ 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) == PlaceResult.READY_TO_PLACE) { + if (!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 f6f8fc0d6..b9d599334 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -184,7 +184,7 @@ public class MovementPillar extends Movement { } boolean ladder = fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE; boolean vine = fromDown.getBlock() == Blocks.VINE; - Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F), + Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(positionToPlace), new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch)); if (!ladder) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 9990ed742..1ecf0f92c 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -280,7 +280,7 @@ public class MovementTraverse extends Movement { } } double dist1 = Math.max(Math.abs(ctx.player().posX - (dest.getX() + 0.5D)), Math.abs(ctx.player().posZ - (dest.getZ() + 0.5D))); - PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false); + PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false, true); if ((p == PlaceResult.READY_TO_PLACE || dist1 < 0.6) && !Baritone.settings().assumeSafeWalk.value) { state.setInput(Input.SNEAK, true); } diff --git a/src/main/java/baritone/process/BackfillProcess.java b/src/main/java/baritone/process/BackfillProcess.java index f025c3933..04b3ca78b 100644 --- a/src/main/java/baritone/process/BackfillProcess.java +++ b/src/main/java/baritone/process/BackfillProcess.java @@ -75,7 +75,7 @@ public final class BackfillProcess extends BaritoneProcessHelper { baritone.getInputOverrideHandler().clearAllKeys(); for (BlockPos toPlace : toFillIn()) { MovementState fake = new MovementState(); - switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false)) { + switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false, false)) { case NO_OPTION: continue; case READY_TO_PLACE: diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 4efa2c954..5af434923 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -278,8 +278,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil double placeX = placeAgainstPos.x + aabb.minX * placementMultiplier.x + aabb.maxX * (1 - placementMultiplier.x); double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y); double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z); - Rotation rot = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations()); - RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance()); + Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations()); + RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) { OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot); if (hotbar.isPresent()) { diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index 00273a9f4..a91fda60c 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -232,7 +232,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro both.addAll(openSoulsand); for (BlockPos pos : both) { boolean soulsand = openSoulsand.contains(pos); - Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance()); + Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) { RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance()); if (result.typeOfHit == RayTraceResult.Type.BLOCK && result.sideHit == EnumFacing.UP) { diff --git a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java index 6ce70193f..6dded1dd5 100644 --- a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java +++ b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java @@ -19,6 +19,7 @@ package baritone.utils; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Biomes; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -44,12 +45,12 @@ public final class BlockStateInterfaceAccessWrapper implements IBlockAccess { @Nullable @Override public TileEntity getTileEntity(BlockPos pos) { - throw new UnsupportedOperationException("getTileEntity not supported by BlockStateInterfaceAccessWrapper"); + return null; } @Override public int getCombinedLight(BlockPos pos, int lightValue) { - throw new UnsupportedOperationException("getCombinedLight not supported by BlockStateInterfaceAccessWrapper"); + return 0; } @Override @@ -65,12 +66,12 @@ public final class BlockStateInterfaceAccessWrapper implements IBlockAccess { @Override public Biome getBiome(BlockPos pos) { - throw new UnsupportedOperationException("getBiome not supported by BlockStateInterfaceAccessWrapper"); + return Biomes.FOREST; } @Override public int getStrongPower(BlockPos pos, EnumFacing direction) { - throw new UnsupportedOperationException("getStrongPower not supported by BlockStateInterfaceAccessWrapper"); + return 0; } @Override diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java new file mode 100644 index 000000000..54abbf87f --- /dev/null +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -0,0 +1,89 @@ +/* + * 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 . + */ + +package baritone.utils; + +import org.apache.commons.lang3.SystemUtils; + +import java.awt.*; +import java.io.IOException; + +/** + * This class is not called from the main game thread. + * Do not refer to any Minecraft classes, it wouldn't be thread safe. + * + * @author aUniqueUser + */ +public class NotificationHelper { + + private static TrayIcon trayIcon; + + public static void notify(String text, boolean error) { + if (SystemUtils.IS_OS_WINDOWS) { + windows(text, error); + } else if (SystemUtils.IS_OS_MAC_OSX) { + mac(text); + } else if (SystemUtils.IS_OS_LINUX) { + linux(text); + } + } + + private static void windows(String text, boolean error) { + if (SystemTray.isSupported()) { + try { + if (trayIcon == null) { + SystemTray tray = SystemTray.getSystemTray(); + Image image = Toolkit.getDefaultToolkit().createImage(""); + + trayIcon = new TrayIcon(image, "Baritone"); + trayIcon.setImageAutoSize(true); + trayIcon.setToolTip("Baritone"); + tray.add(trayIcon); + } + + trayIcon.displayMessage("Baritone", text, error ? TrayIcon.MessageType.ERROR : TrayIcon.MessageType.INFO); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + System.out.println("SystemTray is not supported"); + } + } + + private static void mac(String text) { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("osascript", "-e", "display notification \"" + text + "\" with title \"Baritone\""); + try { + processBuilder.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + // The only way to display notifications on linux is to use the java-gnome library, + // or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome + // library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) + private static void linux(String text) { + ProcessBuilder processBuilder = new ProcessBuilder(); + processBuilder.command("notify-send", "-a", "Baritone", text); + try { + processBuilder.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}