Compare commits
222 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd4205c361 | ||
|
|
b81bcf8c6d | ||
|
|
4259764b70 | ||
|
|
8f761f7dff | ||
|
|
cbbaf2aa2f | ||
|
|
dd9b84646a | ||
|
|
94131fd705 | ||
|
|
6d8914e6c9 | ||
|
|
63ee687cee | ||
|
|
ab779dc850 | ||
|
|
c2f35ae46f | ||
|
|
199e0e5ed3 | ||
|
|
a8155b4b0b | ||
|
|
fdd78cf110 | ||
|
|
afff6395d1 | ||
|
|
4d3d48e962 | ||
|
|
36290e4e53 | ||
|
|
fd6923dd28 | ||
|
|
9c64067d49 | ||
|
|
f4d2ea7923 | ||
|
|
ce3d3bb244 | ||
|
|
fa71e7d84f | ||
|
|
b0115b8b4c | ||
|
|
3902b2db3b | ||
|
|
f998dce614 | ||
|
|
2b9084d2f3 | ||
|
|
b3605546ac | ||
|
|
96097ab726 | ||
|
|
be142d79bc | ||
|
|
0fd241a9ba | ||
|
|
7b192f17e8 | ||
|
|
cc015846d2 | ||
|
|
e785bd13f5 | ||
|
|
eb6c0a39ea | ||
|
|
86525f98ec | ||
|
|
94bf703dde | ||
|
|
14bb0a0a80 | ||
|
|
1ee6e04f00 | ||
|
|
ee6796d5e2 | ||
|
|
81d7f3c319 | ||
|
|
9822962d98 | ||
|
|
ce606f826b | ||
|
|
4c4bc8058b | ||
|
|
f0210f7c5f | ||
|
|
aef84eceb8 | ||
|
|
a6ea9ed3a6 | ||
|
|
0815e3c195 | ||
|
|
a1c03eb601 | ||
|
|
1e43563cc3 | ||
|
|
63f3f9123a | ||
|
|
4860d3bd18 | ||
|
|
7fa6593bdc | ||
|
|
e1dd580df8 | ||
|
|
f19e63d6e9 | ||
|
|
130873d91d | ||
|
|
9611cb9057 | ||
|
|
023aa78d8b | ||
|
|
39a231eae0 | ||
|
|
aca6922be0 | ||
|
|
1a52537d0c | ||
|
|
479b4e3349 | ||
|
|
a1e2b018a2 | ||
|
|
aa0f664cda | ||
|
|
2e2f4aee1b | ||
|
|
18474d872c | ||
|
|
44327c009a | ||
|
|
de554655a5 | ||
|
|
bd0c7b9391 | ||
|
|
8d32db5206 | ||
|
|
a6954aa719 | ||
|
|
b4d203ab99 | ||
|
|
bb924ad83f | ||
|
|
79da32cc60 | ||
|
|
c7fe9c3171 | ||
|
|
d70da4f37d | ||
|
|
ccc1b04e81 | ||
|
|
352e428890 | ||
|
|
4679e12588 | ||
|
|
6861bfd4e6 | ||
|
|
0dd4834e18 | ||
|
|
da58988f01 | ||
|
|
b2f3880722 | ||
|
|
0293a76702 | ||
|
|
6a13e94c4f | ||
|
|
79d448e5f4 | ||
|
|
264b3db63c | ||
|
|
c8cd4b5f28 | ||
|
|
c9e81897a5 | ||
|
|
c738007538 | ||
|
|
da8bf6b1b3 | ||
|
|
1501d721e7 | ||
|
|
482d874af2 | ||
|
|
7dcd7384f1 | ||
|
|
2a5ef35794 | ||
|
|
0f09a46540 | ||
|
|
a6d4708ccf | ||
|
|
77303b4a62 | ||
|
|
0ffbb0c151 | ||
|
|
e05010c9d2 | ||
|
|
d0a1c241a4 | ||
|
|
4ea8f23fc7 | ||
|
|
54da0d24a3 | ||
|
|
58ebd5f9a6 | ||
|
|
d60a0bee9e | ||
|
|
e9e26c981a | ||
|
|
5f12f04e87 | ||
|
|
7b7be32ca7 | ||
|
|
a14166b1e2 | ||
|
|
166eb97c3f | ||
|
|
920ce745c2 | ||
|
|
c931cde3ae | ||
|
|
f7a577e163 | ||
|
|
9bf3a041d4 | ||
|
|
85eb7d8043 | ||
|
|
b338dcc9de | ||
|
|
7d9b8ee4f3 | ||
|
|
0f61aaafb8 | ||
|
|
0927e0e017 | ||
|
|
783a7cedc3 | ||
|
|
b1ee23ad50 | ||
|
|
9118e0b368 | ||
|
|
5a0ccac0a1 | ||
|
|
c8419dc362 | ||
|
|
9127ba2fce | ||
|
|
36858ca219 | ||
|
|
30469e2de2 | ||
|
|
79c433b14d | ||
|
|
bc419cfd1a | ||
|
|
09fbf675ec | ||
|
|
2ee119fc64 | ||
|
|
83265fcb54 | ||
|
|
e8b4f4d2b6 | ||
|
|
714c6773c3 | ||
|
|
2fac594315 | ||
|
|
4bec49de5b | ||
|
|
4eaa6e20c3 | ||
|
|
315cc26525 | ||
|
|
794a761243 | ||
|
|
5da14fcb3f | ||
|
|
1047d4ade9 | ||
|
|
0b8fa3ffe3 | ||
|
|
498e4e2d6c | ||
|
|
850c414e8f | ||
|
|
d5a8ed5cb1 | ||
|
|
dd8406c39a | ||
|
|
13469053b9 | ||
|
|
c4c85b4f49 | ||
|
|
af0c3bbd5c | ||
|
|
2fcf9ace64 | ||
|
|
47e1c67bd8 | ||
|
|
7e3aa6efdd | ||
|
|
7a2f26ef62 | ||
|
|
b64154e3b3 | ||
|
|
26256e7155 | ||
|
|
6599736e00 | ||
|
|
343bb20bd8 | ||
|
|
518fa1c74d | ||
|
|
0b72a8b4b3 | ||
|
|
c013d1e0d9 | ||
|
|
fe51220e3c | ||
|
|
44d757347b | ||
|
|
c136182e17 | ||
|
|
a1a9b4e6b9 | ||
|
|
f49df63183 | ||
|
|
96414b37f3 | ||
|
|
544168ff45 | ||
|
|
e0a618a791 | ||
|
|
3333797144 | ||
|
|
f7f003c0f9 | ||
|
|
236d02cb47 | ||
|
|
6e97fe2210 | ||
|
|
6741666c24 | ||
|
|
fcadf68c90 | ||
|
|
65cd6a92d3 | ||
|
|
a09bb0d538 | ||
|
|
2bf475d840 | ||
|
|
76cdaaace6 | ||
|
|
ce59ef559f | ||
|
|
fc3f183dce | ||
|
|
6b6eea2d8c | ||
|
|
e54652941b | ||
|
|
867c01ff86 | ||
|
|
87a9e67ba8 | ||
|
|
bf076f6246 | ||
|
|
75b54dfaec | ||
|
|
71a2219b07 | ||
|
|
ccc3de2d7c | ||
|
|
af11e64cec | ||
|
|
2c3dc5d6b1 | ||
|
|
71482cc984 | ||
|
|
3329db1dae | ||
|
|
926e2d5620 | ||
|
|
d2de8828e7 | ||
|
|
9fcae6560e | ||
|
|
2e8fdd43ee | ||
|
|
27e39c8083 | ||
|
|
a8f373d568 | ||
|
|
71491a7922 | ||
|
|
170c2d35c2 | ||
|
|
bc49b2d5ba | ||
|
|
f58b6b41cb | ||
|
|
ac1ac50158 | ||
|
|
d4103a924d | ||
|
|
bd64f73842 | ||
|
|
cac653ddd9 | ||
|
|
04ff365890 | ||
|
|
54ed6ce5a5 | ||
|
|
32ac46c8a9 | ||
|
|
7ab2cd2a45 | ||
|
|
a07fae6cdd | ||
|
|
3f6af51713 | ||
|
|
8c4e778506 | ||
|
|
65902d556e | ||
|
|
aada9731a6 | ||
|
|
49658078b9 | ||
|
|
bcd097c6cb | ||
|
|
cfec67f1f9 | ||
|
|
aaaf0f8839 | ||
|
|
ee83471bf6 | ||
|
|
610fe6439f | ||
|
|
bd1dcff385 | ||
|
|
226ede7ba2 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* text=auto
|
||||
1
.github/ISSUE_TEMPLATE.md
vendored
Normal file
1
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<!-- No UwU's or OwO's allowed -->
|
||||
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<!-- No UwU's or OwO's allowed -->
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,4 +18,4 @@ classes/
|
||||
|
||||
# Copyright Files
|
||||
!/.idea/copyright/Baritone.xml
|
||||
!/.idea/copyright/profiles_settings.xml
|
||||
!/.idea/copyright/profiles_settings.xml
|
||||
|
||||
@@ -45,6 +45,11 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
Project maintainers have the right and responsibility to immediately remove
|
||||
without any sort of dispute any issues or pull requests that do not align
|
||||
with their corresponding templates. Absolutely no leniancy shall be accepted
|
||||
with these terms.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
|
||||
11
Dockerfile
11
Dockerfile
@@ -1,17 +1,16 @@
|
||||
FROM debian:jessie
|
||||
FROM debian:stretch
|
||||
|
||||
RUN echo 'deb http://deb.debian.org/debian jessie-backports main' > /etc/apt/sources.list.d/jessie-backports.list
|
||||
RUN echo 'deb http://deb.debian.org/debian stretch-backports main' > /etc/apt/sources.list.d/stretch-backports.list
|
||||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
RUN apt update -y
|
||||
|
||||
RUN apt install --target-release jessie-backports \
|
||||
RUN apt install \
|
||||
openjdk-8-jdk \
|
||||
ca-certificates-java \
|
||||
--assume-yes
|
||||
|
||||
RUN apt install -qq --force-yes mesa-utils libgl1-mesa-glx libxcursor1 libxrandr2 libxxf86vm1 x11-xserver-utils xfonts-base xserver-common
|
||||
RUN apt install -qq --assume-yes mesa-utils libgl1-mesa-glx libxcursor1 libxrandr2 libxxf86vm1 x11-xserver-utils xfonts-base xserver-common
|
||||
|
||||
COPY . /code
|
||||
|
||||
@@ -21,4 +20,4 @@ WORKDIR /code
|
||||
# source: https://github.com/tectonicus/tectonicus/issues/60#issuecomment-154239173
|
||||
RUN dpkg -i scripts/xvfb_1.16.4-1_amd64.deb
|
||||
|
||||
RUN ./gradlew build
|
||||
RUN ./gradlew build
|
||||
|
||||
30
README.md
30
README.md
@@ -4,33 +4,37 @@
|
||||
[](LICENSE)
|
||||
[](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade)
|
||||
[](http://hits.dwyl.com/cabaletta/baritone)
|
||||
[](https://github.com/cabaletta/baritone/releases)
|
||||
[](https://github.com/cabaletta/baritone/tree/master/)
|
||||
[](https://github.com/cabaletta/baritone/tree/1.13.2/)
|
||||
[](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md)
|
||||
[](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle)
|
||||
[](https://github.com/cabaletta/baritone/issues)
|
||||
[](https://github.com/cabaletta/baritone/issues)
|
||||
[](https://github.com/cabaletta/baritone/issues/)
|
||||
[](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed)
|
||||
[](https://github.com/cabaletta/baritone/pulls/)
|
||||

|
||||

|
||||

|
||||

|
||||
[](https://minecraft.gamepedia.com/1.12.2)
|
||||

|
||||
[](https://github.com/cabaletta/baritone/graphs/contributors/)
|
||||
[](https://github.com/cabaletta/baritone/commit/)
|
||||
[](https://impactdevelopment.github.io/)
|
||||
[](https://impactdevelopment.github.io/)
|
||||
[](https://github.com/fr1kin/ForgeHax/)
|
||||
[](https://wweclient.com/)
|
||||
[](https://github.com/zeroeightysix/KAMI/)
|
||||
[](https://futureclient.net/)
|
||||
[](https://github.com/fr1kin/ForgeHax)
|
||||
[](http://forthebadge.com/)
|
||||
[](http://forthebadge.com/)
|
||||
|
||||
A Minecraft pathfinder bot.
|
||||
|
||||
Baritone is the pathfinding system used in [Impact](https://impactdevelopment.github.io/) 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.
|
||||
|
||||
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. 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 easiest way to install Baritone is to install [Impact](https://impactdevelopment.github.io/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the forge 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.
|
||||
|
||||
Have committed at least once a day for the last 7 months =D 🦀
|
||||
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).
|
||||
|
||||
Have committed at least once a day for the last 11 months =D 🦀
|
||||
|
||||
1Leijurv3DWTrGAfmmiTphjhXLvQiHg7K2
|
||||
|
||||
@@ -42,11 +46,11 @@ Here are some links to help to get started:
|
||||
|
||||
- [Installation & setup](SETUP.md)
|
||||
|
||||
- [API Javadocs](https://baritone.leijurv.com/)
|
||||
- [API Javadocs](https://baritone.leijurv.com)
|
||||
|
||||
- [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail)
|
||||
|
||||
- [Baritone chat control usage](USAGE.md)
|
||||
- [Usage (chat control)](USAGE.md)
|
||||
|
||||
# API
|
||||
|
||||
@@ -67,7 +71,7 @@ BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAnd
|
||||
|
||||
## Can I use Baritone as a library in my custom utility client?
|
||||
|
||||
That's what it's for, sure! (As long as usage is in compliance with the LGPL 3 License)
|
||||
That's what it's for, sure! (As long as usage is in compliance with the LGPL 3.0 License)
|
||||
|
||||
## How is it so fast?
|
||||
|
||||
|
||||
6
SETUP.md
6
SETUP.md
@@ -1,7 +1,11 @@
|
||||
# Installation
|
||||
|
||||
The easiest way to install Baritone is to install [Impact](https://impactdevelopment.github.io/), which comes with Baritone.
|
||||
|
||||
Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it.
|
||||
|
||||
## Prebuilt official releases
|
||||
These releases are not always completely up to date with latest features, and are only released from `master`. (so if you want `builder` branch for example, you'll have to build it yourself)
|
||||
These releases are not always completely up to date with latest features, and are only released from `master`. (so if you want `backfill-2` branch for example, you'll have to build it yourself)
|
||||
|
||||
Link to the releases page: [Releases](https://github.com/cabaletta/baritone/releases)
|
||||
|
||||
|
||||
41
USAGE.md
41
USAGE.md
@@ -2,30 +2,20 @@
|
||||
|
||||
# Prefix
|
||||
|
||||
Baritone commands can by default be typed in the chatbox. However if you make a typo, like typing "gola 10000 10000" instead of goal it goes into public chat, which is bad.
|
||||
|
||||
Therefore you can use a prefix before your messages.
|
||||
|
||||
On Baritone v1.1.0 and newer: The prefix is `#` by default. Anything beginning with `#` isn't sent, and is only interpreted by Baritone.
|
||||
For older than v1.1.0, `#` must be enabled by toggling on the `prefix` setting.
|
||||
|
||||
**Only** in Impact is `.b` also a valid prefix. In 4.4, `#` does **not** work, neither does saying the commands directly in chat. `#` works by default in 4.5 (not 4.4).
|
||||
|
||||
Other clients like Kami and Asuna have their own custom things (like `-path`), and can disable direct chat control entirely.
|
||||
Baritone's chat control prefix is `#` by default. In Impact, you can also use `.b` as a prefix. (for example, `.b click` instead of `#click`)
|
||||
|
||||
Baritone commands can also by default be typed in the chatbox. However if you make a typo, like typing "gola 10000 10000" instead of "goal" it goes into public chat, which is bad, so using `#` is suggested.
|
||||
|
||||
To disable direct chat control (with no prefix), turn off the `chatControl` setting. To disable chat control with the `#` prefix, turn off the `prefixControl` setting. In Impact, `.b` cannot be disabled. Be careful that you don't leave yourself with all control methods disabled (if you do, reset your settings by deleting the file `minecraft/baritone/settings.txt` and relaunching).
|
||||
|
||||
# Commands
|
||||
|
||||
**All** of these commands may need a prefix before them, as above ^.
|
||||
|
||||
`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java#L53).
|
||||
`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java#L47).
|
||||
|
||||
To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`.
|
||||
|
||||
|
||||
|
||||
|
||||
Some common examples:
|
||||
- `thisway 1000` then `path` to go in the direction you're facing for a thousand blocks
|
||||
- `goal x y z` or `goal x z` or `goal y`, then `path` to go to a certain coordinate
|
||||
@@ -34,16 +24,20 @@ Some common examples:
|
||||
- `cancel` or `stop` to stop everything
|
||||
- `goto portal` or `goto ender_chest` or `goto block_type` to go to a block. (in Impact, `.goto` is an alias for `.b goto` for the most part)
|
||||
- `mine diamond_ore` to mine diamond ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.)
|
||||
- `click` to click your destination on the screen. left click to path into it, right click to path on top of it.
|
||||
- `click` to click your destination on the screen. Right click path to on top of the block, left click to path into it (either at foot level or eye level), and left click and drag to clear all blocks from an area.
|
||||
- `follow playerName` to follow a player. `follow` to follow the entity you're looking at (only works if it hitting range). `followplayers` to follow any players in range (combine with Kill Aura for a fun time).
|
||||
- `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).
|
||||
- `tunnel` to dig just straight ahead and make a 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.
|
||||
- `invert` to invert the current goal and path. This gets as far away from it as possible, instead of as close as possible. For example, do `goal` then `invert` to run as far as possible from where you're standing at the start.
|
||||
- `render` to rerender the world in case `renderCachedChunks` is being glitchy
|
||||
- `version` to get the version of Baritone you're running
|
||||
- `damn` daniel
|
||||
|
||||
For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java).
|
||||
|
||||
For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java).
|
||||
|
||||
All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#field.detail">here</a>.
|
||||
|
||||
@@ -53,18 +47,23 @@ There are about a hundred settings, but here are some fun / interesting / import
|
||||
- `allowPlace`
|
||||
- `allowParkour`
|
||||
- `allowParkourPlace`
|
||||
- `blockPlacementPenalty`
|
||||
- `renderCachedChunks` (and `cachedChunksOpacity`) <-- very fun but you need a beefy computer
|
||||
- `avoidance`
|
||||
- `avoidance` (avoidance of mobs / mob spawners)
|
||||
- `legitMine`
|
||||
- `followRadius`
|
||||
- `backfill` (fill in tunnels behind you)
|
||||
- `buildInLayers`
|
||||
- `buildRepeatDistance` and `buildRepeatDirection`
|
||||
- `worldExploringChunkOffset`
|
||||
- `acceptableThrowawayItems`
|
||||
- `blocksToAvoidBreaking`
|
||||
|
||||
|
||||
|
||||
|
||||
# Troubleshooting / common issues
|
||||
|
||||
## Baritone highlights a block in green but gets completely stuck? Also I'm using Baritone with Future?
|
||||
Baritone is trying to right click to place a block there, but it can't since there's a conflicting mixin. Baritone can't force click right click when Future is also installed. Left click **does work** on recent Baritone even with Future, however. For now, turn off `allowPlace` and Baritone will only search for paths that don't require placing blocks to complete. `allowBreak` can remain on.
|
||||
|
||||
## Why doesn't Baritone respond to any of my chat commands?
|
||||
This could be one of many things.
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
group 'baritone'
|
||||
version '1.2.4'
|
||||
version '1.2.7'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
|
||||
2
scripts/proguard.pro
vendored
2
scripts/proguard.pro
vendored
@@ -21,6 +21,8 @@
|
||||
-keep class baritone.BaritoneProvider
|
||||
-keep class baritone.api.IBaritoneProvider
|
||||
|
||||
-keep class baritone.api.utils.MyChunkPos { *; } # even in standalone we need to keep this for gson reflect
|
||||
|
||||
# setting names are reflected from field names, so keep field names
|
||||
-keepclassmembers class baritone.api.Settings {
|
||||
public <fields>;
|
||||
|
||||
@@ -71,6 +71,18 @@ public interface IBaritone {
|
||||
*/
|
||||
IBuilderProcess getBuilderProcess();
|
||||
|
||||
/**
|
||||
* @return The {@link IExploreProcess} instance
|
||||
* @see IExploreProcess
|
||||
*/
|
||||
IExploreProcess getExploreProcess();
|
||||
|
||||
/**
|
||||
* @return The {@link IFarmProcess} instance
|
||||
* @see IFarmProcess
|
||||
*/
|
||||
IFarmProcess getFarmProcess();
|
||||
|
||||
/**
|
||||
* @return The {@link ICustomGoalProcess} instance
|
||||
* @see ICustomGoalProcess
|
||||
@@ -115,4 +127,6 @@ public interface IBaritone {
|
||||
* @see IEventBus
|
||||
*/
|
||||
IEventBus getGameEventHandler();
|
||||
|
||||
void openClick();
|
||||
}
|
||||
|
||||
@@ -18,13 +18,18 @@
|
||||
package baritone.api;
|
||||
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.api.utils.TypeUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -58,7 +63,9 @@ public final class Settings {
|
||||
|
||||
/**
|
||||
* It doesn't actually take twenty ticks to place a block, this cost is so high
|
||||
* because we want to generally conserve blocks which might be limited
|
||||
* because we want to generally conserve blocks which might be limited.
|
||||
* <p>
|
||||
* Decrease to make Baritone more often consider paths that would require placing blocks
|
||||
*/
|
||||
public final Setting<Double> blockPlacementPenalty = new Setting<>(20D);
|
||||
|
||||
@@ -77,7 +84,7 @@ public final class Settings {
|
||||
/**
|
||||
* Walking on water uses up hunger really quick, so penalize it
|
||||
*/
|
||||
public final Setting<Double> walkOnWaterOnePenalty = new Setting<>(5D);
|
||||
public final Setting<Double> walkOnWaterOnePenalty = new Setting<>(3D);
|
||||
|
||||
/**
|
||||
* Allow Baritone to fall arbitrary distances and place a water bucket beneath it.
|
||||
@@ -91,6 +98,11 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> assumeWalkOnWater = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* If you have Fire Resistance and Jesus then I guess you could turn this on lol
|
||||
*/
|
||||
public final Setting<Boolean> assumeWalkOnLava = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* Assume step functionality; don't jump on an Ascend.
|
||||
*/
|
||||
@@ -108,7 +120,7 @@ public final class Settings {
|
||||
/**
|
||||
* If true, parkour is allowed to make jumps when standing on blocks at the maximum height, so player feet is y=256
|
||||
* <p>
|
||||
* Defaults to false because this fails on constantiam
|
||||
* Defaults to false because this fails on constantiam. Please let me know if this is ever disabled. Please.
|
||||
*/
|
||||
public final Setting<Boolean> allowJumpAt256 = new Setting<>(false);
|
||||
|
||||
@@ -121,15 +133,48 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> allowDiagonalDescend = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* Allow mining the block directly beneath its feet
|
||||
* <p>
|
||||
* Turn this off to force it to make more staircases and less shafts
|
||||
*/
|
||||
public final Setting<Boolean> allowDownward = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.)
|
||||
*/
|
||||
public final Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList(
|
||||
Item.getItemFromBlock(Blocks.DIRT),
|
||||
Item.getItemFromBlock(Blocks.COBBLESTONE),
|
||||
Item.getItemFromBlock(Blocks.NETHERRACK)
|
||||
Item.getItemFromBlock(Blocks.NETHERRACK),
|
||||
Item.getItemFromBlock(Blocks.STONE)
|
||||
)));
|
||||
|
||||
/**
|
||||
* Blocks that Baritone will attempt to avoid (Used in avoidance)
|
||||
*/
|
||||
public final Setting<List<Block>> blocksToAvoid = new Setting<>(new ArrayList<>(
|
||||
// Leave Empty by Default
|
||||
));
|
||||
|
||||
/**
|
||||
* Blocks that Baritone is not allowed to break
|
||||
*/
|
||||
public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet?
|
||||
Blocks.CRAFTING_TABLE,
|
||||
Blocks.FURNACE,
|
||||
Blocks.LIT_FURNACE,
|
||||
Blocks.CHEST,
|
||||
Blocks.TRAPPED_CHEST
|
||||
)));
|
||||
|
||||
/**
|
||||
* If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
|
||||
* <p>
|
||||
* I.E. it will never trigger cascading sand / gravel falls
|
||||
*/
|
||||
public final Setting<Boolean> avoidUpdatingFallingBlocks = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real
|
||||
* pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario.
|
||||
@@ -170,6 +215,18 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> sprintAscends = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway.
|
||||
* <p>
|
||||
* This helps with speed at >=20m/s
|
||||
*/
|
||||
public final Setting<Boolean> overshootTraverse = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* When breaking blocks for a movement, wait until all falling blocks have settled before continuing
|
||||
*/
|
||||
public final Setting<Boolean> pauseMiningForFallingBlocks = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* How many ticks between right clicks are allowed. Default in game is 4
|
||||
*/
|
||||
@@ -386,10 +443,12 @@ public final class Settings {
|
||||
* On save, delete from RAM any cached regions that are more than 1024 blocks away from the player
|
||||
* <p>
|
||||
* Temporarily disabled
|
||||
* <p>
|
||||
* Temporarily reenabled
|
||||
*
|
||||
* @see <a href="https://github.com/cabaletta/baritone/issues/248">Issue #248</a>
|
||||
*/
|
||||
public final Setting<Boolean> pruneRegionsFromRAM = new Setting<>(false);
|
||||
public final Setting<Boolean> pruneRegionsFromRAM = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* Remember the contents of containers (chests, echests, furnaces)
|
||||
@@ -398,6 +457,11 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> containerMemory = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* Fill in blocks behind you
|
||||
*/
|
||||
public final Setting<Boolean> backfill = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* Print all the debug messages to chat
|
||||
*/
|
||||
@@ -424,6 +488,11 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> renderGoal = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* Render selection boxes
|
||||
*/
|
||||
public final Setting<Boolean> renderSelectionBoxes = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* Ignore depth when rendering the goal
|
||||
*/
|
||||
@@ -476,6 +545,8 @@ public final class Settings {
|
||||
|
||||
/**
|
||||
* Exclusively use cached chunks for pathing
|
||||
* <p>
|
||||
* Never turn this on
|
||||
*/
|
||||
public final Setting<Boolean> pathThroughCachedOnly = new Setting<>(false);
|
||||
|
||||
@@ -506,7 +577,7 @@ public final class Settings {
|
||||
public final Setting<Boolean> 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<Float> cachedChunksOpacity = new Setting<>(0.5f);
|
||||
@@ -521,6 +592,16 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> walkWhileBreaking = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* When a new segment is calculated that doesn't overlap with the current one, but simply begins where the current segment ends,
|
||||
* splice it on and make a longer combined path. If this setting is off, any planned segment will not be spliced and will instead
|
||||
* be the "next path" in PathingBehavior, and will only start after this one ends. Turning this off hurts planning ahead,
|
||||
* because the next segment will exist even if it's very short.
|
||||
*
|
||||
* @see #planningTickLookahead
|
||||
*/
|
||||
public final Setting<Boolean> splicePath = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* If we are more than 300 movements into the current path, discard the oldest segments, as they are no longer useful
|
||||
*/
|
||||
@@ -547,6 +628,68 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> exploreForBlocks = new Setting<>(true);
|
||||
|
||||
/**
|
||||
* While exploring the world, offset the closest unloaded chunk by this much in both axes.
|
||||
* <p>
|
||||
* This can result in more efficient loading, if you set this to the render distance.
|
||||
*/
|
||||
public final Setting<Integer> worldExploringChunkOffset = new Setting<>(0);
|
||||
|
||||
/**
|
||||
* Take the 10 closest chunks, even if they aren't strictly tied for distance metric from origin.
|
||||
*/
|
||||
public final Setting<Integer> exploreChunkSetMinimumSize = new Setting<>(10);
|
||||
|
||||
/**
|
||||
* Attempt to maintain Y coordinate while exploring
|
||||
* <p>
|
||||
* -1 to disable
|
||||
*/
|
||||
public final Setting<Integer> exploreMaintainY = new Setting<>(64);
|
||||
|
||||
/**
|
||||
* Replant nether wart while farming
|
||||
*/
|
||||
public final Setting<Boolean> replantNetherWart = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
|
||||
* <p>
|
||||
* Only if you have a beefy CPU and automatically mine blocks that are in cache
|
||||
*/
|
||||
public final Setting<Boolean> extendCacheOnThreshold = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* Don't consider the next layer in builder until the current one is done
|
||||
*/
|
||||
public final Setting<Boolean> buildInLayers = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* false = build from bottom to top
|
||||
* <p>
|
||||
* true = build from top to bottom
|
||||
*/
|
||||
public final Setting<Boolean> layerOrder = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* 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<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
|
||||
|
||||
/**
|
||||
* Allow standing above a block while mining it, in BuilderProcess
|
||||
* <p>
|
||||
* Experimental
|
||||
*/
|
||||
public final Setting<Boolean> breakFromAbove = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* As well as breaking from above, set a goal to up and to the side of all blocks to break.
|
||||
* <p>
|
||||
* Never turn this on without also turning on breakFromAbove.
|
||||
*/
|
||||
public final Setting<Boolean> goalBreakFromAbove = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)?
|
||||
*/
|
||||
@@ -633,11 +776,10 @@ public final class Settings {
|
||||
public final Setting<Integer> followRadius = new Setting<>(3);
|
||||
|
||||
/**
|
||||
* true = exploration uses pythagorean distance to choose closest uncached chunk
|
||||
* <p>
|
||||
* false = exploration uses manhattan / taxicab distance to choose
|
||||
* Turn this on if your exploration filter is enormous, you don't want it to check if it's done,
|
||||
* and you are just fine with it just hanging on completion
|
||||
*/
|
||||
public final Setting<Boolean> exploreUsePythagorean = new Setting<>(false);
|
||||
public final Setting<Boolean> disableCompletionCheck = new Setting<>(false);
|
||||
|
||||
/**
|
||||
* Cached chunks (regardless of if they're in RAM or saved to disk) expire and are deleted after this number of seconds
|
||||
@@ -668,6 +810,11 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getMinecraft().ingameGUI.getChatGUI()::printChatMessage);
|
||||
|
||||
/**
|
||||
* The size of the box that is rendered when the current goal is a GoalYLevel
|
||||
*/
|
||||
public final Setting<Double> yLevelBoxSize = new Setting<>(15D);
|
||||
|
||||
/**
|
||||
* The color of the current path
|
||||
*/
|
||||
@@ -719,11 +866,12 @@ public final class Settings {
|
||||
*/
|
||||
public final List<Setting<?>> allSettings;
|
||||
|
||||
public final Map<Setting<?>, Type> settingTypes;
|
||||
|
||||
public final class Setting<T> {
|
||||
public T value;
|
||||
public final T defaultValue;
|
||||
private String name;
|
||||
private final Class<T> klass;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Setting(T value) {
|
||||
@@ -732,7 +880,6 @@ public final class Settings {
|
||||
}
|
||||
this.value = value;
|
||||
this.defaultValue = value;
|
||||
this.klass = (Class<T>) value.getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -750,7 +897,8 @@ public final class Settings {
|
||||
}
|
||||
|
||||
public Class<T> getValueClass() {
|
||||
return klass;
|
||||
// noinspection unchecked
|
||||
return (Class<T>) TypeUtils.resolveBaseClass(getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -764,14 +912,21 @@ public final class Settings {
|
||||
public void reset() {
|
||||
value = defaultValue;
|
||||
}
|
||||
|
||||
public final Type getType() {
|
||||
return settingTypes.get(this);
|
||||
}
|
||||
}
|
||||
|
||||
// here be dragons
|
||||
|
||||
Settings() {
|
||||
Field[] temp = getClass().getFields();
|
||||
HashMap<String, Setting<?>> tmpByName = new HashMap<>();
|
||||
|
||||
Map<String, Setting<?>> tmpByName = new HashMap<>();
|
||||
List<Setting<?>> tmpAll = new ArrayList<>();
|
||||
Map<Setting<?>, Type> tmpSettingTypes = new HashMap<>();
|
||||
|
||||
try {
|
||||
for (Field field : temp) {
|
||||
if (field.getType().equals(Setting.class)) {
|
||||
@@ -784,6 +939,7 @@ public final class Settings {
|
||||
}
|
||||
tmpByName.put(name, setting);
|
||||
tmpAll.add(setting);
|
||||
tmpSettingTypes.put(setting, ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
@@ -791,6 +947,7 @@ public final class Settings {
|
||||
}
|
||||
byLowerName = Collections.unmodifiableMap(tmpByName);
|
||||
allSettings = Collections.unmodifiableList(tmpAll);
|
||||
settingTypes = Collections.unmodifiableMap(tmpSettingTypes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -23,9 +23,8 @@ import baritone.api.event.listener.IGameEventListener;
|
||||
/**
|
||||
* A behavior is simply a type that is able to listen to events.
|
||||
*
|
||||
* @see IGameEventListener
|
||||
*
|
||||
* @author Brady
|
||||
* @see IGameEventListener
|
||||
* @since 9/23/2018
|
||||
*/
|
||||
public interface IBehavior extends AbstractGameEventListener {}
|
||||
|
||||
@@ -80,6 +80,13 @@ public interface IPathingBehavior extends IBehavior {
|
||||
*/
|
||||
boolean cancelEverything();
|
||||
|
||||
/**
|
||||
* PLEASE never call this
|
||||
* <p>
|
||||
* If cancelEverything was like "kill" this is "sudo kill -9". Or shutting off your computer.
|
||||
*/
|
||||
void forceCancel();
|
||||
|
||||
/**
|
||||
* Returns the current path, from the current path executor, if there is one.
|
||||
*
|
||||
|
||||
@@ -81,4 +81,6 @@ public interface ICachedWorld {
|
||||
* in a new thread by default.
|
||||
*/
|
||||
void save();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.cache;
|
||||
package baritone.api.cache;
|
||||
|
||||
import baritone.api.cache.IWaypoint;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -47,7 +46,7 @@ public class Waypoint implements IWaypoint {
|
||||
* @param location The waypoint location
|
||||
* @param creationTimestamp When the waypoint was created
|
||||
*/
|
||||
Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) {
|
||||
public Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) {
|
||||
this.name = name;
|
||||
this.tag = tag;
|
||||
this.location = location;
|
||||
@@ -61,6 +61,6 @@ public class GoalNear implements Goal, IGoalRenderPos {
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
", rangeSq=" + rangeSq +
|
||||
'}';
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.pathing.goals;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* Dig a tunnel in a certain direction, but if you have to deviate from the path, go back to where you started
|
||||
*/
|
||||
public class GoalStrictDirection implements Goal {
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
public final int dx;
|
||||
public final int dz;
|
||||
|
||||
public GoalStrictDirection(BlockPos origin, EnumFacing direction) {
|
||||
x = origin.getX();
|
||||
y = origin.getY();
|
||||
z = origin.getZ();
|
||||
dx = direction.getXOffset();
|
||||
dz = direction.getZOffset();
|
||||
if (dx == 0 && dz == 0) {
|
||||
throw new IllegalArgumentException(direction + "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGoal(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(int x, int y, int z) {
|
||||
int distanceFromStartInDesiredDirection = (x - this.x) * dx + (z - this.z) * dz;
|
||||
|
||||
int distanceFromStartInIncorrectDirection = Math.abs((x - this.x) * dz) + Math.abs((z - this.z) * dx);
|
||||
|
||||
int verticalDistanceFromStart = Math.abs(y - this.y);
|
||||
|
||||
// we want heuristic to decrease as desiredDirection increases
|
||||
double heuristic = -distanceFromStartInDesiredDirection * 100;
|
||||
|
||||
heuristic += distanceFromStartInIncorrectDirection * 1000;
|
||||
heuristic += verticalDistanceFromStart * 1000;
|
||||
return heuristic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalStrictDirection{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
", dx=" + dx +
|
||||
", dz=" + dz +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -31,17 +31,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos {
|
||||
/**
|
||||
* The X block position of this goal
|
||||
*/
|
||||
private final int x;
|
||||
protected final int x;
|
||||
|
||||
/**
|
||||
* The Y block position of this goal
|
||||
*/
|
||||
private final int y;
|
||||
protected final int y;
|
||||
|
||||
/**
|
||||
* The Z block position of this goal
|
||||
*/
|
||||
private final int z;
|
||||
protected final int z;
|
||||
|
||||
public GoalTwoBlocks(BlockPos pos) {
|
||||
this(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package baritone.api.process;
|
||||
|
||||
import baritone.api.utils.ISchematic;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
import java.io.File;
|
||||
@@ -46,4 +48,15 @@ public interface IBuilderProcess extends IBaritoneProcess {
|
||||
* @return Whether or not the schematic was able to load from file
|
||||
*/
|
||||
boolean build(String name, File schematic, Vec3i origin);
|
||||
|
||||
default boolean build(String schematicFile, BlockPos origin) {
|
||||
File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile);
|
||||
return build(schematicFile, file, origin);
|
||||
}
|
||||
|
||||
void pause();
|
||||
|
||||
void resume();
|
||||
|
||||
void clearArea(BlockPos corner1, BlockPos corner2);
|
||||
}
|
||||
|
||||
26
src/api/java/baritone/api/process/IExploreProcess.java
Normal file
26
src/api/java/baritone/api/process/IExploreProcess.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.process;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface IExploreProcess extends IBaritoneProcess {
|
||||
void explore(int centerX, int centerZ);
|
||||
|
||||
void applyJsonFilter(Path path, boolean invert) throws Exception;
|
||||
}
|
||||
22
src/api/java/baritone/api/process/IFarmProcess.java
Normal file
22
src/api/java/baritone/api/process/IFarmProcess.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.process;
|
||||
|
||||
public interface IFarmProcess extends IBaritoneProcess {
|
||||
void farm();
|
||||
}
|
||||
@@ -25,4 +25,6 @@ import net.minecraft.block.Block;
|
||||
public interface IGetToBlockProcess extends IBaritoneProcess {
|
||||
|
||||
void getToBlock(Block block);
|
||||
|
||||
boolean blacklistClosest();
|
||||
}
|
||||
|
||||
@@ -51,5 +51,10 @@ public enum PathingCommandType {
|
||||
* <p>
|
||||
* Cancel the current path if the goals are not equal
|
||||
*/
|
||||
FORCE_REVALIDATE_GOAL_AND_PATH
|
||||
FORCE_REVALIDATE_GOAL_AND_PATH,
|
||||
|
||||
/**
|
||||
* Go and ask the next process what to do
|
||||
*/
|
||||
DEFER
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
*
|
||||
|
||||
63
src/api/java/baritone/api/utils/BlockUtils.java
Normal file
63
src/api/java/baritone/api/utils/BlockUtils.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.utils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockUtils {
|
||||
private static transient Map<String, Block> resourceCache = new HashMap<>();
|
||||
|
||||
public static String blockToString(Block block) {
|
||||
ResourceLocation loc = Block.REGISTRY.getNameForObject(block);
|
||||
String name = loc.getPath(); // normally, only write the part after the minecraft:
|
||||
if (!loc.getNamespace().equals("minecraft")) {
|
||||
// Baritone is running on top of forge with mods installed, perhaps?
|
||||
name = loc.toString(); // include the namespace with the colon
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static Block stringToBlockRequired(String name) {
|
||||
Block block = stringToBlockNullable(name);
|
||||
Objects.requireNonNull(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
public static Block stringToBlockNullable(String name) {
|
||||
// do NOT just replace this with a computeWithAbsent, it isn't thread safe
|
||||
Block block = resourceCache.get(name); // map is never mutated in place so this is safe
|
||||
if (block != null) {
|
||||
return block;
|
||||
}
|
||||
if (resourceCache.containsKey(name)) {
|
||||
return null; // cached as null
|
||||
}
|
||||
block = Block.getBlockFromName(name.contains(":") ? name : "minecraft:" + name);
|
||||
Map<String, Block> copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification
|
||||
copy.put(name, block);
|
||||
resourceCache = copy;
|
||||
return block;
|
||||
}
|
||||
|
||||
private BlockUtils() {}
|
||||
}
|
||||
@@ -15,41 +15,36 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils;
|
||||
package baritone.api.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.cache.IRememberedInventory;
|
||||
import baritone.api.cache.IWaypoint;
|
||||
import baritone.api.cache.Waypoint;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.pathing.goals.*;
|
||||
import baritone.api.pathing.movement.ActionCosts;
|
||||
import baritone.api.process.IBaritoneProcess;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.Moves;
|
||||
import baritone.process.CustomGoalProcess;
|
||||
import baritone.utils.pathing.SegmentedCalculator;
|
||||
import baritone.api.process.ICustomGoalProcess;
|
||||
import baritone.api.process.IGetToBlockProcess;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
public class ExampleBaritoneControl implements Helper, AbstractGameEventListener {
|
||||
|
||||
private static final String HELP_MSG =
|
||||
"baritone - Output settings into chat\n" +
|
||||
@@ -73,6 +68,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
"get - Same as list\n" +
|
||||
"show - Same as list\n" +
|
||||
"save - Saves a waypoint (works but don't try to make sense of it)\n" +
|
||||
"delete - Deletes a waypoint\n" +
|
||||
"goto - Paths towards specified block or waypoint\n" +
|
||||
"spawn - Paths towards world spawn or your most recent bed right-click\n" +
|
||||
"sethome - Sets \"home\"\n" +
|
||||
@@ -83,21 +79,26 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
|
||||
private static final String COMMAND_PREFIX = "#";
|
||||
|
||||
public ExampleBaritoneControl(Baritone baritone) {
|
||||
super(baritone);
|
||||
public final IBaritone baritone;
|
||||
public final IPlayerContext ctx;
|
||||
|
||||
public ExampleBaritoneControl(IBaritone baritone) {
|
||||
this.baritone = baritone;
|
||||
this.ctx = baritone.getPlayerContext();
|
||||
baritone.getGameEventHandler().registerEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendChatMessage(ChatEvent event) {
|
||||
String msg = event.getMessage();
|
||||
if (Baritone.settings().prefixControl.value && msg.startsWith(COMMAND_PREFIX)) {
|
||||
if (BaritoneAPI.getSettings().prefixControl.value && msg.startsWith(COMMAND_PREFIX)) {
|
||||
if (!runCommand(msg.substring(COMMAND_PREFIX.length()))) {
|
||||
logDirect("Invalid command");
|
||||
}
|
||||
event.cancel(); // always cancel if using prefixControl
|
||||
return;
|
||||
}
|
||||
if (!Baritone.settings().chatControl.value && !Baritone.settings().removePrefix.value) {
|
||||
if (!BaritoneAPI.getSettings().chatControl.value && !BaritoneAPI.getSettings().removePrefix.value) {
|
||||
return;
|
||||
}
|
||||
if (runCommand(msg)) {
|
||||
@@ -107,20 +108,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
|
||||
public boolean runCommand(String msg0) { // you may think this can be private, but impcat calls it from .b =)
|
||||
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
||||
PathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||
CustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
||||
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||
List<Settings.Setting<Boolean>> toggleable = BaritoneAPI.getSettings().getAllValuesByType(Boolean.class);
|
||||
for (Settings.Setting<Boolean> setting : toggleable) {
|
||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||
setting.value ^= true;
|
||||
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
||||
SettingsUtil.save(Baritone.settings());
|
||||
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) {
|
||||
logDirect("All settings that have been modified from their default values:");
|
||||
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(Baritone.settings())) {
|
||||
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(BaritoneAPI.getSettings())) {
|
||||
logDirect(setting.toString());
|
||||
}
|
||||
return true;
|
||||
@@ -130,15 +131,15 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
try {
|
||||
int page = Integer.parseInt(rest.trim());
|
||||
int min = page * 10;
|
||||
int max = Math.min(Baritone.settings().allSettings.size(), (page + 1) * 10);
|
||||
int max = Math.min(BaritoneAPI.getSettings().allSettings.size(), (page + 1) * 10);
|
||||
logDirect("Settings " + min + " to " + (max - 1) + ":");
|
||||
for (int i = min; i < max; i++) {
|
||||
logDirect(Baritone.settings().allSettings.get(i).toString());
|
||||
logDirect(BaritoneAPI.getSettings().allSettings.get(i).toString());
|
||||
}
|
||||
} catch (Exception ex) { // NumberFormatException | ArrayIndexOutOfBoundsException and probably some others I'm forgetting lol
|
||||
ex.printStackTrace();
|
||||
logDirect("All settings:");
|
||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
||||
for (Settings.Setting<?> setting : BaritoneAPI.getSettings().allSettings) {
|
||||
logDirect(setting.toString());
|
||||
}
|
||||
logDirect("To get one page of ten settings at a time, do settings <num>");
|
||||
@@ -154,26 +155,26 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
if (msg.contains(" ")) {
|
||||
String settingName = msg.substring(0, msg.indexOf(' '));
|
||||
String settingValue = msg.substring(msg.indexOf(' ') + 1);
|
||||
Settings.Setting setting = Baritone.settings().byLowerName.get(settingName);
|
||||
Settings.Setting setting = BaritoneAPI.getSettings().byLowerName.get(settingName);
|
||||
if (setting != null) {
|
||||
if (settingValue.equals("reset")) {
|
||||
logDirect("Resetting setting " + settingName + " to default value.");
|
||||
setting.reset();
|
||||
} else {
|
||||
try {
|
||||
SettingsUtil.parseAndApply(Baritone.settings(), settingName, settingValue);
|
||||
SettingsUtil.parseAndApply(BaritoneAPI.getSettings(), settingName, settingValue);
|
||||
} catch (Exception ex) {
|
||||
logDirect("Unable to parse setting");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
SettingsUtil.save(Baritone.settings());
|
||||
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||
logDirect(setting.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Baritone.settings().byLowerName.containsKey(msg)) {
|
||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg);
|
||||
if (BaritoneAPI.getSettings().byLowerName.containsKey(msg)) {
|
||||
Settings.Setting<?> setting = BaritoneAPI.getSettings().byLowerName.get(msg);
|
||||
logDirect(setting.toString());
|
||||
return true;
|
||||
}
|
||||
@@ -197,6 +198,17 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
logDirect("Goal: " + goal);
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("crash")) {
|
||||
StringBuilder meme = new StringBuilder();
|
||||
CrashReport rep = new CrashReport("Manually triggered debug crash", new Throwable());
|
||||
mc.addGraphicsAndWorldToCrashReport(rep);
|
||||
new ReportedException(rep).printStackTrace();
|
||||
rep.getSectionsInStringBuilder(meme);
|
||||
System.out.println(meme);
|
||||
logDirect(meme.toString());
|
||||
logDirect("ok");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("path")) {
|
||||
if (pathingBehavior.getGoal() == null) {
|
||||
logDirect("No goal.");
|
||||
@@ -209,7 +221,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("fullpath")) {
|
||||
/*if (msg.equals("fullpath")) {
|
||||
if (pathingBehavior.getGoal() == null) {
|
||||
logDirect("No goal.");
|
||||
} else {
|
||||
@@ -225,7 +237,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
if (msg.equals("proc")) {
|
||||
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
|
||||
if (!proc.isPresent()) {
|
||||
@@ -283,7 +295,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("come")) {
|
||||
customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(mc.getRenderViewEntity())));
|
||||
customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity())));
|
||||
logDirect("Coming");
|
||||
return true;
|
||||
}
|
||||
@@ -334,7 +346,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
if (suffix.isEmpty()) {
|
||||
// clear the area from the current goal to here
|
||||
Goal goal = baritone.getPathingBehavior().getGoal();
|
||||
if (goal == null || !(goal instanceof GoalBlock)) {
|
||||
if (!(goal instanceof GoalBlock)) {
|
||||
logDirect("Need to specify goal of opposite corner");
|
||||
return true;
|
||||
}
|
||||
@@ -353,41 +365,41 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
baritone.getBuilderProcess().clearArea(corner1, corner2);
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("resume")) {
|
||||
baritone.getBuilderProcess().resume();
|
||||
logDirect("resumed");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("pause")) {
|
||||
baritone.getBuilderProcess().pause();
|
||||
logDirect("paused");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("reset")) {
|
||||
for (Settings.Setting setting : Baritone.settings().allSettings) {
|
||||
for (Settings.Setting setting : BaritoneAPI.getSettings().allSettings) {
|
||||
setting.reset();
|
||||
}
|
||||
SettingsUtil.save(Baritone.settings());
|
||||
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||
logDirect("Baritone settings reset");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("tunnel")) {
|
||||
customGoalProcess.setGoalAndPath(new GoalStrictDirection(ctx.playerFeet(), ctx.player().getHorizontalFacing()));
|
||||
logDirect("tunneling");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("render")) {
|
||||
BetterBlockPos pf = ctx.playerFeet();
|
||||
Minecraft.getMinecraft().renderGlobal.markBlockRangeForRenderUpdate(pf.x - 500, pf.y - 500, pf.z - 500, pf.x + 500, pf.y + 500, pf.z + 500);
|
||||
logDirect("okay");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("echest")) {
|
||||
Optional<List<ItemStack>> contents = baritone.getMemoryBehavior().echest();
|
||||
if (contents.isPresent()) {
|
||||
logDirect("echest contents:");
|
||||
log(contents.get());
|
||||
} else {
|
||||
logDirect("echest contents unknown");
|
||||
}
|
||||
if (msg.equals("farm")) {
|
||||
baritone.getFarmProcess().farm();
|
||||
logDirect("farming");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("chests")) {
|
||||
System.out.println(baritone.getWorldProvider());
|
||||
System.out.println(baritone.getWorldProvider().getCurrentWorld());
|
||||
|
||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory());
|
||||
|
||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories());
|
||||
|
||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet());
|
||||
|
||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet());
|
||||
for (Map.Entry<BlockPos, IRememberedInventory> entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) {
|
||||
logDirect(entry.getKey() + "");
|
||||
log(entry.getValue().getContents());
|
||||
@@ -417,10 +429,33 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
Entity effectivelyFinal = toFollow.get();
|
||||
baritone.getFollowProcess().follow(x -> effectivelyFinal.equals(x));
|
||||
baritone.getFollowProcess().follow(effectivelyFinal::equals);
|
||||
logDirect("Following " + toFollow.get());
|
||||
return true;
|
||||
}
|
||||
if (msg.startsWith("explorefilter")) {
|
||||
// explorefilter blah.json
|
||||
// means that entries in blah.json are already explored
|
||||
// explorefilter blah.json invert
|
||||
// means that entries in blah.json are NOT already explored
|
||||
String path = msg.substring("explorefilter".length()).trim();
|
||||
String[] parts = path.split(" ");
|
||||
Path path1 = Minecraft.getMinecraft().gameDir.toPath().resolve(parts[0]);
|
||||
boolean invert = parts.length > 1;
|
||||
try {
|
||||
baritone.getExploreProcess().applyJsonFilter(path1, invert);
|
||||
logDirect("Loaded filter. Inverted: " + invert);
|
||||
if (invert) {
|
||||
logDirect("Chunks on this list will be treated as possibly unexplored, all others will be treated as certainly explored");
|
||||
} else {
|
||||
logDirect("Chunks on this list will be treated as certainly explored, all others will be treated as possibly unexplored");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logDirect("Unable to load " + path1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("reloadall")) {
|
||||
baritone.getWorldProvider().getCurrentWorld().getCachedWorld().reloadAllFromDisk();
|
||||
logDirect("ok");
|
||||
@@ -446,14 +481,27 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
logDirect("Exploring from " + centerX + "," + centerZ);
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("blacklist")) {
|
||||
IGetToBlockProcess proc = baritone.getGetToBlockProcess();
|
||||
if (!proc.isActive()) {
|
||||
logDirect("GetToBlockProcess is not currently active");
|
||||
return true;
|
||||
}
|
||||
if (proc.blacklistClosest()) {
|
||||
logDirect("Blacklisted closest instances");
|
||||
} else {
|
||||
logDirect("No known locations, unable to blacklist");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.startsWith("find")) {
|
||||
String blockType = msg.substring(4).trim();
|
||||
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
||||
logDirect("Have " + locs.size() + " locations");
|
||||
for (BlockPos pos : locs) {
|
||||
Block actually = BlockStateInterface.get(ctx, pos).getBlock();
|
||||
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
||||
System.out.println("Was looking for " + blockType + " but actually found " + actually + " " + ChunkPacker.blockToString(actually));
|
||||
Block actually = ctx.world().getBlockState(pos).getBlock();
|
||||
if (!BlockUtils.blockToString(actually).equalsIgnoreCase(blockType)) {
|
||||
logDebug("Was looking for " + blockType + " but actually found " + actually + " " + BlockUtils.blockToString(actually));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -462,14 +510,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
String[] blockTypes = msg.substring(4).trim().split(" ");
|
||||
try {
|
||||
int quantity = Integer.parseInt(blockTypes[1]);
|
||||
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
|
||||
Objects.requireNonNull(block);
|
||||
Block block = BlockUtils.stringToBlockRequired(blockTypes[0]);
|
||||
baritone.getMineProcess().mine(quantity, block);
|
||||
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
||||
return true;
|
||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
||||
for (String s : blockTypes) {
|
||||
if (ChunkPacker.stringToBlock(s) == null) {
|
||||
if (BlockUtils.stringToBlockNullable(s) == null) {
|
||||
logDirect(s + " isn't a valid block name");
|
||||
return true;
|
||||
}
|
||||
@@ -480,12 +527,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("click")) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiClick()));
|
||||
} catch (Exception ignored) {}
|
||||
}).start();
|
||||
baritone.openClick();
|
||||
logDirect("aight dude");
|
||||
return true;
|
||||
}
|
||||
@@ -505,9 +547,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
// for example, "show deaths"
|
||||
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||
}
|
||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||
IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType);
|
||||
if (tag == null) {
|
||||
logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||
logDirect("Not a valid tag. Tags are: " + Arrays.asList(IWaypoint.Tag.values()).toString().toLowerCase());
|
||||
return true;
|
||||
}
|
||||
Set<IWaypoint> waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag);
|
||||
@@ -538,21 +580,32 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
}
|
||||
name = parts[0];
|
||||
}
|
||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, pos));
|
||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, IWaypoint.Tag.USER, pos));
|
||||
logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints.");
|
||||
return true;
|
||||
}
|
||||
if (msg.startsWith("delete")) {
|
||||
String name = msg.substring(6).trim();
|
||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getTag() == IWaypoint.Tag.USER && w.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
if (waypoint == null) {
|
||||
logDirect("No user defined position under the name '" + name + "' found.");
|
||||
return true;
|
||||
}
|
||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().removeWaypoint(waypoint);
|
||||
logDirect("Deleted user defined position under name '" + name + "'.");
|
||||
return true;
|
||||
}
|
||||
if (msg.startsWith("goto")) {
|
||||
String waypointType = msg.substring(4).trim();
|
||||
if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
|
||||
if (waypointType.endsWith("s") && IWaypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
|
||||
// for example, "show deaths"
|
||||
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||
}
|
||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
||||
IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType);
|
||||
IWaypoint waypoint;
|
||||
if (tag == null) {
|
||||
String mining = waypointType;
|
||||
Block block = ChunkPacker.stringToBlock(mining);
|
||||
Block block = BlockUtils.stringToBlockNullable(mining);
|
||||
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||
if (block == null) {
|
||||
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
||||
@@ -575,12 +628,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Goal goal = waypoint.getTag() == Waypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation());
|
||||
Goal goal = waypoint.getTag() == IWaypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation());
|
||||
customGoalProcess.setGoalAndPath(goal);
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("spawn") || msg.equals("bed")) {
|
||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED);
|
||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(IWaypoint.Tag.BED);
|
||||
if (waypoint == null) {
|
||||
BlockPos spawnPoint = ctx.player().getBedLocation();
|
||||
// for some reason the default spawnpoint is underground sometimes
|
||||
@@ -595,12 +648,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("sethome")) {
|
||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, ctx.playerFeet()));
|
||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", IWaypoint.Tag.HOME, ctx.playerFeet()));
|
||||
logDirect("Saved. Say home to set goal.");
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("home")) {
|
||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME);
|
||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(IWaypoint.Tag.HOME);
|
||||
if (waypoint == null) {
|
||||
logDirect("home not saved");
|
||||
} else {
|
||||
@@ -610,23 +663,6 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("costs")) {
|
||||
List<Movement> moves = Stream.of(Moves.values()).map(x -> x.apply0(new CalculationContext(baritone), ctx.playerFeet())).collect(Collectors.toCollection(ArrayList::new));
|
||||
while (moves.contains(null)) {
|
||||
moves.remove(null);
|
||||
}
|
||||
moves.sort(Comparator.comparingDouble(move -> move.getCost(new CalculationContext(baritone))));
|
||||
for (Movement move : moves) {
|
||||
String[] parts = move.getClass().toString().split("\\.");
|
||||
double cost = move.getCost();
|
||||
String strCost = cost + "";
|
||||
if (cost >= ActionCosts.COST_INF) {
|
||||
strCost = "IMPOSSIBLE";
|
||||
}
|
||||
logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (msg.equals("damn")) {
|
||||
logDirect("daniel");
|
||||
}
|
||||
@@ -648,18 +684,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
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");
|
||||
@@ -15,9 +15,9 @@
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils;
|
||||
package baritone.api.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
@@ -50,7 +50,7 @@ public interface Helper {
|
||||
* @param message The message to display in chat
|
||||
*/
|
||||
default void logDebug(String message) {
|
||||
if (!Baritone.settings().chatDebug.value) {
|
||||
if (!BaritoneAPI.getSettings().chatDebug.value) {
|
||||
//System.out.println("Suppressed debug message:");
|
||||
//System.out.println(message);
|
||||
return;
|
||||
@@ -67,6 +67,6 @@ public interface Helper {
|
||||
ITextComponent component = MESSAGE_PREFIX.createCopy();
|
||||
component.getStyle().setColor(TextFormatting.GRAY);
|
||||
component.appendSibling(new TextComponentString(" " + message));
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.value.accept(component));
|
||||
Minecraft.getMinecraft().addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component));
|
||||
}
|
||||
}
|
||||
@@ -71,20 +71,26 @@ public interface IPlayerContext {
|
||||
* @return The position of the highlighted block
|
||||
*/
|
||||
default Optional<BlockPos> getSelectedBlock() {
|
||||
if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
return Optional.of(objectMouseOver().getBlockPos());
|
||||
RayTraceResult result = objectMouseOver();
|
||||
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||
return Optional.of(result.getBlockPos());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
default boolean isLookingAt(BlockPos pos) {
|
||||
return getSelectedBlock().equals(Optional.of(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity that the crosshair is currently placed over. Updated once per tick.
|
||||
*
|
||||
* @return The entity
|
||||
*/
|
||||
default Optional<Entity> getSelectedEntity() {
|
||||
if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.ENTITY) {
|
||||
return Optional.of(objectMouseOver().entityHit);
|
||||
RayTraceResult result = objectMouseOver();
|
||||
if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) {
|
||||
return Optional.of(result.entityHit);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -50,4 +50,6 @@ public interface IPlayerController {
|
||||
}
|
||||
|
||||
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
|
||||
|
||||
EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.api.utils;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
* Basic representation of a schematic. Provides the dimensions and
|
||||
@@ -44,6 +45,19 @@ public interface ISchematic {
|
||||
return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ();
|
||||
}
|
||||
|
||||
default int size(EnumFacing.Axis axis) {
|
||||
switch (axis) {
|
||||
case X:
|
||||
return widthX();
|
||||
case Y:
|
||||
return heightY();
|
||||
case Z:
|
||||
return lengthZ();
|
||||
default:
|
||||
throw new UnsupportedOperationException(axis + "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the desired block state at a given (X, Y, Z) position relative to the origin (0, 0, 0).
|
||||
*
|
||||
|
||||
37
src/api/java/baritone/api/utils/MyChunkPos.java
Normal file
37
src/api/java/baritone/api/utils/MyChunkPos.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.utils;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Need a non obfed chunkpos that we can load using GSON
|
||||
*/
|
||||
public class MyChunkPos {
|
||||
|
||||
@SerializedName("x")
|
||||
public int x;
|
||||
|
||||
@SerializedName("y")
|
||||
public int z;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + ", " + z;
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ public final class RotationUtils {
|
||||
*/
|
||||
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
|
||||
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
|
||||
if (pos.equals(baritone.getPlayerContext().getSelectedBlock().orElse(null))) {
|
||||
if (baritone.getPlayerContext().isLookingAt(pos)) {
|
||||
/*
|
||||
* why add 0.0001?
|
||||
* to indicate that we actually have a desired pitch
|
||||
|
||||
@@ -18,32 +18,36 @@
|
||||
package baritone.api.utils;
|
||||
|
||||
import baritone.api.Settings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
|
||||
public class SettingsUtil {
|
||||
|
||||
private static final Path SETTINGS_PATH = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt");
|
||||
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>[^ ]+)"); // 2 words separated by spaces
|
||||
|
||||
private static final Map<Class<?>, SettingsIO> map;
|
||||
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>.+)"); // key and value split by the first space
|
||||
|
||||
private static boolean isComment(String line) {
|
||||
return line.startsWith("#") || line.startsWith("//");
|
||||
@@ -79,6 +83,8 @@ public class SettingsUtil {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
} catch (NoSuchFileException ignored) {
|
||||
System.out.println("Baritone settings file not found, resetting.");
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!");
|
||||
ex.printStackTrace();
|
||||
@@ -118,11 +124,11 @@ public class SettingsUtil {
|
||||
if (setting.getName().equals("logger")) {
|
||||
return "logger";
|
||||
}
|
||||
SettingsIO io = map.get(setting.getValueClass());
|
||||
Parser io = Parser.getParser(setting.getType());
|
||||
if (io == null) {
|
||||
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName());
|
||||
}
|
||||
return setting.getName() + " " + io.toString.apply(setting.value);
|
||||
return setting.getName() + " " + io.toString(new ParserContext(setting), setting.value);
|
||||
}
|
||||
|
||||
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
||||
@@ -131,45 +137,132 @@ public class SettingsUtil {
|
||||
throw new IllegalStateException("No setting by that name");
|
||||
}
|
||||
Class intendedType = setting.getValueClass();
|
||||
SettingsIO ioMethod = map.get(intendedType);
|
||||
Object parsed = ioMethod.parser.apply(settingValue);
|
||||
ISettingParser ioMethod = Parser.getParser(setting.getType());
|
||||
Object parsed = ioMethod.parse(new ParserContext(setting), settingValue);
|
||||
if (!intendedType.isInstance(parsed)) {
|
||||
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
|
||||
}
|
||||
setting.value = parsed;
|
||||
}
|
||||
|
||||
private enum SettingsIO {
|
||||
private interface ISettingParser<T> {
|
||||
|
||||
T parse(ParserContext context, String raw);
|
||||
|
||||
String toString(ParserContext context, T value);
|
||||
|
||||
boolean accepts(Type type);
|
||||
}
|
||||
|
||||
private static class ParserContext {
|
||||
|
||||
private final Settings.Setting<?> setting;
|
||||
|
||||
private ParserContext(Settings.Setting<?> setting) {
|
||||
this.setting = setting;
|
||||
}
|
||||
|
||||
private Settings.Setting<?> getSetting() {
|
||||
return this.setting;
|
||||
}
|
||||
}
|
||||
|
||||
private enum Parser implements ISettingParser {
|
||||
|
||||
DOUBLE(Double.class, Double::parseDouble),
|
||||
BOOLEAN(Boolean.class, Boolean::parseBoolean),
|
||||
INTEGER(Integer.class, Integer::parseInt),
|
||||
FLOAT(Float.class, Float::parseFloat),
|
||||
LONG(Long.class, Long::parseLong),
|
||||
ENUMFACING(EnumFacing.class, EnumFacing::byName),
|
||||
COLOR(
|
||||
Color.class,
|
||||
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()),
|
||||
BlockUtils::blockToString
|
||||
),
|
||||
ITEM(
|
||||
Item.class,
|
||||
str -> Item.getByNameOrId(str.trim()),
|
||||
item -> Item.REGISTRY.getNameForObject(item).toString()
|
||||
),
|
||||
LIST() {
|
||||
@Override
|
||||
public Object parse(ParserContext context, String raw) {
|
||||
Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0];
|
||||
Parser parser = Parser.getParser(type);
|
||||
|
||||
ITEM_LIST(ArrayList.class, str -> Stream.of(str.split(",")).map(Item::getByNameOrId).collect(Collectors.toCollection(ArrayList::new)), list -> ((ArrayList<Item>) list).stream().map(Item.REGISTRY::getNameForObject).map(ResourceLocation::toString).collect(Collectors.joining(","))),
|
||||
COLOR(Color.class, 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());
|
||||
return Arrays.stream(raw.split(","))
|
||||
.map(s -> parser.parse(context, s))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ParserContext context, Object value) {
|
||||
Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0];
|
||||
Parser parser = Parser.getParser(type);
|
||||
|
||||
Class<?> klass;
|
||||
Function<String, Object> parser;
|
||||
Function<Object, String> toString;
|
||||
return ((List<?>) value).stream()
|
||||
.map(o -> parser.toString(context, o))
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
<T> SettingsIO(Class<T> klass, Function<String, T> parser) {
|
||||
@Override
|
||||
public boolean accepts(Type type) {
|
||||
return List.class.isAssignableFrom(TypeUtils.resolveBaseClass(type));
|
||||
}
|
||||
};
|
||||
|
||||
private final Class<?> klass;
|
||||
private final Function<String, Object> parser;
|
||||
private final Function<Object, String> toString;
|
||||
|
||||
Parser() {
|
||||
this.klass = null;
|
||||
this.parser = null;
|
||||
this.toString = null;
|
||||
}
|
||||
|
||||
<T> Parser(Class<T> klass, Function<String, T> parser) {
|
||||
this(klass, parser, Object::toString);
|
||||
}
|
||||
|
||||
<T> SettingsIO(Class<T> klass, Function<String, T> parser, Function<T, String> toString) {
|
||||
<T> Parser(Class<T> klass, Function<String, T> parser, Function<T, String> toString) {
|
||||
this.klass = klass;
|
||||
this.parser = parser::apply;
|
||||
this.toString = x -> toString.apply((T) x);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
HashMap<Class<?>, SettingsIO> tempMap = new HashMap<>();
|
||||
for (SettingsIO type : SettingsIO.values()) {
|
||||
tempMap.put(type.klass, type);
|
||||
@Override
|
||||
public Object parse(ParserContext context, String raw) {
|
||||
Object parsed = this.parser.apply(raw);
|
||||
Objects.requireNonNull(parsed);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(ParserContext context, Object value) {
|
||||
return this.toString.apply(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accepts(Type type) {
|
||||
return type instanceof Class && this.klass.isAssignableFrom((Class) type);
|
||||
}
|
||||
|
||||
public static Parser getParser(Type type) {
|
||||
return Arrays.stream(values())
|
||||
.filter(parser -> parser.accepts(type))
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
map = Collections.unmodifiableMap(tempMap);
|
||||
}
|
||||
}
|
||||
|
||||
44
src/api/java/baritone/api/utils/TypeUtils.java
Normal file
44
src/api/java/baritone/api/utils/TypeUtils.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.utils;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 4/20/2019
|
||||
*/
|
||||
public final class TypeUtils {
|
||||
|
||||
private TypeUtils() {}
|
||||
|
||||
/**
|
||||
* Resolves the "base type" for the specified type. For example, if the specified
|
||||
* type is {@code List<String>}, then {@code List.class} will be returned. If the
|
||||
* specified type is already a class, then it is directly returned.
|
||||
*
|
||||
* @param type The type to resolve
|
||||
* @return The base class
|
||||
*/
|
||||
public static Class<?> resolveBaseClass(Type type) {
|
||||
return type instanceof Class ? (Class<?>) type
|
||||
: type instanceof ParameterizedType ? (Class<?>) ((ParameterizedType) type).getRawType()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class MixinChunkRenderContainer {
|
||||
)
|
||||
)
|
||||
private BlockPos getPosition(RenderChunk renderChunkIn) {
|
||||
if (Baritone.settings().renderCachedChunks.value && Minecraft.getMinecraft().getIntegratedServer() == null && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) {
|
||||
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer() && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) {
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableBlend();
|
||||
GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.value);
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class MixinChunkRenderWorker {
|
||||
)
|
||||
)
|
||||
private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) {
|
||||
if (Baritone.settings().renderCachedChunks.value && Minecraft.getMinecraft().getIntegratedServer() == null) {
|
||||
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
|
||||
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
|
||||
IPlayerContext ctx = baritone.getPlayerContext();
|
||||
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MixinRenderChunk {
|
||||
if (!chunkCache.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (Baritone.settings().renderCachedChunks.value && Minecraft.getMinecraft().getIntegratedServer() == null) {
|
||||
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
|
||||
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
|
||||
IPlayerContext ctx = baritone.getPlayerContext();
|
||||
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
|
||||
@@ -76,7 +76,7 @@ public class MixinRenderChunk {
|
||||
)
|
||||
)
|
||||
private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) {
|
||||
if (Baritone.settings().renderCachedChunks.value && Minecraft.getMinecraft().getIntegratedServer() == null) {
|
||||
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
|
||||
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
|
||||
IPlayerContext ctx = baritone.getPlayerContext();
|
||||
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MixinRenderList {
|
||||
)
|
||||
)
|
||||
private void popMatrix() {
|
||||
if (Baritone.settings().renderCachedChunks.value && Minecraft.getMinecraft().getIntegratedServer() == null) {
|
||||
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
|
||||
// reset the blend func to normal (not dependent on constant alpha)
|
||||
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MixinVboRenderList {
|
||||
)
|
||||
)
|
||||
private void popMatrix() {
|
||||
if (Baritone.settings().renderCachedChunks.value && Minecraft.getMinecraft().getIntegratedServer() == null) {
|
||||
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
|
||||
// reset the blend func to normal (not dependent on constant alpha)
|
||||
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.utils.ExampleBaritoneControl;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.behavior.*;
|
||||
import baritone.cache.WorldProvider;
|
||||
@@ -33,8 +35,6 @@ import net.minecraft.client.Minecraft;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@@ -67,7 +67,6 @@ public class Baritone implements IBaritone {
|
||||
|
||||
private GameEventHandler gameEventHandler;
|
||||
|
||||
private List<Behavior> behaviors;
|
||||
private PathingBehavior pathingBehavior;
|
||||
private LookBehavior lookBehavior;
|
||||
private MemoryBehavior memoryBehavior;
|
||||
@@ -80,6 +79,8 @@ public class Baritone implements IBaritone {
|
||||
private CustomGoalProcess customGoalProcess;
|
||||
private BuilderProcess builderProcess;
|
||||
private ExploreProcess exploreProcess;
|
||||
private BackfillProcess backfillProcess;
|
||||
private FarmProcess farmProcess;
|
||||
|
||||
private PathingControlManager pathingControlManager;
|
||||
|
||||
@@ -101,7 +102,6 @@ public class Baritone implements IBaritone {
|
||||
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
||||
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
||||
|
||||
this.behaviors = new ArrayList<>();
|
||||
{
|
||||
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||
pathingBehavior = new PathingBehavior(this);
|
||||
@@ -120,6 +120,8 @@ public class Baritone implements IBaritone {
|
||||
getToBlockProcess = new GetToBlockProcess(this);
|
||||
builderProcess = new BuilderProcess(this);
|
||||
exploreProcess = new ExploreProcess(this);
|
||||
backfillProcess = new BackfillProcess(this);
|
||||
farmProcess = new FarmProcess(this);
|
||||
}
|
||||
|
||||
this.worldProvider = new WorldProvider();
|
||||
@@ -136,12 +138,7 @@ public class Baritone implements IBaritone {
|
||||
return this.pathingControlManager;
|
||||
}
|
||||
|
||||
public List<Behavior> getBehaviors() {
|
||||
return this.behaviors;
|
||||
}
|
||||
|
||||
public void registerBehavior(Behavior behavior) {
|
||||
this.behaviors.add(behavior);
|
||||
this.gameEventHandler.registerEventListener(behavior);
|
||||
}
|
||||
|
||||
@@ -197,6 +194,10 @@ public class Baritone implements IBaritone {
|
||||
return this.mineProcess;
|
||||
}
|
||||
|
||||
public FarmProcess getFarmProcess() {
|
||||
return this.farmProcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingBehavior getPathingBehavior() {
|
||||
return this.pathingBehavior;
|
||||
@@ -212,6 +213,16 @@ public class Baritone implements IBaritone {
|
||||
return this.gameEventHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openClick() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Helper.mc.addScheduledTask(() -> Helper.mc.displayGuiScreen(new GuiClick()));
|
||||
} catch (Exception ignored) {}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static Settings settings() {
|
||||
return BaritoneAPI.getSettings();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.List;
|
||||
public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
private final Baritone primary = new Baritone();
|
||||
private final List<IBaritone> all = Collections.singletonList(primary);
|
||||
|
||||
@Override
|
||||
public IBaritone getPrimaryBaritone() {
|
||||
@@ -40,8 +41,7 @@ public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
@Override
|
||||
public List<IBaritone> getAllBaritones() {
|
||||
// TODO return a CopyOnWriteArrayList
|
||||
return Collections.singletonList(primary);
|
||||
return all;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.OptionalInt;
|
||||
import java.util.Random;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class InventoryBehavior extends Behavior {
|
||||
public final class InventoryBehavior extends Behavior {
|
||||
public InventoryBehavior(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
@@ -123,27 +123,27 @@ public class InventoryBehavior extends Behavior {
|
||||
|
||||
public boolean hasGenericThrowaway() {
|
||||
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
||||
if (throwaway(false, item::equals)) {
|
||||
if (throwaway(false, stack -> item.equals(stack.getItem()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean selectThrowawayForLocation(int x, int y, int z) {
|
||||
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
|
||||
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
||||
if (maybe != null && throwaway(true, item -> item instanceof ItemBlock && ((ItemBlock) item).getBlock().equals(maybe.getBlock()))) {
|
||||
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
|
||||
return true; // gotem
|
||||
}
|
||||
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
||||
if (throwaway(true, item::equals)) {
|
||||
if (throwaway(select, stack -> item.equals(stack.getItem()))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean throwaway(boolean select, Predicate<? super Item> desired) {
|
||||
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
|
||||
EntityPlayerSP p = ctx.player();
|
||||
NonNullList<ItemStack> inv = p.inventory.mainInventory;
|
||||
for (byte i = 0; i < 9; i++) {
|
||||
@@ -153,14 +153,14 @@ public class InventoryBehavior extends Behavior {
|
||||
// and then it's called during execution
|
||||
// since this function is never called during cost calculation, we don't need to migrate
|
||||
// acceptableThrowawayItems to the CalculationContext
|
||||
if (desired.test(item.getItem())) {
|
||||
if (desired.test(item)) {
|
||||
if (select) {
|
||||
p.inventory.currentItem = i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (desired.test(p.inventory.offHandInventory.get(0).getItem())) {
|
||||
if (desired.test(p.inventory.offHandInventory.get(0))) {
|
||||
// main hand takes precedence over off hand
|
||||
// that means that if we have block A selected in main hand and block B in off hand, right clicking places block B
|
||||
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
|
||||
|
||||
@@ -72,8 +72,8 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
||||
float oldPitch = ctx.player().rotationPitch;
|
||||
float desiredPitch = this.target.getPitch();
|
||||
ctx.player().rotationPitch = desiredPitch;
|
||||
if (desiredPitch == oldPitch) {
|
||||
//nudgeToLevel();
|
||||
if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) {
|
||||
nudgeToLevel();
|
||||
}
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
package baritone.behavior;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.Waypoint;
|
||||
import baritone.api.event.events.BlockInteractEvent;
|
||||
import baritone.api.event.events.PacketEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.cache.ContainerMemory;
|
||||
import baritone.cache.Waypoint;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBed;
|
||||
|
||||
@@ -25,6 +25,7 @@ import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.PathCalculationResult;
|
||||
import baritone.api.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.pathing.calc.AStarPathFinder;
|
||||
@@ -32,7 +33,6 @@ import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.path.PathExecutor;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.PathRenderer;
|
||||
import baritone.utils.PathingCommandContext;
|
||||
import baritone.utils.pathing.Favoring;
|
||||
@@ -65,7 +65,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
|
||||
private boolean lastAutoJump;
|
||||
|
||||
private BlockPos expectedSegmentStart;
|
||||
private BetterBlockPos expectedSegmentStart;
|
||||
|
||||
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
|
||||
|
||||
@@ -195,7 +195,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
current.onTick();
|
||||
return;
|
||||
}
|
||||
current = current.trySplice(next);
|
||||
if (Baritone.settings().splicePath.value) {
|
||||
current = current.trySplice(next);
|
||||
}
|
||||
if (next != null && current.getPath().getDest().equals(next.getPath().getDest())) {
|
||||
next = null;
|
||||
}
|
||||
@@ -325,6 +327,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
|
||||
public void softCancelIfSafe() {
|
||||
synchronized (pathPlanLock) {
|
||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
|
||||
if (!isSafeToCancel()) {
|
||||
return;
|
||||
}
|
||||
@@ -332,7 +335,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
next = null;
|
||||
}
|
||||
cancelRequested = true;
|
||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
|
||||
// do everything BUT clear keys
|
||||
}
|
||||
|
||||
@@ -340,17 +342,18 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
public void secretInternalSegmentCancel() {
|
||||
queuePathEvent(PathEvent.CANCELED);
|
||||
synchronized (pathPlanLock) {
|
||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
|
||||
if (current != null) {
|
||||
current = null;
|
||||
next = null;
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
|
||||
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void forceCancel() { // NOT exposed on public api
|
||||
@Override
|
||||
public void forceCancel() { // exposed on public api because :sob:
|
||||
cancelEverything();
|
||||
secretInternalSegmentCancel();
|
||||
synchronized (pathCalcLock) {
|
||||
@@ -358,11 +361,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
}
|
||||
}
|
||||
|
||||
public void secretCursedFunctionDoNotCall(IPath path) {
|
||||
/*public void secretCursedFunctionDoNotCall(IPath path) {
|
||||
synchronized (pathPlanLock) {
|
||||
current = new PathExecutor(this, path);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public CalculationContext secretInternalGetCalculationContext() {
|
||||
return context;
|
||||
|
||||
112
src/main/java/baritone/cache/CachedChunk.java
vendored
112
src/main/java/baritone/cache/CachedChunk.java
vendored
@@ -17,7 +17,9 @@
|
||||
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.api.utils.BlockUtils;
|
||||
import baritone.utils.pathing.PathingBlockType;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -32,64 +34,60 @@ import java.util.*;
|
||||
*/
|
||||
public final class CachedChunk {
|
||||
|
||||
public static final Set<Block> BLOCKS_TO_KEEP_TRACK_OF;
|
||||
public static final ImmutableSet<Block> BLOCKS_TO_KEEP_TRACK_OF = ImmutableSet.of(
|
||||
Blocks.DIAMOND_BLOCK,
|
||||
//Blocks.COAL_ORE,
|
||||
Blocks.COAL_BLOCK,
|
||||
//Blocks.IRON_ORE,
|
||||
Blocks.IRON_BLOCK,
|
||||
//Blocks.GOLD_ORE,
|
||||
Blocks.GOLD_BLOCK,
|
||||
Blocks.EMERALD_ORE,
|
||||
Blocks.EMERALD_BLOCK,
|
||||
|
||||
static {
|
||||
HashSet<Block> temp = new HashSet<>();
|
||||
//temp.add(Blocks.DIAMOND_ORE);
|
||||
temp.add(Blocks.DIAMOND_BLOCK);
|
||||
//temp.add(Blocks.COAL_ORE);
|
||||
temp.add(Blocks.COAL_BLOCK);
|
||||
//temp.add(Blocks.IRON_ORE);
|
||||
temp.add(Blocks.IRON_BLOCK);
|
||||
//temp.add(Blocks.GOLD_ORE);
|
||||
temp.add(Blocks.GOLD_BLOCK);
|
||||
temp.add(Blocks.EMERALD_ORE);
|
||||
temp.add(Blocks.EMERALD_BLOCK);
|
||||
Blocks.ENDER_CHEST,
|
||||
Blocks.FURNACE,
|
||||
Blocks.CHEST,
|
||||
Blocks.TRAPPED_CHEST,
|
||||
Blocks.END_PORTAL,
|
||||
Blocks.END_PORTAL_FRAME,
|
||||
Blocks.MOB_SPAWNER,
|
||||
Blocks.BARRIER,
|
||||
Blocks.OBSERVER,
|
||||
Blocks.WHITE_SHULKER_BOX,
|
||||
Blocks.ORANGE_SHULKER_BOX,
|
||||
Blocks.MAGENTA_SHULKER_BOX,
|
||||
Blocks.LIGHT_BLUE_SHULKER_BOX,
|
||||
Blocks.YELLOW_SHULKER_BOX,
|
||||
Blocks.LIME_SHULKER_BOX,
|
||||
Blocks.PINK_SHULKER_BOX,
|
||||
Blocks.GRAY_SHULKER_BOX,
|
||||
Blocks.SILVER_SHULKER_BOX,
|
||||
Blocks.CYAN_SHULKER_BOX,
|
||||
Blocks.PURPLE_SHULKER_BOX,
|
||||
Blocks.BLUE_SHULKER_BOX,
|
||||
Blocks.BROWN_SHULKER_BOX,
|
||||
Blocks.GREEN_SHULKER_BOX,
|
||||
Blocks.RED_SHULKER_BOX,
|
||||
Blocks.BLACK_SHULKER_BOX,
|
||||
Blocks.PORTAL,
|
||||
Blocks.HOPPER,
|
||||
Blocks.BEACON,
|
||||
Blocks.BREWING_STAND,
|
||||
Blocks.SKULL,
|
||||
Blocks.ENCHANTING_TABLE,
|
||||
Blocks.ANVIL,
|
||||
Blocks.LIT_FURNACE,
|
||||
Blocks.BED,
|
||||
Blocks.DRAGON_EGG,
|
||||
Blocks.JUKEBOX,
|
||||
Blocks.END_GATEWAY,
|
||||
Blocks.WEB,
|
||||
Blocks.NETHER_WART,
|
||||
Blocks.LADDER,
|
||||
Blocks.VINE
|
||||
);
|
||||
|
||||
temp.add(Blocks.ENDER_CHEST);
|
||||
temp.add(Blocks.FURNACE);
|
||||
temp.add(Blocks.CHEST);
|
||||
temp.add(Blocks.TRAPPED_CHEST);
|
||||
temp.add(Blocks.END_PORTAL);
|
||||
temp.add(Blocks.END_PORTAL_FRAME);
|
||||
temp.add(Blocks.MOB_SPAWNER);
|
||||
temp.add(Blocks.BARRIER);
|
||||
temp.add(Blocks.OBSERVER);
|
||||
temp.add(Blocks.WHITE_SHULKER_BOX);
|
||||
temp.add(Blocks.ORANGE_SHULKER_BOX);
|
||||
temp.add(Blocks.MAGENTA_SHULKER_BOX);
|
||||
temp.add(Blocks.LIGHT_BLUE_SHULKER_BOX);
|
||||
temp.add(Blocks.YELLOW_SHULKER_BOX);
|
||||
temp.add(Blocks.LIME_SHULKER_BOX);
|
||||
temp.add(Blocks.PINK_SHULKER_BOX);
|
||||
temp.add(Blocks.GRAY_SHULKER_BOX);
|
||||
temp.add(Blocks.SILVER_SHULKER_BOX);
|
||||
temp.add(Blocks.CYAN_SHULKER_BOX);
|
||||
temp.add(Blocks.PURPLE_SHULKER_BOX);
|
||||
temp.add(Blocks.BLUE_SHULKER_BOX);
|
||||
temp.add(Blocks.BROWN_SHULKER_BOX);
|
||||
temp.add(Blocks.GREEN_SHULKER_BOX);
|
||||
temp.add(Blocks.RED_SHULKER_BOX);
|
||||
temp.add(Blocks.BLACK_SHULKER_BOX);
|
||||
temp.add(Blocks.PORTAL);
|
||||
temp.add(Blocks.HOPPER);
|
||||
temp.add(Blocks.BEACON);
|
||||
temp.add(Blocks.BREWING_STAND);
|
||||
temp.add(Blocks.SKULL);
|
||||
temp.add(Blocks.ENCHANTING_TABLE);
|
||||
temp.add(Blocks.ANVIL);
|
||||
temp.add(Blocks.LIT_FURNACE);
|
||||
temp.add(Blocks.BED);
|
||||
temp.add(Blocks.DRAGON_EGG);
|
||||
temp.add(Blocks.JUKEBOX);
|
||||
temp.add(Blocks.END_GATEWAY);
|
||||
temp.add(Blocks.WEB);
|
||||
temp.add(Blocks.NETHER_WART);
|
||||
temp.add(Blocks.LADDER);
|
||||
temp.add(Blocks.VINE);
|
||||
BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* The size of the chunk data in bits. Equal to 16 KiB.
|
||||
@@ -177,7 +175,7 @@ public final class CachedChunk {
|
||||
if (special != null) {
|
||||
String str = special.get(index);
|
||||
if (str != null) {
|
||||
return ChunkPacker.stringToBlock(str).getDefaultState();
|
||||
return BlockUtils.stringToBlockRequired(str).getDefaultState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.cache;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.ICachedRegion;
|
||||
import baritone.api.utils.BlockUtils;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@@ -149,7 +150,7 @@ public final class CachedRegion implements ICachedRegion {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
if (chunks[x][z] != null) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
out.writeUTF(ChunkPacker.blockToString(chunks[x][z].getOverview()[i].getBlock()));
|
||||
out.writeUTF(BlockUtils.blockToString(chunks[x][z].getOverview()[i].getBlock()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,7 +241,7 @@ public final class CachedRegion implements ICachedRegion {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
if (present[x][z]) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
overview[x][z][i] = ChunkPacker.stringToBlock(in.readUTF()).getDefaultState();
|
||||
overview[x][z][i] = BlockUtils.stringToBlockRequired(in.readUTF()).getDefaultState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,6 +256,7 @@ public final class CachedRegion implements ICachedRegion {
|
||||
int numSpecialBlockTypes = in.readShort() & 0xffff;
|
||||
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
||||
String blockName = in.readUTF();
|
||||
BlockUtils.stringToBlockRequired(blockName);
|
||||
List<BlockPos> locs = new ArrayList<>();
|
||||
location[x][z].put(blockName, locs);
|
||||
int numLocations = in.readShort() & 0xffff;
|
||||
|
||||
13
src/main/java/baritone/cache/CachedWorld.java
vendored
13
src/main/java/baritone/cache/CachedWorld.java
vendored
@@ -22,7 +22,7 @@ import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.cache.ICachedWorld;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.api.utils.Helper;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -70,8 +70,6 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
this.directory = directory.toString();
|
||||
this.dimension = dimension;
|
||||
System.out.println("Cached world directory: " + directory);
|
||||
// Insert an invalid region element
|
||||
cachedRegions.put(0, null);
|
||||
Baritone.getExecutor().execute(new PackerThread());
|
||||
Baritone.getExecutor().execute(() -> {
|
||||
try {
|
||||
@@ -182,8 +180,8 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
if (region == null) {
|
||||
continue;
|
||||
}
|
||||
int distX = (region.getX() << 9 + 256) - pruneCenter.getX();
|
||||
int distZ = (region.getZ() << 9 + 256) - pruneCenter.getZ();
|
||||
int distX = ((region.getX() << 9) + 256) - pruneCenter.getX();
|
||||
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");
|
||||
@@ -218,7 +216,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
if (mostRecentlyModified == null) {
|
||||
return new BlockPos(0, 0, 0);
|
||||
}
|
||||
return new BlockPos(mostRecentlyModified.x << 4 + 8, 0, mostRecentlyModified.z << 4 + 8);
|
||||
return new BlockPos((mostRecentlyModified.x << 4) + 8, 0, (mostRecentlyModified.z << 4) + 8);
|
||||
}
|
||||
|
||||
private synchronized List<CachedRegion> allRegions() {
|
||||
@@ -305,6 +303,9 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
} catch (Throwable th) {
|
||||
// in the case of an exception, keep consuming from the queue so as not to leak memory
|
||||
th.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
33
src/main/java/baritone/cache/ChunkPacker.java
vendored
33
src/main/java/baritone/cache/ChunkPacker.java
vendored
@@ -17,12 +17,12 @@
|
||||
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.api.utils.BlockUtils;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.pathing.PathingBlockType;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.BlockStateContainer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
@@ -36,8 +36,6 @@ import java.util.*;
|
||||
*/
|
||||
public final class ChunkPacker {
|
||||
|
||||
private static final Map<String, Block> resourceCache = new HashMap<>();
|
||||
|
||||
private ChunkPacker() {}
|
||||
|
||||
public static CachedChunk pack(Chunk chunk) {
|
||||
@@ -75,7 +73,7 @@ public final class ChunkPacker {
|
||||
bitSet.set(index + 1, bits[1]);
|
||||
Block block = state.getBlock();
|
||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
|
||||
String name = blockToString(block);
|
||||
String name = BlockUtils.blockToString(block);
|
||||
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -90,8 +88,7 @@ public final class ChunkPacker {
|
||||
IBlockState[] blocks = new IBlockState[256];
|
||||
|
||||
for (int z = 0; z < 16; z++) {
|
||||
https:
|
||||
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
||||
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 255; y >= 0; y--) {
|
||||
int index = CachedChunk.getPositionIndex(x, y, z);
|
||||
@@ -106,19 +103,6 @@ public final class ChunkPacker {
|
||||
return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public static String blockToString(Block block) {
|
||||
ResourceLocation loc = Block.REGISTRY.getNameForObject(block);
|
||||
String name = loc.getPath(); // normally, only write the part after the minecraft:
|
||||
if (!loc.getNamespace().equals("minecraft")) {
|
||||
// Baritone is running on top of forge with mods installed, perhaps?
|
||||
name = loc.toString(); // include the namespace with the colon
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static Block stringToBlock(String name) {
|
||||
return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n));
|
||||
}
|
||||
|
||||
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
|
||||
Block block = state.getBlock();
|
||||
@@ -128,15 +112,20 @@ public final class ChunkPacker {
|
||||
if (MovementHelper.possiblyFlowing(state)) {
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
if (
|
||||
(x != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)))
|
||||
|| (x != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)))
|
||||
|| (z != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)))
|
||||
|| (z != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1)))
|
||||
) {
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
if (x == 0 || x == 15 || z == 0 || z == 15) {
|
||||
if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) == -1000.0F) {
|
||||
return PathingBlockType.WATER;
|
||||
}
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
if (MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1))) {
|
||||
return PathingBlockType.AVOID;
|
||||
}
|
||||
return PathingBlockType.WATER;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.cache;
|
||||
|
||||
import baritone.api.cache.IWaypoint;
|
||||
import baritone.api.cache.IWaypointCollection;
|
||||
import baritone.api.cache.Waypoint;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -19,7 +19,7 @@ package baritone.cache;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.IWorldProvider;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||
import baritone.utils.accessor.IChunkProviderServer;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
@@ -62,7 +62,7 @@ public class WorldProvider implements IWorldProvider, Helper {
|
||||
IntegratedServer integratedServer = mc.getIntegratedServer();
|
||||
|
||||
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
|
||||
if (integratedServer != null) {
|
||||
if (mc.isSingleplayer()) {
|
||||
WorldServer localServerWorld = integratedServer.getWorld(dimension);
|
||||
IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
|
||||
IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
|
||||
|
||||
38
src/main/java/baritone/cache/WorldScanner.java
vendored
38
src/main/java/baritone/cache/WorldScanner.java
vendored
@@ -28,15 +28,15 @@ import net.minecraft.world.chunk.BlockStateContainer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public enum WorldScanner implements IWorldScanner {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private static final int[] DEFAULT_COORDINATE_ITERATION_ORDER = IntStream.range(0, 16).toArray();
|
||||
|
||||
@Override
|
||||
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) {
|
||||
if (blocks.contains(null)) {
|
||||
@@ -53,6 +53,9 @@ public enum WorldScanner implements IWorldScanner {
|
||||
int playerChunkZ = ctx.playerFeet().getZ() >> 4;
|
||||
int playerY = ctx.playerFeet().getY();
|
||||
|
||||
int playerYBlockStateContainerIndex = playerY >> 4;
|
||||
int[] coordinateIterationOrder = IntStream.range(0, 16).boxed().sorted(Comparator.comparingInt(y -> Math.abs(y - playerYBlockStateContainerIndex))).mapToInt(x -> x).toArray();
|
||||
|
||||
int searchRadiusSq = 0;
|
||||
boolean foundWithinY = false;
|
||||
while (true) {
|
||||
@@ -72,7 +75,9 @@ public enum WorldScanner implements IWorldScanner {
|
||||
continue;
|
||||
}
|
||||
allUnloaded = false;
|
||||
scanChunkInto(chunkX << 4, chunkZ << 4, chunk, blocks, res, max, yLevelThreshold, playerY);
|
||||
if (scanChunkInto(chunkX << 4, chunkZ << 4, chunk, blocks, res, max, yLevelThreshold, playerY, coordinateIterationOrder)) {
|
||||
foundWithinY = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((allUnloaded && foundChunks)
|
||||
@@ -100,13 +105,15 @@ public enum WorldScanner implements IWorldScanner {
|
||||
}
|
||||
|
||||
ArrayList<BlockPos> res = new ArrayList<>();
|
||||
scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY);
|
||||
scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY, DEFAULT_COORDINATE_ITERATION_ORDER);
|
||||
return res;
|
||||
}
|
||||
|
||||
public void scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List<Block> search, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY) {
|
||||
private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List<Block> search, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
|
||||
ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray();
|
||||
for (int y0 = 0; y0 < 16; y0++) {
|
||||
boolean foundWithinY = false;
|
||||
for (int yIndex = 0; yIndex < 16; yIndex++) {
|
||||
int y0 = coordinateIterationOrder[yIndex];
|
||||
ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0];
|
||||
if (extendedblockstorage == null) {
|
||||
continue;
|
||||
@@ -121,14 +128,23 @@ public enum WorldScanner implements IWorldScanner {
|
||||
IBlockState state = bsc.get(x, y, z);
|
||||
if (search.contains(state.getBlock())) {
|
||||
int yy = yReal | y;
|
||||
result.add(new BlockPos(chunkX | x, yy, chunkZ | z));
|
||||
if (result.size() >= max && Math.abs(yy - playerY) < yLevelThreshold) {
|
||||
return;
|
||||
if (result.size() >= max) {
|
||||
if (Math.abs(yy - playerY) < yLevelThreshold) {
|
||||
foundWithinY = true;
|
||||
} else {
|
||||
if (foundWithinY) {
|
||||
// have found within Y in this chunk, so don't need to consider outside Y
|
||||
// TODO continue iteration to one more sorted Y coordinate block
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.add(new BlockPos(chunkX | x, yy, chunkZ | z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return foundWithinY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import baritone.api.event.events.*;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
|
||||
@@ -86,8 +86,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch {
|
||||
if (slowPath) {
|
||||
try {
|
||||
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.value);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
} catch (InterruptedException ignored) {}
|
||||
}
|
||||
PathNode currentNode = openSet.removeLowest();
|
||||
mostRecentConsidered = currentNode;
|
||||
|
||||
@@ -22,9 +22,9 @@ import baritone.api.pathing.calc.IPath;
|
||||
import baritone.api.pathing.calc.IPathFinder;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.PathCalculationResult;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.utils.Helper;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -186,7 +186,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper {
|
||||
}
|
||||
|
||||
protected Optional<IPath> bestSoFar(boolean logInfo, int numNodes) {
|
||||
if (startNode == null || bestSoFar == null) {
|
||||
if (startNode == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
double bestDist = 0;
|
||||
|
||||
@@ -21,11 +21,11 @@ import baritone.api.pathing.calc.IPath;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.movement.IMovement;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.Moves;
|
||||
import baritone.pathing.path.CutoffPath;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.pathing.PathBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -96,7 +96,7 @@ class Path extends PathBase {
|
||||
}
|
||||
PathNode current = end;
|
||||
LinkedList<BetterBlockPos> tempPath = new LinkedList<>();
|
||||
LinkedList<PathNode> tempNodes = new LinkedList();
|
||||
LinkedList<PathNode> tempNodes = new LinkedList<>();
|
||||
// Repeatedly inserting to the beginning of an arraylist is O(n^2)
|
||||
// Instead, do it into a linked list, then convert at the end
|
||||
while (current != null) {
|
||||
|
||||
@@ -60,6 +60,7 @@ public class CalculationContext {
|
||||
public final boolean allowJumpAt256;
|
||||
public final boolean assumeWalkOnWater;
|
||||
public final boolean allowDiagonalDescend;
|
||||
public final boolean allowDownward;
|
||||
public final int maxFallHeightNoWater;
|
||||
public final int maxFallHeightBucket;
|
||||
public final double waterWalkSpeed;
|
||||
@@ -91,6 +92,7 @@ public class CalculationContext {
|
||||
this.allowJumpAt256 = Baritone.settings().allowJumpAt256.value;
|
||||
this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.value;
|
||||
this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.value;
|
||||
this.allowDownward = Baritone.settings().allowDownward.value;
|
||||
this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.value;
|
||||
this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.value;
|
||||
int depth = EnchantmentHelper.getDepthStriderModifier(player);
|
||||
|
||||
@@ -17,24 +17,25 @@
|
||||
|
||||
package baritone.pathing.movement;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.pathing.movement.IMovement;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.entity.item.EntityFallingBlock;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Movement implements IMovement, MovementHelper {
|
||||
|
||||
public static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN};
|
||||
public static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN};
|
||||
|
||||
protected final IBaritone baritone;
|
||||
protected final IPlayerContext ctx;
|
||||
@@ -61,6 +62,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||
public List<BlockPos> toPlaceCached = null;
|
||||
public List<BlockPos> toWalkIntoCached = null;
|
||||
|
||||
private Set<BetterBlockPos> validPositionsCached = null;
|
||||
|
||||
private Boolean calculatedWhileLoaded;
|
||||
|
||||
protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
|
||||
@@ -98,6 +101,20 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
protected abstract Set<BetterBlockPos> calculateValidPositions();
|
||||
|
||||
public Set<BetterBlockPos> getValidPositions() {
|
||||
if (validPositionsCached == null) {
|
||||
validPositionsCached = calculateValidPositions();
|
||||
Objects.requireNonNull(validPositionsCached);
|
||||
}
|
||||
return validPositionsCached;
|
||||
}
|
||||
|
||||
protected boolean playerInValidPosition() {
|
||||
return getValidPositions().contains(ctx.playerFeet()) || getValidPositions().contains(((PathingBehavior) baritone.getPathingBehavior()).pathStart());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the execution of the latest Movement
|
||||
* State, and offers a Status to the calling class.
|
||||
@@ -112,6 +129,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||
currentState.setInput(Input.JUMP, true);
|
||||
}
|
||||
if (ctx.player().isEntityInsideOpaqueBlock()) {
|
||||
ctx.getSelectedBlock().ifPresent(pos -> MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, pos)));
|
||||
currentState.setInput(Input.CLICK_LEFT, true);
|
||||
}
|
||||
|
||||
@@ -140,14 +158,17 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||
}
|
||||
boolean somethingInTheWay = false;
|
||||
for (BetterBlockPos blockPos : positionsToBreak) {
|
||||
if (!ctx.world().getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(0, 0, 0, 1, 1.1, 1).offset(blockPos)).isEmpty() && Baritone.settings().pauseMiningForFallingBlocks.value) {
|
||||
return false;
|
||||
}
|
||||
if (!MovementHelper.canWalkThrough(ctx, blockPos) && !(BlockStateInterface.getBlock(ctx, blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try
|
||||
somethingInTheWay = true;
|
||||
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
|
||||
if (reachable.isPresent()) {
|
||||
Rotation rotTowardsBlock = reachable.get();
|
||||
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
||||
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
|
||||
if (Objects.equals(ctx.getSelectedBlock().orElse(null), blockPos) || ctx.playerRotations().isReallyCloseTo(rotTowardsBlock)) {
|
||||
if (ctx.isLookingAt(blockPos) || ctx.playerRotations().isReallyCloseTo(rotTowardsBlock)) {
|
||||
state.setInput(Input.CLICK_LEFT, true);
|
||||
}
|
||||
return false;
|
||||
@@ -270,4 +291,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||
}
|
||||
return toWalkIntoCached;
|
||||
}
|
||||
|
||||
public BlockPos[] toBreakAll() {
|
||||
return positionsToBreak;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import baritone.utils.ToolSet;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
@@ -38,7 +37,7 @@ import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP;
|
||||
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
|
||||
|
||||
/**
|
||||
* Static helpers for cost calculation
|
||||
@@ -52,11 +51,27 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
||||
|| b instanceof BlockSilverfish // obvious reasons
|
||||
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||
|| bsi.get0(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side
|
||||
|| bsi.get0(x + 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| bsi.get0(x - 1, y, z).getBlock() instanceof BlockLiquid
|
||||
|| bsi.get0(x, y, z + 1).getBlock() instanceof BlockLiquid
|
||||
|| bsi.get0(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
||||
|| avoidAdjacentBreaking(bsi, x, y + 1, z, true)
|
||||
|| avoidAdjacentBreaking(bsi, x + 1, y, z, false)
|
||||
|| avoidAdjacentBreaking(bsi, x - 1, y, z, false)
|
||||
|| avoidAdjacentBreaking(bsi, x, y, z + 1, false)
|
||||
|| avoidAdjacentBreaking(bsi, x, y, z - 1, false);
|
||||
}
|
||||
|
||||
static boolean avoidAdjacentBreaking(BlockStateInterface bsi, int x, int y, int z, boolean directlyAbove) {
|
||||
// returns true if you should avoid breaking a block that's adjacent to this one (e.g. lava that will start flowing if you give it a path)
|
||||
// this is only called for north, south, east, west, and up. this is NOT called for down.
|
||||
// we assume that it's ALWAYS okay to break the block thats ABOVE liquid
|
||||
IBlockState state = bsi.get0(x, y, z);
|
||||
Block block = state.getBlock();
|
||||
if (!directlyAbove // it is fine to mine a block that has a falling block directly above, this (the cost of breaking the stacked fallings) is included in cost calculations
|
||||
// therefore if directlyAbove is true, we will actually ignore if this is falling
|
||||
&& block instanceof BlockFalling // obviously, this check is only valid for falling blocks
|
||||
&& Baritone.settings().avoidUpdatingFallingBlocks.value // and if the setting is enabled
|
||||
&& 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
|
||||
}
|
||||
return block instanceof BlockLiquid;
|
||||
}
|
||||
|
||||
static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {
|
||||
@@ -72,7 +87,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (block == Blocks.AIR) { // early return for most common case
|
||||
return true;
|
||||
}
|
||||
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull) {
|
||||
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block instanceof BlockTrapDoor) {
|
||||
return false;
|
||||
}
|
||||
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
|
||||
return false;
|
||||
}
|
||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||
@@ -84,9 +102,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (block == Blocks.CARPET) {
|
||||
return canWalkOn(bsi, x, y - 1, z);
|
||||
}
|
||||
boolean snow = block instanceof BlockSnow;
|
||||
boolean trapdoor = block instanceof BlockTrapDoor;
|
||||
if (snow || trapdoor) {
|
||||
if (block instanceof BlockSnow) {
|
||||
// we've already checked doors and fence gates
|
||||
// so the only remaining dynamic isPassables are snow and trapdoor
|
||||
// if they're cached as a top block, we don't know their metadata
|
||||
@@ -94,19 +110,13 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (!bsi.worldContainsLoadedChunk(x, z)) {
|
||||
return true;
|
||||
}
|
||||
if (snow) {
|
||||
// the check in BlockSnow.isPassable is layers < 5
|
||||
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
|
||||
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
||||
return false;
|
||||
}
|
||||
// ok, it's low enough we could walk through it, but is it supported?
|
||||
return canWalkOn(bsi, x, y - 1, z);
|
||||
// the check in BlockSnow.isPassable is layers < 5
|
||||
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
|
||||
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
||||
return false;
|
||||
}
|
||||
if (trapdoor) {
|
||||
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
// ok, it's low enough we could walk through it, but is it supported?
|
||||
return canWalkOn(bsi, x, y - 1, z);
|
||||
}
|
||||
if (isFlowing(x, y, z, state, bsi)) {
|
||||
return false; // Don't walk through flowing liquids
|
||||
@@ -298,6 +308,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
// if assumeWalkOnWater is off, we can only walk on water if there is water above it
|
||||
return isWater(up) ^ Baritone.settings().assumeWalkOnWater.value;
|
||||
}
|
||||
if (Baritone.settings().assumeWalkOnLava.value && isLava(block) && !isFlowing(x, y, z, state, bsi)) {
|
||||
return true;
|
||||
}
|
||||
if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) {
|
||||
return true;
|
||||
}
|
||||
@@ -317,6 +330,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state);
|
||||
}
|
||||
|
||||
static boolean canWalkOn(IPlayerContext ctx, BlockPos pos) {
|
||||
return canWalkOn(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) {
|
||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
||||
}
|
||||
@@ -351,6 +368,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
||||
Block block = state.getBlock();
|
||||
if (!canWalkThrough(context.bsi, x, y, z, state)) {
|
||||
if (block instanceof BlockLiquid) {
|
||||
return COST_INF;
|
||||
}
|
||||
double mult = context.breakCostMultiplierAt(x, y, z);
|
||||
if (mult >= COST_INF) {
|
||||
return COST_INF;
|
||||
@@ -358,16 +378,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
if (avoidBreaking(context.bsi, x, y, z, state)) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (block instanceof BlockLiquid) {
|
||||
return COST_INF;
|
||||
}
|
||||
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
|
||||
double strVsBlock = context.toolSet.getStrVsBlock(state);
|
||||
if (strVsBlock <= 0) {
|
||||
return COST_INF;
|
||||
}
|
||||
|
||||
double result = m / strVsBlock;
|
||||
double result = 1 / strVsBlock;
|
||||
result += context.breakBlockAdditionalCost;
|
||||
result *= mult;
|
||||
if (includeFalling) {
|
||||
@@ -484,10 +499,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
found = true;
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
|
||||
Helper.HELPER.logDebug("bb pls get me some blocks. dirt or cobble");
|
||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(false, placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
|
||||
Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
|
||||
state.setStatus(MovementStatus.UNREACHABLE);
|
||||
return PlaceResult.NO_OPTION;
|
||||
}
|
||||
@@ -513,10 +528,15 @@ 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))) {
|
||||
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||
return PlaceResult.READY_TO_PLACE;
|
||||
}
|
||||
}
|
||||
return found ? PlaceResult.ATTEMPTING : PlaceResult.NO_OPTION;
|
||||
if (found) {
|
||||
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||
return PlaceResult.ATTEMPTING;
|
||||
}
|
||||
return PlaceResult.NO_OPTION;
|
||||
}
|
||||
|
||||
enum PlaceResult {
|
||||
|
||||
@@ -27,11 +27,14 @@ import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementAscend extends Movement {
|
||||
|
||||
private int ticksWithoutPlacement = 0;
|
||||
@@ -51,6 +54,17 @@ public class MovementAscend extends Movement {
|
||||
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
BetterBlockPos prior = new BetterBlockPos(src.subtract(getDirection()).up()); // sometimes we back up to place the block, also sprint ascends, also skip descend to straight ascend
|
||||
return ImmutableSet.of(src,
|
||||
src.up(),
|
||||
dest,
|
||||
prior,
|
||||
prior.up()
|
||||
);
|
||||
}
|
||||
|
||||
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
||||
IBlockState toPlace = context.get(destX, y, destZ);
|
||||
double additionalPlacementCost = 0;
|
||||
@@ -64,9 +78,9 @@ public class MovementAscend extends Movement {
|
||||
}
|
||||
boolean foundPlaceOption = false;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
||||
int againstY = y + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
|
||||
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
|
||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
||||
int againstY = y + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
|
||||
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
|
||||
if (againstX == x && againstZ == z) { // we might be able to backplace now, but it doesn't matter because it will have been broken by the time we'd need to use it
|
||||
continue;
|
||||
}
|
||||
@@ -143,6 +157,10 @@ public class MovementAscend extends Movement {
|
||||
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
if (ctx.playerFeet().y < src.y) {
|
||||
// this check should run even when in preparing state (breaking blocks)
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
super.updateState(state);
|
||||
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
|
||||
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
|
||||
@@ -154,10 +172,6 @@ public class MovementAscend extends Movement {
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
}
|
||||
|
||||
if (ctx.playerFeet().y < src.y) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
|
||||
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
||||
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
||||
ticksWithoutPlacement++;
|
||||
@@ -198,8 +212,6 @@ public class MovementAscend extends Movement {
|
||||
return state.setInput(Input.JUMP, true);
|
||||
}
|
||||
|
||||
|
||||
// System.out.println(flatDistToNext + " " + sideDist);
|
||||
if (flatDistToNext > 1.2 || sideDist > 0.2) {
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.pathing.MutableMoveResult;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -37,6 +38,8 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementDescend extends Movement {
|
||||
|
||||
private int numTicks = 0;
|
||||
@@ -61,6 +64,11 @@ public class MovementDescend extends Movement {
|
||||
return result.cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
return ImmutableSet.of(src, dest.up(), dest);
|
||||
}
|
||||
|
||||
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
||||
double totalCost = 0;
|
||||
IBlockState destDown = context.get(destX, y - 1, destZ);
|
||||
|
||||
@@ -28,6 +28,7 @@ import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.pathing.MutableMoveResult;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -36,6 +37,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementDiagonal extends Movement {
|
||||
|
||||
@@ -64,6 +66,16 @@ public class MovementDiagonal extends Movement {
|
||||
return result.cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
BetterBlockPos diagA = new BetterBlockPos(src.x, src.y, dest.z);
|
||||
BetterBlockPos diagB = new BetterBlockPos(dest.x, src.y, src.z);
|
||||
if (dest.y != src.y) { // only if allowDiagonalDescend
|
||||
return ImmutableSet.of(src, dest.up(), diagA, diagB, dest, diagA.down(), diagB.down());
|
||||
}
|
||||
return ImmutableSet.of(src, dest, diagA, diagB);
|
||||
}
|
||||
|
||||
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
||||
IBlockState destInto = context.get(destX, y, destZ);
|
||||
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) {
|
||||
@@ -171,8 +183,9 @@ public class MovementDiagonal extends Movement {
|
||||
}
|
||||
|
||||
if (ctx.playerFeet().equals(dest)) {
|
||||
state.setStatus(MovementStatus.SUCCESS);
|
||||
return state;
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
} else if (!playerInValidPosition() && !(MovementHelper.isLiquid(ctx, src) && getValidPositions().contains(ctx.playerFeet().up()))) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
if (sprint()) {
|
||||
state.setInput(Input.SPRINT, true);
|
||||
@@ -181,7 +194,7 @@ public class MovementDiagonal extends Movement {
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean sprint() {
|
||||
private boolean sprint() {
|
||||
if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && !Baritone.settings().sprintInWater.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,10 +24,13 @@ import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementDownward extends Movement {
|
||||
|
||||
private int numTicks = 0;
|
||||
@@ -47,7 +50,15 @@ public class MovementDownward extends Movement {
|
||||
return cost(context, src.x, src.y, src.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
return ImmutableSet.of(src, dest);
|
||||
}
|
||||
|
||||
public static double cost(CalculationContext context, int x, int y, int z) {
|
||||
if (!context.allowDownward) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (!MovementHelper.canWalkOn(context.bsi, x, y - 2, z)) {
|
||||
return COST_INF;
|
||||
}
|
||||
@@ -70,6 +81,8 @@ public class MovementDownward extends Movement {
|
||||
|
||||
if (ctx.playerFeet().equals(dest)) {
|
||||
return state.setStatus(MovementStatus.SUCCESS);
|
||||
} else if (!playerInValidPosition()) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
double diffX = ctx.player().posX - (dest.getX() + 0.5);
|
||||
double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
|
||||
|
||||
@@ -39,11 +39,12 @@ import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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.util.math.Vec3i;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementFall extends Movement {
|
||||
|
||||
@@ -64,6 +65,16 @@ public class MovementFall extends Movement {
|
||||
return result.cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
Set<BetterBlockPos> set = new HashSet<>();
|
||||
set.add(src);
|
||||
for (int y = src.y - dest.y; y >= 0; y--) {
|
||||
set.add(dest.up(y));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private boolean willPlaceBucket() {
|
||||
CalculationContext context = new CalculationContext(baritone);
|
||||
MutableMoveResult result = new MutableMoveResult();
|
||||
@@ -92,8 +103,7 @@ public class MovementFall extends Movement {
|
||||
|
||||
targetRotation = new Rotation(toDest.getYaw(), 90.0F);
|
||||
|
||||
RayTraceResult trace = ctx.objectMouseOver();
|
||||
if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK && (trace.getBlockPos().equals(dest) || trace.getBlockPos().equals(dest.down()))) {
|
||||
if (ctx.isLookingAt(dest) || ctx.isLookingAt(dest.down())) {
|
||||
state.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementParkour extends Movement {
|
||||
|
||||
private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
|
||||
@@ -106,7 +109,9 @@ public class MovementParkour extends Movement {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i)) {
|
||||
IBlockState landingOn = context.bsi.get0(x + xDiff * i, y - 1, z + zDiff * i);
|
||||
// farmland needs to be canwalkon otherwise farm can never work at all, but we want to specifically disallow ending a jumy on farmland haha
|
||||
if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i, landingOn)) {
|
||||
res.x = x + xDiff * i;
|
||||
res.y = y;
|
||||
res.z = z + zDiff * i;
|
||||
@@ -132,9 +137,9 @@ public class MovementParkour extends Movement {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
||||
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
|
||||
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
|
||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
||||
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
|
||||
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
|
||||
if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast
|
||||
continue;
|
||||
}
|
||||
@@ -172,6 +177,17 @@ public class MovementParkour extends Movement {
|
||||
return res.cost;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
Set<BetterBlockPos> set = new HashSet<>();
|
||||
for (int i = 0; i <= dist; i++) {
|
||||
for (int y = 0; y < 2; y++) {
|
||||
set.add(src.offset(direction, i).up(y));
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean safeToCancel(MovementState state) {
|
||||
// once this movement is instantiated, the state is default to PREPPING
|
||||
|
||||
@@ -30,6 +30,7 @@ import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -37,7 +38,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementPillar extends Movement {
|
||||
|
||||
@@ -50,6 +51,11 @@ public class MovementPillar extends Movement {
|
||||
return cost(context, src.x, src.y, src.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
return ImmutableSet.of(src, dest);
|
||||
}
|
||||
|
||||
public static double cost(CalculationContext context, int x, int y, int z) {
|
||||
Block from = context.get(x, y, z).getBlock();
|
||||
boolean ladder = from == Blocks.LADDER || from == Blocks.VINE;
|
||||
@@ -208,7 +214,7 @@ public class MovementPillar extends Movement {
|
||||
return state;
|
||||
} else {
|
||||
// Get ready to place a throwaway block
|
||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(src.x, src.y, src.z)) {
|
||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, src.x, src.y, src.z)) {
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
|
||||
@@ -240,10 +246,9 @@ public class MovementPillar extends Movement {
|
||||
Block fr = frState.getBlock();
|
||||
// TODO: Evaluate usage of getMaterial().isReplaceable()
|
||||
if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) {
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance());
|
||||
if (reachable.isPresent()) {
|
||||
state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
|
||||
}
|
||||
RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance())
|
||||
.map(rot -> new MovementState.MovementTarget(rot, true))
|
||||
.ifPresent(state::setTarget);
|
||||
state.setInput(Input.JUMP, false); // breaking is like 5x slower when you're jumping
|
||||
state.setInput(Input.CLICK_LEFT, true);
|
||||
blockIsThere = false;
|
||||
|
||||
@@ -30,16 +30,14 @@ import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class MovementTraverse extends Movement {
|
||||
|
||||
@@ -63,6 +61,11 @@ public class MovementTraverse extends Movement {
|
||||
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||
return ImmutableSet.of(src, dest);
|
||||
}
|
||||
|
||||
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
||||
IBlockState pb0 = context.get(destX, y + 1, destZ);
|
||||
IBlockState pb1 = context.get(destX, y, destZ);
|
||||
@@ -124,9 +127,9 @@ public class MovementTraverse extends Movement {
|
||||
double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break
|
||||
double WC = throughWater ? context.waterWalkSpeed : WALK_ONE_BLOCK_COST;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
||||
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
|
||||
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
|
||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
||||
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
|
||||
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
|
||||
if (againstX == x && againstZ == z) { // this would be a backplace
|
||||
continue;
|
||||
}
|
||||
@@ -151,6 +154,8 @@ public class MovementTraverse extends Movement {
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
|
||||
IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
|
||||
if (state.getStatus() != MovementStatus.RUNNING) {
|
||||
// if the setting is enabled
|
||||
if (!Baritone.settings().walkWhileBreaking.value) {
|
||||
@@ -161,10 +166,10 @@ public class MovementTraverse extends Movement {
|
||||
return state;
|
||||
}
|
||||
// and if it's fine to walk into the blocks in front
|
||||
if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[0]).getBlock())) {
|
||||
if (MovementHelper.avoidWalkingInto(pb0.getBlock())) {
|
||||
return state;
|
||||
}
|
||||
if (MovementHelper.avoidWalkingInto(BlockStateInterface.get(ctx, positionsToBreak[1]).getBlock())) {
|
||||
if (MovementHelper.avoidWalkingInto(pb1.getBlock())) {
|
||||
return state;
|
||||
}
|
||||
// and we aren't already pressed up against the block
|
||||
@@ -172,14 +177,23 @@ public class MovementTraverse extends Movement {
|
||||
if (dist < 0.83) {
|
||||
return state;
|
||||
}
|
||||
if (!state.getTarget().getRotation().isPresent()) {
|
||||
// this can happen rarely when the server lags and doesn't send the falling sand entity until you've already walked through the block and are now mining the next one
|
||||
return state;
|
||||
}
|
||||
|
||||
// combine the yaw to the center of the destination, and the pitch to the specific block we're trying to break
|
||||
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
|
||||
float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();
|
||||
float pitchToBreak = state.getTarget().getRotation().get().getPitch();
|
||||
if ((pb0.isFullCube() || pb0.getBlock() instanceof BlockAir && (pb1.isFullCube() || pb1.getBlock() instanceof BlockAir))) {
|
||||
// in the meantime, before we're right up against the block, we can break efficiently at this angle
|
||||
pitchToBreak = 26;
|
||||
}
|
||||
|
||||
state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true));
|
||||
return state.setInput(Input.MOVE_FORWARD, true).setInput(Input.SPRINT, true);
|
||||
return state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true))
|
||||
.setInput(Input.MOVE_FORWARD, true)
|
||||
.setInput(Input.SPRINT, true);
|
||||
}
|
||||
|
||||
//sneak may have been set to true in the PREPPING state while mining an adjacent block
|
||||
@@ -187,31 +201,19 @@ public class MovementTraverse extends Movement {
|
||||
|
||||
Block fd = BlockStateInterface.get(ctx, src.down()).getBlock();
|
||||
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
|
||||
IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
|
||||
IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
|
||||
|
||||
boolean door = pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor;
|
||||
if (door) {
|
||||
boolean isDoorActuallyBlockingUs = false;
|
||||
if (pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, src, dest)) {
|
||||
isDoorActuallyBlockingUs = true;
|
||||
} else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, dest, src)) {
|
||||
isDoorActuallyBlockingUs = true;
|
||||
}
|
||||
if (isDoorActuallyBlockingUs && !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
|
||||
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), positionsToBreak[0]), ctx.playerRotations()), true))
|
||||
.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
if ((pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor)
|
||||
&& (pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, src, dest)
|
||||
|| pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, dest, src))
|
||||
&& !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
|
||||
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), positionsToBreak[0]), ctx.playerRotations()), true))
|
||||
.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
|
||||
if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
|
||||
BlockPos blocked = null;
|
||||
if (!MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up())) {
|
||||
blocked = positionsToBreak[0];
|
||||
} else if (!MovementHelper.isGatePassable(ctx, positionsToBreak[1], src)) {
|
||||
blocked = positionsToBreak[1];
|
||||
}
|
||||
|
||||
BlockPos blocked = !MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up()) ? positionsToBreak[0]
|
||||
: !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1]
|
||||
: null;
|
||||
if (blocked != null) {
|
||||
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), blocked), ctx.playerRotations()), true))
|
||||
.setInput(Input.CLICK_RIGHT, true);
|
||||
@@ -219,22 +221,25 @@ public class MovementTraverse extends Movement {
|
||||
}
|
||||
|
||||
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder;
|
||||
BlockPos whereAmI = ctx.playerFeet();
|
||||
if (whereAmI.getY() != dest.getY() && !ladder) {
|
||||
BlockPos feet = ctx.playerFeet();
|
||||
if (feet.getY() != dest.getY() && !ladder) {
|
||||
logDebug("Wrong Y coordinate");
|
||||
if (whereAmI.getY() < dest.getY()) {
|
||||
state.setInput(Input.JUMP, true);
|
||||
if (feet.getY() < dest.getY()) {
|
||||
return state.setInput(Input.JUMP, true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
if (isTheBridgeBlockThere) {
|
||||
if (ctx.playerFeet().equals(dest)) {
|
||||
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();
|
||||
Block high = BlockStateInterface.get(ctx, src.up()).getBlock();
|
||||
if (!ctx.player().onGround && (low == Blocks.VINE || low == Blocks.LADDER || high == Blocks.VINE || high == Blocks.LADDER)) {
|
||||
if (ctx.player().posY > src.y + 0.1D && !ctx.player().onGround && (low == Blocks.VINE || low == Blocks.LADDER || high == Blocks.VINE || high == Blocks.LADDER)) {
|
||||
// hitting W could cause us to climb the ladder instead of going forward
|
||||
// wait until we're on the ground
|
||||
return state;
|
||||
@@ -242,19 +247,20 @@ public class MovementTraverse extends Movement {
|
||||
BlockPos into = dest.subtract(src).add(dest);
|
||||
Block intoBelow = BlockStateInterface.get(ctx, into).getBlock();
|
||||
Block intoAbove = BlockStateInterface.get(ctx, into.up()).getBlock();
|
||||
if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, ctx.playerFeet()) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
|
||||
if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, feet) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
|
||||
state.setInput(Input.SPRINT, true);
|
||||
}
|
||||
Block destDown = BlockStateInterface.get(ctx, dest.down()).getBlock();
|
||||
if (whereAmI.getY() != dest.getY() && ladder && (destDown == Blocks.VINE || destDown == Blocks.LADDER)) {
|
||||
new MovementPillar(baritone, dest.down(), dest).updateState(state); // i'm sorry
|
||||
return state;
|
||||
|
||||
IBlockState destDown = BlockStateInterface.get(ctx, dest.down());
|
||||
BlockPos against = positionsToBreak[0];
|
||||
if (feet.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) {
|
||||
against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.getValue(BlockLadder.FACING).getOpposite());
|
||||
}
|
||||
MovementHelper.moveTowards(ctx, state, positionsToBreak[0]);
|
||||
MovementHelper.moveTowards(ctx, state, against);
|
||||
return state;
|
||||
} else {
|
||||
wasTheBridgeBlockAlwaysThere = false;
|
||||
Block standingOn = BlockStateInterface.get(ctx, ctx.playerFeet().down()).getBlock();
|
||||
Block standingOn = BlockStateInterface.get(ctx, feet.down()).getBlock();
|
||||
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118
|
||||
double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().posX), Math.abs(dest.getZ() + 0.5 - ctx.player().posZ));
|
||||
if (dist < 0.85) { // 0.5 + 0.3 + epsilon
|
||||
@@ -292,7 +298,7 @@ public class MovementTraverse extends Movement {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (whereAmI.equals(dest)) {
|
||||
if (feet.equals(dest)) {
|
||||
// If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
|
||||
// Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
|
||||
double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D;
|
||||
@@ -311,7 +317,7 @@ public class MovementTraverse extends Movement {
|
||||
} else {
|
||||
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
||||
}
|
||||
if (Objects.equals(ctx.getSelectedBlock().orElse(null), goalLook)) {
|
||||
if (ctx.isLookingAt(goalLook)) {
|
||||
return state.setInput(Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
||||
}
|
||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
|
||||
@@ -23,10 +23,7 @@ import baritone.api.pathing.movement.ActionCosts;
|
||||
import baritone.api.pathing.movement.IMovement;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.pathing.path.IPathExecutor;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.VecUtils;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||
@@ -35,9 +32,7 @@ import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.movements.*;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -104,14 +99,13 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
if (pathPosition >= path.length()) {
|
||||
return true; // stop bugging me, I'm done
|
||||
}
|
||||
BetterBlockPos whereShouldIBe = path.positions().get(pathPosition);
|
||||
Movement movement = (Movement) path.movements().get(pathPosition);
|
||||
BetterBlockPos whereAmI = ctx.playerFeet();
|
||||
if (!whereShouldIBe.equals(whereAmI) && !Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip
|
||||
for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
|
||||
if (whereAmI.equals(path.positions().get(i))) {
|
||||
logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i);
|
||||
if (!movement.getValidPositions().contains(whereAmI)) {
|
||||
for (int i = 0; i < pathPosition && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
|
||||
if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
|
||||
int previousPos = pathPosition;
|
||||
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
|
||||
pathPosition = i;
|
||||
for (int j = pathPosition; j <= previousPos; j++) {
|
||||
path.movements().get(j).reset();
|
||||
}
|
||||
@@ -120,9 +114,9 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int i = pathPosition + 3; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing)
|
||||
for (int i = pathPosition + 3; i < path.length() - 1; i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing)
|
||||
// also don't check pathPosition+2 because reasons
|
||||
if (whereAmI.equals(path.positions().get(i))) {
|
||||
if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
|
||||
if (i - pathPosition > 2) {
|
||||
logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i);
|
||||
}
|
||||
@@ -151,38 +145,6 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
cancel();
|
||||
return false;
|
||||
}
|
||||
//this commented block is literally cursed.
|
||||
/*Out.log(actions.get(pathPosition));
|
||||
if (pathPosition < actions.size() - 1) {//if there are two ActionBridges in a row and they are at right angles, walk diagonally. This makes it so you walk at 45 degrees along a zigzag path instead of doing inefficient zigging and zagging
|
||||
if ((actions.get(pathPosition) instanceof ActionBridge) && (actions.get(pathPosition + 1) instanceof ActionBridge)) {
|
||||
ActionBridge curr = (ActionBridge) actions.get(pathPosition);
|
||||
ActionBridge next = (ActionBridge) actions.get(pathPosition + 1);
|
||||
if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two movement are not parallel, so this is a right angle
|
||||
if (curr.amIGood() && next.amIGood()) {//nothing in the way
|
||||
BlockPos cornerToCut1 = new BlockPos(next.to.getX() - next.from.getX() + curr.from.getX(), next.to.getY(), next.to.getZ() - next.from.getZ() + curr.from.getZ());
|
||||
BlockPos cornerToCut2 = cornerToCut1.up();
|
||||
//Block corner1 = Baritone.get(cornerToCut1).getBlock();
|
||||
//Block corner2 = Baritone.get(cornerToCut2).getBlock();
|
||||
//Out.gui("Cutting conner " + cornerToCut1 + " " + corner1, Out.Mode.Debug);
|
||||
if (!Action.avoidWalkingInto(cornerToCut1) && !Action.avoidWalkingInto(cornerToCut2)) {
|
||||
double x = (next.from.getX() + next.to.getX() + 1.0D) * 0.5D;
|
||||
double z = (next.from.getZ() + next.to.getZ() + 1.0D) * 0.5D;
|
||||
MovementManager.clearMovement();
|
||||
if (!MovementManager.forward && curr.oneInTen != null && curr.oneInTen) {
|
||||
MovementManager.clearMovement();
|
||||
MovementManager.forward = LookManager.lookAtCoords(x, 0, z, false);
|
||||
} else {
|
||||
MovementManager.moveTowardsCoords(x, 0, z);
|
||||
}
|
||||
if (MovementManager.forward && !MovementManager.backward) {
|
||||
thePlayer.setSprinting(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//long start = System.nanoTime() / 1000000L;
|
||||
BlockStateInterface bsi = new BlockStateInterface(ctx);
|
||||
for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
|
||||
@@ -209,10 +171,10 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
HashSet<BlockPos> newPlace = new HashSet<>();
|
||||
HashSet<BlockPos> newWalkInto = new HashSet<>();
|
||||
for (int i = pathPosition; i < path.movements().size(); i++) {
|
||||
Movement movement = (Movement) path.movements().get(i);
|
||||
newBreak.addAll(movement.toBreak(bsi));
|
||||
newPlace.addAll(movement.toPlace(bsi));
|
||||
newWalkInto.addAll(movement.toWalkInto(bsi));
|
||||
Movement m = (Movement) path.movements().get(i);
|
||||
newBreak.addAll(m.toBreak(bsi));
|
||||
newPlace.addAll(m.toPlace(bsi));
|
||||
newWalkInto.addAll(m.toWalkInto(bsi));
|
||||
}
|
||||
toBreak = newBreak;
|
||||
toPlace = newPlace;
|
||||
@@ -223,7 +185,14 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
if (end - start > 0) {
|
||||
System.out.println("Recalculating break and place took " + (end - start) + "ms");
|
||||
}*/
|
||||
IMovement movement = path.movements().get(pathPosition);
|
||||
if (pathPosition < path.movements().size() - 1) {
|
||||
IMovement next = path.movements().get(pathPosition + 1);
|
||||
if (!behavior.baritone.bsi.worldContainsLoadedChunk(next.getDest().x, next.getDest().z)) {
|
||||
logDebug("Pausing since destination is at edge of loaded chunks");
|
||||
clearKeys();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
boolean canCancel = movement.safeToCancel();
|
||||
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
||||
costEstimateIndex = pathPosition;
|
||||
@@ -237,7 +206,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
}
|
||||
}
|
||||
}
|
||||
double currentCost = ((Movement) movement).recalculateCost(behavior.secretInternalGetCalculationContext());
|
||||
double currentCost = movement.recalculateCost(behavior.secretInternalGetCalculationContext());
|
||||
if (currentCost >= ActionCosts.COST_INF && canCancel) {
|
||||
logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||
cancel();
|
||||
@@ -289,11 +258,13 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
private Tuple<Double, BlockPos> closestPathPos(IPath path) {
|
||||
double best = -1;
|
||||
BlockPos bestPos = null;
|
||||
for (BlockPos pos : path.positions()) {
|
||||
double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos);
|
||||
if (dist < best || best == -1) {
|
||||
best = dist;
|
||||
bestPos = pos;
|
||||
for (IMovement movement : path.movements()) {
|
||||
for (BlockPos pos : ((Movement) movement).getValidPositions()) {
|
||||
double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos);
|
||||
if (dist < best || best == -1) {
|
||||
best = dist;
|
||||
bestPos = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Tuple<>(best, bestPos);
|
||||
@@ -441,7 +412,10 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
IMovement prev = path.movements().get(pathPosition - 1);
|
||||
if (prev instanceof MovementDescend && prev.getDirection().up().equals(current.getDirection().down())) {
|
||||
BlockPos center = current.getSrc().up();
|
||||
if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand
|
||||
// playerFeet adds 0.1251 to account for soul sand
|
||||
// farmland is 0.9375
|
||||
// 0.07 is to account for farmland
|
||||
if (ctx.player().posY >= center.getY() - 0.07) {
|
||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
|
||||
return true;
|
||||
}
|
||||
@@ -566,7 +540,10 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) {
|
||||
return true;
|
||||
}
|
||||
if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(ctx, next.getDest().down())) {
|
||||
if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) {
|
||||
return false;
|
||||
}
|
||||
if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) {
|
||||
return true;
|
||||
}
|
||||
return next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.value;
|
||||
@@ -608,7 +585,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
ret.costEstimateIndex = costEstimateIndex;
|
||||
ret.ticksOnCurrent = ticksOnCurrent;
|
||||
return ret;
|
||||
}).orElse(cutIfTooLong());
|
||||
}).orElseGet(this::cutIfTooLong); // dont actually call cutIfTooLong every tick if we won't actually use it, use a method reference
|
||||
}
|
||||
|
||||
private PathExecutor cutIfTooLong() {
|
||||
|
||||
143
src/main/java/baritone/process/BackfillProcess.java
Normal file
143
src/main/java/baritone/process/BackfillProcess.java
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.process;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.Movement;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.pathing.movement.MovementState;
|
||||
import baritone.pathing.path.PathExecutor;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.EmptyChunk;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class BackfillProcess extends BaritoneProcessHelper {
|
||||
|
||||
public HashMap<BlockPos, IBlockState> blocksToReplace = new HashMap<>();
|
||||
|
||||
public BackfillProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
if (ctx.player() == null || ctx.world() == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Baritone.settings().backfill.value) {
|
||||
return false;
|
||||
}
|
||||
if (Baritone.settings().allowParkour.value) {
|
||||
logDirect("Backfill cannot be used with allowParkour true");
|
||||
Baritone.settings().backfill.value = false;
|
||||
return false;
|
||||
}
|
||||
amIBreakingABlockHMMMMMMM();
|
||||
for (BlockPos pos : new ArrayList<>(blocksToReplace.keySet())) {
|
||||
if (ctx.world().getChunk(pos) instanceof EmptyChunk) {
|
||||
blocksToReplace.remove(pos);
|
||||
}
|
||||
}
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
|
||||
return !toFillIn().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
if (!isSafeToCancel) {
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
for (BlockPos toPlace : toFillIn()) {
|
||||
MovementState fake = new MovementState();
|
||||
switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false)) {
|
||||
case NO_OPTION:
|
||||
continue;
|
||||
case READY_TO_PLACE:
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
case ATTEMPTING:
|
||||
// patience
|
||||
baritone.getLookBehavior().updateTarget(fake.getTarget().getRotation().get(), true);
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.DEFER); // cede to other process
|
||||
}
|
||||
|
||||
public void amIBreakingABlockHMMMMMMM() {
|
||||
if (!ctx.getSelectedBlock().isPresent()) {
|
||||
return;
|
||||
}
|
||||
blocksToReplace.put(ctx.getSelectedBlock().get(), ctx.world().getBlockState(ctx.getSelectedBlock().get()));
|
||||
}
|
||||
|
||||
public List<BlockPos> toFillIn() {
|
||||
return blocksToReplace
|
||||
.keySet()
|
||||
.stream()
|
||||
.filter(pos -> ctx.world().getBlockState(pos).getBlock() == Blocks.AIR)
|
||||
.filter(pos -> ctx.world().mayPlace(Blocks.DIRT, pos, false, EnumFacing.UP, null))
|
||||
.filter(pos -> !partOfCurrentMovement(pos))
|
||||
.sorted(Comparator.<BlockPos>comparingDouble(ctx.player()::getDistanceSq).reversed())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean partOfCurrentMovement(BlockPos pos) {
|
||||
PathExecutor exec = baritone.getPathingBehavior().getCurrent();
|
||||
if (exec == null || exec.finished() || exec.failed()) {
|
||||
return false;
|
||||
}
|
||||
Movement movement = (Movement) exec.getPath().movements().get(exec.getPosition());
|
||||
return Arrays.asList(movement.toBreakAll()).contains(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLostControl() {
|
||||
if (blocksToReplace != null && !blocksToReplace.isEmpty()) {
|
||||
blocksToReplace.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayName0() {
|
||||
return "Backfill";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double priority() {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,10 @@ import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.PathingCommandContext;
|
||||
import baritone.utils.schematic.AirSchematic;
|
||||
import baritone.utils.schematic.Schematic;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -50,33 +52,42 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||
|
||||
public class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
|
||||
|
||||
public BuilderProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
public final class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
|
||||
|
||||
private HashSet<BetterBlockPos> incorrectPositions;
|
||||
private LongOpenHashSet observedCompleted; // positions that are completed even if they're out of render distance and we can't make sure right now
|
||||
private String name;
|
||||
private ISchematic realSchematic;
|
||||
private ISchematic schematic;
|
||||
private Vec3i origin;
|
||||
private int ticks;
|
||||
private boolean paused;
|
||||
private int layer;
|
||||
|
||||
public boolean build(String schematicFile, BlockPos origin) {
|
||||
File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile);
|
||||
System.out.println(file + " " + file.exists());
|
||||
return build(schematicFile, file, origin);
|
||||
public BuilderProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(String name, ISchematic schematic, Vec3i origin) {
|
||||
this.name = name;
|
||||
this.schematic = schematic;
|
||||
this.realSchematic = null;
|
||||
this.origin = origin;
|
||||
this.paused = false;
|
||||
this.layer = 0;
|
||||
this.observedCompleted = new LongOpenHashSet();
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
paused = false;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
paused = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,21 +137,24 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
public Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
|
||||
private Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
|
||||
BetterBlockPos center = ctx.playerFeet();
|
||||
BetterBlockPos pathStart = baritone.getPathingBehavior().pathStart();
|
||||
for (int dx = -5; dx <= 5; dx++) {
|
||||
for (int dy = 0; dy <= 5; dy++) {
|
||||
for (int dy = Baritone.settings().breakFromAbove.value ? -1 : 0; dy <= 5; dy++) {
|
||||
for (int dz = -5; dz <= 5; dz++) {
|
||||
int x = center.x + dx;
|
||||
int y = center.y + dy;
|
||||
int z = center.z + dz;
|
||||
if (dy == -1 && x == pathStart.x && z == pathStart.z) {
|
||||
continue; // dont mine what we're supported by, but not directly standing on
|
||||
}
|
||||
IBlockState desired = bcc.getSchematic(x, y, z);
|
||||
if (desired == null) {
|
||||
continue; // irrelevant
|
||||
}
|
||||
IBlockState curr = bcc.bsi.get0(x, y, z);
|
||||
if (curr.getBlock() != Blocks.AIR && !valid(curr, desired)) {
|
||||
if (curr.getBlock() != Blocks.AIR && !(curr.getBlock() instanceof BlockLiquid) && !valid(curr, desired)) {
|
||||
BetterBlockPos pos = new BetterBlockPos(x, y, z);
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
|
||||
if (rot.isPresent()) {
|
||||
@@ -154,10 +168,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
}
|
||||
|
||||
public class Placement {
|
||||
final int hotbarSelection;
|
||||
final BlockPos placeAgainst;
|
||||
final EnumFacing side;
|
||||
final Rotation rot;
|
||||
private final int hotbarSelection;
|
||||
private final BlockPos placeAgainst;
|
||||
private final EnumFacing side;
|
||||
private final Rotation rot;
|
||||
|
||||
public Placement(int hotbarSelection, BlockPos placeAgainst, EnumFacing side, Rotation rot) {
|
||||
this.hotbarSelection = hotbarSelection;
|
||||
@@ -167,7 +181,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
|
||||
private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
|
||||
BetterBlockPos center = ctx.playerFeet();
|
||||
for (int dx = -5; dx <= 5; dx++) {
|
||||
for (int dy = -5; dy <= 1; dy++) {
|
||||
@@ -196,7 +210,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
|
||||
private Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
|
||||
for (EnumFacing against : EnumFacing.values()) {
|
||||
BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
|
||||
IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
|
||||
@@ -224,8 +238,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
public OptionalInt hasAnyItemThatWouldPlace(IBlockState desired, RayTraceResult result, Rotation rot) {
|
||||
private OptionalInt hasAnyItemThatWouldPlace(IBlockState desired, RayTraceResult result, Rotation rot) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
|
||||
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
|
||||
@@ -269,34 +282,86 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
double z = side.getZOffset() == 0 ? 0.5 : (1 + side.getZOffset()) / 2D;
|
||||
return new Vec3d[]{new Vec3d(x, 0.25, z), new Vec3d(x, 0.75, z)};
|
||||
default: // null
|
||||
throw new NullPointerException();
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
// TODO somehow tell inventorybehavior what we'd like to have on the hotbar
|
||||
// perhaps take the 16 closest positions in incorrectPositions to ctx.playerFeet that aren't desired to be air, and then snag the top 4 most common block states, then request those on the hotbar
|
||||
|
||||
|
||||
// this will work as is, but it'll be trashy
|
||||
// need to iterate over incorrectPositions and see which ones we can "correct" from our current standing position
|
||||
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
BuilderCalculationContext bcc = new BuilderCalculationContext();
|
||||
if (!recalc(bcc)) {
|
||||
logDirect("Done building");
|
||||
onLostControl();
|
||||
return null;
|
||||
}
|
||||
trim(bcc);
|
||||
if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
|
||||
ticks = 5;
|
||||
} else {
|
||||
ticks--;
|
||||
}
|
||||
Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
if (paused) {
|
||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
if (Baritone.settings().buildInLayers.value) {
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int heightY() {
|
||||
return realSchematic.heightY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lengthZ() {
|
||||
return realSchematic.lengthZ();
|
||||
}
|
||||
};
|
||||
}
|
||||
BuilderCalculationContext bcc = new BuilderCalculationContext();
|
||||
if (!recalc(bcc)) {
|
||||
if (Baritone.settings().buildInLayers.value && layer < realSchematic.heightY()) {
|
||||
logDirect("Starting layer " + layer);
|
||||
layer++;
|
||||
return onTick(calcFailed, isSafeToCancel);
|
||||
}
|
||||
Vec3i repeat = Baritone.settings().buildRepeat.value;
|
||||
if (repeat.equals(new Vec3i(0, 0, 0))) {
|
||||
logDirect("Done building");
|
||||
onLostControl();
|
||||
return null;
|
||||
}
|
||||
// build repeat time
|
||||
layer = 0;
|
||||
origin = new BlockPos(origin).add(repeat);
|
||||
logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
|
||||
return onTick(calcFailed, isSafeToCancel);
|
||||
}
|
||||
trim();
|
||||
|
||||
Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
|
||||
if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
|
||||
// we'd like to pause to break this block
|
||||
// only change look direction if it's safe (don't want to fuck up an in progress parkour for example
|
||||
@@ -310,10 +375,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
// and is unable since it's unsneaked in the intermediary tick
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
|
||||
}
|
||||
if (Objects.equals(ctx.objectMouseOver().getBlockPos(), pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
||||
if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
List<IBlockState> desirableOnHotbar = new ArrayList<>();
|
||||
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
|
||||
@@ -322,10 +387,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
baritone.getLookBehavior().updateTarget(rot, true);
|
||||
ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
|
||||
if ((Objects.equals(ctx.objectMouseOver().getBlockPos(), toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
||||
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
|
||||
List<IBlockState> approxPlacable = placable(36);
|
||||
@@ -359,15 +424,15 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
if (goal == null) {
|
||||
goal = assemble(bcc, approxPlacable); // we're far away, so assume that we have our whole inventory to recalculate placable properly
|
||||
if (goal == null) {
|
||||
logDirect("Unable to do it =(");
|
||||
onLostControl();
|
||||
return null;
|
||||
logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
|
||||
paused = true;
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
}
|
||||
return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
|
||||
}
|
||||
|
||||
public boolean recalc(BuilderCalculationContext bcc) {
|
||||
private boolean recalc(BuilderCalculationContext bcc) {
|
||||
if (incorrectPositions == null) {
|
||||
incorrectPositions = new HashSet<>();
|
||||
fullRecalc(bcc);
|
||||
@@ -382,7 +447,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
return !incorrectPositions.isEmpty();
|
||||
}
|
||||
|
||||
public void trim(BuilderCalculationContext bcc) {
|
||||
private void trim() {
|
||||
HashSet<BetterBlockPos> copy = new HashSet<>(incorrectPositions);
|
||||
copy.removeIf(pos -> pos.distanceSq(ctx.player().posX, ctx.player().posY, ctx.player().posZ) > 200);
|
||||
if (!copy.isEmpty()) {
|
||||
@@ -390,7 +455,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
}
|
||||
}
|
||||
|
||||
public void recalcNearby(BuilderCalculationContext bcc) {
|
||||
private void recalcNearby(BuilderCalculationContext bcc) {
|
||||
BetterBlockPos center = ctx.playerFeet();
|
||||
for (int dx = -5; dx <= 5; dx++) {
|
||||
for (int dy = -5; dy <= 5; dy++) {
|
||||
@@ -401,10 +466,13 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
IBlockState desired = bcc.getSchematic(x, y, z);
|
||||
if (desired != null) {
|
||||
// we care about this position
|
||||
BetterBlockPos pos = new BetterBlockPos(x, y, z);
|
||||
if (valid(bcc.bsi.get0(x, y, z), desired)) {
|
||||
incorrectPositions.remove(new BetterBlockPos(x, y, z));
|
||||
incorrectPositions.remove(pos);
|
||||
observedCompleted.add(BetterBlockPos.longHash(pos));
|
||||
} else {
|
||||
incorrectPositions.add(new BetterBlockPos(x, y, z));
|
||||
incorrectPositions.add(pos);
|
||||
observedCompleted.remove(BetterBlockPos.longHash(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,15 +480,32 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
}
|
||||
}
|
||||
|
||||
public void fullRecalc(BuilderCalculationContext bcc) {
|
||||
private void fullRecalc(BuilderCalculationContext bcc) {
|
||||
incorrectPositions = new HashSet<>();
|
||||
for (int y = 0; y < schematic.heightY(); y++) {
|
||||
for (int z = 0; z < schematic.lengthZ(); z++) {
|
||||
for (int x = 0; x < schematic.widthX(); x++) {
|
||||
if (schematic.inSchematic(x, y, z)) {
|
||||
if (!valid(bcc.bsi.get0(x + origin.getX(), y + origin.getY(), z + origin.getZ()), schematic.desiredState(x, y, z))) {
|
||||
incorrectPositions.add(new BetterBlockPos(x + origin.getX(), y + origin.getY(), z + origin.getZ()));
|
||||
if (!schematic.inSchematic(x, y, z)) {
|
||||
continue;
|
||||
}
|
||||
int blockX = x + origin.getX();
|
||||
int blockY = y + origin.getY();
|
||||
int blockZ = z + origin.getZ();
|
||||
if (bcc.bsi.worldContainsLoadedChunk(blockX, blockZ)) { // check if its in render distance, not if its in cache
|
||||
// we can directly observe this block, it is in render distance
|
||||
if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z))) {
|
||||
observedCompleted.add(BetterBlockPos.longHash(blockX, blockY, blockZ));
|
||||
} else {
|
||||
incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
|
||||
observedCompleted.remove(BetterBlockPos.longHash(blockX, blockY, blockZ));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// this is not in render distance
|
||||
if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ))) {
|
||||
// and we've never seen this position be correct
|
||||
// therefore mark as incorrect
|
||||
incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,17 +513,45 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
}
|
||||
|
||||
private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlacable) {
|
||||
List<BetterBlockPos> placable = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() == Blocks.AIR && approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))).collect(Collectors.toList());
|
||||
Goal[] toBreak = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() != Blocks.AIR).map(GoalBreak::new).toArray(Goal[]::new);
|
||||
Goal[] toPlace = placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(pos -> placementgoal(pos, bcc)).toArray(Goal[]::new);
|
||||
List<BetterBlockPos> placable = new ArrayList<>();
|
||||
List<BetterBlockPos> breakable = new ArrayList<>();
|
||||
List<BetterBlockPos> sourceLiquids = new ArrayList<>();
|
||||
incorrectPositions.forEach(pos -> {
|
||||
IBlockState state = bcc.bsi.get0(pos);
|
||||
if (state.getBlock() instanceof BlockAir) {
|
||||
if (approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))) {
|
||||
placable.add(pos);
|
||||
}
|
||||
} else {
|
||||
if (state.getBlock() instanceof BlockLiquid) {
|
||||
// if the block itself is JUST a liquid (i.e. not just a waterlogged block), we CANNOT break it
|
||||
// TODO for 1.13 make sure that this only matches pure water, not waterlogged blocks
|
||||
if (!MovementHelper.possiblyFlowing(state)) {
|
||||
// if it's a source block then we want to replace it with a throwaway
|
||||
sourceLiquids.add(pos);
|
||||
}
|
||||
} else {
|
||||
breakable.add(pos);
|
||||
}
|
||||
}
|
||||
});
|
||||
List<Goal> toBreak = new ArrayList<>();
|
||||
breakable.forEach(pos -> toBreak.add(breakGoal(pos, bcc)));
|
||||
List<Goal> toPlace = new ArrayList<>();
|
||||
placable.forEach(pos -> {
|
||||
if (!placable.contains(pos.down()) && !placable.contains(pos.down(2))) {
|
||||
toPlace.add(placementGoal(pos, bcc));
|
||||
}
|
||||
});
|
||||
sourceLiquids.forEach(pos -> toPlace.add(new GoalBlock(pos.up())));
|
||||
|
||||
if (toPlace.length != 0) {
|
||||
return new JankyGoalComposite(new GoalComposite(toPlace), new GoalComposite(toBreak));
|
||||
if (!toPlace.isEmpty()) {
|
||||
return new JankyGoalComposite(new GoalComposite(toPlace.toArray(new Goal[0])), new GoalComposite(toBreak.toArray(new Goal[0])));
|
||||
}
|
||||
if (toBreak.length == 0) {
|
||||
if (toBreak.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new GoalComposite(toBreak);
|
||||
return new GoalComposite(toBreak.toArray(new Goal[0]));
|
||||
}
|
||||
|
||||
public static class JankyGoalComposite implements Goal {
|
||||
@@ -484,12 +597,12 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
}
|
||||
}
|
||||
|
||||
public Goal placementgoal(BlockPos pos, BuilderCalculationContext bcc) {
|
||||
if (ctx.world().getBlockState(pos).getBlock() != Blocks.AIR) {
|
||||
private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) {
|
||||
if (ctx.world().getBlockState(pos).getBlock() != Blocks.AIR) { // TODO can this even happen?
|
||||
return new GoalPlace(pos);
|
||||
}
|
||||
boolean allowSameLevel = ctx.world().getBlockState(pos.up()).getBlock() != Blocks.AIR;
|
||||
for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP) {
|
||||
for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP) {
|
||||
if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && ctx.world().mayPlace(bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()).getBlock(), pos, false, facing, null)) {
|
||||
return new GoalAdjacent(pos, allowSameLevel);
|
||||
}
|
||||
@@ -497,8 +610,23 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
return new GoalPlace(pos);
|
||||
}
|
||||
|
||||
private Goal breakGoal(BlockPos pos, BuilderCalculationContext bcc) {
|
||||
if (Baritone.settings().goalBreakFromAbove.value && bcc.bsi.get0(pos.up()).getBlock() instanceof BlockAir && bcc.bsi.get0(pos.up(2)).getBlock() instanceof BlockAir) { // TODO maybe possible without the up(2) check?
|
||||
return new JankyGoalComposite(new GoalBreak(pos), new GoalGetToBlock(pos.up()) {
|
||||
@Override
|
||||
public boolean isInGoal(int x, int y, int z) {
|
||||
if (y > this.y || (x == this.x && y == this.y && z == this.z)) {
|
||||
return false;
|
||||
}
|
||||
return super.isInGoal(x, y, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
return new GoalBreak(pos);
|
||||
}
|
||||
|
||||
public static class GoalAdjacent extends GoalGetToBlock {
|
||||
boolean allowSameLevel;
|
||||
private boolean allowSameLevel;
|
||||
|
||||
public GoalAdjacent(BlockPos pos, boolean allowSameLevel) {
|
||||
super(pos);
|
||||
@@ -540,14 +668,18 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
incorrectPositions = null;
|
||||
name = null;
|
||||
schematic = null;
|
||||
realSchematic = null;
|
||||
layer = 0;
|
||||
paused = false;
|
||||
observedCompleted = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayName0() {
|
||||
return "Building " + name;
|
||||
return paused ? "Builder Paused" : "Building " + name;
|
||||
}
|
||||
|
||||
public List<IBlockState> placable(int size) {
|
||||
private List<IBlockState> placable(int size) {
|
||||
List<IBlockState> result = new ArrayList<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
|
||||
@@ -562,7 +694,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean valid(IBlockState current, IBlockState desired) {
|
||||
private boolean valid(IBlockState current, IBlockState desired) {
|
||||
// TODO more complicated comparison logic I guess
|
||||
return desired == null || current.equals(desired);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import baritone.utils.BaritoneProcessHelper;
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
||||
public final class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
||||
|
||||
/**
|
||||
* The current goal
|
||||
@@ -90,6 +90,9 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
||||
}
|
||||
if (this.goal == null || (this.goal.isInGoal(ctx.playerFeet()) && this.goal.isInGoal(baritone.getPathingBehavior().pathStart()))) {
|
||||
onLostControl(); // we're there xd
|
||||
if (Baritone.settings().disconnectOnArrival.value) {
|
||||
ctx.world().sendQuittingDisconnectingPacket();
|
||||
}
|
||||
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||
}
|
||||
return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||
|
||||
@@ -19,17 +19,36 @@ package baritone.process;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.ICachedWorld;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalComposite;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import baritone.api.pathing.goals.GoalYLevel;
|
||||
import baritone.api.process.IExploreProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.utils.MyChunkPos;
|
||||
import baritone.cache.CachedWorld;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
public class ExploreProcess extends BaritoneProcessHelper {
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ExploreProcess extends BaritoneProcessHelper implements IExploreProcess {
|
||||
|
||||
private BlockPos explorationOrigin;
|
||||
|
||||
private IChunkFilter filter;
|
||||
|
||||
private int distanceCompleted;
|
||||
|
||||
public ExploreProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
@@ -39,8 +58,25 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
||||
return explorationOrigin != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explore(int centerX, int centerZ) {
|
||||
explorationOrigin = new BlockPos(centerX, 0, centerZ);
|
||||
distanceCompleted = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyJsonFilter(Path path, boolean invert) throws Exception {
|
||||
filter = new JsonChunkFilter(path, invert);
|
||||
}
|
||||
|
||||
public IChunkFilter calcFilter() {
|
||||
IChunkFilter filter;
|
||||
if (this.filter != null) {
|
||||
filter = new EitherChunk(this.filter, new BaritoneChunkCache());
|
||||
} else {
|
||||
filter = new BaritoneChunkCache();
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,41 +86,193 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
||||
onLostControl();
|
||||
return null;
|
||||
}
|
||||
BlockPos closestUncached = closestUncachedChunk(explorationOrigin);
|
||||
IChunkFilter filter = calcFilter();
|
||||
if (!Baritone.settings().disableCompletionCheck.value && filter.countRemain() == 0) {
|
||||
logDirect("Explored all chunks");
|
||||
onLostControl();
|
||||
return null;
|
||||
}
|
||||
Goal[] closestUncached = closestUncachedChunks(explorationOrigin, filter);
|
||||
if (closestUncached == null) {
|
||||
logDebug("awaiting region load from disk");
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
System.out.println("Closest uncached: " + closestUncached);
|
||||
return new PathingCommand(new GoalXZ(closestUncached.getX(), closestUncached.getZ()), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
|
||||
return new PathingCommand(new GoalComposite(closestUncached), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
|
||||
}
|
||||
|
||||
private BlockPos closestUncachedChunk(BlockPos pos) {
|
||||
int chunkX = pos.getX() >> 4;
|
||||
int chunkZ = pos.getZ() >> 4;
|
||||
ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
||||
for (int dist = 0; ; dist++) {
|
||||
private Goal[] closestUncachedChunks(BlockPos center, IChunkFilter filter) {
|
||||
int chunkX = center.getX() >> 4;
|
||||
int chunkZ = center.getZ() >> 4;
|
||||
int count = Math.min(filter.countRemain(), Baritone.settings().exploreChunkSetMinimumSize.value);
|
||||
List<BlockPos> centers = new ArrayList<>();
|
||||
int renderDistance = Baritone.settings().worldExploringChunkOffset.value;
|
||||
for (int dist = distanceCompleted; ; dist++) {
|
||||
for (int dx = -dist; dx <= dist; dx++) {
|
||||
for (int dz = -dist; dz <= dist; dz++) {
|
||||
int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz + dz : Math.abs(dx) + Math.abs(dz);
|
||||
int zval = dist - Math.abs(dx);
|
||||
for (int mult = 0; mult < 2; mult++) {
|
||||
int dz = (mult * 2 - 1) * zval; // dz can be either -zval or zval
|
||||
int trueDist = Math.abs(dx) + Math.abs(dz);
|
||||
if (trueDist != dist) {
|
||||
continue; // not considering this one just yet in our expanding search
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
int centerX = (chunkX + dx) * 16 + 8;
|
||||
int centerZ = (chunkZ + dz) * 18 + 8;
|
||||
|
||||
if (cache.isCached(centerX, centerZ)) {
|
||||
continue;
|
||||
switch (filter.isAlreadyExplored(chunkX + dx, chunkZ + dz)) {
|
||||
case UNKNOWN:
|
||||
return null; // awaiting load
|
||||
case NOT_EXPLORED:
|
||||
break; // note: this breaks the switch not the for
|
||||
case EXPLORED:
|
||||
continue; // note: this continues the for
|
||||
default:
|
||||
}
|
||||
if (!((CachedWorld) cache).regionLoaded(centerX, centerZ)) {
|
||||
Baritone.getExecutor().execute(() -> {
|
||||
((CachedWorld) cache).tryLoadFromDisk(centerX >> 9, centerZ >> 9);
|
||||
});
|
||||
return null; // we still need to load regions from disk in order to decide properly
|
||||
int centerX = ((chunkX + dx) << 4) + 8;
|
||||
int centerZ = ((chunkZ + dz) << 4) + 8;
|
||||
int offset = renderDistance << 4;
|
||||
if (dx < 0) {
|
||||
centerX -= offset;
|
||||
} else {
|
||||
centerX += offset;
|
||||
}
|
||||
return new BlockPos(centerX, 0, centerZ);
|
||||
if (dz < 0) {
|
||||
centerZ -= offset;
|
||||
} else {
|
||||
centerZ += offset;
|
||||
}
|
||||
centers.add(new BlockPos(centerX, 0, centerZ));
|
||||
}
|
||||
}
|
||||
if (centers.size() >= count) {
|
||||
return centers.stream().map(pos -> createGoal(pos.getX(), pos.getZ())).toArray(Goal[]::new);
|
||||
}
|
||||
if (centers.isEmpty()) {
|
||||
// we have explored everything from 0 to dist inclusive
|
||||
// next time we should start our check at dist+1
|
||||
distanceCompleted = dist + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Goal createGoal(int x, int z) {
|
||||
if (Baritone.settings().exploreMaintainY.value == -1) {
|
||||
return new GoalXZ(x, z);
|
||||
}
|
||||
// don't use a goalblock because we still want isInGoal to return true if X and Z are correct
|
||||
// we just want to try and maintain Y on the way there, not necessarily end at that specific Y
|
||||
return new GoalXZ(x, z) {
|
||||
@Override
|
||||
public double heuristic(int x, int y, int z) {
|
||||
return super.heuristic(x, y, z) + GoalYLevel.calculate(Baritone.settings().exploreMaintainY.value, y);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private enum Status {
|
||||
EXPLORED, NOT_EXPLORED, UNKNOWN;
|
||||
}
|
||||
|
||||
private interface IChunkFilter {
|
||||
Status isAlreadyExplored(int chunkX, int chunkZ);
|
||||
|
||||
int countRemain();
|
||||
}
|
||||
|
||||
private class BaritoneChunkCache implements IChunkFilter {
|
||||
|
||||
private final ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
||||
|
||||
@Override
|
||||
public Status isAlreadyExplored(int chunkX, int chunkZ) {
|
||||
int centerX = chunkX << 4;
|
||||
int centerZ = chunkZ << 4;
|
||||
if (cache.isCached(centerX, centerZ)) {
|
||||
return Status.EXPLORED;
|
||||
}
|
||||
if (!((CachedWorld) cache).regionLoaded(centerX, centerZ)) {
|
||||
Baritone.getExecutor().execute(() -> {
|
||||
((CachedWorld) cache).tryLoadFromDisk(centerX >> 9, centerZ >> 9);
|
||||
});
|
||||
return Status.UNKNOWN; // we still need to load regions from disk in order to decide properly
|
||||
}
|
||||
return Status.NOT_EXPLORED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countRemain() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
private class JsonChunkFilter implements IChunkFilter {
|
||||
private final boolean invert; // if true, the list is interpreted as a list of chunks that are NOT explored, if false, the list is interpreted as a list of chunks that ARE explored
|
||||
private final LongOpenHashSet inFilter;
|
||||
private final MyChunkPos[] positions;
|
||||
|
||||
private JsonChunkFilter(Path path, boolean invert) throws Exception { // ioexception, json exception, etc
|
||||
this.invert = invert;
|
||||
Gson gson = new GsonBuilder().create();
|
||||
positions = gson.fromJson(new InputStreamReader(Files.newInputStream(path)), MyChunkPos[].class);
|
||||
logDirect("Loaded " + positions.length + " positions");
|
||||
inFilter = new LongOpenHashSet();
|
||||
for (MyChunkPos mcp : positions) {
|
||||
inFilter.add(ChunkPos.asLong(mcp.x, mcp.z));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status isAlreadyExplored(int chunkX, int chunkZ) {
|
||||
if (inFilter.contains(ChunkPos.asLong(chunkX, chunkZ)) ^ invert) {
|
||||
// either it's on the list of explored chunks, or it's not on the list of unexplored chunks
|
||||
// either way, we have it
|
||||
return Status.EXPLORED;
|
||||
} else {
|
||||
// either it's not on the list of explored chunks, or it's on the list of unexplored chunks
|
||||
// either way, it depends on if baritone has cached it so defer to that
|
||||
return Status.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countRemain() {
|
||||
if (!invert) {
|
||||
// if invert is false, anything not on the list is uncached
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
// but if invert is true, anything not on the list IS assumed cached
|
||||
// so we are done if everything on our list is cached!
|
||||
int countRemain = 0;
|
||||
BaritoneChunkCache bcc = new BaritoneChunkCache();
|
||||
for (MyChunkPos pos : positions) {
|
||||
if (bcc.isAlreadyExplored(pos.x, pos.z) != Status.EXPLORED) {
|
||||
// either waiting for it or dont have it at all
|
||||
countRemain++;
|
||||
if (countRemain >= Baritone.settings().exploreChunkSetMinimumSize.value) {
|
||||
return countRemain;
|
||||
}
|
||||
}
|
||||
}
|
||||
return countRemain;
|
||||
}
|
||||
}
|
||||
|
||||
private class EitherChunk implements IChunkFilter {
|
||||
private final IChunkFilter a;
|
||||
private final IChunkFilter b;
|
||||
|
||||
private EitherChunk(IChunkFilter a, IChunkFilter b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status isAlreadyExplored(int chunkX, int chunkZ) {
|
||||
if (a.isAlreadyExplored(chunkX, chunkZ) == Status.EXPLORED) {
|
||||
return Status.EXPLORED;
|
||||
}
|
||||
return b.isAlreadyExplored(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countRemain() {
|
||||
return Math.min(a.countRemain(), b.countRemain());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +283,6 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
||||
|
||||
@Override
|
||||
public String displayName0() {
|
||||
return "Exploring around " + explorationOrigin + ", currently going to " + closestUncachedChunk(explorationOrigin);
|
||||
return "Exploring around " + explorationOrigin + ", distance completed " + distanceCompleted + ", currently going to " + new GoalComposite(closestUncachedChunks(explorationOrigin, calcFilter()));
|
||||
}
|
||||
}
|
||||
|
||||
283
src/main/java/baritone/process/FarmProcess.java
Normal file
283
src/main/java/baritone/process/FarmProcess.java
Normal file
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.process;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.pathing.goals.GoalComposite;
|
||||
import baritone.api.process.IFarmProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemDye;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
|
||||
|
||||
private boolean active;
|
||||
|
||||
private static final List<Item> FARMLAND_PLANTABLE = Arrays.asList(
|
||||
Items.BEETROOT_SEEDS,
|
||||
Items.MELON_SEEDS,
|
||||
Items.WHEAT_SEEDS,
|
||||
Items.PUMPKIN_SEEDS,
|
||||
Items.POTATO,
|
||||
Items.CARROT
|
||||
);
|
||||
|
||||
private static final List<Item> PICKUP_DROPPED = Arrays.asList(
|
||||
Items.BEETROOT_SEEDS,
|
||||
Items.WHEAT,
|
||||
Items.MELON_SEEDS,
|
||||
Items.MELON,
|
||||
Items.WHEAT_SEEDS,
|
||||
Items.WHEAT,
|
||||
Items.PUMPKIN_SEEDS,
|
||||
Items.POTATO,
|
||||
Items.CARROT,
|
||||
Items.BEETROOT,
|
||||
Item.getItemFromBlock(Blocks.PUMPKIN),
|
||||
Item.getItemFromBlock(Blocks.MELON_BLOCK),
|
||||
Items.NETHER_WART,
|
||||
Items.REEDS,
|
||||
Item.getItemFromBlock(Blocks.CACTUS)
|
||||
);
|
||||
|
||||
public FarmProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void farm() {
|
||||
active = true;
|
||||
}
|
||||
|
||||
private enum Harvest {
|
||||
WHEAT((BlockCrops) Blocks.WHEAT),
|
||||
CARROTS((BlockCrops) Blocks.CARROTS),
|
||||
POTATOES((BlockCrops) Blocks.POTATOES),
|
||||
BEETROOT((BlockCrops) Blocks.BEETROOTS),
|
||||
PUMPKIN(Blocks.PUMPKIN, state -> true),
|
||||
MELON(Blocks.MELON_BLOCK, state -> true),
|
||||
NETHERWART(Blocks.NETHER_WART, state -> state.getValue(BlockNetherWart.AGE) >= 3),
|
||||
SUGARCANE(Blocks.REEDS, null) {
|
||||
@Override
|
||||
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
|
||||
return world.getBlockState(pos.down()).getBlock() instanceof BlockReed;
|
||||
}
|
||||
},
|
||||
CACTUS(Blocks.CACTUS, null) {
|
||||
@Override
|
||||
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
|
||||
return world.getBlockState(pos.down()).getBlock() instanceof BlockCactus;
|
||||
}
|
||||
};
|
||||
public final Block block;
|
||||
public final Predicate<IBlockState> readyToHarvest;
|
||||
|
||||
Harvest(BlockCrops blockCrops) {
|
||||
this(blockCrops, blockCrops::isMaxAge);
|
||||
// max age is 7 for wheat, carrots, and potatoes, but 3 for beetroot
|
||||
}
|
||||
|
||||
Harvest(Block block, Predicate<IBlockState> readyToHarvest) {
|
||||
this.block = block;
|
||||
this.readyToHarvest = readyToHarvest;
|
||||
}
|
||||
|
||||
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
|
||||
return readyToHarvest.test(state);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean readyForHarvest(World world, BlockPos pos, IBlockState state) {
|
||||
for (Harvest harvest : Harvest.values()) {
|
||||
if (harvest.block == state.getBlock()) {
|
||||
return harvest.readyToHarvest(world, pos, state);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPlantable(ItemStack stack) {
|
||||
return FARMLAND_PLANTABLE.contains(stack.getItem());
|
||||
}
|
||||
|
||||
private boolean isBoneMeal(ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.getItem() instanceof ItemDye && EnumDyeColor.byDyeDamage(stack.getMetadata()) == EnumDyeColor.WHITE;
|
||||
}
|
||||
|
||||
private boolean isNetherWart(ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
ArrayList<Block> scan = new ArrayList<>();
|
||||
for (Harvest harvest : Harvest.values()) {
|
||||
scan.add(harvest.block);
|
||||
}
|
||||
scan.add(Blocks.FARMLAND);
|
||||
if (Baritone.settings().replantNetherWart.value) {
|
||||
scan.add(Blocks.SOUL_SAND);
|
||||
}
|
||||
|
||||
List<BlockPos> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 4);
|
||||
|
||||
List<BlockPos> toBreak = new ArrayList<>();
|
||||
List<BlockPos> openFarmland = new ArrayList<>();
|
||||
List<BlockPos> bonemealable = new ArrayList<>();
|
||||
List<BlockPos> openSoulsand = new ArrayList<>();
|
||||
for (BlockPos pos : locations) {
|
||||
IBlockState state = ctx.world().getBlockState(pos);
|
||||
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
|
||||
if (state.getBlock() == Blocks.FARMLAND) {
|
||||
if (airAbove) {
|
||||
openFarmland.add(pos);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (state.getBlock() == Blocks.SOUL_SAND) {
|
||||
if (airAbove) {
|
||||
openSoulsand.add(pos);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (readyForHarvest(ctx.world(), pos, state)) {
|
||||
toBreak.add(pos);
|
||||
continue;
|
||||
}
|
||||
if (state.getBlock() instanceof IGrowable) {
|
||||
IGrowable ig = (IGrowable) state.getBlock();
|
||||
if (ig.canGrow(ctx.world(), pos, state, true) && ig.canUseBonemeal(ctx.world(), ctx.world().rand, pos, state)) {
|
||||
bonemealable.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
for (BlockPos pos : toBreak) {
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||
if (rot.isPresent() && isSafeToCancel) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
|
||||
if (ctx.isLookingAt(pos)) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
}
|
||||
ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
|
||||
both.addAll(openSoulsand);
|
||||
for (BlockPos pos : both) {
|
||||
boolean soulsand = openSoulsand.contains(pos);
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance());
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
if (ctx.isLookingAt(pos)) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : bonemealable) {
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
if (ctx.isLookingAt(pos)) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (calcFailed) {
|
||||
logDirect("Farm failed");
|
||||
onLostControl();
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
|
||||
List<Goal> goalz = new ArrayList<>();
|
||||
for (BlockPos pos : toBreak) {
|
||||
goalz.add(new BuilderProcess.GoalBreak(pos));
|
||||
}
|
||||
if (baritone.getInventoryBehavior().throwaway(false, this::isPlantable)) {
|
||||
for (BlockPos pos : openFarmland) {
|
||||
goalz.add(new GoalBlock(pos.up()));
|
||||
}
|
||||
}
|
||||
if (baritone.getInventoryBehavior().throwaway(false, this::isNetherWart)) {
|
||||
for (BlockPos pos : openSoulsand) {
|
||||
goalz.add(new GoalBlock(pos.up()));
|
||||
}
|
||||
}
|
||||
if (baritone.getInventoryBehavior().throwaway(false, this::isBoneMeal)) {
|
||||
for (BlockPos pos : bonemealable) {
|
||||
goalz.add(new GoalBlock(pos));
|
||||
}
|
||||
}
|
||||
for (Entity entity : ctx.world().loadedEntityList) {
|
||||
if (entity instanceof EntityItem && entity.onGround) {
|
||||
EntityItem ei = (EntityItem) entity;
|
||||
if (PICKUP_DROPPED.contains(ei.getItem().getItem())) {
|
||||
// +0.1 because of farmland's 0.9375 dummy height lol
|
||||
goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLostControl() {
|
||||
active = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayName0() {
|
||||
return "Farming";
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,12 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
||||
}
|
||||
|
||||
private void scanWorld() {
|
||||
cache = Stream.of(ctx.world().loadedEntityList, ctx.world().playerEntities).flatMap(List::stream).filter(this::followable).filter(this.filter).distinct().collect(Collectors.toCollection(ArrayList::new));
|
||||
cache = Stream.of(ctx.world().loadedEntityList, ctx.world().playerEntities)
|
||||
.flatMap(List::stream)
|
||||
.filter(this::followable)
|
||||
.filter(this.filter)
|
||||
.distinct()
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +107,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
||||
|
||||
@Override
|
||||
public String displayName0() {
|
||||
return "Follow " + cache;
|
||||
return "Following " + cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {
|
||||
public final class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {
|
||||
|
||||
private Block gettingTo;
|
||||
private List<BlockPos> knownLocations;
|
||||
@@ -42,6 +42,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
private BlockPos start;
|
||||
|
||||
private int tickCount = 0;
|
||||
private int arrivalTickCount = 0;
|
||||
|
||||
public GetToBlockProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
@@ -53,6 +54,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
gettingTo = block;
|
||||
start = ctx.playerFeet();
|
||||
blacklist = new ArrayList<>();
|
||||
arrivalTickCount = 0;
|
||||
rescan(new ArrayList<>(), new CalculationContext(baritone));
|
||||
}
|
||||
|
||||
@@ -117,7 +119,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
}
|
||||
|
||||
// blacklist the closest block and its adjacent blocks
|
||||
public synchronized void blacklistClosest() {
|
||||
public synchronized boolean blacklistClosest() {
|
||||
List<BlockPos> newBlacklist = new ArrayList<>();
|
||||
knownLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(newBlacklist::add);
|
||||
outer:
|
||||
@@ -140,6 +142,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
}
|
||||
logDebug("Blacklisting unreachable locations " + newBlacklist);
|
||||
blacklist.addAll(newBlacklist);
|
||||
return !newBlacklist.isEmpty();
|
||||
}
|
||||
|
||||
// safer than direct double comparison from distanceSq
|
||||
@@ -195,6 +198,10 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (arrivalTickCount++ > 20) {
|
||||
logDirect("Right click timed out");
|
||||
return true;
|
||||
}
|
||||
return false; // trying to right click, will do it next tick or so
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,16 +22,21 @@ import baritone.api.pathing.goals.*;
|
||||
import baritone.api.process.IMineProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.utils.BlockUtils;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.cache.CachedChunk;
|
||||
import baritone.cache.ChunkPacker;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -43,6 +48,8 @@ import net.minecraft.world.World;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||
|
||||
/**
|
||||
* Mine blocks of a certain type
|
||||
*
|
||||
@@ -81,26 +88,47 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (calcFailed && !knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
|
||||
logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance...");
|
||||
knownOreLocations.stream().sorted(Comparator.comparingDouble(ctx.player()::getDistanceSq)).findFirst().ifPresent(blacklist::add);
|
||||
knownOreLocations.removeIf(blacklist::contains);
|
||||
calcFailed = false; // 😎
|
||||
}
|
||||
if (calcFailed) {
|
||||
logDirect("Unable to find any path to " + mining + ", canceling Mine");
|
||||
cancel();
|
||||
return null;
|
||||
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<BlockPos> curr = new ArrayList<>(knownOreLocations);
|
||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
|
||||
CalculationContext context = new CalculationContext(baritone, true);
|
||||
Baritone.getExecutor().execute(() -> rescan(curr, context));
|
||||
}
|
||||
if (Baritone.settings().legitMine.value) {
|
||||
addNearby();
|
||||
}
|
||||
Optional<BlockPos> shaft = curr.stream()
|
||||
.filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())
|
||||
.filter(pos -> pos.getY() >= ctx.playerFeet().getY())
|
||||
.filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
|
||||
.min(Comparator.comparingDouble(ctx.player()::getDistanceSq));
|
||||
baritone.getInputOverrideHandler().clearAllKeys();
|
||||
if (shaft.isPresent() && ctx.player().onGround) {
|
||||
BlockPos pos = shaft.get();
|
||||
IBlockState state = baritone.bsi.get0(pos);
|
||||
if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) {
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||
if (rot.isPresent() && isSafeToCancel) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
|
||||
if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot.get())) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
PathingCommand command = updateGoal();
|
||||
if (command == null) {
|
||||
// none in range
|
||||
@@ -127,7 +155,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
if (!locs.isEmpty()) {
|
||||
List<BlockPos> locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT, blacklist);
|
||||
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
|
||||
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(ctx, loc, locs2)).toArray(Goal[]::new));
|
||||
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new));
|
||||
knownOreLocations = locs2;
|
||||
return new PathingCommand(goal, legit ? PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH : PathingCommandType.REVALIDATE_GOAL_AND_PATH);
|
||||
}
|
||||
@@ -177,20 +205,83 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
knownOreLocations = locs;
|
||||
}
|
||||
|
||||
private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List<BlockPos> locs) {
|
||||
private boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List<BlockPos> locs) {
|
||||
// Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of)
|
||||
if (locs.contains(pos)) {
|
||||
return true;
|
||||
}
|
||||
Block block = BlockStateInterface.getBlock(ctx, pos);
|
||||
if (Baritone.settings().internalMiningAirException.value && block instanceof BlockAir) {
|
||||
return true;
|
||||
}
|
||||
return mining.contains(block);
|
||||
}
|
||||
|
||||
private Goal coalesce(BlockPos loc, List<BlockPos> locs) {
|
||||
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof BlockFalling);
|
||||
if (!Baritone.settings().forceInternalMining.value) {
|
||||
return new GoalTwoBlocks(loc);
|
||||
if (assumeVerticalShaftMine) {
|
||||
// we can get directly below the block
|
||||
return new GoalThreeBlocks(loc);
|
||||
} else {
|
||||
// we need to get feet or head into the block
|
||||
return new GoalTwoBlocks(loc);
|
||||
}
|
||||
}
|
||||
boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs);
|
||||
boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs);
|
||||
boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs);
|
||||
if (upwardGoal == downwardGoal) { // symmetric
|
||||
if (doubleDownwardGoal && assumeVerticalShaftMine) {
|
||||
// we have a checkerboard like pattern
|
||||
// this one, and the one two below it
|
||||
// therefore it's fine to path to immediately below this one, since your feet will be in the doubleDownwardGoal
|
||||
// but only if assumeVerticalShaftMine
|
||||
return new GoalThreeBlocks(loc);
|
||||
} else {
|
||||
// this block has nothing interesting two below, but is symmetric vertically so we can get either feet or head into it
|
||||
return new GoalTwoBlocks(loc);
|
||||
}
|
||||
}
|
||||
if (upwardGoal) {
|
||||
// downwardGoal known to be false
|
||||
// ignore the gap then potential doubleDownward, because we want to path feet into this one and head into upwardGoal
|
||||
return new GoalBlock(loc);
|
||||
}
|
||||
// upwardGoal known to be false, downwardGoal known to be true
|
||||
if (doubleDownwardGoal && assumeVerticalShaftMine) {
|
||||
// this block and two below it are goals
|
||||
// path into the center of the one below, because that includes directly below this one
|
||||
return new GoalTwoBlocks(loc.down());
|
||||
}
|
||||
// upwardGoal false, downwardGoal true, doubleDownwardGoal false
|
||||
// just this block and the one immediately below, no others
|
||||
return new GoalBlock(loc.down());
|
||||
}
|
||||
|
||||
private static class GoalThreeBlocks extends GoalTwoBlocks {
|
||||
|
||||
public GoalThreeBlocks(BlockPos pos) {
|
||||
super(pos);
|
||||
}
|
||||
|
||||
// Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of)
|
||||
boolean upwardGoal = locs.contains(loc.up()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.up()) == Blocks.AIR);
|
||||
boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.down()) == Blocks.AIR);
|
||||
return upwardGoal == downwardGoal ? new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : new GoalBlock(loc.down());
|
||||
@Override
|
||||
public boolean isInGoal(int x, int y, int z) {
|
||||
return x == this.x && (y == this.y || y == this.y - 1 || y == this.y - 2) && z == this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(int x, int y, int z) {
|
||||
int xDiff = x - this.x;
|
||||
int yDiff = y - this.y;
|
||||
int zDiff = z - this.z;
|
||||
return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {
|
||||
if (!Baritone.settings().mineScanDroppedItems.value) {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Set<Item> searchingFor = new HashSet<>();
|
||||
for (Block block : mining) {
|
||||
@@ -214,24 +305,20 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
public static List<BlockPos> searchWorld(CalculationContext ctx, List<Block> mining, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist) {
|
||||
List<BlockPos> locs = new ArrayList<>();
|
||||
List<Block> uninteresting = new ArrayList<>();
|
||||
//long b = System.currentTimeMillis();
|
||||
for (Block m : mining) {
|
||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) {
|
||||
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
|
||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), Baritone.settings().maxCachedWorldScanCount.value, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2));
|
||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(BlockUtils.blockToString(m), Baritone.settings().maxCachedWorldScanCount.value, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2));
|
||||
} else {
|
||||
uninteresting.add(m);
|
||||
}
|
||||
}
|
||||
locs = prune(ctx, locs, mining, max, blacklist);
|
||||
//System.out.println("Scan of cached chunks took " + (System.currentTimeMillis() - b) + "ms");
|
||||
if (locs.isEmpty()) {
|
||||
if (locs.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) {
|
||||
uninteresting = mining;
|
||||
}
|
||||
if (!uninteresting.isEmpty()) {
|
||||
//long before = System.currentTimeMillis();
|
||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 32)); // maxSearchRadius is NOT sq
|
||||
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
|
||||
}
|
||||
locs.addAll(alreadyKnown);
|
||||
return prune(ctx, locs, mining, max, blacklist);
|
||||
@@ -264,7 +351,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
List<BlockPos> dropped = droppedItemsScan(mining, ctx.world);
|
||||
dropped.removeIf(drop -> {
|
||||
for (BlockPos pos : locs2) {
|
||||
if (pos.distanceSq(drop) <= 9 && mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx.bsi, pos)) { // TODO maybe drop also has to be supported? no lava below?
|
||||
if (pos.distanceSq(drop) <= 9 && mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx, pos)) { // TODO maybe drop also has to be supported? no lava below?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -278,11 +365,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
.filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
|
||||
|
||||
// remove any that are implausible to mine (encased in bedrock, or touching lava)
|
||||
.filter(pos -> MineProcess.plausibleToBreak(ctx.bsi, pos))
|
||||
.filter(pos -> MineProcess.plausibleToBreak(ctx, pos))
|
||||
|
||||
.filter(pos -> !blacklist.contains(pos))
|
||||
|
||||
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().playerFeet()::distanceSq))
|
||||
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player()::getDistanceSq))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (locs.size() > max) {
|
||||
@@ -291,18 +378,18 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return locs;
|
||||
}
|
||||
|
||||
public static boolean plausibleToBreak(BlockStateInterface bsi, BlockPos pos) {
|
||||
if (MovementHelper.avoidBreaking(bsi, pos.getX(), pos.getY(), pos.getZ(), bsi.get0(pos))) {
|
||||
public static boolean plausibleToBreak(CalculationContext ctx, BlockPos pos) {
|
||||
if (MovementHelper.getMiningDurationTicks(ctx, pos.getX(), pos.getY(), pos.getZ(), ctx.bsi.get0(pos), true) >= COST_INF) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// bedrock above and below makes it implausible, otherwise we're good
|
||||
return !(bsi.get0(pos.up()).getBlock() == Blocks.BEDROCK && bsi.get0(pos.down()).getBlock() == Blocks.BEDROCK);
|
||||
return !(ctx.bsi.get0(pos.up()).getBlock() == Blocks.BEDROCK && ctx.bsi.get0(pos.down()).getBlock() == Blocks.BEDROCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mineByName(int quantity, String... blocks) {
|
||||
mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlock).toArray(Block[]::new));
|
||||
mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(BlockUtils::stringToBlockRequired).toArray(Block[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.process.IBaritoneProcess;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
|
||||
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@@ -46,6 +47,9 @@ public class BlockPlaceHelper implements Helper {
|
||||
ctx.player().swingArm(hand);
|
||||
return;
|
||||
}
|
||||
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == EnumActionResult.SUCCESS) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ public class GuiClick extends GuiScreen {
|
||||
currentMouseOver = result.getBlockPos();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +86,6 @@ public class GuiClick extends GuiScreen {
|
||||
clickStart = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
clickStart = currentMouseOver;
|
||||
@@ -104,7 +102,7 @@ public class GuiClick extends GuiScreen {
|
||||
PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(currentMouseOver), Color.CYAN);
|
||||
if (clickStart != null && !clickStart.equals(currentMouseOver)) {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
GlStateManager.color(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F);
|
||||
GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
|
||||
GlStateManager.disableTexture2D();
|
||||
@@ -120,11 +118,9 @@ public class GuiClick extends GuiScreen {
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Vec3d toWorld(double x, double y, double z) {
|
||||
private Vec3d toWorld(double x, double y, double z) {
|
||||
boolean result = GLU.gluUnProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_WORLD_BUFFER.clear());
|
||||
if (result) {
|
||||
return new Vec3d(TO_WORLD_BUFFER.get(0), TO_WORLD_BUFFER.get(1), TO_WORLD_BUFFER.get(2));
|
||||
|
||||
@@ -23,6 +23,7 @@ import baritone.api.event.events.RenderEvent;
|
||||
import baritone.api.pathing.calc.IPath;
|
||||
import baritone.api.pathing.goals.*;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.pathing.path.PathExecutor;
|
||||
@@ -83,17 +84,22 @@ public final class PathRenderer implements Helper {
|
||||
if (goal != null && Baritone.settings().renderGoal.value) {
|
||||
drawDankLitGoalBox(renderView, goal, partialTicks, Baritone.settings().colorGoalBox.value);
|
||||
}
|
||||
|
||||
if (!Baritone.settings().renderPath.value) {
|
||||
return;
|
||||
}
|
||||
PathExecutor current = behavior.getCurrent(); // this should prevent most race conditions?
|
||||
PathExecutor next = behavior.getNext(); // like, now it's not possible for current!=null to be true, then suddenly false because of another thread
|
||||
if (current != null && Baritone.settings().renderSelectionBoxes.value) {
|
||||
drawManySelectionBoxes(renderView, current.toBreak(), Baritone.settings().colorBlocksToBreak.value);
|
||||
drawManySelectionBoxes(renderView, current.toPlace(), Baritone.settings().colorBlocksToPlace.value);
|
||||
drawManySelectionBoxes(renderView, current.toWalkInto(), Baritone.settings().colorBlocksToWalkInto.value);
|
||||
}
|
||||
|
||||
//drawManySelectionBoxes(player, Collections.singletonList(behavior.pathStart()), partialTicks, Color.WHITE);
|
||||
//long start = System.nanoTime();
|
||||
|
||||
|
||||
PathExecutor current = behavior.getCurrent(); // this should prevent most race conditions?
|
||||
PathExecutor next = behavior.getNext(); // like, now it's not possible for current!=null to be true, then suddenly false because of another thread
|
||||
|
||||
// Render the current path, if there is one
|
||||
if (current != null && current.getPath() != null) {
|
||||
int renderBegin = Math.max(current.getPosition() - 3, 0);
|
||||
@@ -104,11 +110,6 @@ public final class PathRenderer implements Helper {
|
||||
}
|
||||
|
||||
//long split = System.nanoTime();
|
||||
if (current != null) {
|
||||
drawManySelectionBoxes(renderView, current.toBreak(), Baritone.settings().colorBlocksToBreak.value);
|
||||
drawManySelectionBoxes(renderView, current.toPlace(), Baritone.settings().colorBlocksToPlace.value);
|
||||
drawManySelectionBoxes(renderView, current.toWalkInto(), Baritone.settings().colorBlocksToWalkInto.value);
|
||||
}
|
||||
|
||||
// If there is a path calculation currently running, render the path calculation process
|
||||
behavior.getInProgress().ifPresent(currentlyRunning -> {
|
||||
@@ -175,7 +176,7 @@ public final class PathRenderer implements Helper {
|
||||
}
|
||||
GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], alpha);
|
||||
}
|
||||
drawLine(player, x1, y1, z1, x2, y2, z2);
|
||||
drawLine(x1, y1, z1, x2, y2, z2);
|
||||
tessellator.draw();
|
||||
}
|
||||
if (Baritone.settings().renderPathIgnoreDepth.value) {
|
||||
@@ -187,7 +188,7 @@ public final class PathRenderer implements Helper {
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
|
||||
public static void drawLine(Entity player, double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z) {
|
||||
public static void drawLine(double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z) {
|
||||
double d0 = mc.getRenderManager().viewerPosX;
|
||||
double d1 = mc.getRenderManager().viewerPosY;
|
||||
double d2 = mc.getRenderManager().viewerPosZ;
|
||||
@@ -275,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;
|
||||
}
|
||||
@@ -340,6 +341,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;
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
p.secretInternalSetGoal(null);
|
||||
return;
|
||||
}
|
||||
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE) {
|
||||
// if control has changed, and the new process wants to do something
|
||||
if (!Objects.equals(inControlThisTick, inControlLastTick) && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) {
|
||||
// if control has changed from a real process to another real process, and the new process wants to do something
|
||||
p.cancelSegmentIfSafe();
|
||||
// get rid of the in progress stuff from the last process
|
||||
}
|
||||
@@ -200,10 +200,10 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
|
||||
if (exec == null) {
|
||||
if (proc.isActive()) {
|
||||
throw new IllegalStateException(proc.displayName() + " returned null PathingCommand");
|
||||
throw new IllegalStateException(proc.displayName() + " actively returned null PathingCommand");
|
||||
}
|
||||
proc.onLostControl();
|
||||
} else {
|
||||
// no need to call onLostControl; they are reporting inactive.
|
||||
} else if (exec.commandType != PathingCommandType.DEFER) {
|
||||
inControlThisTick = proc;
|
||||
if (!proc.isTemporary()) {
|
||||
iterator.forEachRemaining(IBaritoneProcess::onLostControl);
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.minecraft.util.MovementInput;
|
||||
public class PlayerMovementInput extends MovementInput {
|
||||
private final InputOverrideHandler handler;
|
||||
|
||||
public PlayerMovementInput(InputOverrideHandler handler) {
|
||||
PlayerMovementInput(InputOverrideHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class PlayerMovementInput extends MovementInput {
|
||||
this.moveStrafe = 0.0F;
|
||||
this.moveForward = 0.0F;
|
||||
|
||||
jump = handler.isInputForcedDown(Input.JUMP); // oppa gangnam
|
||||
jump = handler.isInputForcedDown(Input.JUMP); // oppa gangnam style
|
||||
|
||||
if (this.forwardKeyDown = handler.isInputForcedDown(Input.MOVE_FORWARD)) {
|
||||
this.moveForward++;
|
||||
|
||||
@@ -65,10 +65,10 @@ public class ToolSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Using the best tool on the hotbar, how long would it take to mine this block
|
||||
* Using the best tool on the hotbar, how fast we can mine this block
|
||||
*
|
||||
* @param state the blockstate to be mined
|
||||
* @return how long it would take in ticks
|
||||
* @return the speed of how fast we'll mine it. 1/(time in ticks)
|
||||
*/
|
||||
public double getStrVsBlock(IBlockState state) {
|
||||
return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation);
|
||||
@@ -128,7 +128,11 @@ public class ToolSet {
|
||||
*/
|
||||
private double getBestDestructionTime(Block b) {
|
||||
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b));
|
||||
return calculateSpeedVsBlock(stack, b.getDefaultState());
|
||||
return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b);
|
||||
}
|
||||
|
||||
private double avoidanceMultiplier(Block b) {
|
||||
return Baritone.settings().blocksToAvoidBreaking.value.contains(b) ? 0.1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,10 +64,13 @@ public class Avoidance {
|
||||
double mobSpawnerCoeff = Baritone.settings().mobSpawnerAvoidanceCoefficient.value;
|
||||
double mobCoeff = Baritone.settings().mobAvoidanceCoefficient.value;
|
||||
if (mobSpawnerCoeff != 1.0D) {
|
||||
ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2).forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.value)));
|
||||
ctx.worldData().getCachedWorld().getLocationsOf("mob_spawner", 1, ctx.playerFeet().x, ctx.playerFeet().z, 2)
|
||||
.forEach(mobspawner -> res.add(new Avoidance(mobspawner, mobSpawnerCoeff, Baritone.settings().mobSpawnerAvoidanceRadius.value)));
|
||||
}
|
||||
if (mobCoeff != 1.0D) {
|
||||
ctx.world().loadedEntityList.stream().filter(entity -> entity instanceof EntityMob).forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
|
||||
ctx.world().loadedEntityList.stream()
|
||||
.filter(entity -> entity instanceof EntityMob)
|
||||
.forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.utils.pathing;
|
||||
|
||||
import baritone.api.pathing.calc.IPath;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
|
||||
@@ -31,7 +32,7 @@ public final class Favoring {
|
||||
for (Avoidance avoid : Avoidance.create(ctx)) {
|
||||
avoid.applySpherical(favorings);
|
||||
}
|
||||
System.out.println("Favoring size: " + favorings.size());
|
||||
Helper.HELPER.logDebug("Favoring size: " + favorings.size());
|
||||
}
|
||||
|
||||
public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SegmentedCalculator {
|
||||
private Optional<IPath> doCalc() {
|
||||
Optional<IPath> soFar = Optional.empty();
|
||||
while (true) {
|
||||
PathCalculationResult result = segment(soFar);
|
||||
PathCalculationResult result = segment(soFar.orElse(null));
|
||||
switch (result.getType()) {
|
||||
case SUCCESS_SEGMENT:
|
||||
case SUCCESS_TO_GOAL:
|
||||
@@ -62,8 +62,8 @@ public class SegmentedCalculator {
|
||||
default: // CANCELLATION and null should not be possible, nothing else has access to this, so it can't have been canceled
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
IPath segment = result.getPath().get(); // path calculation result type is SUCCESS_SEGMENT, so the path must be present
|
||||
IPath combined = soFar.map(previous -> (IPath) SplicedPath.trySplice(previous, segment, true).get()).orElse(segment);
|
||||
IPath segment = result.getPath().orElseThrow(IllegalStateException::new); // path calculation result type is SUCCESS_SEGMENT, so the path must be present
|
||||
IPath combined = soFar.map(previous -> (IPath) SplicedPath.trySplice(previous, segment, true).orElseThrow(IllegalStateException::new)).orElse(segment);
|
||||
loadAdjacent(combined.getDest().getX(), combined.getDest().getZ());
|
||||
soFar = Optional.of(combined);
|
||||
if (result.getType() == PathCalculationResult.Type.SUCCESS_TO_GOAL) {
|
||||
@@ -85,9 +85,9 @@ public class SegmentedCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
private PathCalculationResult segment(Optional<IPath> previous) {
|
||||
BetterBlockPos segmentStart = previous.map(IPath::getDest).orElse(start); // <-- e p i c
|
||||
AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous.orElse(null), context), context); // this is on another thread, so cannot include mob avoidances.
|
||||
private PathCalculationResult segment(IPath previous) {
|
||||
BetterBlockPos segmentStart = previous != null ? previous.getDest() : start;
|
||||
AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous, context), context); // this is on another thread, so cannot include mob avoidances.
|
||||
return search.calculate(Baritone.settings().primaryTimeoutMS.value, Baritone.settings().failureTimeoutMS.value); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ package baritone.utils.player;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package baritone.utils.player;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -72,4 +72,9 @@ public enum PrimaryPlayerController implements IPlayerController, Helper {
|
||||
// primaryplayercontroller is always in a WorldClient so this is ok
|
||||
return mc.playerController.processRightClickBlock(player, (WorldClient) world, pos, direction, vec, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand) {
|
||||
return mc.playerController.processRightClick(player, world, hand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ public class OpenSetsTest {
|
||||
return testSizes;
|
||||
}
|
||||
|
||||
private static void removeAndTest(int amount, IOpenSet[] test, Optional<Collection<PathNode>> mustContain) {
|
||||
private static void removeAndTest(int amount, IOpenSet[] test, Collection<PathNode> mustContain) {
|
||||
double[][] results = new double[test.length][amount];
|
||||
for (int i = 0; i < test.length; i++) {
|
||||
long before = System.nanoTime() / 1000000L;
|
||||
for (int j = 0; j < amount; j++) {
|
||||
PathNode pn = test[i].removeLowest();
|
||||
if (mustContain.isPresent() && !mustContain.get().contains(pn)) {
|
||||
throw new IllegalStateException(mustContain.get() + " " + pn);
|
||||
if (mustContain != null && !mustContain.contains(pn)) {
|
||||
throw new IllegalStateException(mustContain + " " + pn);
|
||||
}
|
||||
results[i][j] = pn.combinedCost;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public class OpenSetsTest {
|
||||
|
||||
System.out.println("Removal round 1");
|
||||
// remove a quarter of the nodes and verify that they are indeed the size/4 lowest ones
|
||||
removeAndTest(size / 4, test, Optional.of(lowestQuarter));
|
||||
removeAndTest(size / 4, test, lowestQuarter);
|
||||
|
||||
// none of them should be empty (sanity check)
|
||||
for (IOpenSet set : test) {
|
||||
@@ -160,7 +160,7 @@ public class OpenSetsTest {
|
||||
|
||||
System.out.println("Removal round 2");
|
||||
// remove the remaining 3/4
|
||||
removeAndTest(size - size / 4, test, Optional.empty());
|
||||
removeAndTest(size - size / 4, test, null);
|
||||
|
||||
// every set should now be empty
|
||||
for (IOpenSet set : test) {
|
||||
|
||||
Reference in New Issue
Block a user