Compare commits
524 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 | |||
| 89fb5cecd5 | |||
| a75317cc2c | |||
| ee6df270ce | |||
| e09541151f | |||
| 74e0552be0 | |||
| 909ab553eb | |||
| 866408aece | |||
| 2215f170df | |||
| a5601fd89a | |||
| fa8f2632f5 | |||
| 52d8d271f1 | |||
| b240e8420a | |||
| 25024b58de | |||
| ba31d209c9 | |||
| 7974d9135b | |||
| a5a795a22c | |||
| 416b5b66d2 | |||
| 88e41f37b1 | |||
| 7cfa837604 | |||
| 6b7aca3081 | |||
| 580af2ab06 | |||
| d144d30890 | |||
| ecac546c6d | |||
| 76297e8176 | |||
| d90f391b5e | |||
| d80ae57964 | |||
| 74d7483b3c | |||
| b3c580e657 | |||
| 8050b69f2f | |||
| 459720c348 | |||
| a73f5c1359 | |||
| 71cb0f6d36 | |||
| 0d15225b1d | |||
| 826f3788d0 | |||
| 2133ab39b7 | |||
| 558c14a375 | |||
| 882ac41291 | |||
| 66c7a3f513 | |||
| 5904441a7e | |||
| c465228531 | |||
| 81b22019dd | |||
| 3e47d485f9 | |||
| 701bc772a8 | |||
| 3ae05b7348 | |||
| 2e186019f5 | |||
| 4c6f321cff | |||
| c72eb3e195 | |||
| a4237bf1f9 | |||
| e767e34b92 | |||
| 8ac82ebe2a | |||
| 0ed6ccab71 | |||
| bf25d7328e | |||
| a47b0c0581 | |||
| 596849c7e6 | |||
| 76914b7859 | |||
| 3dbbe053d7 | |||
| c474cdb1f8 | |||
| 3de02cbf21 | |||
| 26fefc70f0 | |||
| 4086c9f4b5 | |||
| c947c77853 | |||
| 9be44c0371 | |||
| 5412fa6cfd | |||
| 6e7320b954 | |||
| fbb2d37634 | |||
| 7afe16fc10 | |||
| b19f241d81 | |||
| 583ce80003 | |||
| 195c33407e | |||
| 600c5b77ad | |||
| f1084fab76 | |||
| bd65e32407 | |||
| e4416f424a | |||
| 73ec110b22 | |||
| 0bce801a3f | |||
| e8e00e8dfb | |||
| cc4335e48e | |||
| 5427911da3 | |||
| c808d5a42d | |||
| 3b46dbd6a1 | |||
| e63b2f1bf1 | |||
| d32e822057 | |||
| 2b672998e1 | |||
| e18dc7c7e7 | |||
| 16dcd2f44d | |||
| eb9f755b54 | |||
| 29a9e6e1d1 | |||
| 1f52f706ed | |||
| bf12763a10 | |||
| 963641a818 | |||
| 3e94d92fbd | |||
| a72040f83d | |||
| 84d8f826ff | |||
| 70d216b29f | |||
| 66356d5334 | |||
| d9625dfe78 | |||
| 6d847577d8 | |||
| 8fd687f9d7 | |||
| f7a9380b9d | |||
| 5617c595b2 | |||
| 8770524679 | |||
| a8ddb2fcf1 | |||
| 76c4ca9ba6 | |||
| ed2b0f0bb9 | |||
| 6702b44b3e | |||
| c486d8241e | |||
| d2bb8c374e | |||
| 530cecea5b | |||
| 266e2dada9 | |||
| ce73d34627 | |||
| 11af0a7aac | |||
| 46c2d8f7c7 | |||
| 38127011fb | |||
| 89b5ce4b63 | |||
| 4fe9c180d5 | |||
| f094e83e4d | |||
| 5b6c9fc348 | |||
| 3f1ee100bf | |||
| 41b1106c72 | |||
| b27d95a615 | |||
| 5b8a83853d | |||
| d0548b2715 | |||
| bffeb9c862 | |||
| dbd760fbcb | |||
| a84b3bfc7a | |||
| e8d3bf509c | |||
| b2583773d5 | |||
| 9ecd24c755 | |||
| f1bacd6210 | |||
| a21ec54d4f | |||
| 0b4efb24ae | |||
| c473914d05 | |||
| 90a1fa8337 | |||
| 99cb7f5142 | |||
| 4026b850f8 | |||
| aac7ebf6dd | |||
| 8d481ba394 | |||
| 24fa75c24e | |||
| cf38d593b8 | |||
| 36f608c63c | |||
| 1d88564a72 | |||
| 503f2fb197 | |||
| bb000c4e3f | |||
| 4868ed7560 | |||
| 7017e9e2ea | |||
| a18eb90702 | |||
| 9d1d4fe0d9 | |||
| 1a430dc2cf | |||
| e37a09a1c8 | |||
| d0d8b12fb8 | |||
| 9a29f9ce57 | |||
| 42513e4b56 | |||
| 67fa91abe8 | |||
| d8348ad292 | |||
| 6faa7344aa | |||
| 299540725e | |||
| 0ef08142fd | |||
| c0761c0eef | |||
| 8694d926c4 | |||
| 46f8829951 | |||
| 4c4bce3561 | |||
| 68e8717b5c | |||
| b484e6fa3f | |||
| aa8773a67e | |||
| a822d3ef05 | |||
| 311cf81e8a | |||
| bf9ee918f3 | |||
| 92ba76e7a1 | |||
| 3326339263 | |||
| 52cafbc7aa | |||
| efb316de14 | |||
| 3cf944398f | |||
| d2bfd47039 | |||
| 920cb6556b | |||
| cd3ae2a7f5 | |||
| b12fedb2d9 | |||
| 1cae7ad6b1 | |||
| 7dd881aa9a | |||
| c7ad235110 | |||
| a989547976 | |||
| fa75880626 | |||
| 529895f970 | |||
| 3d5de440fd | |||
| 568bb1b0e8 | |||
| b9ae8306dd | |||
| 4aededff46 | |||
| ed8f9863e3 | |||
| e85de55c8f | |||
| adbf927270 | |||
| dfe171a5c2 | |||
| b55e449398 | |||
| 62b11c0a8a | |||
| 90cb11f55e | |||
| 40a66b0306 | |||
| 8c899698e0 | |||
| 58fa1571f3 | |||
| 2cbe77aa04 | |||
| a0c2935580 | |||
| 798f25ff81 | |||
| 57b2e360ca | |||
| ee23d59e11 | |||
| 04e7da9b73 | |||
| 5382d265f2 | |||
| 0e1534613c | |||
| d799fac688 | |||
| 913247996e | |||
| dc3bab26de | |||
| 5c1cf050e2 | |||
| 747bee41b7 | |||
| 246c00c773 | |||
| 272dd79426 | |||
| b953da0341 | |||
| c2a6445c9e | |||
| b177ae7ee6 | |||
| 22bd5be5a9 | |||
| 90fa347fc2 | |||
| 68a9a1439a | |||
| 8947eff3b1 | |||
| 06b3c5ddb5 | |||
| 5fb8a1d3d1 | |||
| b4d307d4cc | |||
| 306bd18a40 | |||
| 1968f47fc9 | |||
| 9b42aa3634 | |||
| 9faa0ddc62 | |||
| 6a2cd9d3ba | |||
| 9028564c10 | |||
| 8f2b23f8f9 | |||
| b471d7419e | |||
| 5179cfc5ba | |||
| 784b2f541d | |||
| 735cf47c35 | |||
| 056742479e | |||
| 840b7e6987 | |||
| a87772c98c | |||
| c15f1e8276 | |||
| 49148dfb7a | |||
| 177f5de2bd | |||
| 96360ddb24 | |||
| f5f2e4970e | |||
| 742256c130 | |||
| b4a622d319 | |||
| b0c4752397 | |||
| bf78a4dfad | |||
| 8d7841b069 | |||
| 396eaa148c | |||
| 2a244f1e53 | |||
| 847181ada4 | |||
| f274f5a0ef | |||
| bb41883070 | |||
| fca5457ab9 | |||
| 4f355ed4a2 | |||
| b1452c714a | |||
| aba48cca53 | |||
| 772d5fb0cc | |||
| 6b6f8cadb2 | |||
| 82ab79e915 | |||
| 863471b5f1 | |||
| 314f280400 | |||
| b75f4bf9a9 | |||
| 253d67ce78 | |||
| 1753bc18c1 | |||
| eceba13164 | |||
| 3c6c640f50 | |||
| 30e3018966 | |||
| 5ab0bb3c0d | |||
| 0de1517bd8 | |||
| 39c6d81b9e | |||
| 1c1fbe83ec | |||
| ccd56e0368 | |||
| 38c7f226cb | |||
| f5446cc415 | |||
| aa2e680568 | |||
| bc651cb774 | |||
| 20b03d0004 | |||
| b005ce8e6b | |||
| 979b8b2663 | |||
| 69b1decbba | |||
| d32c92cbde | |||
| cef88cde20 | |||
| aa3833915b | |||
| 0c0bbeff27 | |||
| ceda14096c | |||
| d5b393d6bd | |||
| e2cdd6a7f9 | |||
| 261d02e67b | |||
| a6ce4694fc | |||
| 14bc65468a | |||
| 56d109bf0a | |||
| a965859095 | |||
| 863ae447b9 | |||
| 4dd922f1b5 | |||
| f95dc40f4c | |||
| 81786f7a7c | |||
| 1381d8d94c | |||
| 1dca02517e | |||
| b109fc7420 | |||
| c74c01271d | |||
| 702b916948 | |||
| 8ed2431f37 | |||
| c45cbebcce | |||
| 251110c4f8 |
@@ -0,0 +1 @@
|
|||||||
|
* text=auto
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!-- No UwU's or OwO's allowed -->
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!-- No UwU's or OwO's allowed -->
|
||||||
@@ -9,6 +9,7 @@ install:
|
|||||||
- travis_retry docker build -t cabaletta/baritone .
|
- travis_retry docker build -t cabaletta/baritone .
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- docker run --rm cabaletta/baritone ./gradlew javadoc
|
||||||
- docker run --name baritone cabaletta/baritone /bin/sh -c "set -e; /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 128x128x24 -ac +extension GLX +render; DISPLAY=:99 BARITONE_AUTO_TEST=true ./gradlew runClient"
|
- docker run --name baritone cabaletta/baritone /bin/sh -c "set -e; /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 128x128x24 -ac +extension GLX +render; DISPLAY=:99 BARITONE_AUTO_TEST=true ./gradlew runClient"
|
||||||
- docker cp baritone:/code/dist dist
|
- docker cp baritone:/code/dist dist
|
||||||
- ls dist
|
- ls dist
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as
|
||||||
|
contributors and maintainers pledge to making participation in our project and
|
||||||
|
our community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||||
|
level of experience, education, socio-economic status, nationality, personal
|
||||||
|
appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment
|
||||||
|
include:
|
||||||
|
|
||||||
|
* No Anime
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* Anime
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||||
|
advances
|
||||||
|
* ~~Trolling, insulting/derogatory comments, and personal or political attacks~~
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic
|
||||||
|
address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable
|
||||||
|
behavior and are expected to take appropriate and fair corrective action in
|
||||||
|
response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or
|
||||||
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||||
|
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
|
||||||
|
when an individual is representing the project or its community. Examples of
|
||||||
|
representing a project or community include using an official project e-mail
|
||||||
|
address, posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event. Representation of a project may be
|
||||||
|
further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported by contacting the project team at complaints@leijurv.com. All
|
||||||
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
|
is deemed necessary and appropriate to the circumstances. The project team is
|
||||||
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||||
|
Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||||
|
faith may face temporary or permanent repercussions as determined by other
|
||||||
|
members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||||
|
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see
|
||||||
|
https://www.contributor-covenant.org/faq
|
||||||
+4
-5
@@ -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
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
|
||||||
RUN apt update -y
|
RUN apt update -y
|
||||||
|
|
||||||
RUN apt install --target-release jessie-backports \
|
RUN apt install \
|
||||||
openjdk-8-jdk \
|
openjdk-8-jdk \
|
||||||
ca-certificates-java \
|
|
||||||
--assume-yes
|
--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
|
COPY . /code
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -4,13 +4,14 @@
|
|||||||
- **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it.
|
- **Block breaking** Baritone considers breaking blocks as part of its path. It also takes into account your current tool set and hot bar. For example, if you have a Eff V diamond pick, it may choose to mine through a stone barrier, while if you only had a wood pick it might be faster to climb over it.
|
||||||
- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. <a href="https://www.youtube.com/watch?v=F6FbI1L9UmU">Example</a>
|
- **Block placing** Baritone considers placing blocks as part of its path. This includes sneak-back-placing, pillaring, etc. It has a configurable penalty of placing a block (set to 1 second by default), to conserve its resources. The list of acceptable throwaway blocks is also configurable, and is cobble, dirt, or netherrack by default. <a href="https://www.youtube.com/watch?v=F6FbI1L9UmU">Example</a>
|
||||||
- **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water.
|
- **Falling** Baritone will fall up to 3 blocks onto solid ground (configurable, if you have Feather Falling and/or don't mind taking a little damage). If you have a water bucket on your hotbar, it will fall up to 23 blocks and place the bucket beneath it. It will fall an unlimited distance into existing still water.
|
||||||
- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`).
|
- **Vines and ladders** Baritone understands how to climb and descend vines and ladders. There is experimental support for more advanced maneuvers, like strafing to a different ladder / vine column in midair (off by default, setting named `allowVines`). Baritone can break its fall by grabbing ladders / vines midair, and understands when that is and isn't possible.
|
||||||
- **Opening fence gates and doors**
|
- **Opening fence gates and doors**
|
||||||
- **Slabs and stairs**
|
- **Slabs and stairs**
|
||||||
- **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore).
|
- **Falling blocks** Baritone understands the costs of breaking blocks with falling blocks on top, and includes all of their break costs. Additionally, since it avoids breaking any blocks touching a liquid, it won't break the bottom of a gravel stack below a lava lake (anymore).
|
||||||
- **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc.
|
- **Avoiding dangerous blocks** Obviously, it knows not to walk through fire or on magma, not to corner over lava (that deals some damage), not to break any blocks touching a liquid (it might drown), etc.
|
||||||
- **Parkour** Sprint jumping over 1, 2, or 3 block gaps
|
- **Parkour** Sprint jumping over 1, 2, or 3 block gaps
|
||||||
- **Parkour place** Sprint jumping over a 3 block gap and placing the block to land on while executing the jump. It's really cool.
|
- **Parkour place** Sprint jumping over a 3 block gap and placing the block to land on while executing the jump. It's really cool.
|
||||||
|
- **Pigs** It can sort of control pigs. I wouldn't rely on it though.
|
||||||
|
|
||||||
# Pathing method
|
# Pathing method
|
||||||
Baritone uses A*, with some modifications:
|
Baritone uses A*, with some modifications:
|
||||||
@@ -21,9 +22,9 @@ Baritone uses A*, with some modifications:
|
|||||||
- **Backtrack cost favoring** While calculating the next segment, Baritone favors backtracking its current segment. The cost is decreased heavily, but is still positive (this won't cause it to backtrack if it doesn't need to). This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. <a href="https://www.youtube.com/watch?v=CGiMcb8-99Y">Example</a>
|
- **Backtrack cost favoring** While calculating the next segment, Baritone favors backtracking its current segment. The cost is decreased heavily, but is still positive (this won't cause it to backtrack if it doesn't need to). This allows it to splice and jump onto the next segment as early as possible, if the next segment begins with a backtrack of the current one. <a href="https://www.youtube.com/watch?v=CGiMcb8-99Y">Example</a>
|
||||||
- **Backtrack detection and pausing** While path calculation happens on a separate thread, the main game thread has access to the latest node considered, and the best path so far (those are rendered light blue and dark blue respectively). When the current best path (rendered dark blue) passes through the player's current position on the current path segment, path execution is paused (if it's safe to do so), because there's no point continuing forward if we're about to turn around and go back that same way. Note that the current best path as reported by the path calculation thread takes into account the incremental cost backoff system, so it's accurate to what the path calculation thread will actually pick once it finishes.
|
- **Backtrack detection and pausing** While path calculation happens on a separate thread, the main game thread has access to the latest node considered, and the best path so far (those are rendered light blue and dark blue respectively). When the current best path (rendered dark blue) passes through the player's current position on the current path segment, path execution is paused (if it's safe to do so), because there's no point continuing forward if we're about to turn around and go back that same way. Note that the current best path as reported by the path calculation thread takes into account the incremental cost backoff system, so it's accurate to what the path calculation thread will actually pick once it finishes.
|
||||||
|
|
||||||
# Configuring Baritone
|
# Chat control
|
||||||
All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>.
|
|
||||||
To change 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 `pathTimeoutMS 250`). It's case insensitive.
|
- [Baritone chat control usage](USAGE.md)
|
||||||
|
|
||||||
# Goals
|
# Goals
|
||||||
The pathing goal can be set to any of these options:
|
The pathing goal can be set to any of these options:
|
||||||
@@ -46,7 +47,6 @@ Things it doesn't have yet
|
|||||||
See <a href="https://github.com/cabaletta/baritone/issues">issues</a> for more.
|
See <a href="https://github.com/cabaletta/baritone/issues">issues</a> for more.
|
||||||
|
|
||||||
Things it may not ever have, from most likely to least likely =(
|
Things it may not ever have, from most likely to least likely =(
|
||||||
- Pigs
|
|
||||||
- Boats
|
- Boats
|
||||||
- Horses (2x3 path instead of 1x2)
|
- Horses (2x3 path instead of 1x2)
|
||||||
- Elytra
|
- Elytra
|
||||||
|
|||||||
-96
@@ -1,96 +0,0 @@
|
|||||||
# Integration between Baritone and Impact
|
|
||||||
Impact 4.4 has Baritone included.
|
|
||||||
|
|
||||||
These instructions apply to Impact 4.3 (and potentially other hacked clients).
|
|
||||||
|
|
||||||
To run Baritone on Vanilla, just follow the instructions in the README (it's `./gradlew runClient`).
|
|
||||||
|
|
||||||
|
|
||||||
## An Introduction
|
|
||||||
There are some basic steps to getting Baritone setup with Impact.
|
|
||||||
- Acquiring a build of Baritone
|
|
||||||
- Placing Baritone in the libraries directory
|
|
||||||
- Modifying the Impact Profile JSON to run baritone
|
|
||||||
- How to use Baritone
|
|
||||||
|
|
||||||
## Acquiring a build of Baritone
|
|
||||||
There are two methods of acquiring a build of Baritone
|
|
||||||
|
|
||||||
### Official Release (Not always up to date)
|
|
||||||
https://github.com/cabaletta/baritone/releases
|
|
||||||
|
|
||||||
For Impact 4.3, there is no Baritone integration yet, so you will want `baritone-standalone-X.Y.Z.jar`.
|
|
||||||
|
|
||||||
Any official release will be GPG signed by leijurv (44A3EA646EADAC6A) and ZeroMemes (73A788379A197567). Please verify that the hash of the file you download is in `checksums.txt` and that `checksums_signed.asc` is a valid signature by those two public keys of `checksums.txt`.
|
|
||||||
|
|
||||||
The build is fully deterministic and reproducible, and you can verify Travis did it properly by running `docker build --no-cache -t cabaletta/baritone . && docker run --rm cabaletta/baritone cat /code/dist/checksums.txt` yourself and comparing the shasum. This works identically on Travis, Mac, and Linux (if you have docker on Windows, I'd be grateful if you could let me know if it works there too).
|
|
||||||
|
|
||||||
### Building Baritone yourself
|
|
||||||
There are a few steps to this
|
|
||||||
- Clone this repository
|
|
||||||
- Setup the project as instructed in the README
|
|
||||||
- Run the ``build`` gradle task. You can either do this using IntelliJ's gradle UI or through a
|
|
||||||
command line
|
|
||||||
- Windows: ``gradlew build``
|
|
||||||
- Mac/Linux: ``./gradlew build``
|
|
||||||
- The build should be exported into ``/build/libs/baritone-X.Y.Z.jar``
|
|
||||||
|
|
||||||
## Placing Baritone in the libraries directory
|
|
||||||
``/libraries`` is a neat directory in your <a href="https://minecraft.gamepedia.com/.minecraft">Minecraft Installation Directory</a>
|
|
||||||
that contains all of the dependencies that are required from the game and some mods. This is where we will be
|
|
||||||
putting baritone.
|
|
||||||
- Locate the ``libraries`` folder, it should be in the Minecraft Installation Directory
|
|
||||||
- Create 3 new subdirectories starting from ``libraries``
|
|
||||||
- ``cabaletta``
|
|
||||||
- ``baritone``
|
|
||||||
- ``X.Y.Z``
|
|
||||||
- Copy the build of Baritone that was acquired earlier, and place it into the ``X.Y.Z`` folder
|
|
||||||
- The full path should look like ``<Minecraft>/libraries/cabaletta/baritone/X.Y.Z/baritone-X.Y.Z.jar``
|
|
||||||
|
|
||||||
## Modifying the Impact Profile JSON to run baritone
|
|
||||||
The final step is "registering" the Baritone library with Impact, so that it loads on launch.
|
|
||||||
- Ensure your Minecraft launcher is closed
|
|
||||||
- Navigate back to the Minecraft Installation Directory
|
|
||||||
- Find the ``versions`` directory, and open in
|
|
||||||
- In here there should be a ``1.12.2-Impact_4.3`` folder.
|
|
||||||
- If you don't have any Impact folder or have a version older than 4.3, you can download Impact <a href="https://impactdevelopment.github.io">here</a>.
|
|
||||||
- Open the folder and inside there should be a file called ``1.12.2-Impact_4.3.json``
|
|
||||||
- Open the JSON file with a text editor that supports your system's line endings
|
|
||||||
- For example, Notepad on Windows likely will NOT work for this. You should instead use a Text Editor like
|
|
||||||
<a href="https://notepad-plus-plus.org/">Notepad++</a> if you're on Windows. (For other systems, I'm not sure
|
|
||||||
what would work the best so you may have to do some research.)
|
|
||||||
- Find the ``libraries`` array in the JSON. It should look something like this.
|
|
||||||
```
|
|
||||||
"libraries": [
|
|
||||||
{
|
|
||||||
"name": "net.minecraft:launchwrapper:1.12"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.github.ImpactDevelopment:Impact:4.3-1.12.2",
|
|
||||||
"url": "https://impactdevelopment.github.io/maven/"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.github.ImpactDeveloment:ClientAPI:3.0.2",
|
|
||||||
"url": "https://impactdevelopment.github.io/maven/"
|
|
||||||
},
|
|
||||||
...
|
|
||||||
```
|
|
||||||
- Create two new objects in the array, between the ``Impact`` and ``ClientAPI`` dependencies preferably.
|
|
||||||
```
|
|
||||||
{
|
|
||||||
"name": "cabaletta:baritone:X.Y.Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "com.github.ImpactDevelopment:SimpleTweaker:1.2",
|
|
||||||
"url": "https://impactdevelopment.github.io/maven/"
|
|
||||||
},
|
|
||||||
```
|
|
||||||
- Now find the ``"minecraftArguments": "..."`` text near the top.
|
|
||||||
- At the very end of the quotes where it says ``--tweakClass clientapi.load.ClientTweaker"``, add on the following so it looks like:
|
|
||||||
- ``--tweakClass clientapi.load.ClientTweaker --tweakClass baritone.launch.BaritoneTweakerOptifine"``
|
|
||||||
- If you didn't close your launcher for this step, restart it now.
|
|
||||||
- You can now launch Impact 4.3 as normal, and Baritone should start up
|
|
||||||
|
|
||||||
## How to use Baritone
|
|
||||||
Instructions on how to use Baritone are limited, and you may have to read a little bit of code (Really nothing much
|
|
||||||
just plain English), you can view that <a href="https://github.com/cabaletta/baritone#chat-control">here</a>.
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
@@ -1,65 +1,68 @@
|
|||||||
# Baritone
|
# Baritone
|
||||||
[](https://travis-ci.com/cabaletta/baritone)
|
[](https://travis-ci.com/cabaletta/baritone)
|
||||||
[](https://github.com/cabaletta/baritone/releases)
|
[](https://github.com/cabaletta/baritone/releases)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade)
|
[](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)
|
[](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://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle)
|
||||||
[](https://github.com/cabaletta/baritone/issues)
|
[](https://github.com/cabaletta/baritone/issues)
|
||||||
[](https://minecraft.gamepedia.com/1.12.2)
|
[](https://github.com/cabaletta/baritone/issues/)
|
||||||
[](https://impactdevelopment.github.io/)
|
[](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed)
|
||||||
[](https://github.com/zeroeightysix/KAMI/)
|
[](https://github.com/cabaletta/baritone/pulls/)
|
||||||
[](https://github.com/EmotionalLove/Asuna/)
|

|
||||||
[](https://futureclient.net/)
|

|
||||||
|

|
||||||
|
[](https://github.com/cabaletta/baritone/graphs/contributors/)
|
||||||
|
[](https://github.com/cabaletta/baritone/commit/)
|
||||||
|
[](https://impactdevelopment.github.io/)
|
||||||
|
[](https://github.com/fr1kin/ForgeHax/)
|
||||||
|
[](https://wweclient.com/)
|
||||||
|
[](https://futureclient.net/)
|
||||||
|
[](http://forthebadge.com/)
|
||||||
|
[](http://forthebadge.com/)
|
||||||
|
|
||||||
A Minecraft pathfinder bot.
|
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.
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/),
|
This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/),
|
||||||
the original version of the bot for Minecraft 1.8, rebuilt for 1.12.2. Baritone focuses on reliability and particularly performance (it's over [29x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths).
|
the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 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
|
||||||
|
|
||||||
|
# Getting Started
|
||||||
|
|
||||||
Here are some links to help to get started:
|
Here are some links to help to get started:
|
||||||
|
|
||||||
- [Features](FEATURES.md)
|
- [Features](FEATURES.md)
|
||||||
|
|
||||||
- [Installation](INSTALL.md)
|
- [Installation & setup](SETUP.md)
|
||||||
|
|
||||||
# Setup
|
- [API Javadocs](https://baritone.leijurv.com)
|
||||||
|
|
||||||
## Command Line
|
- [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail)
|
||||||
On Mac OSX and Linux, use `./gradlew` instead of `gradlew`.
|
|
||||||
|
|
||||||
Running Baritone:
|
- [Usage (chat control)](USAGE.md)
|
||||||
|
|
||||||
```
|
# API
|
||||||
$ gradlew runClient
|
|
||||||
```
|
|
||||||
|
|
||||||
Building Baritone:
|
The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/).
|
||||||
```
|
Please note that usage of anything located outside of the ``baritone.api`` package is not supported by the API release
|
||||||
$ gradlew build
|
jar.
|
||||||
```
|
|
||||||
|
|
||||||
To replace out Impact 4.4's Baritone build with a customized one, switch to the `impact4.4-compat` branch, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.0.0/baritone-api-1.0.0.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.4/1.12.2-Impact_4.4.json`, find the line `"name": "cabaletta:baritone-api:1.0.0"`, remove the comma from the end, and entirely remove the line that's immediately after (starts with `"url"`).
|
Below is an example of basic usage for changing some settings, and then pathing to a X/Z goal.
|
||||||
|
|
||||||
## IntelliJ's Gradle UI
|
|
||||||
- Open the project in IntelliJ as a Gradle project
|
|
||||||
- Run the Gradle tasks `setupDecompWorkspace` then `genIntellijRuns`
|
|
||||||
- Refresh the Gradle project (or, to be safe, just restart IntelliJ)
|
|
||||||
- Select the "Minecraft Client" launch config
|
|
||||||
- In `Edit Configurations...` you may need to select `baritone_launch` for `Use classpath of module:`.
|
|
||||||
|
|
||||||
# Chat control
|
|
||||||
[Defined Here](src/main/java/baritone/utils/ExampleBaritoneControl.java)
|
|
||||||
|
|
||||||
Quick start example: `thisway 1000` or `goal 70` to set the goal, `path` to actually start pathing. Also try `mine diamond_ore`. `cancel` to cancel.
|
|
||||||
|
|
||||||
# API example
|
|
||||||
|
|
||||||
```
|
```
|
||||||
BaritoneAPI.getSettings().allowSprint.value = true;
|
BaritoneAPI.getSettings().allowSprint.value = true;
|
||||||
BaritoneAPI.getSettings().pathTimeoutMS.value = 2000L;
|
BaritoneAPI.getSettings().primaryTimeoutMS.value = 2000L;
|
||||||
|
|
||||||
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalXZ(10000, 20000));
|
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalXZ(10000, 20000));
|
||||||
```
|
```
|
||||||
@@ -68,11 +71,11 @@ BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAnd
|
|||||||
|
|
||||||
## Can I use Baritone as a library in my custom utility client?
|
## Can I use Baritone as a library in my custom utility client?
|
||||||
|
|
||||||
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?
|
## How is it so fast?
|
||||||
|
|
||||||
Magic. (Hours of [Leijurv](https://github.com/leijurv) enduring excruciating pain)
|
Magic. (Hours of [leijurv](https://github.com/leijurv) enduring excruciating pain)
|
||||||
|
|
||||||
## Why is it called Baritone?
|
## Why is it called Baritone?
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
# 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 `backfill-2` branch for example, you'll have to build it yourself)
|
||||||
|
|
||||||
|
Link to the releases page: [Releases](https://github.com/cabaletta/baritone/releases)
|
||||||
|
|
||||||
|
Any official release will be GPG signed by leijurv (44A3EA646EADAC6A) and ZeroMemes (73A788379A197567). Please verify that the hash of the file you download is in `checksums.txt` and that `checksums_signed.asc` is a valid signature by those two public keys of `checksums.txt`.
|
||||||
|
|
||||||
|
The build is fully deterministic and reproducible, and you can verify Travis did it properly by running `docker build --no-cache -t cabaletta/baritone .` yourself and comparing the shasum. This works identically on Travis, Mac, and Linux (if you have docker on Windows, I'd be grateful if you could let me know if it works there too).
|
||||||
|
|
||||||
|
|
||||||
|
## Artifacts
|
||||||
|
|
||||||
|
Building Baritone will result in 5 artifacts created in the ``dist`` directory. These are the same as the artifacts created in the [releases](https://github.com/cabaletta/baritone/releases).
|
||||||
|
|
||||||
|
**The Forge release can simply be added as a Forge mod.**
|
||||||
|
|
||||||
|
If another one of your Forge mods has a Baritone integration, you want `baritone-api-forge-VERSION.jar`. Otherwise, you want `baritone-standalone-forge-VERSION.jar`
|
||||||
|
|
||||||
|
- **API**: Only the non-api packages are obfuscated. This should be used in environments where other mods would like to use Baritone's features.
|
||||||
|
- **Forge API**: Same as API, but packaged for Forge. This should be used where another mod has a Baritone integration.
|
||||||
|
- **Standalone**: Everything is obfuscated. This should be used in environments where there are no other mods present that would like to use Baritone's features.
|
||||||
|
- **Forge Standalone**: Same as Standalone, but packaged for Forge. This should be used when Baritone is your only Forge mod, or none of your other Forge mods integrate with Baritone.
|
||||||
|
- **Unoptimized**: Nothing is obfuscated. This shouldn't be used ever in production.
|
||||||
|
|
||||||
|
## More Info
|
||||||
|
To replace out Impact 4.5's Baritone build with a customized one, build Baritone as above then copy & **rename** `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.2/baritone-api-1.2.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.5/1.12.2-Impact_4.5.json`, find the line `"name": "cabaletta:baritone-api:1.2"`, remove the comma from the end, and **entirely remove the NEXT line** (starts with `"url"`). **Restart your launcher** then load as normal.
|
||||||
|
|
||||||
|
You can verify whether or not it worked by running `.b version` in chat (only valid in Impact). It should print out the version that you downloaded. Note: The version that comes with 4.5 is `v1.2.3`.
|
||||||
|
|
||||||
|
## Build it yourself
|
||||||
|
- Clone or download Baritone
|
||||||
|
|
||||||
|

|
||||||
|
- If you choose to download, make sure you extract the ZIP archive.
|
||||||
|
- Follow one of the instruction sets below, based on your preference
|
||||||
|
|
||||||
|
## Command Line
|
||||||
|
On Mac OSX and Linux, use `./gradlew` instead of `gradlew`.
|
||||||
|
|
||||||
|
Setting up the Environment:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ gradlew setupDecompWorkspace
|
||||||
|
$ gradlew --refresh-dependencies
|
||||||
|
```
|
||||||
|
|
||||||
|
Running Baritone:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ gradlew runClient
|
||||||
|
```
|
||||||
|
|
||||||
|
For information on how to build baritone, see [Building Baritone](#building-baritone)
|
||||||
|
|
||||||
|
## IntelliJ
|
||||||
|
- Open the project in IntelliJ as a Gradle project
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Run the Gradle tasks `setupDecompWorkspace` then `genIntellijRuns`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Refresh the Gradle project (or, to be safe, just restart IntelliJ)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Select the "Minecraft Client" launch config
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Click on ``Edit Configurations...`` from the same dropdown and select the "Minecraft Client" config
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- In `Edit Configurations...` you need to select `baritone_launch` for `Use classpath of module:`.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
# Building
|
||||||
|
|
||||||
|
Make sure that you have properly [setup](#setup) the environment before trying to build it.
|
||||||
|
|
||||||
|
## Command Line
|
||||||
|
|
||||||
|
```
|
||||||
|
$ gradlew build
|
||||||
|
```
|
||||||
|
|
||||||
|
## IntelliJ
|
||||||
|
|
||||||
|
- Navigate to the gradle tasks on the right tab as follows
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Double click on **build** to run it
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
(assuming you already have Baritone [set up](SETUP.md))
|
||||||
|
|
||||||
|
# Prefix
|
||||||
|
|
||||||
|
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/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
|
||||||
|
- `goal` to set the goal to your player's feet
|
||||||
|
- `goal clear` to clear the goal
|
||||||
|
- `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. 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.
|
||||||
|
- `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/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>.
|
||||||
|
|
||||||
|
There are about a hundred settings, but here are some fun / interesting / important ones that you might want to look at changing in normal usage of Baritone. The documentation for each can be found at the above links.
|
||||||
|
- `allowBreak`
|
||||||
|
- `allowSprint`
|
||||||
|
- `allowPlace`
|
||||||
|
- `allowParkour`
|
||||||
|
- `allowParkourPlace`
|
||||||
|
- `blockPlacementPenalty`
|
||||||
|
- `renderCachedChunks` (and `cachedChunksOpacity`) <-- very fun but you need a beefy computer
|
||||||
|
- `avoidance` (avoidance of mobs / mob spawners)
|
||||||
|
- `legitMine`
|
||||||
|
- `followRadius`
|
||||||
|
- `backfill` (fill in tunnels behind you)
|
||||||
|
- `buildInLayers`
|
||||||
|
- `buildRepeatDistance` and `buildRepeatDirection`
|
||||||
|
- `worldExploringChunkOffset`
|
||||||
|
- `acceptableThrowawayItems`
|
||||||
|
- `blocksToAvoidBreaking`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Troubleshooting / common issues
|
||||||
|
|
||||||
|
## Why doesn't Baritone respond to any of my chat commands?
|
||||||
|
This could be one of many things.
|
||||||
|
|
||||||
|
First, make sure it's actually installed. An easy way to check is seeing if it created the folder `baritone` in your Minecraft folder.
|
||||||
|
|
||||||
|
Second, make sure that you're using the prefix properly, and that chat control is enabled in the way you expect.
|
||||||
|
|
||||||
|
For example, Impact disables direct chat control. (i.e. anything typed in chat without a prefix will be ignored and sent publicly). **This is a saved setting**, so if you run Impact once, `chatControl` will be off from then on, **even in other clients**.
|
||||||
|
So you'll need to use the `#` prefix or edit `baritone/settings.txt` in your Minecraft folder to undo that (specifically, remove the line `chatControl false` then restart your client).
|
||||||
|
|
||||||
|
|
||||||
|
## Why can I do `.goto x z` in Impact but nowhere else? Why can I do `-path to x z` in KAMI but nowhere else?
|
||||||
|
These are custom commands that they added; those aren't from Baritone.
|
||||||
|
The equivalent you're looking for is `goal x z` then `path`.
|
||||||
+16
-3
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
group 'baritone'
|
group 'baritone'
|
||||||
version '1.0.0-hotfix-2'
|
version '1.2.7'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
@@ -48,6 +48,7 @@ apply plugin: 'org.spongepowered.mixin'
|
|||||||
sourceCompatibility = targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = '1.8'
|
||||||
compileJava {
|
compileJava {
|
||||||
sourceCompatibility = targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = '1.8'
|
||||||
|
options.encoding = "UTF-8" // allow emoji in comments :^)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@@ -94,19 +95,31 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
mixin {
|
||||||
defaultObfuscationEnv notch
|
defaultObfuscationEnv searge
|
||||||
add sourceSets.launch, 'mixins.baritone.refmap.json'
|
add sourceSets.launch, 'mixins.baritone.refmap.json'
|
||||||
}
|
}
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
|
options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error
|
||||||
|
options.linkSource true
|
||||||
|
options.encoding "UTF-8" // allow emoji in comments :^)
|
||||||
source = sourceSets.api.allJava
|
source = sourceSets.api.allJava
|
||||||
classpath = sourceSets.api.compileClasspath
|
classpath += sourceSets.api.compileClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
from sourceSets.launch.output, sourceSets.api.output
|
from sourceSets.launch.output, sourceSets.api.output
|
||||||
preserveFileTimestamps = false
|
preserveFileTimestamps = false
|
||||||
reproducibleFileOrder = true
|
reproducibleFileOrder = true
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
'MixinConfigs': 'mixins.baritone.json',
|
||||||
|
|
||||||
|
'Implementation-Title': 'Baritone',
|
||||||
|
'Implementation-Version': version
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task proguard(type: ProguardTask) {
|
task proguard(type: ProguardTask) {
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package baritone.gradle.task;
|
package baritone.gradle.task;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import org.gradle.api.DefaultTask;
|
import org.gradle.api.DefaultTask;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -26,7 +24,6 @@ import java.io.InputStream;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@@ -34,8 +31,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
class BaritoneGradleTask extends DefaultTask {
|
class BaritoneGradleTask extends DefaultTask {
|
||||||
|
|
||||||
protected static final JsonParser PARSER = new JsonParser();
|
|
||||||
|
|
||||||
protected static final String
|
protected static final String
|
||||||
PROGUARD_ZIP = "proguard.zip",
|
PROGUARD_ZIP = "proguard.zip",
|
||||||
PROGUARD_JAR = "proguard.jar",
|
PROGUARD_JAR = "proguard.jar",
|
||||||
@@ -45,26 +40,28 @@ class BaritoneGradleTask extends DefaultTask {
|
|||||||
PROGUARD_STANDALONE_CONFIG = "standalone.pro",
|
PROGUARD_STANDALONE_CONFIG = "standalone.pro",
|
||||||
PROGUARD_EXPORT_PATH = "proguard_out.jar",
|
PROGUARD_EXPORT_PATH = "proguard_out.jar",
|
||||||
|
|
||||||
VERSION_MANIFEST = "version_manifest.json",
|
|
||||||
|
|
||||||
TEMP_LIBRARY_DIR = "tempLibraries/",
|
TEMP_LIBRARY_DIR = "tempLibraries/",
|
||||||
|
|
||||||
ARTIFACT_STANDARD = "%s-%s.jar",
|
ARTIFACT_STANDARD = "%s-%s.jar",
|
||||||
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
|
ARTIFACT_UNOPTIMIZED = "%s-unoptimized-%s.jar",
|
||||||
ARTIFACT_API = "%s-api-%s.jar",
|
ARTIFACT_API = "%s-api-%s.jar",
|
||||||
ARTIFACT_STANDALONE = "%s-standalone-%s.jar";
|
ARTIFACT_STANDALONE = "%s-standalone-%s.jar",
|
||||||
|
ARTIFACT_FORGE_API = "%s-api-forge-%s.jar",
|
||||||
|
ARTIFACT_FORGE_STANDALONE = "%s-standalone-forge-%s.jar";
|
||||||
|
|
||||||
protected String artifactName, artifactVersion;
|
protected String artifactName, artifactVersion;
|
||||||
protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, proguardOut;
|
protected Path artifactPath, artifactUnoptimizedPath, artifactApiPath, artifactStandalonePath, artifactForgeApiPath, artifactForgeStandalonePath, proguardOut;
|
||||||
|
|
||||||
protected void verifyArtifacts() throws IllegalStateException {
|
protected void verifyArtifacts() throws IllegalStateException {
|
||||||
this.artifactName = getProject().getName();
|
this.artifactName = getProject().getName();
|
||||||
this.artifactVersion = getProject().getVersion().toString();
|
this.artifactVersion = getProject().getVersion().toString();
|
||||||
|
|
||||||
this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
|
this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
|
||||||
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
|
this.artifactUnoptimizedPath = this.getBuildFile(formatVersion(ARTIFACT_UNOPTIMIZED));
|
||||||
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
|
this.artifactApiPath = this.getBuildFile(formatVersion(ARTIFACT_API));
|
||||||
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
|
this.artifactStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_STANDALONE));
|
||||||
|
this.artifactForgeApiPath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_API));
|
||||||
|
this.artifactForgeStandalonePath = this.getBuildFile(formatVersion(ARTIFACT_FORGE_STANDALONE));
|
||||||
|
|
||||||
this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH);
|
this.proguardOut = this.getTemporaryFile(PROGUARD_EXPORT_PATH);
|
||||||
|
|
||||||
@@ -95,8 +92,4 @@ class BaritoneGradleTask extends DefaultTask {
|
|||||||
protected Path getBuildFile(String file) {
|
protected Path getBuildFile(String file) {
|
||||||
return getRelativeFile("build/libs/" + file);
|
return getRelativeFile("build/libs/" + file);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JsonElement readJson(List<String> lines) {
|
|
||||||
return PARSER.parse(String.join("\n", lines));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,11 @@ public class CreateDistTask extends BaritoneGradleTask {
|
|||||||
super.verifyArtifacts();
|
super.verifyArtifacts();
|
||||||
|
|
||||||
// Define the distribution file paths
|
// Define the distribution file paths
|
||||||
Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API));
|
Path api = getRelativeFile("dist/" + formatVersion(ARTIFACT_API));
|
||||||
Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE));
|
Path standalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE));
|
||||||
Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED));
|
Path unoptimized = getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED));
|
||||||
|
Path forgeApi = getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API));
|
||||||
|
Path forgeStandalone = getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE));
|
||||||
|
|
||||||
// NIO will not automatically create directories
|
// NIO will not automatically create directories
|
||||||
Path dir = getRelativeFile("dist/");
|
Path dir = getRelativeFile("dist/");
|
||||||
@@ -53,12 +55,14 @@ public class CreateDistTask extends BaritoneGradleTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy build jars to dist/
|
// Copy build jars to dist/
|
||||||
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
|
Files.copy(this.artifactApiPath, api, REPLACE_EXISTING);
|
||||||
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
|
Files.copy(this.artifactStandalonePath, standalone, REPLACE_EXISTING);
|
||||||
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
|
Files.copy(this.artifactUnoptimizedPath, unoptimized, REPLACE_EXISTING);
|
||||||
|
Files.copy(this.artifactForgeApiPath, forgeApi, REPLACE_EXISTING);
|
||||||
|
Files.copy(this.artifactForgeStandalonePath, forgeStandalone, REPLACE_EXISTING);
|
||||||
|
|
||||||
// Calculate all checksums and format them like "shasum"
|
// Calculate all checksums and format them like "shasum"
|
||||||
List<String> shasum = Stream.of(api, standalone, unoptimized)
|
List<String> shasum = Stream.of(api, forgeApi, standalone, forgeStandalone, unoptimized)
|
||||||
.map(path -> sha1(path) + " " + path.getFileName().toString())
|
.map(path -> sha1(path) + " " + path.getFileName().toString())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
|
|
||||||
private List<String> requiredLibraries;
|
private List<String> requiredLibraries;
|
||||||
|
|
||||||
|
private File mixin;
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
protected void exec() throws Exception {
|
protected void exec() throws Exception {
|
||||||
super.verifyArtifacts();
|
super.verifyArtifacts();
|
||||||
@@ -79,7 +81,7 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
Files.delete(this.artifactUnoptimizedPath);
|
Files.delete(this.artifactUnoptimizedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString());
|
Determinizer.determinize(this.artifactPath.toString(), this.artifactUnoptimizedPath.toString(), Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadProguard() throws Exception {
|
private void downloadProguard() throws Exception {
|
||||||
@@ -173,10 +175,16 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
// Find the library jar file, and copy it to tempLibraries
|
// Find the library jar file, and copy it to tempLibraries
|
||||||
for (File file : pair.getLeft().files(pair.getRight())) {
|
for (File file : pair.getLeft().files(pair.getRight())) {
|
||||||
if (file.getName().startsWith(lib)) {
|
if (file.getName().startsWith(lib)) {
|
||||||
|
if (lib.contains("mixin")) {
|
||||||
|
mixin = file;
|
||||||
|
}
|
||||||
Files.copy(file.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), REPLACE_EXISTING);
|
Files.copy(file.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mixin == null) {
|
||||||
|
throw new IllegalStateException("Unable to find mixin jar");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// a bunch of epic stuff to get the path to the cached jar
|
// a bunch of epic stuff to get the path to the cached jar
|
||||||
@@ -264,12 +272,14 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
|
|
||||||
private void proguardApi() throws Exception {
|
private void proguardApi() throws Exception {
|
||||||
runProguard(getTemporaryFile(PROGUARD_API_CONFIG));
|
runProguard(getTemporaryFile(PROGUARD_API_CONFIG));
|
||||||
Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString());
|
Determinizer.determinize(this.proguardOut.toString(), this.artifactApiPath.toString(), Optional.empty());
|
||||||
|
Determinizer.determinize(this.proguardOut.toString(), this.artifactForgeApiPath.toString(), Optional.of(mixin));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void proguardStandalone() throws Exception {
|
private void proguardStandalone() throws Exception {
|
||||||
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
|
runProguard(getTemporaryFile(PROGUARD_STANDALONE_CONFIG));
|
||||||
Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString());
|
Determinizer.determinize(this.proguardOut.toString(), this.artifactStandalonePath.toString(), Optional.empty());
|
||||||
|
Determinizer.determinize(this.proguardOut.toString(), this.artifactForgeStandalonePath.toString(), Optional.of(mixin));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
@@ -298,8 +308,8 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
.start();
|
.start();
|
||||||
|
|
||||||
// We can't do output inherit process I/O with gradle for some reason and have it work, so we have to do this
|
// We can't do output inherit process I/O with gradle for some reason and have it work, so we have to do this
|
||||||
this.printOutputLog(p.getInputStream());
|
this.printOutputLog(p.getInputStream(), System.out);
|
||||||
this.printOutputLog(p.getErrorStream());
|
this.printOutputLog(p.getErrorStream(), System.err);
|
||||||
|
|
||||||
// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
|
// Halt the current thread until the process is complete, if the exit code isn't 0, throw an exception
|
||||||
int exitCode = p.waitFor();
|
int exitCode = p.waitFor();
|
||||||
@@ -308,12 +318,12 @@ public class ProguardTask extends BaritoneGradleTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printOutputLog(InputStream stream) {
|
private void printOutputLog(InputStream stream, PrintStream outerr) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
System.out.println(line);
|
outerr.println(line);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ import com.google.gson.stream.JsonReader;
|
|||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
@@ -39,7 +36,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class Determinizer {
|
public class Determinizer {
|
||||||
|
|
||||||
public static void determinize(String inputPath, String outputPath) throws IOException {
|
public static void determinize(String inputPath, String outputPath, Optional<File> toInclude) throws IOException {
|
||||||
System.out.println("Running Determinizer");
|
System.out.println("Running Determinizer");
|
||||||
System.out.println(" Input path: " + inputPath);
|
System.out.println(" Input path: " + inputPath);
|
||||||
System.out.println(" Output path: " + outputPath);
|
System.out.println(" Output path: " + outputPath);
|
||||||
@@ -66,10 +63,30 @@ public class Determinizer {
|
|||||||
if (entry.getName().endsWith(".refmap.json")) {
|
if (entry.getName().endsWith(".refmap.json")) {
|
||||||
JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject();
|
JsonObject object = new JsonParser().parse(new InputStreamReader(jarFile.getInputStream(entry))).getAsJsonObject();
|
||||||
jos.write(writeSorted(object).getBytes());
|
jos.write(writeSorted(object).getBytes());
|
||||||
|
} else if (entry.getName().equals("META-INF/MANIFEST.MF") && toInclude.isPresent()) { // only replace for forge jar
|
||||||
|
ByteArrayOutputStream cancer = new ByteArrayOutputStream();
|
||||||
|
copy(jarFile.getInputStream(entry), cancer);
|
||||||
|
String manifest = new String(cancer.toByteArray());
|
||||||
|
if (!manifest.contains("baritone.launch.BaritoneTweaker")) {
|
||||||
|
throw new IllegalStateException("unable to replace");
|
||||||
|
}
|
||||||
|
manifest = manifest.replace("baritone.launch.BaritoneTweaker", "org.spongepowered.asm.launch.MixinTweaker");
|
||||||
|
jos.write(manifest.getBytes());
|
||||||
} else {
|
} else {
|
||||||
copy(jarFile.getInputStream(entry), jos);
|
copy(jarFile.getInputStream(entry), jos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (toInclude.isPresent()) {
|
||||||
|
try (JarFile mixin = new JarFile(toInclude.get())) {
|
||||||
|
for (JarEntry entry : mixin.stream().sorted(Comparator.comparing(JarEntry::getName)).collect(Collectors.toList())) {
|
||||||
|
if (entry.getName().startsWith("META-INF") && !entry.getName().startsWith("META-INF/services")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
jos.putNextEntry(entry);
|
||||||
|
copy(mixin.getInputStream(entry), jos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
jos.finish();
|
jos.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-2
@@ -12,14 +12,16 @@
|
|||||||
-flattenpackagehierarchy
|
-flattenpackagehierarchy
|
||||||
-repackageclasses 'baritone'
|
-repackageclasses 'baritone'
|
||||||
|
|
||||||
|
# lwjgl is weird
|
||||||
|
-dontwarn org.lwjgl.**
|
||||||
|
|
||||||
-keep class baritone.api.** { *; } # this is the keep api
|
-keep class baritone.api.** { *; } # this is the keep api
|
||||||
|
|
||||||
# service provider needs these class names
|
# service provider needs these class names
|
||||||
-keep class baritone.BaritoneProvider
|
-keep class baritone.BaritoneProvider
|
||||||
-keep class baritone.api.IBaritoneProvider
|
-keep class baritone.api.IBaritoneProvider
|
||||||
|
|
||||||
# hack
|
-keep class baritone.api.utils.MyChunkPos { *; } # even in standalone we need to keep this for gson reflect
|
||||||
-keep class baritone.utils.ExampleBaritoneControl { *; } # have to include this string to remove this keep in the standalone build: # this is the keep api
|
|
||||||
|
|
||||||
# setting names are reflected from field names, so keep field names
|
# setting names are reflected from field names, so keep field names
|
||||||
-keepclassmembers class baritone.api.Settings {
|
-keepclassmembers class baritone.api.Settings {
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ import java.util.Iterator;
|
|||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API exposure for various things implemented in Baritone.
|
* Exposes the {@link IBaritoneProvider} instance and the {@link Settings} instance for API usage.
|
||||||
* <p>
|
|
||||||
* W.I.P
|
|
||||||
*
|
*
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 9/23/2018
|
* @since 9/23/2018
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ import baritone.api.behavior.IPathingBehavior;
|
|||||||
import baritone.api.cache.IWorldProvider;
|
import baritone.api.cache.IWorldProvider;
|
||||||
import baritone.api.event.listener.IEventBus;
|
import baritone.api.event.listener.IEventBus;
|
||||||
import baritone.api.pathing.calc.IPathingControlManager;
|
import baritone.api.pathing.calc.IPathingControlManager;
|
||||||
import baritone.api.process.ICustomGoalProcess;
|
import baritone.api.process.*;
|
||||||
import baritone.api.process.IFollowProcess;
|
|
||||||
import baritone.api.process.IGetToBlockProcess;
|
|
||||||
import baritone.api.process.IMineProcess;
|
|
||||||
import baritone.api.utils.IInputOverrideHandler;
|
import baritone.api.utils.IInputOverrideHandler;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
|
|
||||||
@@ -36,22 +33,13 @@ import baritone.api.utils.IPlayerContext;
|
|||||||
public interface IBaritone {
|
public interface IBaritone {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The {@link IFollowProcess} instance
|
* Call as soon as Minecraft is ready, initializes all of the processes, behaviors, etc. This will
|
||||||
* @see IFollowProcess
|
* only effectively be ran once, any additional calls are redundant because the initialization state
|
||||||
|
* is saved.
|
||||||
|
* <p>
|
||||||
|
* Or whenever your overeager utility client wants.
|
||||||
*/
|
*/
|
||||||
IFollowProcess getFollowProcess();
|
void init();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The {@link ILookBehavior} instance
|
|
||||||
* @see ILookBehavior
|
|
||||||
*/
|
|
||||||
ILookBehavior getLookBehavior();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The {@link IMineProcess} instance
|
|
||||||
* @see IMineProcess
|
|
||||||
*/
|
|
||||||
IMineProcess getMineProcess();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The {@link IPathingBehavior} instance
|
* @return The {@link IPathingBehavior} instance
|
||||||
@@ -59,21 +47,86 @@ public interface IBaritone {
|
|||||||
*/
|
*/
|
||||||
IPathingBehavior getPathingBehavior();
|
IPathingBehavior getPathingBehavior();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link ILookBehavior} instance
|
||||||
|
* @see ILookBehavior
|
||||||
|
*/
|
||||||
|
ILookBehavior getLookBehavior();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IFollowProcess} instance
|
||||||
|
* @see IFollowProcess
|
||||||
|
*/
|
||||||
|
IFollowProcess getFollowProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IMineProcess} instance
|
||||||
|
* @see IMineProcess
|
||||||
|
*/
|
||||||
|
IMineProcess getMineProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IBuilderProcess} instance
|
||||||
|
* @see IBuilderProcess
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
ICustomGoalProcess getCustomGoalProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IGetToBlockProcess} instance
|
||||||
|
* @see IGetToBlockProcess
|
||||||
|
*/
|
||||||
|
IGetToBlockProcess getGetToBlockProcess();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The {@link IWorldProvider} instance
|
* @return The {@link IWorldProvider} instance
|
||||||
* @see IWorldProvider
|
* @see IWorldProvider
|
||||||
*/
|
*/
|
||||||
IWorldProvider getWorldProvider();
|
IWorldProvider getWorldProvider();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link IPathingControlManager} for this {@link IBaritone} instance, which is responsible
|
||||||
|
* for managing the {@link IBaritoneProcess}es which control the {@link IPathingBehavior} state.
|
||||||
|
*
|
||||||
|
* @return The {@link IPathingControlManager} instance
|
||||||
|
* @see IPathingControlManager
|
||||||
|
*/
|
||||||
IPathingControlManager getPathingControlManager();
|
IPathingControlManager getPathingControlManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IInputOverrideHandler} instance
|
||||||
|
* @see IInputOverrideHandler
|
||||||
|
*/
|
||||||
IInputOverrideHandler getInputOverrideHandler();
|
IInputOverrideHandler getInputOverrideHandler();
|
||||||
|
|
||||||
ICustomGoalProcess getCustomGoalProcess();
|
/**
|
||||||
|
* @return The {@link IPlayerContext} instance
|
||||||
IGetToBlockProcess getGetToBlockProcess();
|
* @see IPlayerContext
|
||||||
|
*/
|
||||||
IPlayerContext getPlayerContext();
|
IPlayerContext getPlayerContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IEventBus} instance
|
||||||
|
* @see IEventBus
|
||||||
|
*/
|
||||||
IEventBus getGameEventHandler();
|
IEventBus getGameEventHandler();
|
||||||
|
|
||||||
|
void openClick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ import net.minecraft.client.entity.EntityPlayerSP;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Leijurv
|
* Provides the present {@link IBaritone} instances
|
||||||
|
*
|
||||||
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public interface IBaritoneProvider {
|
public interface IBaritoneProvider {
|
||||||
|
|
||||||
@@ -47,7 +49,8 @@ public interface IBaritoneProvider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be
|
* Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be
|
||||||
* replaced with {@code #getBaritoneForUser(IBaritoneUser)} when {@code bot-system} is merged.
|
* replaced with or be overloaded in addition to {@code #getBaritoneForUser(IBaritoneUser)} when
|
||||||
|
* {@code bot-system} is merged into {@code master}.
|
||||||
*
|
*
|
||||||
* @param player The player
|
* @param player The player
|
||||||
* @return The {@link IBaritone} instance.
|
* @return The {@link IBaritone} instance.
|
||||||
@@ -58,7 +61,7 @@ public interface IBaritoneProvider {
|
|||||||
return baritone;
|
return baritone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("No baritone for player " + player);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -18,9 +18,13 @@
|
|||||||
package baritone.api.behavior;
|
package baritone.api.behavior;
|
||||||
|
|
||||||
import baritone.api.event.listener.AbstractGameEventListener;
|
import baritone.api.event.listener.AbstractGameEventListener;
|
||||||
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A behavior is simply a type that is able to listen to events.
|
||||||
|
*
|
||||||
* @author Brady
|
* @author Brady
|
||||||
|
* @see IGameEventListener
|
||||||
* @since 9/23/2018
|
* @since 9/23/2018
|
||||||
*/
|
*/
|
||||||
public interface IBehavior extends AbstractGameEventListener {}
|
public interface IBehavior extends AbstractGameEventListener {}
|
||||||
|
|||||||
@@ -37,7 +37,26 @@ public interface IPathingBehavior extends IBehavior {
|
|||||||
*
|
*
|
||||||
* @return The estimated remaining ticks in the current segment.
|
* @return The estimated remaining ticks in the current segment.
|
||||||
*/
|
*/
|
||||||
Optional<Double> ticksRemainingInSegment();
|
default Optional<Double> ticksRemainingInSegment() {
|
||||||
|
return ticksRemainingInSegment(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the estimated remaining ticks in the current pathing
|
||||||
|
* segment. Given that the return type is an optional, {@link Optional#empty()}
|
||||||
|
* will be returned in the case that there is no current segment being pathed.
|
||||||
|
*
|
||||||
|
* @param includeCurrentMovement whether or not to include the entirety of the cost of the currently executing movement in the total
|
||||||
|
* @return The estimated remaining ticks in the current segment.
|
||||||
|
*/
|
||||||
|
default Optional<Double> ticksRemainingInSegment(boolean includeCurrentMovement) {
|
||||||
|
IPathExecutor current = getCurrent();
|
||||||
|
if (current == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
int start = includeCurrentMovement ? current.getPosition() : current.getPosition() + 1;
|
||||||
|
return Optional.of(current.getPath().ticksRemainingFrom(start));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The current pathing goal
|
* @return The current pathing goal
|
||||||
@@ -47,7 +66,9 @@ public interface IPathingBehavior extends IBehavior {
|
|||||||
/**
|
/**
|
||||||
* @return Whether or not a path is currently being executed.
|
* @return Whether or not a path is currently being executed.
|
||||||
*/
|
*/
|
||||||
boolean isPathing();
|
default boolean isPathing() {
|
||||||
|
return getCurrent() != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels the pathing behavior or the current path calculation, and all processes that could be controlling path.
|
* Cancels the pathing behavior or the current path calculation, and all processes that could be controlling path.
|
||||||
@@ -59,6 +80,13 @@ public interface IPathingBehavior extends IBehavior {
|
|||||||
*/
|
*/
|
||||||
boolean cancelEverything();
|
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.
|
* Returns the current path, from the current path executor, if there is one.
|
||||||
*
|
*
|
||||||
|
|||||||
+4
-2
@@ -20,7 +20,7 @@ package baritone.api.cache;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@@ -68,7 +68,7 @@ public interface ICachedWorld {
|
|||||||
* @param maxRegionDistanceSq The maximum region distance, squared
|
* @param maxRegionDistanceSq The maximum region distance, squared
|
||||||
* @return The locations found that match the special block
|
* @return The locations found that match the special block
|
||||||
*/
|
*/
|
||||||
LinkedList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq);
|
ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads all of the cached regions in this world from disk. Anything that is not saved
|
* Reloads all of the cached regions in this world from disk. Anything that is not saved
|
||||||
@@ -81,4 +81,6 @@ public interface ICachedWorld {
|
|||||||
* in a new thread by default.
|
* in a new thread by default.
|
||||||
*/
|
*/
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -15,9 +15,8 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* 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 net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -47,7 +46,7 @@ public class Waypoint implements IWaypoint {
|
|||||||
* @param location The waypoint location
|
* @param location The waypoint location
|
||||||
* @param creationTimestamp When the waypoint was created
|
* @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.name = name;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
@@ -17,22 +17,20 @@
|
|||||||
|
|
||||||
package baritone.api.event.events;
|
package baritone.api.event.events;
|
||||||
|
|
||||||
import baritone.api.event.events.type.ManagedPlayerEvent;
|
import baritone.api.event.events.type.Cancellable;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/1/2018
|
* @since 8/1/2018
|
||||||
*/
|
*/
|
||||||
public final class ChatEvent extends ManagedPlayerEvent.Cancellable {
|
public final class ChatEvent extends Cancellable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message being sent
|
* The message being sent
|
||||||
*/
|
*/
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public ChatEvent(EntityPlayerSP player, String message) {
|
public ChatEvent(String message) {
|
||||||
super(player);
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,22 +18,19 @@
|
|||||||
package baritone.api.event.events;
|
package baritone.api.event.events;
|
||||||
|
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.api.event.events.type.ManagedPlayerEvent;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/21/2018
|
* @since 8/21/2018
|
||||||
*/
|
*/
|
||||||
public final class PlayerUpdateEvent extends ManagedPlayerEvent {
|
public final class PlayerUpdateEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of the event
|
* The state of the event
|
||||||
*/
|
*/
|
||||||
private final EventState state;
|
private final EventState state;
|
||||||
|
|
||||||
public PlayerUpdateEvent(EntityPlayerSP player, EventState state) {
|
public PlayerUpdateEvent(EventState state) {
|
||||||
super(player);
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package baritone.api.event.events;
|
package baritone.api.event.events;
|
||||||
|
|
||||||
import baritone.api.event.events.type.ManagedPlayerEvent;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ import net.minecraft.entity.EntityLivingBase;
|
|||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/21/2018
|
* @since 8/21/2018
|
||||||
*/
|
*/
|
||||||
public final class RotationMoveEvent extends ManagedPlayerEvent {
|
public final class RotationMoveEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of event
|
* The type of event
|
||||||
@@ -38,8 +36,7 @@ public final class RotationMoveEvent extends ManagedPlayerEvent {
|
|||||||
*/
|
*/
|
||||||
private float yaw;
|
private float yaw;
|
||||||
|
|
||||||
public RotationMoveEvent(EntityPlayerSP player, Type type, float yaw) {
|
public RotationMoveEvent(Type type, float yaw) {
|
||||||
super(player);
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.yaw = yaw;
|
this.yaw = yaw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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.event.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 1/18/2019
|
||||||
|
*/
|
||||||
|
public final class SprintStateEvent {
|
||||||
|
|
||||||
|
private Boolean state;
|
||||||
|
|
||||||
|
public final void setState(boolean state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Boolean getState() {
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.event.events.type;
|
|
||||||
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An event that has a reference to a locally managed player.
|
|
||||||
*
|
|
||||||
* @author Brady
|
|
||||||
* @since 10/11/2018
|
|
||||||
*/
|
|
||||||
public class ManagedPlayerEvent {
|
|
||||||
|
|
||||||
protected final EntityPlayerSP player;
|
|
||||||
|
|
||||||
public ManagedPlayerEvent(EntityPlayerSP player) {
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final EntityPlayerSP getPlayer() {
|
|
||||||
return this.player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Cancellable extends ManagedPlayerEvent implements ICancellable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not this event has been cancelled
|
|
||||||
*/
|
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public Cancellable(EntityPlayerSP player) {
|
|
||||||
super(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void cancel() {
|
|
||||||
this.cancelled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -57,6 +57,9 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
|||||||
@Override
|
@Override
|
||||||
default void onPlayerRotationMove(RotationMoveEvent event) {}
|
default void onPlayerRotationMove(RotationMoveEvent event) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void onPlayerSprintState(SprintStateEvent event) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void onBlockInteract(BlockInteractEvent event) {}
|
default void onBlockInteract(BlockInteractEvent event) {}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,14 @@ public interface IGameEventListener {
|
|||||||
*/
|
*/
|
||||||
void onPlayerRotationMove(RotationMoveEvent event);
|
void onPlayerRotationMove(RotationMoveEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever the sprint keybind state is checked in {@link EntityPlayerSP#onLivingUpdate}
|
||||||
|
*
|
||||||
|
* @param event The event
|
||||||
|
* @see EntityPlayerSP#onLivingUpdate()
|
||||||
|
*/
|
||||||
|
void onPlayerSprintState(SprintStateEvent event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the local player interacts with a block, whether it is breaking or opening/placing.
|
* Called when the local player interacts with a block, whether it is breaking or opening/placing.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -22,10 +22,26 @@ import baritone.api.process.PathingCommand;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author leijurv
|
||||||
|
*/
|
||||||
public interface IPathingControlManager {
|
public interface IPathingControlManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a process with this pathing control manager. See {@link IBaritoneProcess} for more details.
|
||||||
|
*
|
||||||
|
* @param process The process
|
||||||
|
* @see IBaritoneProcess
|
||||||
|
*/
|
||||||
void registerProcess(IBaritoneProcess process);
|
void registerProcess(IBaritoneProcess process);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The most recent {@link IBaritoneProcess} that had control
|
||||||
|
*/
|
||||||
Optional<IBaritoneProcess> mostRecentInControl();
|
Optional<IBaritoneProcess> mostRecentInControl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The most recent pathing command executed
|
||||||
|
*/
|
||||||
Optional<PathingCommand> mostRecentCommand();
|
Optional<PathingCommand> mostRecentCommand();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class GoalAxis implements Goal {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInGoal(int x, int y, int z) {
|
public boolean isInGoal(int x, int y, int z) {
|
||||||
return y == BaritoneAPI.getSettings().axisHeight.get() && (x == 0 || z == 0 || Math.abs(x) == Math.abs(z));
|
return y == BaritoneAPI.getSettings().axisHeight.value && (x == 0 || z == 0 || Math.abs(x) == Math.abs(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +39,7 @@ public class GoalAxis implements Goal {
|
|||||||
|
|
||||||
double flatAxisDistance = Math.min(x, Math.min(z, diff * SQRT_2_OVER_2));
|
double flatAxisDistance = Math.min(x, Math.min(z, diff * SQRT_2_OVER_2));
|
||||||
|
|
||||||
return flatAxisDistance * BaritoneAPI.getSettings().costHeuristic.get() + GoalYLevel.calculate(BaritoneAPI.getSettings().axisHeight.get(), y);
|
return flatAxisDistance * BaritoneAPI.getSettings().costHeuristic.value + GoalYLevel.calculate(BaritoneAPI.getSettings().axisHeight.value, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,17 +30,17 @@ public class GoalBlock implements Goal, IGoalRenderPos {
|
|||||||
/**
|
/**
|
||||||
* The X block position of this goal
|
* The X block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int x;
|
public final int x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Y block position of this goal
|
* The Y block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int y;
|
public final int y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Z block position of this goal
|
* The Z block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int z;
|
public final int z;
|
||||||
|
|
||||||
public GoalBlock(BlockPos pos) {
|
public GoalBlock(BlockPos pos) {
|
||||||
this(pos.getX(), pos.getY(), pos.getZ());
|
this(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
*/
|
*/
|
||||||
public class GoalGetToBlock implements Goal, IGoalRenderPos {
|
public class GoalGetToBlock implements Goal, IGoalRenderPos {
|
||||||
|
|
||||||
private final int x;
|
public final int x;
|
||||||
private final int y;
|
public final int y;
|
||||||
private final int z;
|
public final int z;
|
||||||
|
|
||||||
public GoalGetToBlock(BlockPos pos) {
|
public GoalGetToBlock(BlockPos pos) {
|
||||||
this.x = pos.getX();
|
this.x = pos.getX();
|
||||||
|
|||||||
@@ -61,6 +61,6 @@ public class GoalNear implements Goal, IGoalRenderPos {
|
|||||||
", y=" + y +
|
", y=" + y +
|
||||||
", z=" + z +
|
", z=" + z +
|
||||||
", rangeSq=" + rangeSq +
|
", 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
|
* The X block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int x;
|
protected final int x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Y block position of this goal
|
* The Y block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int y;
|
protected final int y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Z block position of this goal
|
* The Z block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int z;
|
protected final int z;
|
||||||
|
|
||||||
public GoalTwoBlocks(BlockPos pos) {
|
public GoalTwoBlocks(BlockPos pos) {
|
||||||
this(pos.getX(), pos.getY(), pos.getZ());
|
this(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class GoalXZ implements Goal {
|
|||||||
diagonal = z;
|
diagonal = z;
|
||||||
}
|
}
|
||||||
diagonal *= SQRT_2;
|
diagonal *= SQRT_2;
|
||||||
return (diagonal + straight) * BaritoneAPI.getSettings().costHeuristic.get(); // big TODO tune
|
return (diagonal + straight) * BaritoneAPI.getSettings().costHeuristic.value; // big TODO tune
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {
|
public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class GoalYLevel implements Goal, ActionCosts {
|
|||||||
/**
|
/**
|
||||||
* The target Y level
|
* The target Y level
|
||||||
*/
|
*/
|
||||||
private final int level;
|
public final int level;
|
||||||
|
|
||||||
public GoalYLevel(int level) {
|
public GoalYLevel(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ public interface IMovement {
|
|||||||
*/
|
*/
|
||||||
boolean safeToCancel();
|
boolean safeToCancel();
|
||||||
|
|
||||||
double recalculateCost();
|
|
||||||
|
|
||||||
double calculateCostWithoutCaching();
|
|
||||||
|
|
||||||
boolean calculatedWhileLoaded();
|
boolean calculatedWhileLoaded();
|
||||||
|
|
||||||
BetterBlockPos getSrc();
|
BetterBlockPos getSrc();
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ import baritone.api.pathing.calc.IPath;
|
|||||||
public interface IPathExecutor {
|
public interface IPathExecutor {
|
||||||
|
|
||||||
IPath getPath();
|
IPath getPath();
|
||||||
|
|
||||||
|
int getPosition();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package baritone.api.process;
|
package baritone.api.process;
|
||||||
|
|
||||||
import baritone.api.IBaritone;
|
|
||||||
import baritone.api.behavior.IPathingBehavior;
|
import baritone.api.behavior.IPathingBehavior;
|
||||||
import baritone.api.event.events.PathEvent;
|
import baritone.api.event.events.PathEvent;
|
||||||
|
|
||||||
@@ -25,8 +24,10 @@ import baritone.api.event.events.PathEvent;
|
|||||||
* A process that can control the PathingBehavior.
|
* A process that can control the PathingBehavior.
|
||||||
* <p>
|
* <p>
|
||||||
* Differences between a baritone process and a behavior:
|
* Differences between a baritone process and a behavior:
|
||||||
* Only one baritone process can be active at a time
|
* <ul>
|
||||||
* PathingBehavior can only be controlled by a process
|
* <li>Only one baritone process can be active at a time</li>
|
||||||
|
* <li>PathingBehavior can only be controlled by a process</li>
|
||||||
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* That's it actually
|
* That's it actually
|
||||||
*
|
*
|
||||||
@@ -34,6 +35,16 @@ import baritone.api.event.events.PathEvent;
|
|||||||
*/
|
*/
|
||||||
public interface IBaritoneProcess {
|
public interface IBaritoneProcess {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default priority. Most normal processes should have this value.
|
||||||
|
* <p>
|
||||||
|
* Some examples of processes that should have different values might include some kind of automated mob avoidance
|
||||||
|
* that would be temporary and would forcefully take control. Same for something that pauses pathing for auto eat, etc.
|
||||||
|
* <p>
|
||||||
|
* The value is -1 beacuse that's what Impact 4.5's beta auto walk returns and I want to tie with it.
|
||||||
|
*/
|
||||||
|
double DEFAULT_PRIORITY = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Would this process like to be in control?
|
* Would this process like to be in control?
|
||||||
*
|
*
|
||||||
@@ -81,19 +92,23 @@ public interface IBaritoneProcess {
|
|||||||
*
|
*
|
||||||
* @return A double representing the priority
|
* @return A double representing the priority
|
||||||
*/
|
*/
|
||||||
double priority();
|
default double priority() {
|
||||||
|
return DEFAULT_PRIORITY;
|
||||||
/**
|
}
|
||||||
* Returns which bot this process is associated with. (5000000iq forward thinking)
|
|
||||||
*
|
|
||||||
* @return The Bot associated with this process
|
|
||||||
*/
|
|
||||||
IBaritone associatedWith();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a user-friendly name for this process. Suitable for a HUD.
|
* Returns a user-friendly name for this process. Suitable for a HUD.
|
||||||
*
|
*
|
||||||
* @return A display name that's suitable for a HUD
|
* @return A display name that's suitable for a HUD
|
||||||
*/
|
*/
|
||||||
String displayName();
|
default String displayName() {
|
||||||
|
if (!isActive()) {
|
||||||
|
// i love it when impcat's scuffed HUD calls displayName for inactive processes for 1 tick too long
|
||||||
|
// causing NPEs when the displayname relies on fields that become null when inactive
|
||||||
|
return "INACTIVE";
|
||||||
|
}
|
||||||
|
return displayName0();
|
||||||
|
}
|
||||||
|
|
||||||
|
String displayName0();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 1/15/2019
|
||||||
|
*/
|
||||||
|
public interface IBuilderProcess extends IBaritoneProcess {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests a build for the specified schematic, labeled as specified, with the specified origin.
|
||||||
|
*
|
||||||
|
* @param name A user-friendly name for the schematic
|
||||||
|
* @param schematic The object representation of the schematic
|
||||||
|
* @param origin The origin position of the schematic being built
|
||||||
|
*/
|
||||||
|
void build(String name, ISchematic schematic, Vec3i origin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests a build for the specified schematic, labeled as specified, with the specified origin.
|
||||||
|
*
|
||||||
|
* @param name A user-friendly name for the schematic
|
||||||
|
* @param schematic The file path of the schematic
|
||||||
|
* @param origin The origin position of the schematic being built
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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 {
|
public interface IGetToBlockProcess extends IBaritoneProcess {
|
||||||
|
|
||||||
void getToBlock(Block block);
|
void getToBlock(Block block);
|
||||||
|
|
||||||
|
boolean blacklistClosest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,4 +53,9 @@ public class PathingCommand {
|
|||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
this.commandType = commandType;
|
this.commandType = commandType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return commandType + " " + goal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,5 +51,10 @@ public enum PathingCommandType {
|
|||||||
* <p>
|
* <p>
|
||||||
* Cancel the current path if the goals are not equal
|
* 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) {
|
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)
|
* This is the hashcode implementation of Vec3i (the superclass of the class which I shall not name)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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() {}
|
||||||
|
}
|
||||||
+324
-143
@@ -15,38 +15,36 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* 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.Settings;
|
||||||
|
import baritone.api.behavior.IPathingBehavior;
|
||||||
import baritone.api.cache.IRememberedInventory;
|
import baritone.api.cache.IRememberedInventory;
|
||||||
import baritone.api.cache.IWaypoint;
|
import baritone.api.cache.IWaypoint;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
import baritone.api.event.events.ChatEvent;
|
import baritone.api.event.events.ChatEvent;
|
||||||
|
import baritone.api.event.listener.AbstractGameEventListener;
|
||||||
import baritone.api.pathing.goals.*;
|
import baritone.api.pathing.goals.*;
|
||||||
import baritone.api.pathing.movement.ActionCosts;
|
import baritone.api.process.IBaritoneProcess;
|
||||||
import baritone.api.utils.SettingsUtil;
|
import baritone.api.process.ICustomGoalProcess;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.api.process.IGetToBlockProcess;
|
||||||
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 net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||||
|
import net.minecraft.crash.CrashReport;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ReportedException;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
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 =
|
private static final String HELP_MSG =
|
||||||
"baritone - Output settings into chat\n" +
|
"baritone - Output settings into chat\n" +
|
||||||
@@ -70,129 +68,147 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
"get - Same as list\n" +
|
"get - Same as list\n" +
|
||||||
"show - Same as list\n" +
|
"show - Same as list\n" +
|
||||||
"save - Saves a waypoint (works but don't try to make sense of it)\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" +
|
"goto - Paths towards specified block or waypoint\n" +
|
||||||
"spawn - Paths towards world spawn or your most recent bed right-click\n" +
|
"spawn - Paths towards world spawn or your most recent bed right-click\n" +
|
||||||
"sethome - Sets \"home\"\n" +
|
"sethome - Sets \"home\"\n" +
|
||||||
"home - Paths towards \"home\" \n" +
|
"home - Paths towards \"home\" \n" +
|
||||||
"costs - (debug) all movement costs from current location\n" +
|
"costs - (debug) all movement costs from current location\n" +
|
||||||
"damn - Daniel ";
|
"damn - Daniel\n" +
|
||||||
|
"Go to https://github.com/cabaletta/baritone/blob/master/USAGE.md for more information";
|
||||||
|
|
||||||
public ExampleBaritoneControl(Baritone baritone) {
|
private static final String COMMAND_PREFIX = "#";
|
||||||
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
|
@Override
|
||||||
public void onSendChatMessage(ChatEvent event) {
|
public void onSendChatMessage(ChatEvent event) {
|
||||||
if (!Baritone.settings().chatControl.get() && !Baritone.settings().removePrefix.get()) {
|
String msg = event.getMessage();
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
String msg = event.getMessage();
|
if (!BaritoneAPI.getSettings().chatControl.value && !BaritoneAPI.getSettings().removePrefix.value) {
|
||||||
if (Baritone.settings().prefix.get()) {
|
return;
|
||||||
if (!msg.startsWith("#")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
msg = msg.substring(1);
|
|
||||||
}
|
}
|
||||||
if (runCommand(msg)) {
|
if (runCommand(msg)) {
|
||||||
event.cancel();
|
event.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean runCommand(String msg0) {
|
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
|
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
||||||
PathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||||
CustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||||
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
List<Settings.Setting<Boolean>> toggleable = BaritoneAPI.getSettings().getAllValuesByType(Boolean.class);
|
||||||
for (Settings.Setting<Boolean> setting : toggleable) {
|
for (Settings.Setting<Boolean> setting : toggleable) {
|
||||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||||
setting.value ^= true;
|
setting.value ^= true;
|
||||||
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
||||||
SettingsUtil.save(Baritone.settings());
|
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg.equals("baritone") || msg.equals("settings")) {
|
if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) {
|
||||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
logDirect("All settings that have been modified from their default values:");
|
||||||
|
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(BaritoneAPI.getSettings())) {
|
||||||
logDirect(setting.toString());
|
logDirect(setting.toString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.startsWith("settings")) {
|
||||||
|
String rest = msg.substring("settings".length());
|
||||||
|
try {
|
||||||
|
int page = Integer.parseInt(rest.trim());
|
||||||
|
int min = page * 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(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 : BaritoneAPI.getSettings().allSettings) {
|
||||||
|
logDirect(setting.toString());
|
||||||
|
}
|
||||||
|
logDirect("To get one page of ten settings at a time, do settings <num>");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (msg.equals("") || msg.equals("help") || msg.equals("?")) {
|
if (msg.equals("") || msg.equals("help") || msg.equals("?")) {
|
||||||
for (String line : HELP_MSG.split("\n")) {
|
for (String line : HELP_MSG.split("\n")) {
|
||||||
logDirect(line);
|
logDirect(line);
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.contains(" ")) {
|
if (msg.contains(" ")) {
|
||||||
String[] data = msg.split(" ");
|
String settingName = msg.substring(0, msg.indexOf(' '));
|
||||||
if (data.length == 2) {
|
String settingValue = msg.substring(msg.indexOf(' ') + 1);
|
||||||
Settings.Setting setting = Baritone.settings().byLowerName.get(data[0]);
|
Settings.Setting setting = BaritoneAPI.getSettings().byLowerName.get(settingName);
|
||||||
if (setting != null) {
|
if (setting != null) {
|
||||||
|
if (settingValue.equals("reset")) {
|
||||||
|
logDirect("Resetting setting " + settingName + " to default value.");
|
||||||
|
setting.reset();
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
if (setting.value.getClass() == Long.class) {
|
SettingsUtil.parseAndApply(BaritoneAPI.getSettings(), settingName, settingValue);
|
||||||
setting.value = Long.parseLong(data[1]);
|
} catch (Exception ex) {
|
||||||
}
|
logDirect("Unable to parse setting");
|
||||||
if (setting.value.getClass() == Integer.class) {
|
|
||||||
setting.value = Integer.parseInt(data[1]);
|
|
||||||
}
|
|
||||||
if (setting.value.getClass() == Double.class) {
|
|
||||||
setting.value = Double.parseDouble(data[1]);
|
|
||||||
}
|
|
||||||
if (setting.value.getClass() == Float.class) {
|
|
||||||
setting.value = Float.parseFloat(data[1]);
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
logDirect("Unable to parse " + data[1]);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
SettingsUtil.save(Baritone.settings());
|
|
||||||
logDirect(setting.toString());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||||
|
logDirect(setting.toString());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Baritone.settings().byLowerName.containsKey(msg)) {
|
if (BaritoneAPI.getSettings().byLowerName.containsKey(msg)) {
|
||||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg);
|
Settings.Setting<?> setting = BaritoneAPI.getSettings().byLowerName.get(msg);
|
||||||
logDirect(setting.toString());
|
logDirect(setting.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.startsWith("goal")) {
|
if (msg.startsWith("goal")) {
|
||||||
String[] params = msg.substring(4).trim().split(" ");
|
String rest = msg.substring(4).trim();
|
||||||
if (params[0].equals("")) {
|
|
||||||
params = new String[]{};
|
|
||||||
}
|
|
||||||
Goal goal;
|
Goal goal;
|
||||||
try {
|
if (rest.equals("clear") || rest.equals("none")) {
|
||||||
switch (params.length) {
|
goal = null;
|
||||||
case 0:
|
} else {
|
||||||
goal = new GoalBlock(ctx.playerFeet());
|
String[] params = rest.split(" ");
|
||||||
break;
|
if (params[0].equals("")) {
|
||||||
case 1:
|
params = new String[]{};
|
||||||
if (params[0].equals("clear") || params[0].equals("none")) {
|
}
|
||||||
goal = null;
|
goal = parseGoal(params);
|
||||||
} else {
|
if (goal == null) {
|
||||||
goal = new GoalYLevel(Integer.parseInt(params[0]));
|
return true;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
goal = new GoalXZ(Integer.parseInt(params[0]), Integer.parseInt(params[1]));
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2])));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
logDirect("unable to understand lol");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
logDirect("unable to parse integer " + ex);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
customGoalProcess.setGoal(goal);
|
customGoalProcess.setGoal(goal);
|
||||||
logDirect("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
return true;
|
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 (msg.equals("path")) {
|
||||||
if (pathingBehavior.getGoal() == null) {
|
if (pathingBehavior.getGoal() == null) {
|
||||||
logDirect("No goal.");
|
logDirect("No goal.");
|
||||||
@@ -205,7 +221,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("fullpath")) {
|
/*if (msg.equals("fullpath")) {
|
||||||
if (pathingBehavior.getGoal() == null) {
|
if (pathingBehavior.getGoal() == null) {
|
||||||
logDirect("No goal.");
|
logDirect("No goal.");
|
||||||
} else {
|
} else {
|
||||||
@@ -221,6 +237,29 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}*/
|
||||||
|
if (msg.equals("proc")) {
|
||||||
|
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
|
||||||
|
if (!proc.isPresent()) {
|
||||||
|
logDirect("No process is in control");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
IBaritoneProcess p = proc.get();
|
||||||
|
logDirect("Class: " + p.getClass());
|
||||||
|
logDirect("Priority: " + p.priority());
|
||||||
|
logDirect("Temporary: " + p.isTemporary());
|
||||||
|
logDirect("Display name: " + p.displayName());
|
||||||
|
logDirect("Command: " + baritone.getPathingControlManager().mostRecentCommand());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.equals("version")) {
|
||||||
|
String version = ExampleBaritoneControl.class.getPackage().getImplementationVersion();
|
||||||
|
if (version == null) {
|
||||||
|
logDirect("No version detected. Either dev environment or broken install.");
|
||||||
|
} else {
|
||||||
|
logDirect("You are using Baritone v" + version);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("repack") || msg.equals("rescan")) {
|
if (msg.equals("repack") || msg.equals("rescan")) {
|
||||||
ChunkProviderClient cli = (ChunkProviderClient) ctx.world().getChunkProvider();
|
ChunkProviderClient cli = (ChunkProviderClient) ctx.world().getChunkProvider();
|
||||||
@@ -239,7 +278,28 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Queued " + count + " chunks for repacking");
|
logDirect("Queued " + count + " chunks for repacking");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("axis")) {
|
if (msg.startsWith("build")) {
|
||||||
|
String file;
|
||||||
|
BlockPos origin;
|
||||||
|
try {
|
||||||
|
String[] coords = msg.substring("build".length()).trim().split(" ");
|
||||||
|
file = coords[0] + ".schematic";
|
||||||
|
origin = new BlockPos(parseOrDefault(coords[1], ctx.playerFeet().x), parseOrDefault(coords[2], ctx.playerFeet().y), parseOrDefault(coords[3], ctx.playerFeet().z));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
file = msg.substring(5).trim() + ".schematic";
|
||||||
|
origin = ctx.playerFeet();
|
||||||
|
}
|
||||||
|
logDirect("Loading '" + file + "' to build from origin " + origin);
|
||||||
|
boolean success = baritone.getBuilderProcess().build(file, origin);
|
||||||
|
logDirect(success ? "Loaded" : "Unable to load");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.equals("come")) {
|
||||||
|
customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity())));
|
||||||
|
logDirect("Coming");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.equals("axis") || msg.equals("highway")) {
|
||||||
customGoalProcess.setGoalAndPath(new GoalAxis());
|
customGoalProcess.setGoalAndPath(new GoalAxis());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -279,32 +339,67 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.startsWith("cleararea")) {
|
||||||
|
String suffix = msg.substring("cleararea".length());
|
||||||
|
BlockPos corner1;
|
||||||
|
BlockPos corner2;
|
||||||
|
if (suffix.isEmpty()) {
|
||||||
|
// clear the area from the current goal to here
|
||||||
|
Goal goal = baritone.getPathingBehavior().getGoal();
|
||||||
|
if (!(goal instanceof GoalBlock)) {
|
||||||
|
logDirect("Need to specify goal of opposite corner");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
corner1 = ((GoalBlock) goal).getGoalPos();
|
||||||
|
corner2 = ctx.playerFeet();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
String[] spl = suffix.split(" ");
|
||||||
|
corner1 = ctx.playerFeet();
|
||||||
|
corner2 = new BlockPos(Integer.parseInt(spl[0]), Integer.parseInt(spl[1]), Integer.parseInt(spl[2]));
|
||||||
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {
|
||||||
|
logDirect("unable to parse");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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")) {
|
if (msg.equals("reset")) {
|
||||||
Baritone.settings().reset();
|
for (Settings.Setting setting : BaritoneAPI.getSettings().allSettings) {
|
||||||
|
setting.reset();
|
||||||
|
}
|
||||||
|
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||||
logDirect("Baritone settings reset");
|
logDirect("Baritone settings reset");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("echest")) {
|
if (msg.equals("tunnel")) {
|
||||||
Optional<List<ItemStack>> contents = baritone.getMemoryBehavior().echest();
|
customGoalProcess.setGoalAndPath(new GoalStrictDirection(ctx.playerFeet(), ctx.player().getHorizontalFacing()));
|
||||||
if (contents.isPresent()) {
|
logDirect("tunneling");
|
||||||
logDirect("echest contents:");
|
return true;
|
||||||
log(contents.get());
|
}
|
||||||
} else {
|
if (msg.equals("render")) {
|
||||||
logDirect("echest contents unknown");
|
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("farm")) {
|
||||||
|
baritone.getFarmProcess().farm();
|
||||||
|
logDirect("farming");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("chests")) {
|
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()) {
|
for (Map.Entry<BlockPos, IRememberedInventory> entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) {
|
||||||
logDirect(entry.getKey() + "");
|
logDirect(entry.getKey() + "");
|
||||||
log(entry.getValue().getContents());
|
log(entry.getValue().getContents());
|
||||||
@@ -334,10 +429,33 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Entity effectivelyFinal = toFollow.get();
|
Entity effectivelyFinal = toFollow.get();
|
||||||
baritone.getFollowProcess().follow(x -> effectivelyFinal.equals(x));
|
baritone.getFollowProcess().follow(effectivelyFinal::equals);
|
||||||
logDirect("Following " + toFollow.get());
|
logDirect("Following " + toFollow.get());
|
||||||
return true;
|
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")) {
|
if (msg.equals("reloadall")) {
|
||||||
baritone.getWorldProvider().getCurrentWorld().getCachedWorld().reloadAllFromDisk();
|
baritone.getWorldProvider().getCurrentWorld().getCachedWorld().reloadAllFromDisk();
|
||||||
logDirect("ok");
|
logDirect("ok");
|
||||||
@@ -348,14 +466,42 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("ok");
|
logDirect("ok");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.startsWith("explore")) {
|
||||||
|
String rest = msg.substring("explore".length()).trim();
|
||||||
|
int centerX;
|
||||||
|
int centerZ;
|
||||||
|
try {
|
||||||
|
centerX = Integer.parseInt(rest.split(" ")[0]);
|
||||||
|
centerZ = Integer.parseInt(rest.split(" ")[1]);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
centerX = ctx.playerFeet().x;
|
||||||
|
centerZ = ctx.playerFeet().z;
|
||||||
|
}
|
||||||
|
baritone.getExploreProcess().explore(centerX, centerZ);
|
||||||
|
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")) {
|
if (msg.startsWith("find")) {
|
||||||
String blockType = msg.substring(4).trim();
|
String blockType = msg.substring(4).trim();
|
||||||
LinkedList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
||||||
logDirect("Have " + locs.size() + " locations");
|
logDirect("Have " + locs.size() + " locations");
|
||||||
for (BlockPos pos : locs) {
|
for (BlockPos pos : locs) {
|
||||||
Block actually = BlockStateInterface.get(ctx, pos).getBlock();
|
Block actually = ctx.world().getBlockState(pos).getBlock();
|
||||||
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
if (!BlockUtils.blockToString(actually).equalsIgnoreCase(blockType)) {
|
||||||
System.out.println("Was looking for " + blockType + " but actually found " + actually + " " + ChunkPacker.blockToString(actually));
|
logDebug("Was looking for " + blockType + " but actually found " + actually + " " + BlockUtils.blockToString(actually));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -364,14 +510,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
String[] blockTypes = msg.substring(4).trim().split(" ");
|
String[] blockTypes = msg.substring(4).trim().split(" ");
|
||||||
try {
|
try {
|
||||||
int quantity = Integer.parseInt(blockTypes[1]);
|
int quantity = Integer.parseInt(blockTypes[1]);
|
||||||
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
|
Block block = BlockUtils.stringToBlockRequired(blockTypes[0]);
|
||||||
Objects.requireNonNull(block);
|
|
||||||
baritone.getMineProcess().mine(quantity, block);
|
baritone.getMineProcess().mine(quantity, block);
|
||||||
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
||||||
for (String s : blockTypes) {
|
for (String s : blockTypes) {
|
||||||
if (ChunkPacker.stringToBlock(s) == null) {
|
if (BlockUtils.stringToBlockNullable(s) == null) {
|
||||||
logDirect(s + " isn't a valid block name");
|
logDirect(s + " isn't a valid block name");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -381,7 +526,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.startsWith("thisway")) {
|
if (msg.equals("click")) {
|
||||||
|
baritone.openClick();
|
||||||
|
logDirect("aight dude");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.startsWith("thisway") || msg.startsWith("forward")) {
|
||||||
try {
|
try {
|
||||||
Goal goal = GoalXZ.fromDirection(ctx.playerFeetAsVec(), ctx.player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
Goal goal = GoalXZ.fromDirection(ctx.playerFeetAsVec(), ctx.player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
||||||
customGoalProcess.setGoal(goal);
|
customGoalProcess.setGoal(goal);
|
||||||
@@ -397,9 +547,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
// for example, "show deaths"
|
// for example, "show deaths"
|
||||||
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||||
}
|
}
|
||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType);
|
||||||
if (tag == null) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
Set<IWaypoint> waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag);
|
Set<IWaypoint> waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag);
|
||||||
@@ -430,26 +580,41 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
name = parts[0];
|
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.");
|
logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints.");
|
||||||
return true;
|
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")) {
|
if (msg.startsWith("goto")) {
|
||||||
String waypointType = msg.substring(4).trim();
|
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"
|
// for example, "show deaths"
|
||||||
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||||
}
|
}
|
||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType);
|
||||||
IWaypoint waypoint;
|
IWaypoint waypoint;
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
String mining = waypointType;
|
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());
|
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
logDirect("No locations for " + mining + " known, cancelling");
|
Goal goal = parseGoal(waypointType.split(" "));
|
||||||
|
if (goal != null) {
|
||||||
|
logDirect("Going to " + goal);
|
||||||
|
customGoalProcess.setGoalAndPath(goal);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -463,12 +628,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = waypoint.getTag() == IWaypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation());
|
||||||
customGoalProcess.setGoalAndPath(goal);
|
customGoalProcess.setGoalAndPath(goal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("spawn") || msg.equals("bed")) {
|
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) {
|
if (waypoint == null) {
|
||||||
BlockPos spawnPoint = ctx.player().getBedLocation();
|
BlockPos spawnPoint = ctx.player().getBedLocation();
|
||||||
// for some reason the default spawnpoint is underground sometimes
|
// for some reason the default spawnpoint is underground sometimes
|
||||||
@@ -483,12 +648,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("sethome")) {
|
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.");
|
logDirect("Saved. Say home to set goal.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("home")) {
|
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) {
|
if (waypoint == null) {
|
||||||
logDirect("home not saved");
|
logDirect("home not saved");
|
||||||
} else {
|
} else {
|
||||||
@@ -498,29 +663,16 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
return true;
|
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(Movement::getCost));
|
|
||||||
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")) {
|
if (msg.equals("damn")) {
|
||||||
logDirect("daniel");
|
logDirect("daniel");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int parseOrDefault(String str, int i) {
|
||||||
|
return str.equals("~") ? i : str.startsWith("~") ? Integer.parseInt(str.substring(1)) + i : Integer.parseInt(str);
|
||||||
|
}
|
||||||
|
|
||||||
private void log(List<ItemStack> stacks) {
|
private void log(List<ItemStack> stacks) {
|
||||||
for (ItemStack stack : stacks) {
|
for (ItemStack stack : stacks) {
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
@@ -528,4 +680,33 @@ 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(playerFeet);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.z));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
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");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
logDirect("unable to parse integer " + ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return goal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+4
-4
@@ -15,9 +15,9 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* 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.client.Minecraft;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentString;
|
import net.minecraft.util.text.TextComponentString;
|
||||||
@@ -50,7 +50,7 @@ public interface Helper {
|
|||||||
* @param message The message to display in chat
|
* @param message The message to display in chat
|
||||||
*/
|
*/
|
||||||
default void logDebug(String message) {
|
default void logDebug(String message) {
|
||||||
if (!Baritone.settings().chatDebug.get()) {
|
if (!BaritoneAPI.getSettings().chatDebug.value) {
|
||||||
//System.out.println("Suppressed debug message:");
|
//System.out.println("Suppressed debug message:");
|
||||||
//System.out.println(message);
|
//System.out.println(message);
|
||||||
return;
|
return;
|
||||||
@@ -67,6 +67,6 @@ public interface Helper {
|
|||||||
ITextComponent component = MESSAGE_PREFIX.createCopy();
|
ITextComponent component = MESSAGE_PREFIX.createCopy();
|
||||||
component.getStyle().setColor(TextFormatting.GRAY);
|
component.getStyle().setColor(TextFormatting.GRAY);
|
||||||
component.appendSibling(new TextComponentString(" " + message));
|
component.appendSibling(new TextComponentString(" " + message));
|
||||||
Minecraft.getMinecraft().addScheduledTask(() -> Baritone.settings().logger.get().accept(component));
|
Minecraft.getMinecraft().addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,6 @@ package baritone.api.utils;
|
|||||||
|
|
||||||
import baritone.api.behavior.IBehavior;
|
import baritone.api.behavior.IBehavior;
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@@ -27,8 +26,6 @@ import net.minecraft.client.settings.KeyBinding;
|
|||||||
*/
|
*/
|
||||||
public interface IInputOverrideHandler extends IBehavior {
|
public interface IInputOverrideHandler extends IBehavior {
|
||||||
|
|
||||||
Boolean isInputForcedDown(KeyBinding key);
|
|
||||||
|
|
||||||
boolean isInputForcedDown(Input input);
|
boolean isInputForcedDown(Input input);
|
||||||
|
|
||||||
void setInputForceState(Input input, boolean forced);
|
void setInputForceState(Input input, boolean forced);
|
||||||
|
|||||||
@@ -71,20 +71,26 @@ public interface IPlayerContext {
|
|||||||
* @return The position of the highlighted block
|
* @return The position of the highlighted block
|
||||||
*/
|
*/
|
||||||
default Optional<BlockPos> getSelectedBlock() {
|
default Optional<BlockPos> getSelectedBlock() {
|
||||||
if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.BLOCK) {
|
RayTraceResult result = objectMouseOver();
|
||||||
return Optional.of(objectMouseOver().getBlockPos());
|
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||||
|
return Optional.of(result.getBlockPos());
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
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.
|
* Returns the entity that the crosshair is currently placed over. Updated once per tick.
|
||||||
*
|
*
|
||||||
* @return The entity
|
* @return The entity
|
||||||
*/
|
*/
|
||||||
default Optional<Entity> getSelectedEntity() {
|
default Optional<Entity> getSelectedEntity() {
|
||||||
if (objectMouseOver() != null && objectMouseOver().typeOfHit == RayTraceResult.Type.ENTITY) {
|
RayTraceResult result = objectMouseOver();
|
||||||
return Optional.of(objectMouseOver().entityHit);
|
if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) {
|
||||||
|
return Optional.of(result.entityHit);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,17 @@
|
|||||||
|
|
||||||
package baritone.api.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.ClickType;
|
import net.minecraft.inventory.ClickType;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.GameType;
|
import net.minecraft.world.GameType;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@@ -43,4 +48,8 @@ public interface IPlayerController {
|
|||||||
default double getBlockReachDistance() {
|
default double getBlockReachDistance() {
|
||||||
return this.getGameType().isCreative() ? 5.0F : 4.5F;
|
return this.getGameType().isCreative() ? 5.0F : 4.5F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
|
||||||
|
|
||||||
|
EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.state.IBlockState;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic representation of a schematic. Provides the dimensions and
|
||||||
|
* the desired statefor a given position relative to the origin.
|
||||||
|
*
|
||||||
|
* @author leijurv
|
||||||
|
*/
|
||||||
|
public interface ISchematic {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the block at this coordinate matter to the schematic?
|
||||||
|
* <p>
|
||||||
|
* Normally just a check for if the coordinate is in the cube.
|
||||||
|
* <p>
|
||||||
|
* However, in the case of something like a map art, anything that's below the level of the map art doesn't matter,
|
||||||
|
* so this function should return false in that case. (i.e. it doesn't really have to be air below the art blocks)
|
||||||
|
*
|
||||||
|
* @param x The x position of the block, relative to the origin
|
||||||
|
* @param y The y position of the block, relative to the origin
|
||||||
|
* @param z The z position of the block, relative to the origin
|
||||||
|
* @return Whether or not the specified position is within the bounds of this schematic
|
||||||
|
*/
|
||||||
|
default boolean inSchematic(int x, int y, int z) {
|
||||||
|
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).
|
||||||
|
*
|
||||||
|
* @param x The x position of the block, relative to the origin
|
||||||
|
* @param y The y position of the block, relative to the origin
|
||||||
|
* @param z The z position of the block, relative to the origin
|
||||||
|
* @return The desired block state at the specified position
|
||||||
|
*/
|
||||||
|
IBlockState desiredState(int x, int y, int z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The width (X axis length) of this schematic
|
||||||
|
*/
|
||||||
|
int widthX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The height (Y axis length) of this schematic
|
||||||
|
*/
|
||||||
|
int heightY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The length (Z axis length) of this schematic
|
||||||
|
*/
|
||||||
|
int lengthZ();
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -117,8 +117,12 @@ public class Rotation {
|
|||||||
* @return are they really close
|
* @return are they really close
|
||||||
*/
|
*/
|
||||||
public boolean isReallyCloseTo(Rotation other) {
|
public boolean isReallyCloseTo(Rotation other) {
|
||||||
float yawDiff = Math.abs(this.yaw - other.yaw); // you cant fool me
|
return yawIsReallyClose(other) && Math.abs(this.pitch - other.pitch) < 0.01;
|
||||||
return (yawDiff < 0.01 || yawDiff > 359.9) && Math.abs(this.pitch - other.pitch) < 0.01;
|
}
|
||||||
|
|
||||||
|
public boolean yawIsReallyClose(Rotation other) {
|
||||||
|
float yawDiff = Math.abs(normalizeYaw(yaw) - normalizeYaw(other.yaw)); // you cant fool me
|
||||||
|
return (yawDiff < 0.01 || yawDiff > 359.99);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,4 +151,9 @@ public class Rotation {
|
|||||||
}
|
}
|
||||||
return newYaw;
|
return newYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Yaw: " + yaw + ", Pitch: " + pitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ public final class RotationUtils {
|
|||||||
* @return The wrapped angles
|
* @return The wrapped angles
|
||||||
*/
|
*/
|
||||||
public static Rotation wrapAnglesToRelative(Rotation current, Rotation target) {
|
public static Rotation wrapAnglesToRelative(Rotation current, Rotation target) {
|
||||||
|
if (current.yawIsReallyClose(target)) {
|
||||||
|
return new Rotation(current.getYaw(), target.getPitch());
|
||||||
|
}
|
||||||
return target.subtract(current).normalize().add(current);
|
return target.subtract(current).normalize().add(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +105,7 @@ public final class RotationUtils {
|
|||||||
* @param dest The destination position
|
* @param dest The destination position
|
||||||
* @return The rotation from the origin to the destination
|
* @return The rotation from the origin to the destination
|
||||||
*/
|
*/
|
||||||
public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) {
|
private static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) {
|
||||||
double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z};
|
double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z};
|
||||||
double yaw = MathHelper.atan2(delta[0], -delta[2]);
|
double yaw = MathHelper.atan2(delta[0], -delta[2]);
|
||||||
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
|
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
|
||||||
@@ -151,7 +154,7 @@ public final class RotationUtils {
|
|||||||
*/
|
*/
|
||||||
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
|
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
|
||||||
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
|
||||||
if (pos.equals(baritone.getPlayerContext().getSelectedBlock().orElse(null))) {
|
if (baritone.getPlayerContext().isLookingAt(pos)) {
|
||||||
/*
|
/*
|
||||||
* why add 0.0001?
|
* why add 0.0001?
|
||||||
* to indicate that we actually have a desired pitch
|
* to indicate that we actually have a desired pitch
|
||||||
@@ -196,7 +199,7 @@ public final class RotationUtils {
|
|||||||
* @return The optional rotation
|
* @return The optional rotation
|
||||||
*/
|
*/
|
||||||
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) {
|
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) {
|
||||||
Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos);
|
Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch));
|
||||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance);
|
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance);
|
||||||
//System.out.println(result);
|
//System.out.println(result);
|
||||||
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
|
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
|
||||||
|
|||||||
@@ -18,34 +18,36 @@
|
|||||||
package baritone.api.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.item.Item;
|
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.awt.*;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||||
|
|
||||||
public class SettingsUtil {
|
public class SettingsUtil {
|
||||||
|
|
||||||
private static final Path SETTINGS_PATH = getMinecraft().gameDir.toPath().resolve("baritone").resolve("settings.txt");
|
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 Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>.+)"); // key and value split by the first space
|
||||||
|
|
||||||
private static final Map<Class<?>, SettingsIO> map;
|
|
||||||
|
|
||||||
private static boolean isComment(String line) {
|
private static boolean isComment(String line) {
|
||||||
return line.startsWith("#") || line.startsWith("//");
|
return line.startsWith("#") || line.startsWith("//");
|
||||||
@@ -81,6 +83,8 @@ public class SettingsUtil {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (NoSuchFileException ignored) {
|
||||||
|
System.out.println("Baritone settings file not found, resetting.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!");
|
System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@@ -89,22 +93,8 @@ public class SettingsUtil {
|
|||||||
|
|
||||||
public static synchronized void save(Settings settings) {
|
public static synchronized void save(Settings settings) {
|
||||||
try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) {
|
try (BufferedWriter out = Files.newBufferedWriter(SETTINGS_PATH)) {
|
||||||
for (Settings.Setting setting : settings.allSettings) {
|
for (Settings.Setting setting : modifiedSettings(settings)) {
|
||||||
if (setting.get() == null) {
|
out.write(settingToString(setting) + "\n");
|
||||||
System.out.println("NULL SETTING?" + setting.getName());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (setting.getName().equals("logger")) {
|
|
||||||
continue; // NO
|
|
||||||
}
|
|
||||||
if (setting.value == setting.defaultValue) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SettingsIO io = map.get(setting.getValueClass());
|
|
||||||
if (io == null) {
|
|
||||||
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting + " " + setting.getName());
|
|
||||||
}
|
|
||||||
out.write(setting.getName() + " " + io.toString.apply(setting.get()) + "\n");
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Exception thrown while saving Baritone settings!");
|
System.out.println("Exception thrown while saving Baritone settings!");
|
||||||
@@ -112,51 +102,167 @@ public class SettingsUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
public static List<Settings.Setting> modifiedSettings(Settings settings) {
|
||||||
|
List<Settings.Setting> modified = new ArrayList<>();
|
||||||
|
for (Settings.Setting setting : settings.allSettings) {
|
||||||
|
if (setting.value == null) {
|
||||||
|
System.out.println("NULL SETTING?" + setting.getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (setting.getName().equals("logger")) {
|
||||||
|
continue; // NO
|
||||||
|
}
|
||||||
|
if (setting.value == setting.defaultValue) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
modified.add(setting);
|
||||||
|
}
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String settingToString(Settings.Setting setting) throws IllegalStateException {
|
||||||
|
if (setting.getName().equals("logger")) {
|
||||||
|
return "logger";
|
||||||
|
}
|
||||||
|
Parser io = Parser.getParser(setting.getType());
|
||||||
|
if (io == null) {
|
||||||
|
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName());
|
||||||
|
}
|
||||||
|
return setting.getName() + " " + io.toString(new ParserContext(setting), setting.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
||||||
Settings.Setting setting = settings.byLowerName.get(settingName);
|
Settings.Setting setting = settings.byLowerName.get(settingName);
|
||||||
if (setting == null) {
|
if (setting == null) {
|
||||||
throw new IllegalStateException("No setting by that name");
|
throw new IllegalStateException("No setting by that name");
|
||||||
}
|
}
|
||||||
Class intendedType = setting.getValueClass();
|
Class intendedType = setting.getValueClass();
|
||||||
SettingsIO ioMethod = map.get(intendedType);
|
ISettingParser ioMethod = Parser.getParser(setting.getType());
|
||||||
Object parsed = ioMethod.parser.apply(settingValue);
|
Object parsed = ioMethod.parse(new ParserContext(setting), settingValue);
|
||||||
if (!intendedType.isInstance(parsed)) {
|
if (!intendedType.isInstance(parsed)) {
|
||||||
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
|
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
|
||||||
}
|
}
|
||||||
setting.value = parsed;
|
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),
|
DOUBLE(Double.class, Double::parseDouble),
|
||||||
BOOLEAN(Boolean.class, Boolean::parseBoolean),
|
BOOLEAN(Boolean.class, Boolean::parseBoolean),
|
||||||
INTEGER(Integer.class, Integer::parseInt),
|
INTEGER(Integer.class, Integer::parseInt),
|
||||||
FLOAT(Float.class, Float::parseFloat),
|
FLOAT(Float.class, Float::parseFloat),
|
||||||
LONG(Long.class, Long::parseLong),
|
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(","))),
|
return Arrays.stream(raw.split(","))
|
||||||
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());
|
.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;
|
return ((List<?>) value).stream()
|
||||||
Function<String, Object> parser;
|
.map(o -> parser.toString(context, o))
|
||||||
Function<Object, String> toString;
|
.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);
|
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.klass = klass;
|
||||||
this.parser = parser::apply;
|
this.parser = parser::apply;
|
||||||
this.toString = x -> toString.apply((T) x);
|
this.toString = x -> toString.apply((T) x);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
@Override
|
||||||
HashMap<Class<?>, SettingsIO> tempMap = new HashMap<>();
|
public Object parse(ParserContext context, String raw) {
|
||||||
for (SettingsIO type : SettingsIO.values()) {
|
Object parsed = this.parser.apply(raw);
|
||||||
tempMap.put(type.klass, type);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,15 +17,6 @@
|
|||||||
|
|
||||||
package baritone.api.utils.input;
|
package baritone.api.utils.input;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.settings.GameSettings;
|
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link Enum} representing the inputs that control the player's
|
* An {@link Enum} representing the inputs that control the player's
|
||||||
* behavior. This includes moving, interacting with blocks, jumping,
|
* behavior. This includes moving, interacting with blocks, jumping,
|
||||||
@@ -36,84 +27,45 @@ public enum Input {
|
|||||||
/**
|
/**
|
||||||
* The move forward input
|
* The move forward input
|
||||||
*/
|
*/
|
||||||
MOVE_FORWARD(s -> s.keyBindForward),
|
MOVE_FORWARD,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The move back input
|
* The move back input
|
||||||
*/
|
*/
|
||||||
MOVE_BACK(s -> s.keyBindBack),
|
MOVE_BACK,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The move left input
|
* The move left input
|
||||||
*/
|
*/
|
||||||
MOVE_LEFT(s -> s.keyBindLeft),
|
MOVE_LEFT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The move right input
|
* The move right input
|
||||||
*/
|
*/
|
||||||
MOVE_RIGHT(s -> s.keyBindRight),
|
MOVE_RIGHT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attack input
|
* The attack input
|
||||||
*/
|
*/
|
||||||
CLICK_LEFT(s -> s.keyBindAttack),
|
CLICK_LEFT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The use item input
|
* The use item input
|
||||||
*/
|
*/
|
||||||
CLICK_RIGHT(s -> s.keyBindUseItem),
|
CLICK_RIGHT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The jump input
|
* The jump input
|
||||||
*/
|
*/
|
||||||
JUMP(s -> s.keyBindJump),
|
JUMP,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sneak input
|
* The sneak input
|
||||||
*/
|
*/
|
||||||
SNEAK(s -> s.keyBindSneak),
|
SNEAK,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The sprint input
|
* The sprint input
|
||||||
*/
|
*/
|
||||||
SPRINT(s -> s.keyBindSprint);
|
SPRINT
|
||||||
|
|
||||||
/**
|
|
||||||
* Map of {@link KeyBinding} to {@link Input}. Values should be queried through {@link #getInputForBind(KeyBinding)}
|
|
||||||
*/
|
|
||||||
private static final Map<KeyBinding, Input> bindToInputMap = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The actual game {@link KeyBinding} being forced.
|
|
||||||
*/
|
|
||||||
private final KeyBinding keyBinding;
|
|
||||||
|
|
||||||
Input(Function<GameSettings, KeyBinding> keyBindingMapper) {
|
|
||||||
/*
|
|
||||||
|
|
||||||
Here, a Function is used because referring to a static field in this enum for the game instance,
|
|
||||||
as it was before, wouldn't be possible in an Enum constructor unless the static field was in an
|
|
||||||
interface that this class implemented. (Helper acted as this interface) I didn't feel like making
|
|
||||||
an interface with a game instance field just to not have to do this.
|
|
||||||
|
|
||||||
*/
|
|
||||||
this.keyBinding = keyBindingMapper.apply(Minecraft.getMinecraft().gameSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The actual game {@link KeyBinding} being forced.
|
|
||||||
*/
|
|
||||||
public final KeyBinding getKeyBinding() {
|
|
||||||
return this.keyBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the {@link Input} constant that is associated with the specified {@link KeyBinding}.
|
|
||||||
*
|
|
||||||
* @param binding The {@link KeyBinding} to find the associated {@link Input} for
|
|
||||||
* @return The {@link Input} associated with the specified {@link KeyBinding}
|
|
||||||
*/
|
|
||||||
public static Input getInputForBind(KeyBinding binding) {
|
|
||||||
return bindToInputMap.computeIfAbsent(binding, b -> Arrays.stream(values()).filter(input -> input.keyBinding == b).findFirst().orElse(null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.ChunkRenderContainer;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.chunk.RenderChunk;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import org.lwjgl.opengl.GL14;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
|
@Mixin(ChunkRenderContainer.class)
|
||||||
|
public class MixinChunkRenderContainer {
|
||||||
|
|
||||||
|
@Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
|
||||||
|
method = "preRenderChunk",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/client/renderer/chunk/RenderChunk.getPosition()Lnet/minecraft/util/math/BlockPos;"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private BlockPos getPosition(RenderChunk renderChunkIn) {
|
||||||
|
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);
|
||||||
|
GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO);
|
||||||
|
}
|
||||||
|
return renderChunkIn.getPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.utils.IPlayerContext;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.chunk.ChunkRenderWorker;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(ChunkRenderWorker.class)
|
||||||
|
public abstract class MixinChunkRenderWorker {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
protected abstract boolean isChunkExisting(BlockPos pos, World worldIn);
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "processTask",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/client/renderer/chunk/ChunkRenderWorker.isChunkExisting(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/World;)Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) {
|
||||||
|
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) {
|
||||||
|
return baritone.bsi.isLoaded(pos.getX(), pos.getZ()) || this.isChunkExisting(pos, world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.isChunkExisting(pos, world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.launch.mixins;
|
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
|
||||||
import baritone.api.event.events.RotationMoveEvent;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
import static org.spongepowered.asm.lib.Opcodes.GETFIELD;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Brady
|
|
||||||
* @since 8/21/2018
|
|
||||||
*/
|
|
||||||
@Mixin(Entity.class)
|
|
||||||
public class MixinEntity {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
public float rotationYaw;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event called to override the movement direction when walking
|
|
||||||
*/
|
|
||||||
private RotationMoveEvent motionUpdateRotationEvent;
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "moveRelative",
|
|
||||||
at = @At("HEAD")
|
|
||||||
)
|
|
||||||
private void preMoveRelative(float strafe, float up, float forward, float friction, CallbackInfo ci) {
|
|
||||||
// noinspection ConstantConditions
|
|
||||||
if (EntityPlayerSP.class.isInstance(this)) {
|
|
||||||
this.motionUpdateRotationEvent = new RotationMoveEvent((EntityPlayerSP) (Object) this, RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw);
|
|
||||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.motionUpdateRotationEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(
|
|
||||||
method = "moveRelative",
|
|
||||||
at = @At(
|
|
||||||
value = "FIELD",
|
|
||||||
opcode = GETFIELD,
|
|
||||||
target = "net/minecraft/entity/Entity.rotationYaw:F"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
private float overrideYaw(Entity self) {
|
|
||||||
if (self instanceof EntityPlayerSP) {
|
|
||||||
return this.motionUpdateRotationEvent.getYaw();
|
|
||||||
}
|
|
||||||
return self.rotationYaw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
package baritone.launch.mixins;
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.event.events.RotationMoveEvent;
|
import baritone.api.event.events.RotationMoveEvent;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@@ -55,8 +56,11 @@ public abstract class MixinEntityLivingBase extends Entity {
|
|||||||
private void preMoveRelative(CallbackInfo ci) {
|
private void preMoveRelative(CallbackInfo ci) {
|
||||||
// noinspection ConstantConditions
|
// noinspection ConstantConditions
|
||||||
if (EntityPlayerSP.class.isInstance(this)) {
|
if (EntityPlayerSP.class.isInstance(this)) {
|
||||||
this.jumpRotationEvent = new RotationMoveEvent((EntityPlayerSP) (Object) this, RotationMoveEvent.Type.JUMP, this.rotationYaw);
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
|
if (baritone != null) {
|
||||||
|
this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw);
|
||||||
|
baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +73,30 @@ public abstract class MixinEntityLivingBase extends Entity {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
private float overrideYaw(EntityLivingBase self) {
|
private float overrideYaw(EntityLivingBase self) {
|
||||||
if (self instanceof EntityPlayerSP) {
|
if (self instanceof EntityPlayerSP && BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) != null) {
|
||||||
return this.jumpRotationEvent.getYaw();
|
return this.jumpRotationEvent.getYaw();
|
||||||
}
|
}
|
||||||
return self.rotationYaw;
|
return self.rotationYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "travel",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/entity/EntityLivingBase.moveRelative(FFFF)V"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private void travel(EntityLivingBase self, float strafe, float up, float forward, float friction) {
|
||||||
|
// noinspection ConstantConditions
|
||||||
|
if (!EntityPlayerSP.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) == null) {
|
||||||
|
moveRelative(strafe, up, forward, friction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RotationMoveEvent motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw);
|
||||||
|
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(motionUpdateRotationEvent);
|
||||||
|
float originalYaw = this.rotationYaw;
|
||||||
|
this.rotationYaw = motionUpdateRotationEvent.getYaw();
|
||||||
|
this.moveRelative(strafe, up, forward, friction);
|
||||||
|
this.rotationYaw = originalYaw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,14 @@
|
|||||||
package baritone.launch.mixins;
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
import baritone.api.BaritoneAPI;
|
||||||
import baritone.api.behavior.IPathingBehavior;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.event.events.ChatEvent;
|
import baritone.api.event.events.ChatEvent;
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
import baritone.api.event.events.PlayerUpdateEvent;
|
||||||
|
import baritone.api.event.events.SprintStateEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
|
import baritone.behavior.LookBehavior;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import net.minecraft.entity.player.PlayerCapabilities;
|
import net.minecraft.entity.player.PlayerCapabilities;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -43,8 +46,12 @@ public class MixinEntityPlayerSP {
|
|||||||
cancellable = true
|
cancellable = true
|
||||||
)
|
)
|
||||||
private void sendChatMessage(String msg, CallbackInfo ci) {
|
private void sendChatMessage(String msg, CallbackInfo ci) {
|
||||||
ChatEvent event = new ChatEvent((EntityPlayerSP) (Object) this, msg);
|
ChatEvent event = new ChatEvent(msg);
|
||||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onSendChatMessage(event);
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
|
if (baritone == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
baritone.getGameEventHandler().onSendChatMessage(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
@@ -60,7 +67,10 @@ public class MixinEntityPlayerSP {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
private void onPreUpdate(CallbackInfo ci) {
|
private void onPreUpdate(CallbackInfo ci) {
|
||||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.PRE));
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
|
if (baritone != null) {
|
||||||
|
baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
@@ -73,7 +83,10 @@ public class MixinEntityPlayerSP {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
private void onPostUpdate(CallbackInfo ci) {
|
private void onPostUpdate(CallbackInfo ci) {
|
||||||
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent((EntityPlayerSP) (Object) this, EventState.POST));
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
|
if (baritone != null) {
|
||||||
|
baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(
|
@Redirect(
|
||||||
@@ -84,7 +97,47 @@ public class MixinEntityPlayerSP {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
private boolean isAllowFlying(PlayerCapabilities capabilities) {
|
private boolean isAllowFlying(PlayerCapabilities capabilities) {
|
||||||
IPathingBehavior pathingBehavior = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getPathingBehavior();
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
return !pathingBehavior.isPathing() && capabilities.allowFlying;
|
if (baritone == null) {
|
||||||
|
return capabilities.allowFlying;
|
||||||
|
}
|
||||||
|
return !baritone.getPathingBehavior().isPathing() && capabilities.allowFlying;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "onLivingUpdate",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean isKeyDown(KeyBinding keyBinding) {
|
||||||
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
|
if (baritone == null) {
|
||||||
|
return keyBinding.isKeyDown();
|
||||||
|
}
|
||||||
|
SprintStateEvent event = new SprintStateEvent();
|
||||||
|
baritone.getGameEventHandler().onPlayerSprintState(event);
|
||||||
|
if (event.getState() != null) {
|
||||||
|
return event.getState();
|
||||||
|
}
|
||||||
|
if (baritone != BaritoneAPI.getProvider().getPrimaryBaritone()) {
|
||||||
|
// hitting control shouldn't make all bots sprint
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return keyBinding.isKeyDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "updateRidden",
|
||||||
|
at = @At(
|
||||||
|
value = "HEAD"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private void updateRidden(CallbackInfo cb) {
|
||||||
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
|
||||||
|
if (baritone != null) {
|
||||||
|
((LookBehavior) baritone.getLookBehavior()).pig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.launch.mixins;
|
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
|
||||||
import baritone.utils.Helper;
|
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Brady
|
|
||||||
* @since 7/31/2018
|
|
||||||
*/
|
|
||||||
@Mixin(KeyBinding.class)
|
|
||||||
public class MixinKeyBinding {
|
|
||||||
|
|
||||||
@Shadow
|
|
||||||
public int pressTime;
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "isKeyDown",
|
|
||||||
at = @At("HEAD"),
|
|
||||||
cancellable = true
|
|
||||||
)
|
|
||||||
private void isKeyDown(CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
// only the primary baritone forces keys
|
|
||||||
Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this);
|
|
||||||
if (force != null) {
|
|
||||||
cir.setReturnValue(force); // :sunglasses:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "isPressed",
|
|
||||||
at = @At("HEAD"),
|
|
||||||
cancellable = true
|
|
||||||
)
|
|
||||||
private void isPressed(CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
// only the primary baritone forces keys
|
|
||||||
Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this);
|
|
||||||
if (force != null && force == false) { // <-- cursed
|
|
||||||
if (pressTime > 0) {
|
|
||||||
Helper.HELPER.logDirect("You're trying to press this mouse button but I won't let you");
|
|
||||||
pressTime--;
|
|
||||||
}
|
|
||||||
cir.setReturnValue(force); // :sunglasses:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.utils.IPlayerContext;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.chunk.RenderChunk;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.ChunkCache;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 1/29/2019
|
||||||
|
*/
|
||||||
|
@Mixin(RenderChunk.class)
|
||||||
|
public class MixinRenderChunk {
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "rebuildChunk",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/world/ChunkCache.isEmpty()Z"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private boolean isEmpty(ChunkCache chunkCache) {
|
||||||
|
if (!chunkCache.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
BlockPos position = ((RenderChunk) (Object) this).getPosition();
|
||||||
|
// RenderChunk extends from -1,-1,-1 to +16,+16,+16
|
||||||
|
// then the constructor of ChunkCache extends it one more (presumably to get things like the connected status of fences? idk)
|
||||||
|
// so if ANY of the adjacent chunks are loaded, we are unempty
|
||||||
|
for (int dx = -1; dx <= 1; dx++) {
|
||||||
|
for (int dz = -1; dz <= 1; dz++) {
|
||||||
|
if (baritone.bsi.isLoaded(16 * dx + position.getX(), 16 * dz + position.getZ())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(
|
||||||
|
method = "rebuildChunk",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/world/ChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private IBlockState getBlockState(ChunkCache chunkCache, BlockPos pos) {
|
||||||
|
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) {
|
||||||
|
return baritone.bsi.get0(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunkCache.getBlockState(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.RenderList;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
|
@Mixin(RenderList.class)
|
||||||
|
public class MixinRenderList {
|
||||||
|
|
||||||
|
@Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
|
||||||
|
method = "renderChunkLayer",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private void popMatrix() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.launch.mixins;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.VboRenderList;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
|
@Mixin(VboRenderList.class)
|
||||||
|
public class MixinVboRenderList {
|
||||||
|
|
||||||
|
@Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
|
||||||
|
method = "renderChunkLayer",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private void popMatrix() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,14 +12,17 @@
|
|||||||
"MixinBlockPos",
|
"MixinBlockPos",
|
||||||
"MixinChunkProviderClient",
|
"MixinChunkProviderClient",
|
||||||
"MixinChunkProviderServer",
|
"MixinChunkProviderServer",
|
||||||
"MixinEntity",
|
"MixinChunkRenderContainer",
|
||||||
|
"MixinChunkRenderWorker",
|
||||||
"MixinEntityLivingBase",
|
"MixinEntityLivingBase",
|
||||||
"MixinEntityPlayerSP",
|
"MixinEntityPlayerSP",
|
||||||
"MixinEntityRenderer",
|
"MixinEntityRenderer",
|
||||||
"MixinKeyBinding",
|
|
||||||
"MixinMinecraft",
|
"MixinMinecraft",
|
||||||
"MixinNetHandlerPlayClient",
|
"MixinNetHandlerPlayClient",
|
||||||
"MixinNetworkManager",
|
"MixinNetworkManager",
|
||||||
|
"MixinRenderChunk",
|
||||||
|
"MixinRenderList",
|
||||||
|
"MixinVboRenderList",
|
||||||
"MixinWorldClient"
|
"MixinWorldClient"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -21,26 +21,20 @@ import baritone.api.BaritoneAPI;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
import baritone.api.event.listener.IEventBus;
|
import baritone.api.event.listener.IEventBus;
|
||||||
|
import baritone.api.utils.ExampleBaritoneControl;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import baritone.behavior.*;
|
import baritone.behavior.*;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.event.GameEventHandler;
|
import baritone.event.GameEventHandler;
|
||||||
import baritone.process.CustomGoalProcess;
|
import baritone.process.*;
|
||||||
import baritone.process.FollowProcess;
|
import baritone.utils.*;
|
||||||
import baritone.process.GetToBlockProcess;
|
|
||||||
import baritone.process.MineProcess;
|
|
||||||
import baritone.utils.BaritoneAutoTest;
|
|
||||||
import baritone.utils.ExampleBaritoneControl;
|
|
||||||
import baritone.utils.InputOverrideHandler;
|
|
||||||
import baritone.utils.PathingControlManager;
|
|
||||||
import baritone.utils.player.PrimaryPlayerContext;
|
import baritone.utils.player.PrimaryPlayerContext;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.SynchronousQueue;
|
import java.util.concurrent.SynchronousQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@@ -73,26 +67,33 @@ public class Baritone implements IBaritone {
|
|||||||
|
|
||||||
private GameEventHandler gameEventHandler;
|
private GameEventHandler gameEventHandler;
|
||||||
|
|
||||||
private List<Behavior> behaviors;
|
|
||||||
private PathingBehavior pathingBehavior;
|
private PathingBehavior pathingBehavior;
|
||||||
private LookBehavior lookBehavior;
|
private LookBehavior lookBehavior;
|
||||||
private MemoryBehavior memoryBehavior;
|
private MemoryBehavior memoryBehavior;
|
||||||
|
private InventoryBehavior inventoryBehavior;
|
||||||
private InputOverrideHandler inputOverrideHandler;
|
private InputOverrideHandler inputOverrideHandler;
|
||||||
|
|
||||||
private FollowProcess followProcess;
|
private FollowProcess followProcess;
|
||||||
private MineProcess mineProcess;
|
private MineProcess mineProcess;
|
||||||
private GetToBlockProcess getToBlockProcess;
|
private GetToBlockProcess getToBlockProcess;
|
||||||
private CustomGoalProcess customGoalProcess;
|
private CustomGoalProcess customGoalProcess;
|
||||||
|
private BuilderProcess builderProcess;
|
||||||
|
private ExploreProcess exploreProcess;
|
||||||
|
private BackfillProcess backfillProcess;
|
||||||
|
private FarmProcess farmProcess;
|
||||||
|
|
||||||
private PathingControlManager pathingControlManager;
|
private PathingControlManager pathingControlManager;
|
||||||
|
|
||||||
private IPlayerContext playerContext;
|
private IPlayerContext playerContext;
|
||||||
private WorldProvider worldProvider;
|
private WorldProvider worldProvider;
|
||||||
|
|
||||||
|
public BlockStateInterface bsi;
|
||||||
|
|
||||||
Baritone() {
|
Baritone() {
|
||||||
this.gameEventHandler = new GameEventHandler(this);
|
this.gameEventHandler = new GameEventHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public synchronized void init() {
|
public synchronized void init() {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
return;
|
return;
|
||||||
@@ -101,13 +102,12 @@ public class Baritone implements IBaritone {
|
|||||||
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
||||||
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
||||||
|
|
||||||
this.behaviors = new ArrayList<>();
|
|
||||||
{
|
{
|
||||||
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||||
pathingBehavior = new PathingBehavior(this);
|
pathingBehavior = new PathingBehavior(this);
|
||||||
lookBehavior = new LookBehavior(this);
|
lookBehavior = new LookBehavior(this);
|
||||||
memoryBehavior = new MemoryBehavior(this);
|
memoryBehavior = new MemoryBehavior(this);
|
||||||
new InventoryBehavior(this);
|
inventoryBehavior = new InventoryBehavior(this);
|
||||||
inputOverrideHandler = new InputOverrideHandler(this);
|
inputOverrideHandler = new InputOverrideHandler(this);
|
||||||
new ExampleBaritoneControl(this);
|
new ExampleBaritoneControl(this);
|
||||||
}
|
}
|
||||||
@@ -118,6 +118,10 @@ public class Baritone implements IBaritone {
|
|||||||
mineProcess = new MineProcess(this);
|
mineProcess = new MineProcess(this);
|
||||||
customGoalProcess = new CustomGoalProcess(this); // very high iq
|
customGoalProcess = new CustomGoalProcess(this); // very high iq
|
||||||
getToBlockProcess = new GetToBlockProcess(this);
|
getToBlockProcess = new GetToBlockProcess(this);
|
||||||
|
builderProcess = new BuilderProcess(this);
|
||||||
|
exploreProcess = new ExploreProcess(this);
|
||||||
|
backfillProcess = new BackfillProcess(this);
|
||||||
|
farmProcess = new FarmProcess(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.worldProvider = new WorldProvider();
|
this.worldProvider = new WorldProvider();
|
||||||
@@ -134,12 +138,7 @@ public class Baritone implements IBaritone {
|
|||||||
return this.pathingControlManager;
|
return this.pathingControlManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Behavior> getBehaviors() {
|
|
||||||
return this.behaviors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerBehavior(Behavior behavior) {
|
public void registerBehavior(Behavior behavior) {
|
||||||
this.behaviors.add(behavior);
|
|
||||||
this.gameEventHandler.registerEventListener(behavior);
|
this.gameEventHandler.registerEventListener(behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,16 +171,33 @@ public class Baritone implements IBaritone {
|
|||||||
return this.followProcess;
|
return this.followProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BuilderProcess getBuilderProcess() {
|
||||||
|
return this.builderProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InventoryBehavior getInventoryBehavior() {
|
||||||
|
return this.inventoryBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LookBehavior getLookBehavior() {
|
public LookBehavior getLookBehavior() {
|
||||||
return this.lookBehavior;
|
return this.lookBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExploreProcess getExploreProcess() {
|
||||||
|
return this.exploreProcess;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MineProcess getMineProcess() {
|
public MineProcess getMineProcess() {
|
||||||
return this.mineProcess;
|
return this.mineProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FarmProcess getFarmProcess() {
|
||||||
|
return this.farmProcess;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PathingBehavior getPathingBehavior() {
|
public PathingBehavior getPathingBehavior() {
|
||||||
return this.pathingBehavior;
|
return this.pathingBehavior;
|
||||||
@@ -197,6 +213,16 @@ public class Baritone implements IBaritone {
|
|||||||
return this.gameEventHandler;
|
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() {
|
public static Settings settings() {
|
||||||
return BaritoneAPI.getSettings();
|
return BaritoneAPI.getSettings();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import java.util.List;
|
|||||||
public final class BaritoneProvider implements IBaritoneProvider {
|
public final class BaritoneProvider implements IBaritoneProvider {
|
||||||
|
|
||||||
private final Baritone primary = new Baritone();
|
private final Baritone primary = new Baritone();
|
||||||
|
private final List<IBaritone> all = Collections.singletonList(primary);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBaritone getPrimaryBaritone() {
|
public IBaritone getPrimaryBaritone() {
|
||||||
@@ -40,8 +41,7 @@ public final class BaritoneProvider implements IBaritoneProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IBaritone> getAllBaritones() {
|
public List<IBaritone> getAllBaritones() {
|
||||||
// TODO return a CopyOnWriteArrayList
|
return all;
|
||||||
return Collections.singletonList(primary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,21 +21,26 @@ import baritone.Baritone;
|
|||||||
import baritone.api.event.events.TickEvent;
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.utils.ToolSet;
|
import baritone.utils.ToolSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.inventory.ClickType;
|
import net.minecraft.inventory.ClickType;
|
||||||
import net.minecraft.item.ItemPickaxe;
|
import net.minecraft.item.*;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.ItemTool;
|
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
|
|
||||||
public class InventoryBehavior extends Behavior {
|
import java.util.ArrayList;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public final class InventoryBehavior extends Behavior {
|
||||||
public InventoryBehavior(Baritone baritone) {
|
public InventoryBehavior(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
if (!Baritone.settings().allowInventory.get()) {
|
if (!Baritone.settings().allowInventory.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.getType() == TickEvent.Type.OUT) {
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
@@ -54,6 +59,34 @@ public class InventoryBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void attemptToPutOnHotbar(int inMainInvy, Predicate<Integer> disallowedHotbar) {
|
||||||
|
OptionalInt destination = getTempHotbarSlot(disallowedHotbar);
|
||||||
|
if (destination.isPresent()) {
|
||||||
|
swapWithHotBar(inMainInvy, destination.getAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public OptionalInt getTempHotbarSlot(Predicate<Integer> disallowedHotbar) {
|
||||||
|
// we're using 0 and 8 for pickaxe and throwaway
|
||||||
|
ArrayList<Integer> candidates = new ArrayList<>();
|
||||||
|
for (int i = 1; i < 8; i++) {
|
||||||
|
if (ctx.player().inventory.mainInventory.get(i).isEmpty() && !disallowedHotbar.test(i)) {
|
||||||
|
candidates.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (candidates.isEmpty()) {
|
||||||
|
for (int i = 1; i < 8; i++) {
|
||||||
|
if (!disallowedHotbar.test(i)) {
|
||||||
|
candidates.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (candidates.isEmpty()) {
|
||||||
|
return OptionalInt.empty();
|
||||||
|
}
|
||||||
|
return OptionalInt.of(candidates.get(new Random().nextInt(candidates.size())));
|
||||||
|
}
|
||||||
|
|
||||||
private void swapWithHotBar(int inInventory, int inHotbar) {
|
private void swapWithHotBar(int inInventory, int inHotbar) {
|
||||||
ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
|
ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
|
||||||
}
|
}
|
||||||
@@ -61,7 +94,7 @@ public class InventoryBehavior extends Behavior {
|
|||||||
private int firstValidThrowaway() { // TODO offhand idk
|
private int firstValidThrowaway() { // TODO offhand idk
|
||||||
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
|
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
|
||||||
for (int i = 0; i < invy.size(); i++) {
|
for (int i = 0; i < invy.size(); i++) {
|
||||||
if (Baritone.settings().acceptableThrowawayItems.get().contains(invy.get(i).getItem())) {
|
if (Baritone.settings().acceptableThrowawayItems.value.contains(invy.get(i).getItem())) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,4 +120,62 @@ public class InventoryBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
return bestInd;
|
return bestInd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasGenericThrowaway() {
|
||||||
|
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
||||||
|
if (throwaway(false, stack -> item.equals(stack.getItem()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
|
||||||
|
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
||||||
|
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(select, stack -> item.equals(stack.getItem()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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++) {
|
||||||
|
ItemStack item = inv.get(i);
|
||||||
|
// this usage of settings() is okay because it's only called once during pathing
|
||||||
|
// (while creating the CalculationContext at the very beginning)
|
||||||
|
// 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)) {
|
||||||
|
if (select) {
|
||||||
|
p.inventory.currentItem = i;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
// so we need to select in the main hand something that doesn't right click
|
||||||
|
// so not a shovel, not a hoe, not a block, etc
|
||||||
|
for (byte i = 0; i < 9; i++) {
|
||||||
|
ItemStack item = inv.get(i);
|
||||||
|
if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) {
|
||||||
|
if (select) {
|
||||||
|
p.inventory.currentItem = i;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
|||||||
@Override
|
@Override
|
||||||
public void updateTarget(Rotation target, boolean force) {
|
public void updateTarget(Rotation target, boolean force) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.force = force || !Baritone.settings().freeLook.get();
|
this.force = force || !Baritone.settings().freeLook.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,7 +63,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Whether or not we're going to silently set our angles
|
// Whether or not we're going to silently set our angles
|
||||||
boolean silent = Baritone.settings().antiCheatCompatibility.get() && !this.force;
|
boolean silent = Baritone.settings().antiCheatCompatibility.value && !this.force;
|
||||||
|
|
||||||
switch (event.getState()) {
|
switch (event.getState()) {
|
||||||
case PRE: {
|
case PRE: {
|
||||||
@@ -72,7 +72,7 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
|||||||
float oldPitch = ctx.player().rotationPitch;
|
float oldPitch = ctx.player().rotationPitch;
|
||||||
float desiredPitch = this.target.getPitch();
|
float desiredPitch = this.target.getPitch();
|
||||||
ctx.player().rotationPitch = desiredPitch;
|
ctx.player().rotationPitch = desiredPitch;
|
||||||
if (desiredPitch == oldPitch) {
|
if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) {
|
||||||
nudgeToLevel();
|
nudgeToLevel();
|
||||||
}
|
}
|
||||||
this.target = null;
|
this.target = null;
|
||||||
@@ -95,15 +95,21 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pig() {
|
||||||
|
if (this.target != null) {
|
||||||
|
ctx.player().rotationYaw = this.target.getYaw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerRotationMove(RotationMoveEvent event) {
|
public void onPlayerRotationMove(RotationMoveEvent event) {
|
||||||
if (this.target != null && !this.force) {
|
if (this.target != null) {
|
||||||
|
|
||||||
event.setYaw(this.target.getYaw());
|
event.setYaw(this.target.getYaw());
|
||||||
|
|
||||||
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
|
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
|
||||||
// Also the type has to be MOTION_UPDATE because that is called after JUMP
|
// Also the type has to be MOTION_UPDATE because that is called after JUMP
|
||||||
if (!Baritone.settings().antiCheatCompatibility.get() && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE) {
|
if (!Baritone.settings().antiCheatCompatibility.value && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE && !this.force) {
|
||||||
this.target = null;
|
this.target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,13 @@
|
|||||||
package baritone.behavior;
|
package baritone.behavior;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
import baritone.api.event.events.BlockInteractEvent;
|
import baritone.api.event.events.BlockInteractEvent;
|
||||||
import baritone.api.event.events.PacketEvent;
|
import baritone.api.event.events.PacketEvent;
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
import baritone.api.event.events.PlayerUpdateEvent;
|
||||||
import baritone.api.event.events.TickEvent;
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.cache.ContainerMemory;
|
import baritone.cache.ContainerMemory;
|
||||||
import baritone.cache.Waypoint;
|
|
||||||
import baritone.pathing.movement.CalculationContext;
|
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockBed;
|
import net.minecraft.block.BlockBed;
|
||||||
@@ -48,6 +47,8 @@ import java.nio.file.Path;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* doesn't work for horse inventories :^)
|
||||||
|
*
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/6/2018
|
* @since 8/6/2018
|
||||||
*/
|
*/
|
||||||
@@ -63,6 +64,9 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onTick(TickEvent event) {
|
public synchronized void onTick(TickEvent event) {
|
||||||
|
if (!Baritone.settings().containerMemory.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.getType() == TickEvent.Type.OUT) {
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
enderChestWindowId = null;
|
enderChestWindowId = null;
|
||||||
futureInventories.clear();
|
futureInventories.clear();
|
||||||
@@ -78,6 +82,9 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onSendPacket(PacketEvent event) {
|
public synchronized void onSendPacket(PacketEvent event) {
|
||||||
|
if (!Baritone.settings().containerMemory.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Packet p = event.getPacket();
|
Packet p = event.getPacket();
|
||||||
|
|
||||||
if (event.getState() == EventState.PRE) {
|
if (event.getState() == EventState.PRE) {
|
||||||
@@ -107,7 +114,6 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p instanceof CPacketCloseWindow) {
|
if (p instanceof CPacketCloseWindow) {
|
||||||
updateInventory();
|
|
||||||
getCurrent().save();
|
getCurrent().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,6 +121,9 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onReceivePacket(PacketEvent event) {
|
public synchronized void onReceivePacket(PacketEvent event) {
|
||||||
|
if (!Baritone.settings().containerMemory.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Packet p = event.getPacket();
|
Packet p = event.getPacket();
|
||||||
|
|
||||||
if (event.getState() == EventState.PRE) {
|
if (event.getState() == EventState.PRE) {
|
||||||
@@ -142,7 +151,6 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p instanceof SPacketCloseWindow) {
|
if (p instanceof SPacketCloseWindow) {
|
||||||
updateInventory();
|
|
||||||
getCurrent().save();
|
getCurrent().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,6 +170,9 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
|
|
||||||
|
|
||||||
private void updateInventory() {
|
private void updateInventory() {
|
||||||
|
if (!Baritone.settings().containerMemory.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int windowId = ctx.player().openContainer.windowId;
|
int windowId = ctx.player().openContainer.windowId;
|
||||||
if (enderChestWindowId != null) {
|
if (enderChestWindowId != null) {
|
||||||
if (windowId == enderChestWindowId) {
|
if (windowId == enderChestWindowId) {
|
||||||
@@ -184,7 +195,7 @@ public final class MemoryBehavior extends Behavior {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos neighboringConnectedBlock(BlockPos in) {
|
private BlockPos neighboringConnectedBlock(BlockPos in) {
|
||||||
BlockStateInterface bsi = new CalculationContext(baritone).bsi;
|
BlockStateInterface bsi = baritone.bsi;
|
||||||
Block block = bsi.get0(in).getBlock();
|
Block block = bsi.get0(in).getBlock();
|
||||||
if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
|
if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
|
||||||
return null; // other things that have contents, but can be placed adjacent without combining
|
return null; // other things that have contents, but can be placed adjacent without combining
|
||||||
|
|||||||
@@ -19,27 +19,24 @@ package baritone.behavior;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.behavior.IPathingBehavior;
|
import baritone.api.behavior.IPathingBehavior;
|
||||||
import baritone.api.event.events.PathEvent;
|
import baritone.api.event.events.*;
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
|
||||||
import baritone.api.event.events.RenderEvent;
|
|
||||||
import baritone.api.event.events.TickEvent;
|
|
||||||
import baritone.api.pathing.calc.IPath;
|
import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.goals.GoalXZ;
|
import baritone.api.pathing.goals.GoalXZ;
|
||||||
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.PathCalculationResult;
|
import baritone.api.utils.PathCalculationResult;
|
||||||
import baritone.api.utils.interfaces.IGoalRenderPos;
|
import baritone.api.utils.interfaces.IGoalRenderPos;
|
||||||
import baritone.pathing.calc.AStarPathFinder;
|
import baritone.pathing.calc.AStarPathFinder;
|
||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.path.CutoffPath;
|
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.PathRenderer;
|
import baritone.utils.PathRenderer;
|
||||||
|
import baritone.utils.PathingCommandContext;
|
||||||
import baritone.utils.pathing.Favoring;
|
import baritone.utils.pathing.Favoring;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -53,9 +50,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
private PathExecutor next;
|
private PathExecutor next;
|
||||||
|
|
||||||
private Goal goal;
|
private Goal goal;
|
||||||
|
private CalculationContext context;
|
||||||
|
|
||||||
private boolean safeToCancel;
|
private boolean safeToCancel;
|
||||||
private boolean pauseRequestedLastTick;
|
private boolean pauseRequestedLastTick;
|
||||||
|
private boolean unpausedLastTick;
|
||||||
private boolean cancelRequested;
|
private boolean cancelRequested;
|
||||||
private boolean calcFailedLastTick;
|
private boolean calcFailedLastTick;
|
||||||
|
|
||||||
@@ -66,6 +65,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
private boolean lastAutoJump;
|
private boolean lastAutoJump;
|
||||||
|
|
||||||
|
private BetterBlockPos expectedSegmentStart;
|
||||||
|
|
||||||
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
|
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
public PathingBehavior(Baritone baritone) {
|
public PathingBehavior(Baritone baritone) {
|
||||||
@@ -93,36 +94,67 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
baritone.getPathingControlManager().cancelEverything();
|
baritone.getPathingControlManager().cancelEverything();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
expectedSegmentStart = pathStart();
|
||||||
baritone.getPathingControlManager().preTick();
|
baritone.getPathingControlManager().preTick();
|
||||||
tickPath();
|
tickPath();
|
||||||
dispatchEvents();
|
dispatchEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerSprintState(SprintStateEvent event) {
|
||||||
|
if (current != null) {
|
||||||
|
event.setState(current.isSprinting());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void tickPath() {
|
private void tickPath() {
|
||||||
if (pauseRequestedLastTick && safeToCancel) {
|
if (pauseRequestedLastTick && safeToCancel) {
|
||||||
pauseRequestedLastTick = false;
|
pauseRequestedLastTick = false;
|
||||||
baritone.getInputOverrideHandler().clearAllKeys();
|
if (unpausedLastTick) {
|
||||||
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
|
||||||
|
}
|
||||||
|
unpausedLastTick = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
unpausedLastTick = true;
|
||||||
if (cancelRequested) {
|
if (cancelRequested) {
|
||||||
cancelRequested = false;
|
cancelRequested = false;
|
||||||
baritone.getInputOverrideHandler().clearAllKeys();
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
}
|
}
|
||||||
if (current == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
safeToCancel = current.onTick();
|
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
|
synchronized (pathCalcLock) {
|
||||||
|
if (inProgress != null) {
|
||||||
|
// we are calculating
|
||||||
|
// are we calculating the right thing though? 🤔
|
||||||
|
BetterBlockPos calcFrom = inProgress.getStart();
|
||||||
|
Optional<IPath> currentBest = inProgress.bestPathSoFar();
|
||||||
|
if ((current == null || !current.getPath().getDest().equals(calcFrom)) // if current ends in inProgress's start, then we're ok
|
||||||
|
&& !calcFrom.equals(ctx.playerFeet()) && !calcFrom.equals(expectedSegmentStart) // if current starts in our playerFeet or pathStart, then we're ok
|
||||||
|
&& (!currentBest.isPresent() || (!currentBest.get().positions().contains(ctx.playerFeet()) && !currentBest.get().positions().contains(expectedSegmentStart))) // if
|
||||||
|
) {
|
||||||
|
// when it was *just* started, currentBest will be empty so we need to also check calcFrom since that's always present
|
||||||
|
inProgress.cancel(); // cancellation doesn't dispatch any events
|
||||||
|
inProgress = null; // this is safe since we hold both locks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
safeToCancel = current.onTick();
|
||||||
if (current.failed() || current.finished()) {
|
if (current.failed() || current.finished()) {
|
||||||
current = null;
|
current = null;
|
||||||
if (goal == null || goal.isInGoal(ctx.playerFeet())) {
|
if (goal == null || goal.isInGoal(ctx.playerFeet())) {
|
||||||
logDebug("All done. At " + goal);
|
logDebug("All done. At " + goal);
|
||||||
queuePathEvent(PathEvent.AT_GOAL);
|
queuePathEvent(PathEvent.AT_GOAL);
|
||||||
next = null;
|
next = null;
|
||||||
|
if (Baritone.settings().disconnectOnArrival.value) {
|
||||||
|
ctx.world().sendQuittingDisconnectingPacket();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (next != null && !next.getPath().positions().contains(ctx.playerFeet())) {
|
if (next != null && !next.getPath().positions().contains(ctx.playerFeet()) && !next.getPath().positions().contains(expectedSegmentStart)) { // can contain either one
|
||||||
// if the current path failed, we may not actually be on the next one, so make sure
|
// if the current path failed, we may not actually be on the next one, so make sure
|
||||||
logDebug("Discarding next path as it does not contain current position");
|
logDebug("Discarding next path as it does not contain current position");
|
||||||
// for example if we had a nicely planned ahead path that starts where current ends
|
// for example if we had a nicely planned ahead path that starts where current ends
|
||||||
@@ -138,18 +170,18 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
queuePathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT);
|
queuePathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT);
|
||||||
current = next;
|
current = next;
|
||||||
next = null;
|
next = null;
|
||||||
current.onTick();
|
current.onTick(); // don't waste a tick doing nothing, get started right away
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// at this point, current just ended, but we aren't in the goal and have no plan for the future
|
// at this point, current just ended, but we aren't in the goal and have no plan for the future
|
||||||
synchronized (pathCalcLock) {
|
synchronized (pathCalcLock) {
|
||||||
if (inProgress != null) {
|
if (inProgress != null) {
|
||||||
queuePathEvent(PathEvent.PATH_FINISHED_NEXT_STILL_CALCULATING);
|
queuePathEvent(PathEvent.PATH_FINISHED_NEXT_STILL_CALCULATING);
|
||||||
// if we aren't calculating right now
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// we aren't calculating
|
||||||
queuePathEvent(PathEvent.CALC_STARTED);
|
queuePathEvent(PathEvent.CALC_STARTED);
|
||||||
findPathInNewThread(pathStart(), true);
|
findPathInNewThread(expectedSegmentStart, true, context);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -163,7 +195,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
current.onTick();
|
current.onTick();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
current = current.trySplice(next);
|
if (Baritone.settings().splicePath.value) {
|
||||||
|
current = current.trySplice(next);
|
||||||
|
}
|
||||||
if (next != null && current.getPath().getDest().equals(next.getPath().getDest())) {
|
if (next != null && current.getPath().getDest().equals(next.getPath().getDest())) {
|
||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
@@ -177,14 +211,16 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
|
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
|
||||||
// and this path dosen't get us all the way there
|
// and this path doesn't get us all the way there
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) {
|
if (ticksRemainingInSegment(false).get() < Baritone.settings().planningTickLookahead.value) {
|
||||||
// and this path has 5 seconds or less left
|
// and this path has 7.5 seconds or less left
|
||||||
|
// don't include the current movement so a very long last movement (e.g. descend) doesn't trip it up
|
||||||
|
// if we actually included current, it wouldn't start planning ahead until the last movement was done, if the last movement took more than 7.5 seconds on its own
|
||||||
logDebug("Path almost over. Planning ahead...");
|
logDebug("Path almost over. Planning ahead...");
|
||||||
queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED);
|
queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED);
|
||||||
findPathInNewThread(current.getPath().getDest(), false);
|
findPathInNewThread(current.getPath().getDest(), false, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,21 +243,36 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Double> ticksRemainingInSegment() {
|
|
||||||
if (current == null) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void secretInternalSetGoal(Goal goal) {
|
public void secretInternalSetGoal(Goal goal) {
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean secretInternalSetGoalAndPath(Goal goal) {
|
public boolean secretInternalSetGoalAndPath(PathingCommand command) {
|
||||||
secretInternalSetGoal(goal);
|
secretInternalSetGoal(command.goal);
|
||||||
return secretInternalPath();
|
if (command instanceof PathingCommandContext) {
|
||||||
|
context = ((PathingCommandContext) command).desiredCalcContext;
|
||||||
|
} else {
|
||||||
|
context = new CalculationContext(baritone, true);
|
||||||
|
}
|
||||||
|
if (goal == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (goal.isInGoal(ctx.playerFeet()) || goal.isInGoal(expectedSegmentStart)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
synchronized (pathPlanLock) {
|
||||||
|
if (current != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
synchronized (pathCalcLock) {
|
||||||
|
if (inProgress != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
queuePathEvent(PathEvent.CALC_STARTED);
|
||||||
|
findPathInNewThread(expectedSegmentStart, true, context);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -244,11 +295,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
return Optional.ofNullable(inProgress);
|
return Optional.ofNullable(inProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPathing() {
|
|
||||||
return this.current != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSafeToCancel() {
|
public boolean isSafeToCancel() {
|
||||||
return current == null || safeToCancel;
|
return current == null || safeToCancel;
|
||||||
}
|
}
|
||||||
@@ -271,7 +317,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
if (doIt) {
|
if (doIt) {
|
||||||
secretInternalSegmentCancel();
|
secretInternalSegmentCancel();
|
||||||
}
|
}
|
||||||
baritone.getPathingControlManager().cancelEverything();
|
baritone.getPathingControlManager().cancelEverything(); // regardless of if we can stop the current segment, we can still stop the processes
|
||||||
return doIt;
|
return doIt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +327,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
public void softCancelIfSafe() {
|
public void softCancelIfSafe() {
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
|
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
|
||||||
if (!isSafeToCancel()) {
|
if (!isSafeToCancel()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -288,7 +335,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
cancelRequested = true;
|
cancelRequested = true;
|
||||||
getInProgress().ifPresent(AbstractNodeCostSearch::cancel); // only cancel ours
|
|
||||||
// do everything BUT clear keys
|
// do everything BUT clear keys
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,51 +342,33 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
public void secretInternalSegmentCancel() {
|
public void secretInternalSegmentCancel() {
|
||||||
queuePathEvent(PathEvent.CANCELED);
|
queuePathEvent(PathEvent.CANCELED);
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
current = null;
|
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
|
||||||
next = null;
|
if (current != null) {
|
||||||
|
current = null;
|
||||||
|
next = null;
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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();
|
cancelEverything();
|
||||||
secretInternalSegmentCancel();
|
secretInternalSegmentCancel();
|
||||||
inProgress = null;
|
synchronized (pathCalcLock) {
|
||||||
}
|
inProgress = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Start calculating a path if we aren't already
|
|
||||||
*
|
|
||||||
* @return true if this call started path calculation, false if it was already calculating or executing a path
|
|
||||||
*/
|
|
||||||
public boolean secretInternalPath() {
|
|
||||||
if (goal == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (goal.isInGoal(ctx.playerFeet())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
synchronized (pathPlanLock) {
|
|
||||||
if (current != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
synchronized (pathCalcLock) {
|
|
||||||
if (inProgress != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
queuePathEvent(PathEvent.CALC_STARTED);
|
|
||||||
findPathInNewThread(pathStart(), true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void secretCursedFunctionDoNotCall(IPath path) {
|
/*public void secretCursedFunctionDoNotCall(IPath path) {
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
current = new PathExecutor(this, path);
|
current = new PathExecutor(this, path);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public CalculationContext secretInternalGetCalculationContext() {
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -371,7 +399,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) {
|
if (MovementHelper.canWalkOn(ctx, possibleSupport.down()) && MovementHelper.canWalkThrough(ctx, possibleSupport) && MovementHelper.canWalkThrough(ctx, possibleSupport.up())) {
|
||||||
// this is plausible
|
// this is plausible
|
||||||
logDebug("Faking path start assuming player is standing off the edge of a block");
|
//logDebug("Faking path start assuming player is standing off the edge of a block");
|
||||||
return possibleSupport;
|
return possibleSupport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,7 +408,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
// !onGround
|
// !onGround
|
||||||
// we're in the middle of a jump
|
// we're in the middle of a jump
|
||||||
if (MovementHelper.canWalkOn(ctx, feet.down().down())) {
|
if (MovementHelper.canWalkOn(ctx, feet.down().down())) {
|
||||||
logDebug("Faking path start assuming player is midair and falling");
|
//logDebug("Faking path start assuming player is midair and falling");
|
||||||
return feet.down();
|
return feet.down();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,7 +422,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
* @param start
|
* @param start
|
||||||
* @param talkAboutIt
|
* @param talkAboutIt
|
||||||
*/
|
*/
|
||||||
private void findPathInNewThread(final BlockPos start, final boolean talkAboutIt) {
|
private void findPathInNewThread(final BlockPos start, final boolean talkAboutIt, CalculationContext context) {
|
||||||
// this must be called with synchronization on pathCalcLock!
|
// this must be called with synchronization on pathCalcLock!
|
||||||
// actually, we can check this, muahaha
|
// actually, we can check this, muahaha
|
||||||
if (!Thread.holdsLock(pathCalcLock)) {
|
if (!Thread.holdsLock(pathCalcLock)) {
|
||||||
@@ -404,6 +432,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
if (inProgress != null) {
|
if (inProgress != null) {
|
||||||
throw new IllegalStateException("Already doing it"); // should have been checked by caller
|
throw new IllegalStateException("Already doing it"); // should have been checked by caller
|
||||||
}
|
}
|
||||||
|
if (!context.safeForThreadedUse) {
|
||||||
|
throw new IllegalStateException("Improper context thread safety level");
|
||||||
|
}
|
||||||
Goal goal = this.goal;
|
Goal goal = this.goal;
|
||||||
if (goal == null) {
|
if (goal == null) {
|
||||||
logDebug("no goal"); // TODO should this be an exception too? definitely should be checked by caller
|
logDebug("no goal"); // TODO should this be an exception too? definitely should be checked by caller
|
||||||
@@ -412,13 +443,12 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
long primaryTimeout;
|
long primaryTimeout;
|
||||||
long failureTimeout;
|
long failureTimeout;
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
primaryTimeout = Baritone.settings().primaryTimeoutMS.get();
|
primaryTimeout = Baritone.settings().primaryTimeoutMS.value;
|
||||||
failureTimeout = Baritone.settings().failureTimeoutMS.get();
|
failureTimeout = Baritone.settings().failureTimeoutMS.value;
|
||||||
} else {
|
} else {
|
||||||
primaryTimeout = Baritone.settings().planAheadPrimaryTimeoutMS.get();
|
primaryTimeout = Baritone.settings().planAheadPrimaryTimeoutMS.value;
|
||||||
failureTimeout = Baritone.settings().planAheadFailureTimeoutMS.get();
|
failureTimeout = Baritone.settings().planAheadFailureTimeoutMS.value;
|
||||||
}
|
}
|
||||||
CalculationContext context = new CalculationContext(baritone, true); // not safe to create on the other thread, it looks up a lot of stuff in minecraft
|
|
||||||
AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context);
|
AbstractNodeCostSearch pathfinder = createPathfinder(start, goal, current == null ? null : current.getPath(), context);
|
||||||
if (!Objects.equals(pathfinder.getGoal(), goal)) { // will return the exact same object if simplification didn't happen
|
if (!Objects.equals(pathfinder.getGoal(), goal)) { // will return the exact same object if simplification didn't happen
|
||||||
logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance");
|
logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance");
|
||||||
@@ -430,37 +460,16 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
|
|
||||||
PathCalculationResult calcResult = pathfinder.calculate(primaryTimeout, failureTimeout);
|
PathCalculationResult calcResult = pathfinder.calculate(primaryTimeout, failureTimeout);
|
||||||
Optional<IPath> path = calcResult.getPath();
|
|
||||||
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
|
|
||||||
path = path.map(p -> {
|
|
||||||
IPath result = p.cutoffAtLoadedChunks(context.bsi);
|
|
||||||
|
|
||||||
if (result instanceof CutoffPath) {
|
|
||||||
logDebug("Cutting off path at edge of loaded chunks");
|
|
||||||
logDebug("Length decreased by " + (p.length() - result.length()));
|
|
||||||
} else {
|
|
||||||
logDebug("Path ends within loaded chunks");
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<PathExecutor> executor = path.map(p -> {
|
|
||||||
IPath result = p.staticCutoff(goal);
|
|
||||||
|
|
||||||
if (result instanceof CutoffPath) {
|
|
||||||
logDebug("Static cutoff " + p.length() + " to " + result.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}).map(p -> new PathExecutor(this, p));
|
|
||||||
|
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
|
Optional<PathExecutor> executor = calcResult.getPath().map(p -> new PathExecutor(PathingBehavior.this, p));
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
if (executor.isPresent()) {
|
if (executor.isPresent()) {
|
||||||
queuePathEvent(PathEvent.CALC_FINISHED_NOW_EXECUTING);
|
if (executor.get().getPath().positions().contains(expectedSegmentStart)) {
|
||||||
current = executor.get();
|
queuePathEvent(PathEvent.CALC_FINISHED_NOW_EXECUTING);
|
||||||
|
current = executor.get();
|
||||||
|
} else {
|
||||||
|
logDebug("Warning: discarding orphan path segment with incorrect start");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (calcResult.getType() != PathCalculationResult.Type.CANCELLATION && calcResult.getType() != PathCalculationResult.Type.EXCEPTION) {
|
if (calcResult.getType() != PathCalculationResult.Type.CANCELLATION && calcResult.getType() != PathCalculationResult.Type.EXCEPTION) {
|
||||||
// don't dispatch CALC_FAILED on cancellation
|
// don't dispatch CALC_FAILED on cancellation
|
||||||
@@ -470,8 +479,12 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
} else {
|
} else {
|
||||||
if (next == null) {
|
if (next == null) {
|
||||||
if (executor.isPresent()) {
|
if (executor.isPresent()) {
|
||||||
queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_FINISHED);
|
if (executor.get().getPath().getSrc().equals(current.getPath().getDest())) {
|
||||||
next = executor.get();
|
queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_FINISHED);
|
||||||
|
next = executor.get();
|
||||||
|
} else {
|
||||||
|
logDebug("Warning: discarding orphan next segment with incorrect start");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
queuePathEvent(PathEvent.NEXT_CALC_FAILED);
|
queuePathEvent(PathEvent.NEXT_CALC_FAILED);
|
||||||
}
|
}
|
||||||
@@ -497,13 +510,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) {
|
public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) {
|
||||||
Goal transformed = goal;
|
Goal transformed = goal;
|
||||||
if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof IGoalRenderPos) {
|
if (Baritone.settings().simplifyUnloadedYCoord.value && goal instanceof IGoalRenderPos) {
|
||||||
BlockPos pos = ((IGoalRenderPos) goal).getGoalPos();
|
BlockPos pos = ((IGoalRenderPos) goal).getGoalPos();
|
||||||
if (!context.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ())) {
|
if (!context.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ())) {
|
||||||
transformed = new GoalXZ(pos.getX(), pos.getZ());
|
transformed = new GoalXZ(pos.getX(), pos.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Favoring favoring = new Favoring(context.getBaritone().getPlayerContext(), previous);
|
Favoring favoring = new Favoring(context.getBaritone().getPlayerContext(), previous, context);
|
||||||
return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoring, context);
|
return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoring, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+86
-60
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import baritone.utils.pathing.PathingBlockType;
|
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.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
@@ -31,62 +34,60 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public final class CachedChunk {
|
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 {
|
Blocks.ENDER_CHEST,
|
||||||
HashSet<Block> temp = new HashSet<>();
|
Blocks.FURNACE,
|
||||||
//temp.add(Blocks.DIAMOND_ORE);
|
Blocks.CHEST,
|
||||||
temp.add(Blocks.DIAMOND_BLOCK);
|
Blocks.TRAPPED_CHEST,
|
||||||
//temp.add(Blocks.COAL_ORE);
|
Blocks.END_PORTAL,
|
||||||
temp.add(Blocks.COAL_BLOCK);
|
Blocks.END_PORTAL_FRAME,
|
||||||
//temp.add(Blocks.IRON_ORE);
|
Blocks.MOB_SPAWNER,
|
||||||
temp.add(Blocks.IRON_BLOCK);
|
Blocks.BARRIER,
|
||||||
//temp.add(Blocks.GOLD_ORE);
|
Blocks.OBSERVER,
|
||||||
temp.add(Blocks.GOLD_BLOCK);
|
Blocks.WHITE_SHULKER_BOX,
|
||||||
temp.add(Blocks.EMERALD_ORE);
|
Blocks.ORANGE_SHULKER_BOX,
|
||||||
temp.add(Blocks.EMERALD_BLOCK);
|
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);
|
|
||||||
BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of the chunk data in bits. Equal to 16 KiB.
|
* The size of the chunk data in bits. Equal to 16 KiB.
|
||||||
@@ -117,6 +118,8 @@ public final class CachedChunk {
|
|||||||
*/
|
*/
|
||||||
private final BitSet data;
|
private final BitSet data;
|
||||||
|
|
||||||
|
private final Int2ObjectOpenHashMap<String> special;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The block names of each surface level block for generating an overview
|
* The block names of each surface level block for generating an overview
|
||||||
*/
|
*/
|
||||||
@@ -138,12 +141,30 @@ public final class CachedChunk {
|
|||||||
this.heightMap = new int[256];
|
this.heightMap = new int[256];
|
||||||
this.specialBlockLocations = specialBlockLocations;
|
this.specialBlockLocations = specialBlockLocations;
|
||||||
this.cacheTimestamp = cacheTimestamp;
|
this.cacheTimestamp = cacheTimestamp;
|
||||||
|
if (specialBlockLocations.isEmpty()) {
|
||||||
|
this.special = null;
|
||||||
|
} else {
|
||||||
|
this.special = new Int2ObjectOpenHashMap<>();
|
||||||
|
setSpecial();
|
||||||
|
}
|
||||||
calculateHeightMap();
|
calculateHeightMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final void setSpecial() {
|
||||||
|
for (Map.Entry<String, List<BlockPos>> entry : specialBlockLocations.entrySet()) {
|
||||||
|
for (BlockPos pos : entry.getValue()) {
|
||||||
|
special.put(getPositionIndex(pos.getX(), pos.getY(), pos.getZ()), entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final IBlockState getBlock(int x, int y, int z, int dimension) {
|
public final IBlockState getBlock(int x, int y, int z, int dimension) {
|
||||||
|
int index = getPositionIndex(x, y, z);
|
||||||
|
PathingBlockType type = getType(index);
|
||||||
int internalPos = z << 4 | x;
|
int internalPos = z << 4 | x;
|
||||||
if (heightMap[internalPos] == y) {
|
if (heightMap[internalPos] == y && type != PathingBlockType.AVOID) {
|
||||||
|
// if the top block in a column is water, we cache it as AVOID but we don't want to just return default state water (which is not flowing) beacuse then it would try to path through it
|
||||||
|
|
||||||
// we have this exact block, it's a surface block
|
// we have this exact block, it's a surface block
|
||||||
/*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state);
|
/*System.out.println("Saying that " + x + "," + y + "," + z + " is " + state);
|
||||||
if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) {
|
if (!Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock().equals(state.getBlock())) {
|
||||||
@@ -151,15 +172,20 @@ public final class CachedChunk {
|
|||||||
}*/
|
}*/
|
||||||
return overview[internalPos];
|
return overview[internalPos];
|
||||||
}
|
}
|
||||||
PathingBlockType type = getType(x, y, z);
|
if (special != null) {
|
||||||
|
String str = special.get(index);
|
||||||
|
if (str != null) {
|
||||||
|
return BlockUtils.stringToBlockRequired(str).getDefaultState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (type == PathingBlockType.SOLID && y == 127 && dimension == -1) {
|
if (type == PathingBlockType.SOLID && y == 127 && dimension == -1) {
|
||||||
return Blocks.BEDROCK.getDefaultState();
|
return Blocks.BEDROCK.getDefaultState();
|
||||||
}
|
}
|
||||||
return ChunkPacker.pathingTypeToBlock(type, dimension);
|
return ChunkPacker.pathingTypeToBlock(type, dimension);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PathingBlockType getType(int x, int y, int z) {
|
private PathingBlockType getType(int index) {
|
||||||
int index = getPositionIndex(x, y, z);
|
|
||||||
return PathingBlockType.fromBits(data.get(index), data.get(index + 1));
|
return PathingBlockType.fromBits(data.get(index), data.get(index + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,11 +213,11 @@ public final class CachedChunk {
|
|||||||
return specialBlockLocations;
|
return specialBlockLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final LinkedList<BlockPos> getAbsoluteBlocks(String blockType) {
|
public final ArrayList<BlockPos> getAbsoluteBlocks(String blockType) {
|
||||||
if (specialBlockLocations.get(blockType) == null) {
|
if (specialBlockLocations.get(blockType) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
LinkedList<BlockPos> res = new LinkedList<>();
|
ArrayList<BlockPos> res = new ArrayList<>();
|
||||||
for (BlockPos pos : specialBlockLocations.get(blockType)) {
|
for (BlockPos pos : specialBlockLocations.get(blockType)) {
|
||||||
res.add(new BlockPos(pos.getX() + x * 16, pos.getY(), pos.getZ() + z * 16));
|
res.add(new BlockPos(pos.getX() + x * 16, pos.getY(), pos.getZ() + z * 16));
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-11
@@ -19,6 +19,7 @@ package baritone.cache;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.cache.ICachedRegion;
|
import baritone.api.cache.ICachedRegion;
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
@@ -87,19 +88,16 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
return chunks[x >> 4][z >> 4] != null;
|
return chunks[x >> 4][z >> 4] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final LinkedList<BlockPos> getLocationsOf(String block) {
|
public final ArrayList<BlockPos> getLocationsOf(String block) {
|
||||||
LinkedList<BlockPos> res = new LinkedList<>();
|
ArrayList<BlockPos> res = new ArrayList<>();
|
||||||
for (int chunkX = 0; chunkX < 32; chunkX++) {
|
for (int chunkX = 0; chunkX < 32; chunkX++) {
|
||||||
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
|
for (int chunkZ = 0; chunkZ < 32; chunkZ++) {
|
||||||
if (chunks[chunkX][chunkZ] == null) {
|
if (chunks[chunkX][chunkZ] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
List<BlockPos> locs = chunks[chunkX][chunkZ].getAbsoluteBlocks(block);
|
ArrayList<BlockPos> locs = chunks[chunkX][chunkZ].getAbsoluteBlocks(block);
|
||||||
if (locs == null) {
|
if (locs != null) {
|
||||||
continue;
|
res.addAll(locs);
|
||||||
}
|
|
||||||
for (BlockPos pos : locs) {
|
|
||||||
res.add(pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +150,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
if (chunks[x][z] != null) {
|
if (chunks[x][z] != null) {
|
||||||
for (int i = 0; i < 256; i++) {
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,7 +241,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
if (present[x][z]) {
|
if (present[x][z]) {
|
||||||
for (int i = 0; i < 256; i++) {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,6 +256,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
int numSpecialBlockTypes = in.readShort() & 0xffff;
|
int numSpecialBlockTypes = in.readShort() & 0xffff;
|
||||||
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
||||||
String blockName = in.readUTF();
|
String blockName = in.readUTF();
|
||||||
|
BlockUtils.stringToBlockRequired(blockName);
|
||||||
List<BlockPos> locs = new ArrayList<>();
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
location[x][z].put(blockName, locs);
|
location[x][z].put(blockName, locs);
|
||||||
int numLocations = in.readShort() & 0xffff;
|
int numLocations = in.readShort() & 0xffff;
|
||||||
@@ -306,7 +305,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized final void removeExpired() {
|
public synchronized final void removeExpired() {
|
||||||
long expiry = Baritone.settings().cachedChunksExpirySeconds.get();
|
long expiry = Baritone.settings().cachedChunksExpirySeconds.value;
|
||||||
if (expiry < 0) {
|
if (expiry < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-13
@@ -22,7 +22,7 @@ import baritone.api.BaritoneAPI;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.cache.ICachedWorld;
|
import baritone.api.cache.ICachedWorld;
|
||||||
import baritone.api.cache.IWorldData;
|
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.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -32,7 +32,6 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
/**
|
/**
|
||||||
* The maximum number of regions in any direction from (0,0)
|
* The maximum number of regions in any direction from (0,0)
|
||||||
*/
|
*/
|
||||||
private static final int REGION_MAX = 58594;
|
private static final int REGION_MAX = 30_000_000 / 512 + 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of all of the cached regions.
|
* A map of all of the cached regions.
|
||||||
@@ -71,8 +70,6 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
this.directory = directory.toString();
|
this.directory = directory.toString();
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
System.out.println("Cached world directory: " + directory);
|
System.out.println("Cached world directory: " + directory);
|
||||||
// Insert an invalid region element
|
|
||||||
cachedRegions.put(0, null);
|
|
||||||
Baritone.getExecutor().execute(new PackerThread());
|
Baritone.getExecutor().execute(new PackerThread());
|
||||||
Baritone.getExecutor().execute(() -> {
|
Baritone.getExecutor().execute(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -108,9 +105,13 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
return region.isCached(blockX & 511, blockZ & 511);
|
return region.isCached(blockX & 511, blockZ & 511);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean regionLoaded(int blockX, int blockZ) {
|
||||||
|
return getRegion(blockX >> 9, blockZ >> 9) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final LinkedList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
|
public final ArrayList<BlockPos> getLocationsOf(String block, int maximum, int centerX, int centerZ, int maxRegionDistanceSq) {
|
||||||
LinkedList<BlockPos> res = new LinkedList<>();
|
ArrayList<BlockPos> res = new ArrayList<>();
|
||||||
int centerRegionX = centerX >> 9;
|
int centerRegionX = centerX >> 9;
|
||||||
int centerRegionZ = centerZ >> 9;
|
int centerRegionZ = centerZ >> 9;
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
CachedRegion region = getOrCreateRegion(regionX, regionZ);
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
// TODO: 100% verify if this or addAll is faster.
|
// TODO: 100% verify if this or addAll is faster.
|
||||||
region.getLocationsOf(block).forEach(res::add);
|
res.addAll(region.getLocationsOf(block));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +147,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void save() {
|
public final void save() {
|
||||||
if (!Baritone.settings().chunkCaching.get()) {
|
if (!Baritone.settings().chunkCaching.value) {
|
||||||
System.out.println("Not saving to disk; chunk caching is disabled.");
|
System.out.println("Not saving to disk; chunk caching is disabled.");
|
||||||
allRegions().forEach(region -> {
|
allRegions().forEach(region -> {
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
@@ -171,7 +172,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
* Delete regions that are too far from the player
|
* Delete regions that are too far from the player
|
||||||
*/
|
*/
|
||||||
private synchronized void prune() {
|
private synchronized void prune() {
|
||||||
if (!Baritone.settings().pruneRegionsFromRAM.get()) {
|
if (!Baritone.settings().pruneRegionsFromRAM.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BlockPos pruneCenter = guessPosition();
|
BlockPos pruneCenter = guessPosition();
|
||||||
@@ -179,8 +180,8 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
if (region == null) {
|
if (region == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int distX = (region.getX() << 9 + 256) - pruneCenter.getX();
|
int distX = ((region.getX() << 9) + 256) - pruneCenter.getX();
|
||||||
int distZ = (region.getZ() << 9 + 256) - pruneCenter.getZ();
|
int distZ = ((region.getZ() << 9) + 256) - pruneCenter.getZ();
|
||||||
double dist = Math.sqrt(distX * distX + distZ * distZ);
|
double dist = Math.sqrt(distX * distX + distZ * distZ);
|
||||||
if (dist > 1024) {
|
if (dist > 1024) {
|
||||||
logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram");
|
logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram");
|
||||||
@@ -215,7 +216,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
if (mostRecentlyModified == null) {
|
if (mostRecentlyModified == null) {
|
||||||
return new BlockPos(0, 0, 0);
|
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() {
|
private synchronized List<CachedRegion> allRegions() {
|
||||||
@@ -302,6 +303,9 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
break;
|
break;
|
||||||
|
} catch (Throwable th) {
|
||||||
|
// in the case of an exception, keep consuming from the queue so as not to leak memory
|
||||||
|
th.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-25
@@ -17,15 +17,12 @@
|
|||||||
|
|
||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.utils.pathing.PathingBlockType;
|
import baritone.utils.pathing.PathingBlockType;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.BlockDoublePlant;
|
|
||||||
import net.minecraft.block.BlockFlower;
|
|
||||||
import net.minecraft.block.BlockTallGrass;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.BlockStateContainer;
|
import net.minecraft.world.chunk.BlockStateContainer;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
@@ -39,8 +36,6 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public final class ChunkPacker {
|
public final class ChunkPacker {
|
||||||
|
|
||||||
private static final Map<String, Block> resourceCache = new HashMap<>();
|
|
||||||
|
|
||||||
private ChunkPacker() {}
|
private ChunkPacker() {}
|
||||||
|
|
||||||
public static CachedChunk pack(Chunk chunk) {
|
public static CachedChunk pack(Chunk chunk) {
|
||||||
@@ -73,12 +68,12 @@ public final class ChunkPacker {
|
|||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
int index = CachedChunk.getPositionIndex(x, y, z);
|
int index = CachedChunk.getPositionIndex(x, y, z);
|
||||||
IBlockState state = bsc.get(x, y1, z);
|
IBlockState state = bsc.get(x, y1, z);
|
||||||
boolean[] bits = getPathingBlockType(state).getBits();
|
boolean[] bits = getPathingBlockType(state, chunk, x, y, z).getBits();
|
||||||
bitSet.set(index, bits[0]);
|
bitSet.set(index, bits[0]);
|
||||||
bitSet.set(index + 1, bits[1]);
|
bitSet.set(index + 1, bits[1]);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
|
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));
|
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,28 +103,33 @@ public final class ChunkPacker {
|
|||||||
return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
|
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) {
|
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
|
||||||
return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PathingBlockType getPathingBlockType(IBlockState state) {
|
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block == Blocks.WATER && !MovementHelper.isFlowing(state)) {
|
if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
|
||||||
// only water source blocks are plausibly usable, flowing water should be avoid
|
// only water source blocks are plausibly usable, flowing water should be avoid
|
||||||
|
// FLOWING_WATER is a waterfall, it doesn't really matter and caching it as AVOID just makes it look wrong
|
||||||
|
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;
|
||||||
|
}
|
||||||
return PathingBlockType.WATER;
|
return PathingBlockType.WATER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MovementHelper.avoidWalkingInto(block) || block == Blocks.FLOWING_WATER || MovementHelper.isBottomSlab(state)) {
|
if (MovementHelper.avoidWalkingInto(block) || MovementHelper.isBottomSlab(state)) {
|
||||||
return PathingBlockType.AVOID;
|
return PathingBlockType.AVOID;
|
||||||
}
|
}
|
||||||
// We used to do an AABB check here
|
// We used to do an AABB check here
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.cache.IContainerMemory;
|
import baritone.api.cache.IContainerMemory;
|
||||||
import baritone.api.cache.IRememberedInventory;
|
import baritone.api.cache.IRememberedInventory;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
@@ -28,6 +29,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -44,6 +46,8 @@ public class ContainerMemory implements IContainerMemory {
|
|||||||
this.saveTo = saveTo;
|
this.saveTo = saveTo;
|
||||||
try {
|
try {
|
||||||
read(Files.readAllBytes(saveTo));
|
read(Files.readAllBytes(saveTo));
|
||||||
|
} catch (NoSuchFileException ignored) {
|
||||||
|
inventories.clear();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
inventories.clear();
|
inventories.clear();
|
||||||
@@ -69,6 +73,9 @@ public class ContainerMemory implements IContainerMemory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save() throws IOException {
|
public synchronized void save() throws IOException {
|
||||||
|
if (!Baritone.settings().containerMemory.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ByteBuf buf = Unpooled.buffer(0, Integer.MAX_VALUE);
|
ByteBuf buf = Unpooled.buffer(0, Integer.MAX_VALUE);
|
||||||
PacketBuffer out = new PacketBuffer(buf);
|
PacketBuffer out = new PacketBuffer(buf);
|
||||||
out.writeInt(inventories.size());
|
out.writeInt(inventories.size());
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package baritone.cache;
|
|||||||
|
|
||||||
import baritone.api.cache.IWaypoint;
|
import baritone.api.cache.IWaypoint;
|
||||||
import baritone.api.cache.IWaypointCollection;
|
import baritone.api.cache.IWaypointCollection;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|||||||
+8
-3
@@ -19,11 +19,12 @@ package baritone.cache;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.cache.IWorldProvider;
|
import baritone.api.cache.IWorldProvider;
|
||||||
import baritone.utils.Helper;
|
import baritone.api.utils.Helper;
|
||||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||||
import baritone.utils.accessor.IChunkProviderServer;
|
import baritone.utils.accessor.IChunkProviderServer;
|
||||||
import net.minecraft.server.integrated.IntegratedServer;
|
import net.minecraft.server.integrated.IntegratedServer;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -61,7 +62,7 @@ public class WorldProvider implements IWorldProvider, Helper {
|
|||||||
IntegratedServer integratedServer = mc.getIntegratedServer();
|
IntegratedServer integratedServer = mc.getIntegratedServer();
|
||||||
|
|
||||||
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
|
// 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);
|
WorldServer localServerWorld = integratedServer.getWorld(dimension);
|
||||||
IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
|
IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
|
||||||
IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
|
IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
|
||||||
@@ -76,7 +77,11 @@ public class WorldProvider implements IWorldProvider, Helper {
|
|||||||
directory = new File(directory, "baritone");
|
directory = new File(directory, "baritone");
|
||||||
readme = directory;
|
readme = directory;
|
||||||
} else { // Otherwise, the server must be remote...
|
} else { // Otherwise, the server must be remote...
|
||||||
directory = new File(Baritone.getDir(), mc.getCurrentServerData().serverIP);
|
String folderName = mc.getCurrentServerData().serverIP;
|
||||||
|
if (SystemUtils.IS_OS_WINDOWS) {
|
||||||
|
folderName = folderName.replace(":", "_");
|
||||||
|
}
|
||||||
|
directory = new File(Baritone.getDir(), folderName);
|
||||||
readme = Baritone.getDir();
|
readme = Baritone.getDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-11
@@ -28,15 +28,15 @@ import net.minecraft.world.chunk.BlockStateContainer;
|
|||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
import java.util.stream.IntStream;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public enum WorldScanner implements IWorldScanner {
|
public enum WorldScanner implements IWorldScanner {
|
||||||
|
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
|
private static final int[] DEFAULT_COORDINATE_ITERATION_ORDER = IntStream.range(0, 16).toArray();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) {
|
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, List<Block> blocks, int max, int yLevelThreshold, int maxSearchRadius) {
|
||||||
if (blocks.contains(null)) {
|
if (blocks.contains(null)) {
|
||||||
@@ -53,6 +53,9 @@ public enum WorldScanner implements IWorldScanner {
|
|||||||
int playerChunkZ = ctx.playerFeet().getZ() >> 4;
|
int playerChunkZ = ctx.playerFeet().getZ() >> 4;
|
||||||
int playerY = ctx.playerFeet().getY();
|
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;
|
int searchRadiusSq = 0;
|
||||||
boolean foundWithinY = false;
|
boolean foundWithinY = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -72,7 +75,9 @@ public enum WorldScanner implements IWorldScanner {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
allUnloaded = false;
|
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)
|
if ((allUnloaded && foundChunks)
|
||||||
@@ -100,13 +105,15 @@ public enum WorldScanner implements IWorldScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<BlockPos> res = new ArrayList<>();
|
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;
|
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();
|
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];
|
ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0];
|
||||||
if (extendedblockstorage == null) {
|
if (extendedblockstorage == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -121,14 +128,23 @@ public enum WorldScanner implements IWorldScanner {
|
|||||||
IBlockState state = bsc.get(x, y, z);
|
IBlockState state = bsc.get(x, y, z);
|
||||||
if (search.contains(state.getBlock())) {
|
if (search.contains(state.getBlock())) {
|
||||||
int yy = yReal | y;
|
int yy = yReal | y;
|
||||||
result.add(new BlockPos(chunkX | x, yy, chunkZ | z));
|
if (result.size() >= max) {
|
||||||
if (result.size() >= max && Math.abs(yy - playerY) < yLevelThreshold) {
|
if (Math.abs(yy - playerY) < yLevelThreshold) {
|
||||||
return;
|
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,8 +22,9 @@ import baritone.api.event.events.*;
|
|||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.api.event.listener.IEventBus;
|
import baritone.api.event.listener.IEventBus;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
@@ -46,6 +47,15 @@ public final class GameEventHandler implements IEventBus, Helper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onTick(TickEvent event) {
|
public final void onTick(TickEvent event) {
|
||||||
|
if (event.getType() == TickEvent.Type.IN) {
|
||||||
|
try {
|
||||||
|
baritone.bsi = new BlockStateInterface(baritone.getPlayerContext(), true);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
baritone.bsi = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
baritone.bsi = null;
|
||||||
|
}
|
||||||
listeners.forEach(l -> l.onTick(event));
|
listeners.forEach(l -> l.onTick(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +131,11 @@ public final class GameEventHandler implements IEventBus, Helper {
|
|||||||
listeners.forEach(l -> l.onPlayerRotationMove(event));
|
listeners.forEach(l -> l.onPlayerRotationMove(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerSprintState(SprintStateEvent event) {
|
||||||
|
listeners.forEach(l -> l.onPlayerSprintState(event));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
listeners.forEach(l -> l.onBlockInteract(event));
|
listeners.forEach(l -> l.onBlockInteract(event));
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import baritone.api.utils.BetterBlockPos;
|
|||||||
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.Moves;
|
import baritone.pathing.movement.Moves;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.pathing.BetterWorldBorder;
|
import baritone.utils.pathing.BetterWorldBorder;
|
||||||
import baritone.utils.pathing.Favoring;
|
import baritone.utils.pathing.Favoring;
|
||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
@@ -37,7 +36,7 @@ import java.util.Optional;
|
|||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
public final class AStarPathFinder extends AbstractNodeCostSearch {
|
||||||
|
|
||||||
private final Favoring favoring;
|
private final Favoring favoring;
|
||||||
private final CalculationContext calcContext;
|
private final CalculationContext calcContext;
|
||||||
@@ -55,30 +54,28 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
startNode.combinedCost = startNode.estimatedCostToGoal;
|
startNode.combinedCost = startNode.estimatedCostToGoal;
|
||||||
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
|
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
|
||||||
openSet.insert(startNode);
|
openSet.insert(startNode);
|
||||||
bestSoFar = new PathNode[COEFFICIENTS.length];//keep track of the best node by the metric of (estimatedCostToGoal + cost / COEFFICIENTS[i])
|
double[] bestHeuristicSoFar = new double[COEFFICIENTS.length];//keep track of the best node by the metric of (estimatedCostToGoal + cost / COEFFICIENTS[i])
|
||||||
double[] bestHeuristicSoFar = new double[COEFFICIENTS.length];
|
|
||||||
for (int i = 0; i < bestHeuristicSoFar.length; i++) {
|
for (int i = 0; i < bestHeuristicSoFar.length; i++) {
|
||||||
bestHeuristicSoFar[i] = startNode.estimatedCostToGoal;
|
bestHeuristicSoFar[i] = startNode.estimatedCostToGoal;
|
||||||
bestSoFar[i] = startNode;
|
bestSoFar[i] = startNode;
|
||||||
}
|
}
|
||||||
MutableMoveResult res = new MutableMoveResult();
|
MutableMoveResult res = new MutableMoveResult();
|
||||||
Favoring favored = favoring;
|
|
||||||
BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder());
|
BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world.getWorldBorder());
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
boolean slowPath = Baritone.settings().slowPath.get();
|
boolean slowPath = Baritone.settings().slowPath.value;
|
||||||
if (slowPath) {
|
if (slowPath) {
|
||||||
logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.<Long>get() + "ms instead of " + primaryTimeout + "ms");
|
logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.value + "ms instead of " + primaryTimeout + "ms");
|
||||||
}
|
}
|
||||||
long primaryTimeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.<Long>get() : primaryTimeout);
|
long primaryTimeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.value : primaryTimeout);
|
||||||
long failureTimeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.<Long>get() : failureTimeout);
|
long failureTimeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.value : failureTimeout);
|
||||||
boolean failing = true;
|
boolean failing = true;
|
||||||
int numNodes = 0;
|
int numNodes = 0;
|
||||||
int numMovementsConsidered = 0;
|
int numMovementsConsidered = 0;
|
||||||
int numEmptyChunk = 0;
|
int numEmptyChunk = 0;
|
||||||
boolean favoring = !favored.isEmpty();
|
boolean isFavoring = !favoring.isEmpty();
|
||||||
int timeCheckInterval = 1 << 6;
|
int timeCheckInterval = 1 << 6;
|
||||||
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
|
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.value; // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
|
||||||
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
double minimumImprovement = Baritone.settings().minimumImprovementRepropagation.value ? MIN_IMPROVEMENT : 0;
|
||||||
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
|
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
|
||||||
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
|
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
|
||||||
long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
|
long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
|
||||||
@@ -88,9 +85,8 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
}
|
}
|
||||||
if (slowPath) {
|
if (slowPath) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.<Long>get());
|
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.value);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ignored) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
PathNode currentNode = openSet.removeLowest();
|
PathNode currentNode = openSet.removeLowest();
|
||||||
mostRecentConsidered = currentNode;
|
mostRecentConsidered = currentNode;
|
||||||
@@ -136,21 +132,13 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset));
|
throw new IllegalStateException(moves + " " + res.y + " " + (currentNode.y + moves.yOffset));
|
||||||
}
|
}
|
||||||
long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z);
|
long hashCode = BetterBlockPos.longHash(res.x, res.y, res.z);
|
||||||
if (favoring) {
|
if (isFavoring) {
|
||||||
// see issue #18
|
// see issue #18
|
||||||
actionCost *= favored.calculate(hashCode);
|
actionCost *= favoring.calculate(hashCode);
|
||||||
}
|
}
|
||||||
PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode);
|
PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode);
|
||||||
double tentativeCost = currentNode.cost + actionCost;
|
double tentativeCost = currentNode.cost + actionCost;
|
||||||
if (tentativeCost < neighbor.cost) {
|
if (neighbor.cost - tentativeCost > minimumImprovement) {
|
||||||
double improvementBy = neighbor.cost - tentativeCost;
|
|
||||||
// there are floating point errors caused by random combinations of traverse and diagonal over a flat area
|
|
||||||
// that means that sometimes there's a cost improvement of like 10 ^ -16
|
|
||||||
// it's not worth the time to update the costs, decrease-key the heap, potentially repropagate, etc
|
|
||||||
if (improvementBy < 0.01 && minimumImprovementRepropagation) {
|
|
||||||
// who cares about a hundredth of a tick? that's half a millisecond for crying out loud!
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
neighbor.previous = currentNode;
|
neighbor.previous = currentNode;
|
||||||
neighbor.cost = tentativeCost;
|
neighbor.cost = tentativeCost;
|
||||||
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
||||||
@@ -159,15 +147,12 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
} else {
|
} else {
|
||||||
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
||||||
}
|
}
|
||||||
for (int i = 0; i < bestSoFar.length; i++) {
|
for (int i = 0; i < COEFFICIENTS.length; i++) {
|
||||||
double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i];
|
double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i];
|
||||||
if (heuristic < bestHeuristicSoFar[i]) {
|
if (bestHeuristicSoFar[i] - heuristic > minimumImprovement) {
|
||||||
if (bestHeuristicSoFar[i] - heuristic < 0.01 && minimumImprovementRepropagation) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
bestHeuristicSoFar[i] = heuristic;
|
bestHeuristicSoFar[i] = heuristic;
|
||||||
bestSoFar[i] = neighbor;
|
bestSoFar[i] = neighbor;
|
||||||
if (getDistFromStartSq(neighbor) > MIN_DIST_PATH * MIN_DIST_PATH) {
|
if (failing && getDistFromStartSq(neighbor) > MIN_DIST_PATH * MIN_DIST_PATH) {
|
||||||
failing = false;
|
failing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,28 +167,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
System.out.println("Open set size: " + openSet.size());
|
System.out.println("Open set size: " + openSet.size());
|
||||||
System.out.println("PathNode map size: " + mapSize());
|
System.out.println("PathNode map size: " + mapSize());
|
||||||
System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second");
|
System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second");
|
||||||
double bestDist = 0;
|
Optional<IPath> result = bestSoFar(true, numNodes);
|
||||||
for (int i = 0; i < bestSoFar.length; i++) {
|
if (result.isPresent()) {
|
||||||
if (bestSoFar[i] == null) {
|
logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
||||||
continue;
|
|
||||||
}
|
|
||||||
double dist = getDistFromStartSq(bestSoFar[i]);
|
|
||||||
if (dist > bestDist) {
|
|
||||||
bestDist = dist;
|
|
||||||
}
|
|
||||||
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
|
||||||
logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
|
|
||||||
if (COEFFICIENTS[i] >= 3) {
|
|
||||||
System.out.println("Warning: cost coefficient is greater than three! Probably means that");
|
|
||||||
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");
|
|
||||||
System.out.println("But I'm going to do it anyway, because yolo");
|
|
||||||
}
|
|
||||||
System.out.println("Path goes for " + Math.sqrt(dist) + " blocks");
|
|
||||||
return Optional.of(new Path(startNode, bestSoFar[i], numNodes, goal, calcContext));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
return result;
|
||||||
logDebug("No path found =(");
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import baritone.api.pathing.calc.IPath;
|
|||||||
import baritone.api.pathing.calc.IPathFinder;
|
import baritone.api.pathing.calc.IPathFinder;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.PathCalculationResult;
|
import baritone.api.utils.PathCalculationResult;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -34,7 +34,7 @@ import java.util.Optional;
|
|||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNodeCostSearch implements IPathFinder {
|
public abstract class AbstractNodeCostSearch implements IPathFinder, Helper {
|
||||||
|
|
||||||
protected final int startX;
|
protected final int startX;
|
||||||
protected final int startY;
|
protected final int startY;
|
||||||
@@ -53,7 +53,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
|
|
||||||
protected PathNode mostRecentConsidered;
|
protected PathNode mostRecentConsidered;
|
||||||
|
|
||||||
protected PathNode[] bestSoFar;
|
protected final PathNode[] bestSoFar = new PathNode[COEFFICIENTS.length];
|
||||||
|
|
||||||
private volatile boolean isFinished;
|
private volatile boolean isFinished;
|
||||||
|
|
||||||
@@ -63,13 +63,23 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
* This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so
|
* This is really complicated and hard to explain. I wrote a comment in the old version of MineBot but it was so
|
||||||
* long it was easier as a Google Doc (because I could insert charts).
|
* long it was easier as a Google Doc (because I could insert charts).
|
||||||
*
|
*
|
||||||
* @see <a href="https://docs.google.com/document/d/1WVHHXKXFdCR1Oz__KtK8sFqyvSwJN_H4lftkHFgmzlc/edit"></a>
|
* @see <a href="https://docs.google.com/document/d/1WVHHXKXFdCR1Oz__KtK8sFqyvSwJN_H4lftkHFgmzlc/edit">here</a>
|
||||||
*/
|
*/
|
||||||
protected static final double[] COEFFICIENTS = {1.5, 2, 2.5, 3, 4, 5, 10}; // big TODO tune
|
protected static final double[] COEFFICIENTS = {1.5, 2, 2.5, 3, 4, 5, 10};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a path goes less than 5 blocks and doesn't make it to its goal, it's not worth considering.
|
* If a path goes less than 5 blocks and doesn't make it to its goal, it's not worth considering.
|
||||||
*/
|
*/
|
||||||
protected final static double MIN_DIST_PATH = 5;
|
protected static final double MIN_DIST_PATH = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* there are floating point errors caused by random combinations of traverse and diagonal over a flat area
|
||||||
|
* that means that sometimes there's a cost improvement of like 10 ^ -16
|
||||||
|
* it's not worth the time to update the costs, decrease-key the heap, potentially repropagate, etc
|
||||||
|
* <p>
|
||||||
|
* who cares about a hundredth of a tick? that's half a millisecond for crying out loud!
|
||||||
|
*/
|
||||||
|
protected static final double MIN_IMPROVEMENT = 0.01;
|
||||||
|
|
||||||
AbstractNodeCostSearch(int startX, int startY, int startZ, Goal goal, CalculationContext context) {
|
AbstractNodeCostSearch(int startX, int startY, int startZ, Goal goal, CalculationContext context) {
|
||||||
this.startX = startX;
|
this.startX = startX;
|
||||||
@@ -77,7 +87,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
this.startZ = startZ;
|
this.startZ = startZ;
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.map = new Long2ObjectOpenHashMap<>(Baritone.settings().pathingMapDefaultSize.value, Baritone.settings().pathingMapLoadFactor.get());
|
this.map = new Long2ObjectOpenHashMap<>(Baritone.settings().pathingMapDefaultSize.value, Baritone.settings().pathingMapLoadFactor.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
@@ -92,13 +102,25 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
cancelRequested = false;
|
cancelRequested = false;
|
||||||
try {
|
try {
|
||||||
IPath path = calculate0(primaryTimeout, failureTimeout).map(IPath::postProcess).orElse(null);
|
IPath path = calculate0(primaryTimeout, failureTimeout).map(IPath::postProcess).orElse(null);
|
||||||
isFinished = true;
|
|
||||||
if (cancelRequested) {
|
if (cancelRequested) {
|
||||||
return new PathCalculationResult(PathCalculationResult.Type.CANCELLATION, path);
|
return new PathCalculationResult(PathCalculationResult.Type.CANCELLATION);
|
||||||
}
|
}
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
return new PathCalculationResult(PathCalculationResult.Type.FAILURE);
|
return new PathCalculationResult(PathCalculationResult.Type.FAILURE);
|
||||||
}
|
}
|
||||||
|
int previousLength = path.length();
|
||||||
|
path = path.cutoffAtLoadedChunks(context.bsi);
|
||||||
|
if (path.length() < previousLength) {
|
||||||
|
Helper.HELPER.logDebug("Cutting off path at edge of loaded chunks");
|
||||||
|
Helper.HELPER.logDebug("Length decreased by " + (previousLength - path.length()));
|
||||||
|
} else {
|
||||||
|
Helper.HELPER.logDebug("Path ends within loaded chunks");
|
||||||
|
}
|
||||||
|
previousLength = path.length();
|
||||||
|
path = path.staticCutoff(goal);
|
||||||
|
if (path.length() < previousLength) {
|
||||||
|
Helper.HELPER.logDebug("Static cutoff " + previousLength + " to " + path.length());
|
||||||
|
}
|
||||||
if (goal.isInGoal(path.getDest())) {
|
if (goal.isInGoal(path.getDest())) {
|
||||||
return new PathCalculationResult(PathCalculationResult.Type.SUCCESS_TO_GOAL, path);
|
return new PathCalculationResult(PathCalculationResult.Type.SUCCESS_TO_GOAL, path);
|
||||||
} else {
|
} else {
|
||||||
@@ -158,25 +180,43 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal, context));
|
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int mapSize() {
|
|
||||||
return map.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<IPath> bestPathSoFar() {
|
public Optional<IPath> bestPathSoFar() {
|
||||||
if (startNode == null || bestSoFar == null) {
|
return bestSoFar(false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Optional<IPath> bestSoFar(boolean logInfo, int numNodes) {
|
||||||
|
if (startNode == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < bestSoFar.length; i++) {
|
double bestDist = 0;
|
||||||
|
for (int i = 0; i < COEFFICIENTS.length; i++) {
|
||||||
if (bestSoFar[i] == null) {
|
if (bestSoFar[i] == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
double dist = getDistFromStartSq(bestSoFar[i]);
|
||||||
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal, context));
|
if (dist > bestDist) {
|
||||||
|
bestDist = dist;
|
||||||
|
}
|
||||||
|
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
|
||||||
|
if (logInfo) {
|
||||||
|
if (COEFFICIENTS[i] >= 3) {
|
||||||
|
System.out.println("Warning: cost coefficient is greater than three! Probably means that");
|
||||||
|
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");
|
||||||
|
System.out.println("But I'm going to do it anyway, because yolo");
|
||||||
|
}
|
||||||
|
System.out.println("Path goes for " + Math.sqrt(dist) + " blocks");
|
||||||
|
logDebug("A* cost coefficient " + COEFFICIENTS[i]);
|
||||||
|
}
|
||||||
|
return Optional.of(new Path(startNode, bestSoFar[i], numNodes, goal, context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// instead of returning bestSoFar[0], be less misleading
|
// instead of returning bestSoFar[0], be less misleading
|
||||||
// if it actually won't find any path, don't make them think it will by rendering a dark blue that will never actually happen
|
// if it actually won't find any path, don't make them think it will by rendering a dark blue that will never actually happen
|
||||||
|
if (logInfo) {
|
||||||
|
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
|
||||||
|
logDebug("No path found =(");
|
||||||
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,4 +229,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
public final Goal getGoal() {
|
public final Goal getGoal() {
|
||||||
return goal;
|
return goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BetterBlockPos getStart() {
|
||||||
|
return new BetterBlockPos(startX, startY, startZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int mapSize() {
|
||||||
|
return map.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ import baritone.api.pathing.calc.IPath;
|
|||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.movement.Moves;
|
import baritone.pathing.movement.Moves;
|
||||||
import baritone.pathing.path.CutoffPath;
|
import baritone.pathing.path.CutoffPath;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.pathing.PathBase;
|
import baritone.utils.pathing.PathBase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -96,7 +96,7 @@ class Path extends PathBase {
|
|||||||
}
|
}
|
||||||
PathNode current = end;
|
PathNode current = end;
|
||||||
LinkedList<BetterBlockPos> tempPath = new LinkedList<>();
|
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)
|
// Repeatedly inserting to the beginning of an arraylist is O(n^2)
|
||||||
// Instead, do it into a linked list, then convert at the end
|
// Instead, do it into a linked list, then convert at the end
|
||||||
while (current != null) {
|
while (current != null) {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 8/7/2018
|
* @since 8/7/2018
|
||||||
@@ -42,6 +44,7 @@ public class CalculationContext {
|
|||||||
|
|
||||||
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
|
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
|
||||||
|
|
||||||
|
public final boolean safeForThreadedUse;
|
||||||
public final IBaritone baritone;
|
public final IBaritone baritone;
|
||||||
public final World world;
|
public final World world;
|
||||||
public final WorldData worldData;
|
public final WorldData worldData;
|
||||||
@@ -50,18 +53,20 @@ public class CalculationContext {
|
|||||||
public final boolean hasWaterBucket;
|
public final boolean hasWaterBucket;
|
||||||
public final boolean hasThrowaway;
|
public final boolean hasThrowaway;
|
||||||
public final boolean canSprint;
|
public final boolean canSprint;
|
||||||
public final double placeBlockCost;
|
protected final double placeBlockCost; // protected because you should call the function instead
|
||||||
public final boolean allowBreak;
|
public final boolean allowBreak;
|
||||||
public final boolean allowParkour;
|
public final boolean allowParkour;
|
||||||
public final boolean allowParkourPlace;
|
public final boolean allowParkourPlace;
|
||||||
public final boolean allowJumpAt256;
|
public final boolean allowJumpAt256;
|
||||||
public final boolean assumeWalkOnWater;
|
public final boolean assumeWalkOnWater;
|
||||||
public final boolean allowDiagonalDescend;
|
public final boolean allowDiagonalDescend;
|
||||||
|
public final boolean allowDownward;
|
||||||
public final int maxFallHeightNoWater;
|
public final int maxFallHeightNoWater;
|
||||||
public final int maxFallHeightBucket;
|
public final int maxFallHeightBucket;
|
||||||
public final double waterWalkSpeed;
|
public final double waterWalkSpeed;
|
||||||
public final double breakBlockAdditionalCost;
|
public final double breakBlockAdditionalCost;
|
||||||
public final double jumpPenalty;
|
public double backtrackCostFavoringCoefficient;
|
||||||
|
public double jumpPenalty;
|
||||||
public final double walkOnWaterOnePenalty;
|
public final double walkOnWaterOnePenalty;
|
||||||
public final BetterWorldBorder worldBorder;
|
public final BetterWorldBorder worldBorder;
|
||||||
|
|
||||||
@@ -70,33 +75,36 @@ public class CalculationContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
|
public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
|
||||||
|
this.safeForThreadedUse = forUseOnAnotherThread;
|
||||||
this.baritone = baritone;
|
this.baritone = baritone;
|
||||||
EntityPlayerSP player = baritone.getPlayerContext().player();
|
EntityPlayerSP player = baritone.getPlayerContext().player();
|
||||||
this.world = baritone.getPlayerContext().world();
|
this.world = baritone.getPlayerContext().world();
|
||||||
this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
|
this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
|
||||||
this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread); // TODO TODO TODO
|
this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread);
|
||||||
this.toolSet = new ToolSet(player);
|
this.toolSet = new ToolSet(player);
|
||||||
this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(baritone.getPlayerContext(), false);
|
this.hasThrowaway = Baritone.settings().allowPlace.value && ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway();
|
||||||
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether();
|
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether();
|
||||||
this.canSprint = Baritone.settings().allowSprint.get() && player.getFoodStats().getFoodLevel() > 6;
|
this.canSprint = Baritone.settings().allowSprint.value && player.getFoodStats().getFoodLevel() > 6;
|
||||||
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get();
|
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.value;
|
||||||
this.allowBreak = Baritone.settings().allowBreak.get();
|
this.allowBreak = Baritone.settings().allowBreak.value;
|
||||||
this.allowParkour = Baritone.settings().allowParkour.get();
|
this.allowParkour = Baritone.settings().allowParkour.value;
|
||||||
this.allowParkourPlace = Baritone.settings().allowParkourPlace.get();
|
this.allowParkourPlace = Baritone.settings().allowParkourPlace.value;
|
||||||
this.allowJumpAt256 = Baritone.settings().allowJumpAt256.get();
|
this.allowJumpAt256 = Baritone.settings().allowJumpAt256.value;
|
||||||
this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.get();
|
this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.value;
|
||||||
this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.get();
|
this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.value;
|
||||||
this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get();
|
this.allowDownward = Baritone.settings().allowDownward.value;
|
||||||
this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get();
|
this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.value;
|
||||||
|
this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.value;
|
||||||
int depth = EnchantmentHelper.getDepthStriderModifier(player);
|
int depth = EnchantmentHelper.getDepthStriderModifier(player);
|
||||||
if (depth > 3) {
|
if (depth > 3) {
|
||||||
depth = 3;
|
depth = 3;
|
||||||
}
|
}
|
||||||
float mult = depth / 3.0F;
|
float mult = depth / 3.0F;
|
||||||
this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult;
|
this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult;
|
||||||
this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.get();
|
this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.value;
|
||||||
this.jumpPenalty = Baritone.settings().jumpPenalty.get();
|
this.backtrackCostFavoringCoefficient = Baritone.settings().backtrackCostFavoringCoefficient.value;
|
||||||
this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.get();
|
this.jumpPenalty = Baritone.settings().jumpPenalty.value;
|
||||||
|
this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.value;
|
||||||
// why cache these things here, why not let the movements just get directly from settings?
|
// why cache these things here, why not let the movements just get directly from settings?
|
||||||
// because if some movements are calculated one way and others are calculated another way,
|
// because if some movements are calculated one way and others are calculated another way,
|
||||||
// then you get a wildly inconsistent path that isn't optimal for either scenario.
|
// then you get a wildly inconsistent path that isn't optimal for either scenario.
|
||||||
@@ -123,21 +131,32 @@ public class CalculationContext {
|
|||||||
return get(x, y, z).getBlock();
|
return get(x, y, z).getBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPlaceThrowawayAt(int x, int y, int z) {
|
public double costOfPlacingAt(int x, int y, int z) {
|
||||||
if (!hasThrowaway) { // only true if allowPlace is true, see constructor
|
if (!hasThrowaway) { // only true if allowPlace is true, see constructor
|
||||||
return false;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (isPossiblyProtected(x, y, z)) {
|
if (isPossiblyProtected(x, y, z)) {
|
||||||
return false;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
return worldBorder.canPlaceAt(x, z); // TODO perhaps MovementHelper.canPlaceAgainst could also use this?
|
if (!worldBorder.canPlaceAt(x, z)) {
|
||||||
|
// TODO perhaps MovementHelper.canPlaceAgainst could also use this?
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
return placeBlockCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canBreakAt(int x, int y, int z) {
|
public double breakCostMultiplierAt(int x, int y, int z) {
|
||||||
if (!allowBreak) {
|
if (!allowBreak) {
|
||||||
return false;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
return !isPossiblyProtected(x, y, z);
|
if (isPossiblyProtected(x, y, z)) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double placeBucketCost() {
|
||||||
|
return placeBlockCost; // shrug
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPossiblyProtected(int x, int y, int z) {
|
public boolean isPossiblyProtected(int x, int y, int z) {
|
||||||
|
|||||||
@@ -17,24 +17,25 @@
|
|||||||
|
|
||||||
package baritone.pathing.movement;
|
package baritone.pathing.movement;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.*;
|
import baritone.api.utils.*;
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
|
import baritone.behavior.PathingBehavior;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
|
import net.minecraft.entity.item.EntityFallingBlock;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public abstract class Movement implements IMovement, MovementHelper {
|
public abstract class Movement implements IMovement, MovementHelper {
|
||||||
|
|
||||||
protected 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 IBaritone baritone;
|
||||||
protected final IPlayerContext ctx;
|
protected final IPlayerContext ctx;
|
||||||
@@ -61,6 +62,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
public List<BlockPos> toPlaceCached = null;
|
public List<BlockPos> toPlaceCached = null;
|
||||||
public List<BlockPos> toWalkIntoCached = null;
|
public List<BlockPos> toWalkIntoCached = null;
|
||||||
|
|
||||||
|
private Set<BetterBlockPos> validPositionsCached = null;
|
||||||
|
|
||||||
private Boolean calculatedWhileLoaded;
|
private Boolean calculatedWhileLoaded;
|
||||||
|
|
||||||
protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
|
protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
|
||||||
@@ -76,29 +79,40 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
this(baritone, src, dest, toBreak, null);
|
this(baritone, src, dest, toBreak, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public double getCost() throws NullPointerException {
|
||||||
public double getCost() {
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCost(CalculationContext context) {
|
||||||
if (cost == null) {
|
if (cost == null) {
|
||||||
cost = calculateCost(new CalculationContext(baritone));
|
cost = calculateCost(context);
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract double calculateCost(CalculationContext context);
|
public abstract double calculateCost(CalculationContext context);
|
||||||
|
|
||||||
@Override
|
public double recalculateCost(CalculationContext context) {
|
||||||
public double recalculateCost() {
|
|
||||||
cost = null;
|
cost = null;
|
||||||
return getCost();
|
return getCost(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void override(double cost) {
|
public void override(double cost) {
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected abstract Set<BetterBlockPos> calculateValidPositions();
|
||||||
public double calculateCostWithoutCaching() {
|
|
||||||
return calculateCost(new CalculationContext(baritone));
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,6 +129,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
currentState.setInput(Input.JUMP, true);
|
currentState.setInput(Input.JUMP, true);
|
||||||
}
|
}
|
||||||
if (ctx.player().isEntityInsideOpaqueBlock()) {
|
if (ctx.player().isEntityInsideOpaqueBlock()) {
|
||||||
|
ctx.getSelectedBlock().ifPresent(pos -> MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, pos)));
|
||||||
currentState.setInput(Input.CLICK_LEFT, true);
|
currentState.setInput(Input.CLICK_LEFT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +138,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
baritone.getLookBehavior().updateTarget(
|
baritone.getLookBehavior().updateTarget(
|
||||||
rotation,
|
rotation,
|
||||||
currentState.getTarget().hasToForceRotations()));
|
currentState.getTarget().hasToForceRotations()));
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
currentState.getInputStates().forEach((input, forced) -> {
|
currentState.getInputStates().forEach((input, forced) -> {
|
||||||
baritone.getInputOverrideHandler().setInputForceState(input, forced);
|
baritone.getInputOverrideHandler().setInputForceState(input, forced);
|
||||||
});
|
});
|
||||||
@@ -143,14 +158,17 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
}
|
}
|
||||||
boolean somethingInTheWay = false;
|
boolean somethingInTheWay = false;
|
||||||
for (BetterBlockPos blockPos : positionsToBreak) {
|
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
|
if (!MovementHelper.canWalkThrough(ctx, blockPos) && !(BlockStateInterface.getBlock(ctx, blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try
|
||||||
somethingInTheWay = true;
|
somethingInTheWay = true;
|
||||||
|
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
||||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
|
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
|
||||||
if (reachable.isPresent()) {
|
if (reachable.isPresent()) {
|
||||||
Rotation rotTowardsBlock = reachable.get();
|
Rotation rotTowardsBlock = reachable.get();
|
||||||
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
|
||||||
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
|
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);
|
state.setInput(Input.CLICK_LEFT, true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -160,7 +178,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
//i dont care if theres snow in the way!!!!!!!
|
//i dont care if theres snow in the way!!!!!!!
|
||||||
//you dont own me!!!!
|
//you dont own me!!!!
|
||||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F),
|
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.player().getPositionEyes(1.0F),
|
||||||
VecUtils.getBlockPosCenter(blockPos)), true)
|
VecUtils.getBlockPosCenter(blockPos), ctx.playerRotations()), true)
|
||||||
);
|
);
|
||||||
// don't check selectedblock on this one, this is a fallback when we can't see any face directly, it's intended to be breaking the "incorrect" block
|
// don't check selectedblock on this one, this is a fallback when we can't see any face directly, it's intended to be breaking the "incorrect" block
|
||||||
state.setInput(Input.CLICK_LEFT, true);
|
state.setInput(Input.CLICK_LEFT, true);
|
||||||
@@ -273,4 +291,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
}
|
}
|
||||||
return toWalkIntoCached;
|
return toWalkIntoCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockPos[] toBreakAll() {
|
||||||
|
return positionsToBreak;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,23 +18,26 @@
|
|||||||
package baritone.pathing.movement;
|
package baritone.pathing.movement;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.ActionCosts;
|
import baritone.api.pathing.movement.ActionCosts;
|
||||||
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.*;
|
import baritone.api.utils.*;
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.ToolSet;
|
import baritone.utils.ToolSet;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.properties.PropertyBool;
|
import net.minecraft.block.properties.PropertyBool;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemPickaxe;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.NonNullList;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static helpers for cost calculation
|
* Static helpers for cost calculation
|
||||||
@@ -48,11 +51,27 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
||||||
|| b instanceof BlockSilverfish // obvious reasons
|
|| b instanceof BlockSilverfish // obvious reasons
|
||||||
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
// 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
|
|| avoidAdjacentBreaking(bsi, x, y + 1, z, true)
|
||||||
|| bsi.get0(x + 1, y, z).getBlock() instanceof BlockLiquid
|
|| avoidAdjacentBreaking(bsi, x + 1, y, z, false)
|
||||||
|| bsi.get0(x - 1, y, z).getBlock() instanceof BlockLiquid
|
|| avoidAdjacentBreaking(bsi, x - 1, y, z, false)
|
||||||
|| bsi.get0(x, y, z + 1).getBlock() instanceof BlockLiquid
|
|| avoidAdjacentBreaking(bsi, x, y, z + 1, false)
|
||||||
|| bsi.get0(x, y, z - 1).getBlock() instanceof BlockLiquid;
|
|| 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) {
|
static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {
|
||||||
@@ -68,7 +87,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (block == Blocks.AIR) { // early return for most common case
|
if (block == Blocks.AIR) { // early return for most common case
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||||
@@ -77,9 +99,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
// be opened by just interacting.
|
// be opened by just interacting.
|
||||||
return block != Blocks.IRON_DOOR;
|
return block != Blocks.IRON_DOOR;
|
||||||
}
|
}
|
||||||
boolean snow = block instanceof BlockSnow;
|
if (block == Blocks.CARPET) {
|
||||||
boolean trapdoor = block instanceof BlockTrapDoor;
|
return canWalkOn(bsi, x, y - 1, z);
|
||||||
if (snow || trapdoor) {
|
}
|
||||||
|
if (block instanceof BlockSnow) {
|
||||||
// we've already checked doors and fence gates
|
// we've already checked doors and fence gates
|
||||||
// so the only remaining dynamic isPassables are snow and trapdoor
|
// so the only remaining dynamic isPassables are snow and trapdoor
|
||||||
// if they're cached as a top block, we don't know their metadata
|
// if they're cached as a top block, we don't know their metadata
|
||||||
@@ -87,25 +110,19 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (!bsi.worldContainsLoadedChunk(x, z)) {
|
if (!bsi.worldContainsLoadedChunk(x, z)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (snow) {
|
// the check in BlockSnow.isPassable is layers < 5
|
||||||
// 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
|
||||||
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
|
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
||||||
if (state.getValue(BlockSnow.LAYERS) >= 3) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// ok, it's low enough we could walk through it, but is it supported?
|
|
||||||
return canWalkOn(bsi, x, y - 1, z);
|
|
||||||
}
|
}
|
||||||
if (trapdoor) {
|
// ok, it's low enough we could walk through it, but is it supported?
|
||||||
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
|
return canWalkOn(bsi, x, y - 1, z);
|
||||||
}
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
}
|
||||||
if (isFlowing(state)) {
|
if (isFlowing(x, y, z, state, bsi)) {
|
||||||
return false; // Don't walk through flowing liquids
|
return false; // Don't walk through flowing liquids
|
||||||
}
|
}
|
||||||
if (block instanceof BlockLiquid) {
|
if (block instanceof BlockLiquid) {
|
||||||
if (Baritone.settings().assumeWalkOnWater.get()) {
|
if (Baritone.settings().assumeWalkOnWater.value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
IBlockState up = bsi.get0(x, y + 1, z);
|
IBlockState up = bsi.get0(x, y + 1, z);
|
||||||
@@ -151,7 +168,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
|| block instanceof BlockSnow
|
|| block instanceof BlockSnow
|
||||||
|| block instanceof BlockLiquid
|
|| block instanceof BlockLiquid
|
||||||
|| block instanceof BlockTrapDoor
|
|| block instanceof BlockTrapDoor
|
||||||
|| block instanceof BlockEndPortal) {
|
|| block instanceof BlockEndPortal
|
||||||
|
|| block instanceof BlockSkull) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
|
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
|
||||||
@@ -266,7 +284,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (state.isBlockNormalCube()) {
|
if (state.isBlockNormalCube()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.get())) { // TODO reconsider this
|
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) {
|
if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) {
|
||||||
@@ -279,22 +297,25 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
// since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
|
// since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
|
||||||
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
|
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
|
||||||
Block up = bsi.get0(x, y + 1, z).getBlock();
|
Block up = bsi.get0(x, y + 1, z).getBlock();
|
||||||
if (up == Blocks.WATERLILY) {
|
if (up == Blocks.WATERLILY || up == Blocks.CARPET) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (isFlowing(state) || block == Blocks.FLOWING_WATER) {
|
if (isFlowing(x, y, z, state, bsi) || block == Blocks.FLOWING_WATER) {
|
||||||
// the only scenario in which we can walk on flowing water is if it's under still water with jesus off
|
// the only scenario in which we can walk on flowing water is if it's under still water with jesus off
|
||||||
return isWater(up) && !Baritone.settings().assumeWalkOnWater.get();
|
return isWater(up) && !Baritone.settings().assumeWalkOnWater.value;
|
||||||
}
|
}
|
||||||
// if assumeWalkOnWater is on, we can only walk on water if there isn't water above it
|
// if assumeWalkOnWater is on, we can only walk on water if there isn't water above it
|
||||||
// if assumeWalkOnWater is off, we can only walk on water if there is water above it
|
// if assumeWalkOnWater is off, we can only walk on water if there is water above it
|
||||||
return isWater(up) ^ Baritone.settings().assumeWalkOnWater.get();
|
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) {
|
if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (block instanceof BlockSlab) {
|
if (block instanceof BlockSlab) {
|
||||||
if (!Baritone.settings().allowWalkOnBottomSlab.get()) {
|
if (!Baritone.settings().allowWalkOnBottomSlab.value) {
|
||||||
if (((BlockSlab) block).isDouble()) {
|
if (((BlockSlab) block).isDouble()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -309,6 +330,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state);
|
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) {
|
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) {
|
||||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
||||||
}
|
}
|
||||||
@@ -318,20 +343,22 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) {
|
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z) {
|
||||||
return canPlaceAgainst(bsi.get0(x, y, z));
|
return canPlaceAgainst(bsi, x, y, z, bsi.get0(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canPlaceAgainst(BlockStateInterface bsi, BlockPos pos) {
|
static boolean canPlaceAgainst(BlockStateInterface bsi, BlockPos pos) {
|
||||||
return canPlaceAgainst(bsi.get0(pos.getX(), pos.getY(), pos.getZ()));
|
return canPlaceAgainst(bsi, pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canPlaceAgainst(IPlayerContext ctx, BlockPos pos) {
|
static boolean canPlaceAgainst(IPlayerContext ctx, BlockPos pos) {
|
||||||
return canPlaceAgainst(new BlockStateInterface(ctx), pos);
|
return canPlaceAgainst(new BlockStateInterface(ctx), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canPlaceAgainst(IBlockState state) {
|
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
|
||||||
// TODO isBlockNormalCube isn't the best check for whether or not we can place a block against it. e.g. glass isn't normalCube but we can place against it
|
// can we look at the center of a side face of this block and likely be able to place?
|
||||||
return state.isBlockNormalCube();
|
// (thats how this check is used)
|
||||||
|
// therefore dont include weird things that we technically could place against (like carpet) but practically can't
|
||||||
|
return state.isBlockNormalCube() || state.isFullBlock() || state.getBlock() == Blocks.GLASS || state.getBlock() == Blocks.STAINED_GLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) {
|
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) {
|
||||||
@@ -341,23 +368,23 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (!canWalkThrough(context.bsi, x, y, z, state)) {
|
if (!canWalkThrough(context.bsi, x, y, z, state)) {
|
||||||
if (!context.canBreakAt(x, y, z)) {
|
if (block instanceof BlockLiquid) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
|
double mult = context.breakCostMultiplierAt(x, y, z);
|
||||||
|
if (mult >= COST_INF) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (avoidBreaking(context.bsi, x, y, z, state)) {
|
if (avoidBreaking(context.bsi, x, y, z, state)) {
|
||||||
return COST_INF;
|
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);
|
double strVsBlock = context.toolSet.getStrVsBlock(state);
|
||||||
if (strVsBlock <= 0) {
|
if (strVsBlock <= 0) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
|
double result = 1 / strVsBlock;
|
||||||
double result = m / strVsBlock;
|
|
||||||
result += context.breakBlockAdditionalCost;
|
result += context.breakBlockAdditionalCost;
|
||||||
|
result *= mult;
|
||||||
if (includeFalling) {
|
if (includeFalling) {
|
||||||
IBlockState above = context.get(x, y + 1, z);
|
IBlockState above = context.get(x, y + 1, z);
|
||||||
if (above.getBlock() instanceof BlockFalling) {
|
if (above.getBlock() instanceof BlockFalling) {
|
||||||
@@ -396,48 +423,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock());
|
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean throwaway(IPlayerContext ctx, boolean select) {
|
|
||||||
EntityPlayerSP p = ctx.player();
|
|
||||||
NonNullList<ItemStack> inv = p.inventory.mainInventory;
|
|
||||||
for (byte i = 0; i < 9; i++) {
|
|
||||||
ItemStack item = inv.get(i);
|
|
||||||
// this usage of settings() is okay because it's only called once during pathing
|
|
||||||
// (while creating the CalculationContext at the very beginning)
|
|
||||||
// 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 (Baritone.settings().acceptableThrowawayItems.get().contains(item.getItem())) {
|
|
||||||
if (select) {
|
|
||||||
p.inventory.currentItem = i;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Baritone.settings().acceptableThrowawayItems.get().contains(p.inventory.offHandInventory.get(0).getItem())) {
|
|
||||||
// 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
|
|
||||||
// so we need to select in the main hand something that doesn't right click
|
|
||||||
// so not a shovel, not a hoe, not a block, etc
|
|
||||||
for (byte i = 0; i < 9; i++) {
|
|
||||||
ItemStack item = inv.get(i);
|
|
||||||
if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) {
|
|
||||||
if (select) {
|
|
||||||
p.inventory.currentItem = i;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
|
static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
|
||||||
EntityPlayerSP player = ctx.player();
|
|
||||||
state.setTarget(new MovementTarget(
|
state.setTarget(new MovementTarget(
|
||||||
new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F),
|
new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||||
VecUtils.getBlockPosCenter(pos),
|
VecUtils.getBlockPosCenter(pos),
|
||||||
new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch),
|
ctx.playerRotations()).getYaw(), ctx.player().rotationPitch),
|
||||||
false
|
false
|
||||||
)).setInput(Input.MOVE_FORWARD, true);
|
)).setInput(Input.MOVE_FORWARD, true);
|
||||||
}
|
}
|
||||||
@@ -480,9 +470,76 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return BlockStateInterface.getBlock(ctx, p) instanceof BlockLiquid;
|
return BlockStateInterface.getBlock(ctx, p) instanceof BlockLiquid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isFlowing(IBlockState state) {
|
static boolean possiblyFlowing(IBlockState state) {
|
||||||
// Will be IFluidState in 1.13
|
// Will be IFluidState in 1.13
|
||||||
return state.getBlock() instanceof BlockLiquid
|
return state.getBlock() instanceof BlockLiquid
|
||||||
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isFlowing(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
|
||||||
|
if (!(state.getBlock() instanceof BlockLiquid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (state.getValue(BlockLiquid.LEVEL) != 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return possiblyFlowing(bsi.get0(x + 1, y, z))
|
||||||
|
|| possiblyFlowing(bsi.get0(x - 1, y, z))
|
||||||
|
|| possiblyFlowing(bsi.get0(x, y, z + 1))
|
||||||
|
|| possiblyFlowing(bsi.get0(x, y, z - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) {
|
||||||
|
IPlayerContext ctx = baritone.getPlayerContext();
|
||||||
|
Optional<Rotation> direct = RotationUtils.reachable(ctx, placeAt); // we assume that if there is a block there, it must be replacable
|
||||||
|
boolean found = false;
|
||||||
|
if (direct.isPresent()) {
|
||||||
|
state.setTarget(new MovementState.MovementTarget(direct.get(), true));
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 5; 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(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;
|
||||||
|
}
|
||||||
|
double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||||
|
double faceY = (placeAt.getY() + against1.getY() + 1.0D) * 0.5D;
|
||||||
|
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||||
|
Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
|
||||||
|
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance());
|
||||||
|
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) {
|
||||||
|
state.setTarget(new MovementState.MovementTarget(place, true));
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
if (!preferDown) {
|
||||||
|
// if preferDown is true, we want the last option
|
||||||
|
// if preferDown is false, we want the first
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ctx.getSelectedBlock().isPresent()) {
|
||||||
|
BlockPos selectedBlock = ctx.getSelectedBlock().get();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||||
|
return PlaceResult.ATTEMPTING;
|
||||||
|
}
|
||||||
|
return PlaceResult.NO_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum PlaceResult {
|
||||||
|
READY_TO_PLACE, ATTEMPTING, NO_OPTION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,21 +21,19 @@ import baritone.Baritone;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
import baritone.api.utils.RotationUtils;
|
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementAscend extends Movement {
|
public class MovementAscend extends Movement {
|
||||||
|
|
||||||
@@ -56,29 +54,42 @@ public class MovementAscend extends Movement {
|
|||||||
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
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) {
|
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
||||||
IBlockState toPlace = context.get(destX, y, destZ);
|
IBlockState toPlace = context.get(destX, y, destZ);
|
||||||
boolean hasToPlace = false;
|
double additionalPlacementCost = 0;
|
||||||
if (!MovementHelper.canWalkOn(context.bsi, destX, y, destZ, toPlace)) {
|
if (!MovementHelper.canWalkOn(context.bsi, destX, y, destZ, toPlace)) {
|
||||||
if (!context.canPlaceThrowawayAt(destX, y, destZ)) {
|
additionalPlacementCost = context.costOfPlacingAt(destX, y, destZ);
|
||||||
|
if (additionalPlacementCost >= COST_INF) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (!MovementHelper.isReplacable(destX, y, destZ, toPlace, context.bsi)) {
|
if (!MovementHelper.isReplacable(destX, y, destZ, toPlace, context.bsi)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
|
boolean foundPlaceOption = false;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
|
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 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 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
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) {
|
if (MovementHelper.canPlaceAgainst(context.bsi, againstX, againstY, againstZ)) {
|
||||||
hasToPlace = true;
|
foundPlaceOption = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasToPlace) { // didn't find a valid place =(
|
if (!foundPlaceOption) { // didn't find a valid place =(
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,10 +140,7 @@ public class MovementAscend extends Movement {
|
|||||||
walk += context.jumpPenalty;
|
walk += context.jumpPenalty;
|
||||||
}
|
}
|
||||||
|
|
||||||
double totalCost = walk;
|
double totalCost = walk + additionalPlacementCost;
|
||||||
if (hasToPlace) {
|
|
||||||
totalCost += context.placeBlockCost;
|
|
||||||
}
|
|
||||||
// start with srcUp2 since we already have its state
|
// start with srcUp2 since we already have its state
|
||||||
// includeFalling isn't needed because of the falling check above -- if srcUp3 is falling we will have already exited with COST_INF if we'd actually have to break it
|
// includeFalling isn't needed because of the falling check above -- if srcUp3 is falling we will have already exited with COST_INF if we'd actually have to break it
|
||||||
totalCost += MovementHelper.getMiningDurationTicks(context, x, y + 2, z, srcUp2, false);
|
totalCost += MovementHelper.getMiningDurationTicks(context, x, y + 2, z, srcUp2, false);
|
||||||
@@ -149,6 +157,10 @@ public class MovementAscend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
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);
|
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
|
// 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)
|
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
|
||||||
@@ -162,64 +174,44 @@ public class MovementAscend extends Movement {
|
|||||||
|
|
||||||
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
||||||
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
||||||
for (int i = 0; i < 5; i++) {
|
ticksWithoutPlacement++;
|
||||||
BlockPos anAgainst = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false) == PlaceResult.READY_TO_PLACE) {
|
||||||
if (anAgainst.equals(src)) {
|
state.setInput(Input.SNEAK, true);
|
||||||
continue;
|
if (ctx.player().isSneaking()) {
|
||||||
}
|
state.setInput(Input.CLICK_RIGHT, true);
|
||||||
if (MovementHelper.canPlaceAgainst(ctx, anAgainst)) {
|
|
||||||
if (!MovementHelper.throwaway(ctx, true)) {//get ready to place a throwaway block
|
|
||||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
|
||||||
}
|
|
||||||
double faceX = (dest.getX() + anAgainst.getX() + 1.0D) * 0.5D;
|
|
||||||
double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
|
|
||||||
double faceZ = (dest.getZ() + anAgainst.getZ() + 1.0D) * 0.5D;
|
|
||||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
|
||||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
|
||||||
|
|
||||||
ctx.getSelectedBlock().ifPresent(selectedBlock -> {
|
|
||||||
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) {
|
|
||||||
ticksWithoutPlacement++;
|
|
||||||
state.setInput(Input.SNEAK, true);
|
|
||||||
if (ctx.player().isSneaking()) {
|
|
||||||
state.setInput(Input.CLICK_RIGHT, true);
|
|
||||||
}
|
|
||||||
if (ticksWithoutPlacement > 10) {
|
|
||||||
// After 10 ticks without placement, we might be standing in the way, move back
|
|
||||||
state.setInput(Input.MOVE_BACK, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
state.setInput(Input.CLICK_LEFT, true); // break whatever replaceable block is in the way
|
|
||||||
}
|
|
||||||
//System.out.println("Trying to look at " + anAgainst + ", actually looking at" + selectedBlock);
|
|
||||||
});
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
if (ticksWithoutPlacement > 10) {
|
||||||
|
// After 10 ticks without placement, we might be standing in the way, move back
|
||||||
|
state.setInput(Input.MOVE_BACK, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
MovementHelper.moveTowards(ctx, state, dest);
|
MovementHelper.moveTowards(ctx, state, dest);
|
||||||
if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) {
|
if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) {
|
||||||
return state; // don't jump while walking from a non double slab into a bottom slab
|
return state; // don't jump while walking from a non double slab into a bottom slab
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Baritone.settings().assumeStep.get()) {
|
if (Baritone.settings().assumeStep.value || ctx.playerFeet().equals(src.up())) {
|
||||||
|
// no need to hit space if we're already jumping
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.playerFeet().equals(src.up())) {
|
|
||||||
return state; // no need to hit space if we're already jumping
|
|
||||||
}
|
|
||||||
|
|
||||||
if (headBonkClear()) {
|
|
||||||
return state.setInput(Input.JUMP, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int xAxis = Math.abs(src.getX() - dest.getX()); // either 0 or 1
|
int xAxis = Math.abs(src.getX() - dest.getX()); // either 0 or 1
|
||||||
int zAxis = Math.abs(src.getZ() - dest.getZ()); // either 0 or 1
|
int zAxis = Math.abs(src.getZ() - dest.getZ()); // either 0 or 1
|
||||||
double flatDistToNext = xAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + zAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
|
double flatDistToNext = xAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + zAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
|
||||||
double sideDist = zAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + xAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
|
double sideDist = zAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + xAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
|
||||||
// System.out.println(flatDistToNext + " " + sideDist);
|
|
||||||
|
double lateralMotion = xAxis * ctx.player().motionZ + zAxis * ctx.player().motionX;
|
||||||
|
if (Math.abs(lateralMotion) > 0.1) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headBonkClear()) {
|
||||||
|
return state.setInput(Input.JUMP, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (flatDistToNext > 1.2 || sideDist > 0.2) {
|
if (flatDistToNext > 1.2 || sideDist > 0.2) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -230,7 +222,7 @@ public class MovementAscend extends Movement {
|
|||||||
return state.setInput(Input.JUMP, true);
|
return state.setInput(Input.JUMP, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean headBonkClear() {
|
public boolean headBonkClear() {
|
||||||
BetterBlockPos startUp = src.up(2);
|
BetterBlockPos startUp = src.up(2);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
BetterBlockPos check = startUp.offset(EnumFacing.byHorizontalIndex(i));
|
BetterBlockPos check = startUp.offset(EnumFacing.byHorizontalIndex(i));
|
||||||
@@ -241,4 +233,10 @@ public class MovementAscend extends Movement {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean safeToCancel(MovementState state) {
|
||||||
|
// if we had to place, don't allow pause
|
||||||
|
return state.getStatus() != MovementStatus.RUNNING || ticksWithoutPlacement == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
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.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementDescend extends Movement {
|
public class MovementDescend extends Movement {
|
||||||
|
|
||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
@@ -61,6 +64,11 @@ public class MovementDescend extends Movement {
|
|||||||
return result.cost;
|
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) {
|
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
||||||
double totalCost = 0;
|
double totalCost = 0;
|
||||||
IBlockState destDown = context.get(destX, y - 1, destZ);
|
IBlockState destDown = context.get(destX, y - 1, destZ);
|
||||||
@@ -122,7 +130,7 @@ public class MovementDescend extends Movement {
|
|||||||
// and potentially replace the water we're going to fall into
|
// and potentially replace the water we're going to fall into
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!MovementHelper.canWalkThrough(context.bsi, destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) {
|
if (!MovementHelper.canWalkThrough(context.bsi, destX, y - 2, destZ, below)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double costSoFar = 0;
|
double costSoFar = 0;
|
||||||
@@ -137,13 +145,14 @@ public class MovementDescend extends Movement {
|
|||||||
IBlockState ontoBlock = context.get(destX, newY, destZ);
|
IBlockState ontoBlock = context.get(destX, newY, destZ);
|
||||||
int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY
|
int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY
|
||||||
double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar;
|
double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar;
|
||||||
if (ontoBlock.getBlock() == Blocks.WATER && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) {
|
if (MovementHelper.isWater(ontoBlock.getBlock())) {
|
||||||
// lilypads are canWalkThrough, but we can't end a fall that should be broken by water if it's covered by a lilypad
|
if (!MovementHelper.canWalkThrough(context.bsi, destX, newY, destZ, ontoBlock)) {
|
||||||
// however, don't return impossible in the lilypad scenario, because we could still jump right on it (water that's below a lilypad is canWalkOn so it works)
|
return false;
|
||||||
|
}
|
||||||
if (context.assumeWalkOnWater) {
|
if (context.assumeWalkOnWater) {
|
||||||
return false; // TODO fix
|
return false; // TODO fix
|
||||||
}
|
}
|
||||||
if (MovementHelper.isFlowing(ontoBlock)) {
|
if (MovementHelper.isFlowing(destX, newY, destZ, ontoBlock, context.bsi)) {
|
||||||
return false; // TODO flowing check required here?
|
return false; // TODO flowing check required here?
|
||||||
}
|
}
|
||||||
if (!MovementHelper.canWalkOn(context.bsi, destX, newY - 1, destZ)) {
|
if (!MovementHelper.canWalkOn(context.bsi, destX, newY - 1, destZ)) {
|
||||||
@@ -157,9 +166,6 @@ public class MovementDescend extends Movement {
|
|||||||
res.cost = tentativeCost;// TODO incorporate water swim up cost?
|
res.cost = tentativeCost;// TODO incorporate water swim up cost?
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (unprotectedFallHeight <= 11 && (ontoBlock.getBlock() == Blocks.VINE || ontoBlock.getBlock() == Blocks.LADDER)) {
|
if (unprotectedFallHeight <= 11 && (ontoBlock.getBlock() == Blocks.VINE || ontoBlock.getBlock() == Blocks.LADDER)) {
|
||||||
// if fall height is greater than or equal to 11, we don't actually grab on to vines or ladders. the more you know
|
// if fall height is greater than or equal to 11, we don't actually grab on to vines or ladders. the more you know
|
||||||
// this effectively "resets" our falling speed
|
// this effectively "resets" our falling speed
|
||||||
@@ -177,13 +183,6 @@ public class MovementDescend extends Movement {
|
|||||||
if (MovementHelper.isBottomSlab(ontoBlock)) {
|
if (MovementHelper.isBottomSlab(ontoBlock)) {
|
||||||
return false; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
|
return false; // falling onto a half slab is really glitchy, and can cause more fall damage than we'd expect
|
||||||
}
|
}
|
||||||
if (context.hasWaterBucket && unprotectedFallHeight <= context.maxFallHeightBucket + 1) {
|
|
||||||
res.x = destX;
|
|
||||||
res.y = newY + 1;// this is the block we're falling onto, so dest is +1
|
|
||||||
res.z = destZ;
|
|
||||||
res.cost = tentativeCost + context.placeBlockCost;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (unprotectedFallHeight <= context.maxFallHeightNoWater + 1) {
|
if (unprotectedFallHeight <= context.maxFallHeightNoWater + 1) {
|
||||||
// fallHeight = 4 means onto.up() is 3 blocks down, which is the max
|
// fallHeight = 4 means onto.up() is 3 blocks down, which is the max
|
||||||
res.x = destX;
|
res.x = destX;
|
||||||
@@ -191,6 +190,13 @@ public class MovementDescend extends Movement {
|
|||||||
res.z = destZ;
|
res.z = destZ;
|
||||||
res.cost = tentativeCost;
|
res.cost = tentativeCost;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
if (context.hasWaterBucket && unprotectedFallHeight <= context.maxFallHeightBucket + 1) {
|
||||||
|
res.x = destX;
|
||||||
|
res.y = newY + 1;// this is the block we're falling onto, so dest is +1
|
||||||
|
res.z = destZ;
|
||||||
|
res.cost = tentativeCost + context.placeBucketCost();
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -205,7 +211,8 @@ public class MovementDescend extends Movement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BlockPos playerFeet = ctx.playerFeet();
|
BlockPos playerFeet = ctx.playerFeet();
|
||||||
if (playerFeet.equals(dest) && (MovementHelper.isLiquid(ctx, dest) || ctx.player().posY - playerFeet.getY() < 0.094)) { // lilypads
|
BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ());
|
||||||
|
if ((playerFeet.equals(dest) || playerFeet.equals(fakeDest)) && (MovementHelper.isLiquid(ctx, dest) || ctx.player().posY - dest.getY() < 0.5)) { // lilypads
|
||||||
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
|
// Wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
|
||||||
return state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
/* else {
|
/* else {
|
||||||
@@ -213,8 +220,8 @@ public class MovementDescend extends Movement {
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
if (safeMode()) {
|
if (safeMode()) {
|
||||||
double destX = (src.getX() + 0.5) * 0.19 + (dest.getX() + 0.5) * 0.81;
|
double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83;
|
||||||
double destZ = (src.getZ() + 0.5) * 0.19 + (dest.getZ() + 0.5) * 0.81;
|
double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83;
|
||||||
EntityPlayerSP player = ctx.player();
|
EntityPlayerSP player = ctx.player();
|
||||||
state.setTarget(new MovementState.MovementTarget(
|
state.setTarget(new MovementState.MovementTarget(
|
||||||
new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F),
|
new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F),
|
||||||
@@ -231,13 +238,8 @@ public class MovementDescend extends Movement {
|
|||||||
double z = ctx.player().posZ - (src.getZ() + 0.5);
|
double z = ctx.player().posZ - (src.getZ() + 0.5);
|
||||||
double fromStart = Math.sqrt(x * x + z * z);
|
double fromStart = Math.sqrt(x * x + z * z);
|
||||||
if (!playerFeet.equals(dest) || ab > 0.25) {
|
if (!playerFeet.equals(dest) || ab > 0.25) {
|
||||||
BlockPos fakeDest = new BlockPos(dest.getX() * 2 - src.getX(), dest.getY(), dest.getZ() * 2 - src.getZ());
|
if (numTicks++ < 20 && fromStart < 1.25) {
|
||||||
if (numTicks++ < 20) {
|
|
||||||
MovementHelper.moveTowards(ctx, state, fakeDest);
|
MovementHelper.moveTowards(ctx, state, fakeDest);
|
||||||
if (fromStart > 1.25) {
|
|
||||||
state.setInput(Input.MOVE_FORWARD, false);
|
|
||||||
state.setInput(Input.MOVE_BACK, true);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
MovementHelper.moveTowards(ctx, state, dest);
|
MovementHelper.moveTowards(ctx, state, dest);
|
||||||
}
|
}
|
||||||
@@ -249,6 +251,10 @@ public class MovementDescend extends Movement {
|
|||||||
// (dest - src) + dest is offset 1 more in the same direction
|
// (dest - src) + dest is offset 1 more in the same direction
|
||||||
// so it's the block we'd need to worry about running into if we decide to sprint straight through this descend
|
// so it's the block we'd need to worry about running into if we decide to sprint straight through this descend
|
||||||
BlockPos into = dest.subtract(src.down()).add(dest);
|
BlockPos into = dest.subtract(src.down()).add(dest);
|
||||||
|
if (skipToAscend()) {
|
||||||
|
// if dest extends into can't walk through, but the two above are can walk through, then we can overshoot and glitch in that weird way
|
||||||
|
return true;
|
||||||
|
}
|
||||||
for (int y = 0; y <= 2; y++) { // we could hit any of the three blocks
|
for (int y = 0; y <= 2; y++) { // we could hit any of the three blocks
|
||||||
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(ctx, into.up(y)))) {
|
if (MovementHelper.avoidWalkingInto(BlockStateInterface.getBlock(ctx, into.up(y)))) {
|
||||||
return true;
|
return true;
|
||||||
@@ -256,4 +262,9 @@ public class MovementDescend extends Movement {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean skipToAscend() {
|
||||||
|
BlockPos into = dest.subtract(src.down()).add(dest);
|
||||||
|
return !MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into)) && MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into).up()) && MovementHelper.canWalkThrough(ctx, new BetterBlockPos(into).up(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.pathing.movement.movements;
|
package baritone.pathing.movement.movements;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
@@ -27,6 +28,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
@@ -35,6 +37,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementDiagonal extends Movement {
|
public class MovementDiagonal extends Movement {
|
||||||
|
|
||||||
@@ -63,6 +66,16 @@ public class MovementDiagonal extends Movement {
|
|||||||
return result.cost;
|
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) {
|
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);
|
IBlockState destInto = context.get(destX, y, destZ);
|
||||||
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) {
|
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) {
|
||||||
@@ -114,7 +127,7 @@ public class MovementDiagonal extends Movement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IBlockState pb3 = context.get(destX, y + 1, z);
|
IBlockState pb3 = context.get(destX, y + 1, z);
|
||||||
if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb3.getBlock()) && pb3.getBlock() != Blocks.WATER))) {
|
if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb3.getBlock()))) {
|
||||||
// at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction
|
// at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -123,7 +136,7 @@ public class MovementDiagonal extends Movement {
|
|||||||
// and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible
|
// and finally, if the cost is nonzero for both ways to approach this diagonal, it's not possible
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb1.getBlock()) && pb1.getBlock() != Blocks.WATER))) {
|
if (optionB == 0 && ((MovementHelper.avoidWalkingInto(pb0.getBlock()) && pb0.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb1.getBlock()))) {
|
||||||
// and now that option B is fully calculated, see if we can edge around that way
|
// and now that option B is fully calculated, see if we can edge around that way
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -170,16 +183,29 @@ public class MovementDiagonal extends Movement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.playerFeet().equals(dest)) {
|
if (ctx.playerFeet().equals(dest)) {
|
||||||
state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
return state;
|
} else if (!playerInValidPosition() && !(MovementHelper.isLiquid(ctx, src) && getValidPositions().contains(ctx.playerFeet().up()))) {
|
||||||
|
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
if (!MovementHelper.isLiquid(ctx, ctx.playerFeet())) {
|
if (sprint()) {
|
||||||
state.setInput(Input.SPRINT, true);
|
state.setInput(Input.SPRINT, true);
|
||||||
}
|
}
|
||||||
MovementHelper.moveTowards(ctx, state, dest);
|
MovementHelper.moveTowards(ctx, state, dest);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean sprint() {
|
||||||
|
if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && !Baritone.settings().sprintInWater.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean prepared(MovementState state) {
|
protected boolean prepared(MovementState state) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user