Compare commits

..

141 Commits

Author SHA1 Message Date
Brady 9a33c5cd9f Merge branch 'master' into bot-system 2020-01-01 19:23:01 -06:00
Brady adff391e45 Merge branch 'schematic-formats' 2019-12-31 18:25:21 -06:00
Brady 4a05837b01 Requested changes 2019-12-31 17:44:20 -06:00
Leijurv a0014fda12 Merge pull request #1216 from FTC55/master
Fixed a rather obnoxious bug that would require a full restart of the client.
2019-12-31 15:35:01 -08:00
FTC55 04190af340 ...more than I thought. Autoreformatted file x2 2019-12-31 19:45:08 +01:00
FTC55 4b10904b97 Git missed some changes. Autoreformatted files. 2019-12-31 19:43:54 +01:00
FTC55 bbb25acff3 Fixed the bug, merged CancelCommand into ExecutionControlCommands 2019-12-31 19:31:30 +01:00
Brady fcfa022232 Clean up BlockOptionalMeta comment and add behavioral clarification 2019-12-30 02:27:20 -06:00
Brady 220ee30d35 Appease Codacy 2019-12-27 21:28:05 -06:00
Brady 812bc0d8c4 Remove redundant parser layer 2019-12-27 01:14:31 -06:00
Brady d712839c25 Make Schematica respect mapArtMode setting 2019-12-25 01:35:10 -06:00
Brady eee705b371 Schematic Format API support 2019-12-24 17:20:00 -06:00
Brady 77bdf6e444 Fix MapSchematic 2019-12-23 18:05:50 -06:00
Brady 0a858c040c Working 2019-12-19 22:15:14 -06:00
Brady eea5b69b6c Utilize new FillSchematic 2019-12-19 12:03:02 -06:00
Brady 6759917a2f Additional clean up 2019-12-19 11:58:47 -06:00
Brady aa3bd80ab2 Clean ups 2019-12-19 11:40:38 -06:00
Brady ea8d7fb3b9 Improve file extension fallback mechanism 2019-12-18 15:19:58 -06:00
Brady b4ddf38116 Check if state is null 2019-12-18 10:27:34 -06:00
Brady 5c9f028103 Initial sponge support 2019-12-18 10:24:43 -06:00
Leijurv 937d4cc884 whoops 2019-12-13 20:46:12 -08:00
Leijurv 2c3e1f4232 builder stuff, fixes #1059 2019-12-13 20:09:04 -08:00
Leijurv ddc681fe77 build repeat count 2019-11-24 11:11:28 -08:00
Leijurv 2b71b31cfa Merge pull request #1087 from cabaletta/ispassable-crash-fix
Fix isPassable crash
2019-11-10 22:52:29 -08:00
Leijurv ed144e995b apparently this usage of > was an invalid javadoc command lol 2019-11-10 14:04:27 -08:00
Brady 7e3a2d3c0a Create a BlockStateInterface specialized IBlockAccess wrapper 2019-11-05 18:17:10 -06:00
Leijurv 152285043d Update USAGE.md 2019-11-05 11:50:27 -08:00
Leijurv ce52201e45 Merge pull request #1097 from greg904/fix-goto-errmsg
Remove error message when running goto with less than 3 args
2019-10-29 21:33:27 -07:00
Leijurv 45ea776090 Update README.md 2019-10-28 10:47:20 -07:00
Leijurv 2ae16d8bb1 configurable block reach distance 2019-10-26 16:01:08 -07:00
Greg Depoire--Ferrer 23fc6c8b49 Add a space between sentences in error message 2019-10-25 14:49:57 +02:00
Greg Depoire--Ferrer 0db4b193e1 Remove hack, add comment, don't use default when arg is required 2019-10-25 14:49:08 +02:00
Greg Depoire--Ferrer 82d520d808 Don't print invalid type error to stderr 2019-10-25 14:42:36 +02:00
Brady 5201d39adf Retain old method signature 2019-10-24 15:20:23 -05:00
Brady f02c33d95a Fix improper tick count incrementation 2019-10-23 17:47:20 -05:00
Brady 43ab4f7d3b Fix isPassable crash 2019-10-22 15:58:10 -05:00
Leijurv 6341f9fcb4 Merge pull request #1072 from 0-x-2-2/disable-autotest-mob-spawning
Disable harmful mob spawning in Travis auto test.
2019-10-17 12:05:24 -07:00
0x22 66ffd1e0d9 Disable harmful mob spawning in Travis auto test. 2019-10-17 14:35:28 -04:00
Leijurv e65c854e6a Update USAGE.md 2019-10-15 11:25:35 -07:00
Brady 4eca960a4c Specify range in IWorldScanner#repack 2019-10-14 15:45:41 -05:00
Leijurv 69bceb43f8 Update USAGE.md 2019-10-12 13:07:12 -07:00
Leijurv 6a8807b0fa documentation stuff 2019-10-12 10:43:01 -07:00
Leijurv e49549117b v1.2.10 2019-10-11 17:08:28 -07:00
Brady 9f5f275a17 Merge branch 'master' into bot-system 2019-10-07 09:42:35 -05:00
Brady ac4895823e Remove comms 2019-10-04 15:52:08 -05:00
Brady 62cea04080 Fix compiler errors 2019-10-04 15:51:44 -05:00
Brady d772a97a0b Fix 2019-10-04 10:22:06 -05:00
Brady 7af0ed6ea1 Merge conflicts 2019-10-04 10:19:35 -05:00
Brady fe3f3a66ce Format bot code 2019-01-22 13:30:11 -06:00
Brady 9c5f82c814 Merge branch 'master' into bot-system 2019-01-18 13:52:22 -06:00
Brady 7c66762f48 Bot system API exposure 2019-01-17 14:43:44 -06:00
Leijurv 830c8190de Merge branch 'comms' into bot-system 2019-01-17 12:18:27 -08:00
Leijurv 47b258d7a4 Merge branch 'master' into comms 2019-01-17 12:16:45 -08:00
Brady df80858c49 Remove duplicate MovementInput implementation, Fixes #312 2019-01-16 13:55:24 -06:00
Brady 5dec544802 Minor fix LOL 2019-01-15 14:59:56 -06:00
Brady 494c056613 Resolve merge conflicts 2019-01-15 14:53:05 -06:00
Brady c0e947f016 Clean up canBreak 2018-12-24 12:23:57 -06:00
Brady c6ce5ea160 Nobody cares about creative mode 2018-12-24 12:19:09 -06:00
Brady 7b2930d5e5 Bot Breaking that is moderately cursed
DMCA gang
2018-12-24 12:11:28 -06:00
Brady 44ca284717 Merge branch 'master' into bot-system 2018-12-18 19:36:10 -06:00
Leijurv 380a645a6c only report items that are actually in the echest 2018-12-17 19:51:24 -08:00
Leijurv 0249bd5dd7 a few more packets, and consistent indexing 2018-12-17 15:15:20 -08:00
Leijurv 8cd8a95763 little fix 2018-12-16 20:14:07 -08:00
Brady 029a2b7f3e Fix NullPointerException 2018-12-15 12:27:19 -06:00
Leijurv 767d0c8ec1 better reporting 2018-12-14 21:57:20 -08:00
Brady 8febed2e42 Remove dependency for PlayerControllerMP implementation 2018-12-14 17:24:07 -06:00
Leijurv 37b1604e5d Merge branch 'master' into comms 2018-12-14 09:38:40 -08:00
Leijurv 82d15570f3 fix rare exception 2018-12-02 16:05:21 -08:00
Leijurv 2c2c420b3a Merge branch 'comms' into bot-system 2018-12-02 13:35:40 -08:00
Leijurv 1422b0a149 Merge branch 'master' into bot-system 2018-12-02 13:35:23 -08:00
Leijurv 6b6dd916b4 Merge branch 'calc-request' into comms 2018-11-23 19:09:01 -08:00
Leijurv 11e44acf65 helper to handle pending msgs 2018-11-23 16:35:03 -08:00
Leijurv 16fec4a1a0 buffered connection creation helper 2018-11-23 16:09:59 -08:00
Leijurv bbded21afb Merge branch 'master' into bot-system 2018-11-23 14:12:02 -08:00
Leijurv 5ae4f23886 Merge branch 'comms' into calc-request 2018-11-23 13:34:48 -08:00
Leijurv f222980a1a move comms to cabaletta.comms 2018-11-23 13:32:18 -08:00
Leijurv c57f65f832 complete new segmented calculation system 2018-11-23 13:17:03 -08:00
Leijurv 85a6ec022e Merge branch 'comms' into calc-request 2018-11-23 13:13:35 -08:00
Leijurv c1032da828 Merge branch 'master' into comms 2018-11-23 13:12:38 -08:00
Leijurv e0d894d296 computation request and response 2018-11-23 12:09:35 -08:00
Leijurv 27c818f873 Merge branch 'comms' into calc-request 2018-11-23 11:49:49 -08:00
Leijurv fdd758bc90 too much log spam 2018-11-23 11:48:01 -08:00
Leijurv 3a2620192b too much log spam 2018-11-23 11:46:47 -08:00
Leijurv c423d5f575 report path start position 2018-11-23 11:35:13 -08:00
Leijurv 81a9b71429 Merge branch 'segment-calculation' into comms 2018-11-23 10:36:56 -08:00
Leijurv 81ecc209d3 synchronize partial reads and writes to a socket 2018-11-23 10:09:13 -08:00
Leijurv 0dc67593bb lots more status 2018-11-18 21:56:46 -08:00
Leijurv 2e180e81ed Merge branch 'comms' of github.com:cabaletta/baritone into comms 2018-11-18 21:42:04 -08:00
Leijurv 0b11057449 Merge branch 'master' into comms 2018-11-18 21:41:50 -08:00
Brady 186652a8d8 Protocol lol 2018-11-18 19:52:11 -06:00
Leijurv 168c151901 Merge branch 'comms' into bot-system 2018-11-18 17:39:35 -08:00
Leijurv 18d8cfb6de Merge branch 'master' into comms 2018-11-18 17:39:26 -08:00
Leijurv f99befd307 oh thats important 2018-11-18 12:04:37 -08:00
Leijurv 9ad35dbf28 remove the useless stuff 2018-11-18 11:35:54 -08:00
Leijurv dfb49179c5 not a handler lol 2018-11-18 11:27:53 -08:00
Brady 3c913a7b85 Fix jar export 2018-11-18 13:27:25 -06:00
Leijurv f01cf669e8 wtf 2018-11-18 11:06:40 -08:00
Leijurv 2d87033f49 f 2018-11-18 11:06:11 -08:00
Leijurv f014e42aa4 initial comms 2018-11-18 11:01:46 -08:00
Brady 46de72e28c Comms Sourceset 2018-11-17 18:07:16 -06:00
Brady 3d5cf9772e Less cancer 2018-11-14 20:55:37 -06:00
Leijurv 7cb38352ac bots 2018-11-14 17:17:52 -08:00
Leijurv 42c78337c7 Merge branch 'master' into bot-system 2018-11-14 16:41:52 -08:00
Brady 0f81212f17 Compile fix 2018-11-13 21:41:52 -06:00
Brady ad0041c2c5 Merge branch 'master' into bot-system 2018-11-13 17:14:29 -06:00
Brady 19e7585cd2 Merge branch 'master' into bot-system 2018-11-11 16:23:47 -06:00
Brady 3aeb29ab22 Merge branch 'master' into bot-system 2018-11-11 13:36:22 -06:00
Brady 8dfe5dfd32 Fix jce.jar not being included as library jar in proguard config 2018-11-09 22:43:00 -06:00
Brady 90236962c4 nice 2018-11-09 22:17:00 -06:00
Brady 2e9e8c1ea1 Actually entirely epic, we're okay 2018-11-09 22:00:11 -06:00
Brady 4bf659e14e Fix ConcurrentModificationException 2018-11-09 21:10:49 -06:00
Brady ceca258867 MORE handlers
also removed scoreboard handlers because lol
2018-11-09 20:50:43 -06:00
Leijurv abda4b3a31 begone 2018-11-09 13:28:49 -08:00
Brady 98664540e2 Merge branch 'master' into bot-system 2018-11-09 14:42:23 -06:00
Brady 484dac66b7 JUMP 2018-11-09 13:58:55 -06:00
Brady 40282cd140 Automatic Disconnect 2018-11-07 16:53:32 -06:00
Brady 41c74cb08c More handlers 2018-11-07 12:23:28 -06:00
Brady 7c92817801 Offline bot testing 2018-11-07 12:01:26 -06:00
Brady 1d56585c67 Fix success connection result 2018-11-06 16:22:24 -06:00
Brady a4ac9c6f8d Bot Connecting 2018-11-06 15:25:25 -06:00
Brady 42d15a7b93 Merge branch 'master' into bot-system 2018-11-06 14:10:11 -06:00
Brady 335c97bae6 Merge branch 'master' into bot-system 2018-11-05 16:06:53 -06:00
Brady 8a8afddce3 Fix bad stack overflow error 2018-10-30 13:57:50 -05:00
Brady c3f6ee87b3 Feed codacy 2018-10-29 23:27:54 -05:00
Brady f45fb3cd8c Add reminder lol 2018-10-29 23:20:11 -05:00
Brady 71c7ed54e5 Reverse increment/decrement 2018-10-29 23:10:46 -05:00
Brady 4f978be2a2 Begin MovementInput implementation 2018-10-29 23:04:26 -05:00
Brady 133d956b3a Create login handler 2018-10-29 22:43:36 -05:00
Brady 095e452632 Merge branch 'master' into bot-system 2018-10-29 22:08:29 -05:00
Brady 047d7f06b8 More handlers 2018-10-26 11:38:52 -05:00
Brady 09a119c4ca More handlers 2018-10-24 20:51:01 -05:00
Brady 746e1f6652 handleTimeUpdate 2018-10-24 19:04:49 -05:00
Brady 1d22cf63f0 Lol 2018-10-23 23:08:43 -05:00
Brady d4b3e71694 handleCombatEvent 2018-10-23 23:07:58 -05:00
Brady a08b406af9 handleCooldown 2018-10-23 23:04:13 -05:00
Brady 1afd367e53 handleResourcePack 2018-10-23 23:00:58 -05:00
Brady 59e920b7b1 Meme 3 2018-10-23 09:58:36 -05:00
Brady 79d230d924 another thought 2018-10-23 00:49:38 -05:00
Brady 29cf79fe17 We don't need the connection handler from the user 2018-10-23 00:46:31 -05:00
Brady 8e75817e29 Meme 2 2018-10-23 00:29:30 -05:00
Brady c6bd3f4f00 Meme 2018-10-23 00:05:48 -05:00
138 changed files with 4314 additions and 1403 deletions
-2
View File
@@ -11,8 +11,6 @@ build/
classes/ classes/
*.class *.class
/out
# IntelliJ Files # IntelliJ Files
.idea/ .idea/
*.iml *.iml
+1 -1
View File
@@ -10,7 +10,7 @@ install:
script: script:
- docker run --rm cabaletta/baritone ./gradlew javadoc - docker run --rm cabaletta/baritone ./gradlew javadoc
- docker run --name baritone cabaletta/baritone /bin/sh -c "/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 runAutoTest; cat /code/autotest/success" - 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
- cat dist/checksums.txt - cat dist/checksums.txt
+36
View File
@@ -0,0 +1,36 @@
# Baritone Comms Protocol
## Data Types
| Name | Descriptor | Java |
|------------|-----------------------------------------------------------|-----------------------------|
| coordinate | Big endian 8-byte floating point number | [readDouble], [writeDouble] |
| string | unsigned short (length) followed by UTF-8 character bytes | [readUTF], [writeUTF] |
## Inbound
Allows the server to execute a chat command on behalf of the client's player
### Chat
| Name | Type |
|---------|--------|
| Message | string |
## Outbound
Update the player position with the server
### Status
| Name | Type |
|------|------------|
| X | coordinate |
| Y | coordinate |
| Z | coordinate |
<!-- External links -->
[readUTF]: https://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readUTF()
[writeUTF]: https://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html#writeUTF(java.lang.String)
[readDouble]: https://docs.oracle.com/javase/7/docs/api/java/io/DataInputStream.html#readDouble()
[writeDouble]: https://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html#writeDouble(double)
+1 -1
View File
@@ -19,7 +19,7 @@
![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code) ![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code)
[![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/)
[![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/)
[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.8%20/%20v1.3.4%20/%20v1.4.1-brightgreen.svg)](https://impactclient.net/) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.10%20/%20v1.3.5%20/%20v1.4.3-brightgreen.svg)](https://impactclient.net/)
[![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/)
[![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api) [![Aristois add-on integration](https://img.shields.io/badge/Aristois%20add--on%20integration-v1.3.4%20/%20v1.4.1-green.svg)](https://gitlab.com/emc-mods-indrit/baritone_api)
[![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/)
+13 -7
View File
@@ -8,11 +8,23 @@ Baritone commands can also by default be typed in the chatbox. However if you ma
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). 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).
# For Baritone 1.2.10+, 1.3.5+, 1.4.2+
Lots of the commands have changed, BUT `#help` is improved vastly (its clickable! commands have tab completion! oh my!).
Try `#help` I promise it won't just send you back here =)
"wtf where is cleararea" -> look at `#help sel`
"wtf where is goto death, goto waypoint" -> look at `#help wp` (a "tag" is like "home" (created automatically on right clicking a bed) or "death" (created automatically on death) or "user" (has to be created manually)). So you might want `#wp save user coolbiome` then, to set the goal `#wp goal coolbiome` then `#path` to path to it. For death, `#wp goal death` (remember stuff is clickable!).
just look at `#help` lmao
# Commands # Commands
**All** of these commands may need a prefix before them, as above ^. **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). `help`
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`. 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`.
@@ -38,12 +50,6 @@ Some common examples:
- `version` to get the version of Baritone you're running - `version` to get the version of Baritone you're running
- `damn` daniel - `damn` daniel
New commands:
- `sel` to manage selections
- some others
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). 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>. 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>.
+14 -69
View File
@@ -16,33 +16,33 @@
*/ */
group 'baritone' group 'baritone'
version '1.3.5' version '1.2.10'
buildscript { buildscript {
repositories { repositories {
jcenter()
maven { maven {
name = 'forge' name = 'forge'
url = 'http://files.minecraftforge.net/maven' url = 'http://files.minecraftforge.net/maven'
} }
maven { maven {
name = 'impactdevelopment-repo' name = 'SpongePowered'
url = 'https://impactdevelopment.github.io/maven/' url = 'http://repo.spongepowered.org/maven'
} }
jcenter()
} }
dependencies { dependencies {
classpath group: 'com.github.ImpactDevelopment', name: 'ForgeGradle', version: '3.0.115' classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath group: 'com.github.ImpactDevelopment', name: 'MixinGradle', version: '0.6.2' classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
} }
} }
import baritone.gradle.task.CreateDistTask import baritone.gradle.task.CreateDistTask
import baritone.gradle.task.ProguardTask import baritone.gradle.task.ProguardTask
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'net.minecraftforge.gradle' apply plugin: 'net.minecraftforge.gradle.tweaker-client'
apply plugin: 'org.spongepowered.mixin' apply plugin: 'org.spongepowered.mixin'
sourceCompatibility = targetCompatibility = '1.8' sourceCompatibility = targetCompatibility = '1.8'
@@ -52,19 +52,8 @@ compileJava {
} }
sourceSets { sourceSets {
api {
compileClasspath += main.compileClasspath
}
main {
compileClasspath += api.output
}
test {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
launch { launch {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
} }
schematica_api { schematica_api {
@@ -76,51 +65,14 @@ sourceSets {
} }
} }
task sourceJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.api.allSource
}
minecraft { minecraft {
mappings channel: 'snapshot', version: '20190307-1.13.1' version = '1.12.2'
reobfMappings 'notch' mappings = 'stable_39'
tweakClass = 'baritone.launch.BaritoneTweaker'
runDir = 'run'
runs { // The sources jar should use SRG names not MCP to ensure compatibility with all mappings
client { makeObfSourceJar = true
workingDirectory project.file('run')
source sourceSets.launch
main 'baritone.launch.LaunchTesting'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', downloadAssets.output
environment 'nativesDirectory', extractNatives.output
environment 'tweakClass', 'baritone.launch.BaritoneTweaker'
if (Os.isFamily(Os.FAMILY_MAC)) {
jvmArgs "-XstartOnFirstThread"
}
}
autoTest {
workingDirectory project.file('autotest')
source sourceSets.launch
main 'baritone.launch.LaunchTesting'
environment 'assetIndex', '{asset_index}'
environment 'assetDirectory', downloadAssets.output
environment 'nativesDirectory', extractNatives.output
environment 'tweakClass', 'baritone.launch.BaritoneTweaker'
environment 'BARITONE_AUTO_TEST', 'true'
if (Os.isFamily(Os.FAMILY_MAC)) {
jvmArgs "-XstartOnFirstThread"
}
}
}
} }
repositories { repositories {
@@ -138,12 +90,6 @@ repositories {
} }
dependencies { dependencies {
minecraft 'com.github.ImpactDevelopment:Vanilla:1.13.2'
runtime launchCompile('net.minecraft:launchwrapper:1.12') {
exclude module: 'lwjgl'
}
runtime launchCompile('org.ow2.asm:asm-debug-all:5.2')
runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2')
runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
// Mixin includes a lot of dependencies that are too up-to-date // Mixin includes a lot of dependencies that are too up-to-date
@@ -153,7 +99,6 @@ dependencies {
exclude module: 'commons-io' exclude module: 'commons-io'
exclude module: 'log4j-core' exclude module: 'log4j-core'
} }
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
} }
@@ -40,13 +40,17 @@ 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",
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();
@@ -56,6 +60,8 @@ class BaritoneGradleTask extends DefaultTask {
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);
@@ -45,6 +45,8 @@ public class CreateDistTask extends BaritoneGradleTask {
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/");
@@ -56,9 +58,11 @@ public class CreateDistTask extends BaritoneGradleTask {
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());
@@ -18,18 +18,27 @@
package baritone.gradle.task; package baritone.gradle.task;
import baritone.gradle.util.Determinizer; import baritone.gradle.util.Determinizer;
import baritone.gradle.util.MappingType;
import baritone.gradle.util.ReobfWrapper;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.internal.plugins.DefaultConvention;
import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
import org.gradle.internal.Pair;
import java.io.*; import java.io.*;
import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
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.nio.file.Paths;
import java.util.List; import java.util.*;
import java.util.stream.Stream; import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@@ -41,12 +50,18 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
*/ */
public class ProguardTask extends BaritoneGradleTask { public class ProguardTask extends BaritoneGradleTask {
private static final Pattern TEMP_LIBRARY_PATTERN = Pattern.compile("-libraryjars 'tempLibraries\\/([a-zA-Z0-9/_\\-\\.]+)\\.jar'");
@Input @Input
private String url; private String url;
@Input @Input
private String extract; private String extract;
private List<String> requiredLibraries;
private File mixin;
@TaskAction @TaskAction
protected void exec() throws Exception { protected void exec() throws Exception {
super.verifyArtifacts(); super.verifyArtifacts();
@@ -56,6 +71,7 @@ public class ProguardTask extends BaritoneGradleTask {
downloadProguard(); downloadProguard();
extractProguard(); extractProguard();
generateConfigs(); generateConfigs();
acquireDependencies();
proguardApi(); proguardApi();
proguardStandalone(); proguardStandalone();
cleanup(); cleanup();
@@ -66,7 +82,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 {
@@ -98,19 +114,7 @@ public class ProguardTask extends BaritoneGradleTask {
Process p = new ProcessBuilder("java", "-verbose").start(); Process p = new ProcessBuilder("java", "-verbose").start();
String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", ""); String out = IOUtils.toString(p.getInputStream(), "UTF-8").split("\n")[0].split("Opened ")[1].replace("]", "");
template.add(2, "-libraryjars '" + out + "'"); template.add(2, "-libraryjars '" + out + "'");
template.add(3, "-libraryjars '" + Paths.get(out).resolveSibling("jce.jar") + "'");
// Discover all of the libraries that we will need to acquire from gradle
acquireDependencies().forEach(f -> {
if (f.toString().endsWith("-recomp.jar")) {
// remove MCP mapped jar
return;
}
if (f.toString().endsWith("client-extra.jar")) {
// go from the extra to the original downloaded client
f = new File(f.getParentFile(), "client.jar");
}
template.add(2, "-libraryjars '" + f + "'");
});
// API config doesn't require any changes from the changes that we made to the template // API config doesn't require any changes from the changes that we made to the template
Files.write(getTemporaryFile(PROGUARD_API_CONFIG), template); Files.write(getTemporaryFile(PROGUARD_API_CONFIG), template);
@@ -119,20 +123,165 @@ public class ProguardTask extends BaritoneGradleTask {
List<String> standalone = new ArrayList<>(template); List<String> standalone = new ArrayList<>(template);
standalone.removeIf(s -> s.contains("# this is the keep api")); standalone.removeIf(s -> s.contains("# this is the keep api"));
Files.write(getTemporaryFile(PROGUARD_STANDALONE_CONFIG), standalone); Files.write(getTemporaryFile(PROGUARD_STANDALONE_CONFIG), standalone);
// Discover all of the libraries that we will need to acquire from gradle
this.requiredLibraries = new ArrayList<>();
template.forEach(line -> {
if (!line.startsWith("#")) {
Matcher m = TEMP_LIBRARY_PATTERN.matcher(line);
if (m.find()) {
this.requiredLibraries.add(m.group(1));
}
}
});
} }
private Stream<File> acquireDependencies() { private void acquireDependencies() throws Exception {
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles().stream().filter(File::isFile);
// Create a map of all of the dependencies that we are able to access in this project
// Likely a better way to do this, I just pair the dependency with the first valid configuration
Map<String, Pair<Configuration, Dependency>> dependencyLookupMap = new HashMap<>();
getProject().getConfigurations().stream().filter(Configuration::isCanBeResolved).forEach(config ->
config.getAllDependencies().forEach(dependency ->
dependencyLookupMap.putIfAbsent(dependency.getName() + "-" + dependency.getVersion(), Pair.of(config, dependency))));
// Create the directory if it doesn't already exist
Path tempLibraries = getTemporaryFile(TEMP_LIBRARY_DIR);
if (!Files.exists(tempLibraries)) {
Files.createDirectory(tempLibraries);
}
// Iterate the required libraries to copy them to tempLibraries
for (String lib : this.requiredLibraries) {
// copy from the forgegradle cache
if (lib.equals("minecraft")) {
Path cachedJar = getMinecraftJar();
Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar");
// TODO: maybe try not to copy every time
Files.copy(cachedJar, inTempDir, REPLACE_EXISTING);
continue;
}
// Find a configuration/dependency pair that matches the desired library
Pair<Configuration, Dependency> pair = null;
for (Map.Entry<String, Pair<Configuration, Dependency>> entry : dependencyLookupMap.entrySet()) {
if (entry.getKey().startsWith(lib)) {
pair = entry.getValue();
}
}
// The pair must be non-null
Objects.requireNonNull(pair);
// Find the library jar file, and copy it to tempLibraries
for (File file : pair.getLeft().files(pair.getRight())) {
if (file.getName().startsWith(lib)) {
if (lib.contains("mixin")) {
mixin = file;
}
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
private Path getMinecraftJar() throws Exception {
MappingType mappingType;
try {
mappingType = getMappingType();
} catch (Exception e) {
System.err.println("Failed to get mapping type, assuming NOTCH.");
mappingType = MappingType.NOTCH;
}
String suffix;
switch (mappingType) {
case NOTCH:
suffix = "";
break;
case SEARGE:
suffix = "-srgBin";
break;
case CUSTOM:
throw new IllegalStateException("Custom mappings not supported!");
default:
throw new IllegalStateException("Unknown mapping type: " + mappingType);
}
DefaultConvention convention = (DefaultConvention) this.getProject().getConvention();
Object extension = convention.getAsMap().get("minecraft");
Objects.requireNonNull(extension);
// for some reason cant use Class.forName
Class<?> class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); // <-- cursed
Field f_replacer = class_baseExtension.getDeclaredField("replacer");
f_replacer.setAccessible(true);
Object replacer = f_replacer.get(extension);
Class<?> class_replacementProvider = replacer.getClass();
Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap");
replacement_replaceMap.setAccessible(true);
Map<String, Object> replacements = (Map) replacement_replaceMap.get(replacer);
String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft";
String mcVersion = replacements.get("MC_VERSION").toString();
String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString();
String fullJarName = "minecraft-" + mcVersion + suffix + ".jar";
String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion);
String jarPath;
if (mappingType == MappingType.SEARGE) {
jarPath = String.format("%s/%s/%s", baseDir, mcpInsert, fullJarName);
} else {
jarPath = baseDir + fullJarName;
}
jarPath = jarPath
.replace("/", File.separator)
.replace("\\", File.separator); // hecking regex
return new File(jarPath).toPath();
}
// throws IllegalStateException if mapping type is ambiguous or it fails to find it
private MappingType getMappingType() {
// if it fails to find this then its probably a forgegradle version problem
Set<Object> reobf = (NamedDomainObjectContainer<Object>) this.getProject().getExtensions().getByName("reobf");
List<MappingType> mappingTypes = getUsedMappingTypes(reobf);
long mappingTypesUsed = mappingTypes.size();
if (mappingTypesUsed == 0) {
throw new IllegalStateException("Failed to find mapping type (no jar task?)");
}
if (mappingTypesUsed > 1) {
throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)");
}
return mappingTypes.get(0);
}
private List<MappingType> getUsedMappingTypes(Set<Object> reobf) {
return reobf.stream()
.map(ReobfWrapper::new)
.map(ReobfWrapper::getMappingType)
.distinct()
.collect(Collectors.toList());
} }
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() {
@@ -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();
} }
} }
@@ -0,0 +1,29 @@
/*
* 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.gradle.util;
/**
* All credits go to AsmLibGradle and its contributors.
*
* @see <a href="https://github.com/pozzed/AsmLibGradle/blob/8f917dbc3939eab7a3d9daf54d9d285fdf34f4b2/src/main/java/net/futureclient/asmlib/forgegradle/MappingType.java">Original Source</a>
*/
public enum MappingType {
SEARGE,
NOTCH,
CUSTOM // forgegradle
}
@@ -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.gradle.util;
import java.lang.reflect.Field;
import java.util.Objects;
/**
* All credits go to AsmLibGradle and its contributors.
*
* @see <a href="https://github.com/pozzed/AsmLibGradle/blob/8f917dbc3939eab7a3d9daf54d9d285fdf34f4b2/src/main/java/net/futureclient/asmlib/forgegradle/ReobfWrapper.java">Original Source</a>
*/
public class ReobfWrapper {
private final Object instance;
private final Class<?> type;
public ReobfWrapper(Object instance) {
this.instance = instance;
Objects.requireNonNull(instance);
this.type = instance.getClass();
}
public String getName() {
try {
Field nameField = type.getDeclaredField("name");
nameField.setAccessible(true);
return (String) nameField.get(this.instance);
} catch (ReflectiveOperationException ex) {
throw new IllegalStateException(ex);
}
}
public MappingType getMappingType() {
try {
Field enumField = type.getDeclaredField("mappingType");
enumField.setAccessible(true);
Enum<?> aEnum = (Enum<?>) enumField.get(this.instance);
MappingType mappingType = MappingType.values()[aEnum.ordinal()];
if (!aEnum.name().equals(mappingType.name())) {
throw new IllegalStateException("ForgeGradle ReobfMappingType is not equivalent to MappingType (version error?)");
}
return mappingType;
} catch (ReflectiveOperationException ex) {
throw new IllegalStateException(ex);
}
}
}
+49 -2
View File
@@ -14,8 +14,6 @@
# lwjgl is weird # lwjgl is weird
-dontwarn org.lwjgl.** -dontwarn org.lwjgl.**
# also lwjgl lol
-dontwarn module-info
-keep class baritone.api.** { *; } # this is the keep api -keep class baritone.api.** { *; } # this is the keep api
@@ -38,6 +36,55 @@
#proguard doesnt like it when it cant find our fake schematica classes #proguard doesnt like it when it cant find our fake schematica classes
-dontwarn baritone.utils.schematic.schematica.** -dontwarn baritone.utils.schematic.schematica.**
# copy all necessary libraries into tempLibraries to build
# The correct jar will be copied from the forgegradle cache based on the mapping type being compiled with
-libraryjars 'tempLibraries/minecraft.jar'
-libraryjars 'tempLibraries/SimpleTweaker-1.2.jar'
-libraryjars 'tempLibraries/authlib-1.5.25.jar'
-libraryjars 'tempLibraries/codecjorbis-20101023.jar'
-libraryjars 'tempLibraries/codecwav-20101023.jar'
-libraryjars 'tempLibraries/commons-codec-1.10.jar'
-libraryjars 'tempLibraries/commons-compress-1.8.1.jar'
-libraryjars 'tempLibraries/commons-io-2.5.jar'
-libraryjars 'tempLibraries/commons-lang3-3.5.jar'
-libraryjars 'tempLibraries/commons-logging-1.1.3.jar'
-libraryjars 'tempLibraries/fastutil-7.1.0.jar'
-libraryjars 'tempLibraries/gson-2.8.0.jar'
-libraryjars 'tempLibraries/guava-21.0.jar'
-libraryjars 'tempLibraries/httpclient-4.3.3.jar'
-libraryjars 'tempLibraries/httpcore-4.3.2.jar'
-libraryjars 'tempLibraries/icu4j-core-mojang-51.2.jar'
-libraryjars 'tempLibraries/jinput-2.0.5.jar'
-libraryjars 'tempLibraries/jna-4.4.0.jar'
-libraryjars 'tempLibraries/jopt-simple-5.0.3.jar'
-libraryjars 'tempLibraries/jsr305-3.0.1.jar'
-libraryjars 'tempLibraries/jutils-1.0.0.jar'
-libraryjars 'tempLibraries/libraryjavasound-20101123.jar'
-libraryjars 'tempLibraries/librarylwjglopenal-20100824.jar'
-libraryjars 'tempLibraries/log4j-api-2.8.1.jar'
-libraryjars 'tempLibraries/log4j-core-2.8.1.jar'
# startsWith is used to check the library, and mac/linux differ in which version they use
# this is FINE
-libraryjars 'tempLibraries/lwjgl-.jar'
-libraryjars 'tempLibraries/lwjgl_util-.jar'
-libraryjars 'tempLibraries/netty-all-4.1.9.Final.jar'
-libraryjars 'tempLibraries/oshi-core-1.1.jar'
-libraryjars 'tempLibraries/patchy-1.1.jar'
-libraryjars 'tempLibraries/platform-3.4.0.jar'
-libraryjars 'tempLibraries/realms-1.10.22.jar'
-libraryjars 'tempLibraries/soundsystem-20120107.jar'
-libraryjars 'tempLibraries/text2speech-1.10.3.jar'
-libraryjars 'tempLibraries/mixin-0.7.11-SNAPSHOT.jar'
-libraryjars 'tempLibraries/launchwrapper-1.11.jar' # TODO why does only 1.11.jar exist?
# Keep - Applications. Keep all application classes, along with their 'main' # Keep - Applications. Keep all application classes, along with their 'main'
# methods. # methods.
@@ -17,9 +17,11 @@
package baritone.api; package baritone.api;
import baritone.api.bot.IUserManager;
import baritone.api.cache.IWorldScanner; import baritone.api.cache.IWorldScanner;
import baritone.api.command.ICommand; import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem; import baritone.api.command.ICommandSystem;
import baritone.api.schematic.ISchematicSystem;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import java.util.List; import java.util.List;
@@ -68,13 +70,18 @@ public interface IBaritoneProvider {
} }
/** /**
* Returns the {@link IWorldScanner} instance. This is not a type returned by * Returns the {@link IWorldScanner} instance. This is not a type returned by a
* {@link IBaritone} implementation, because it is not linked with {@link IBaritone}. * {@link IBaritone} implementation because it is not linked with {@link IBaritone}.
* *
* @return The {@link IWorldScanner} instance. * @return The {@link IWorldScanner} instance.
*/ */
IWorldScanner getWorldScanner(); IWorldScanner getWorldScanner();
/**
* @return The {@link IUserManager} instance.
*/
IUserManager getUserManager();
/** /**
* Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone} * Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone}
* instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s. * instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s.
@@ -82,4 +89,9 @@ public interface IBaritoneProvider {
* @return The {@link ICommandSystem} instance. * @return The {@link ICommandSystem} instance.
*/ */
ICommandSystem getCommandSystem(); ICommandSystem getCommandSystem();
/**
* @return The {@link ISchematicSystem} instance.
*/
ISchematicSystem getSchematicSystem();
} }
+35 -9
View File
@@ -158,10 +158,10 @@ public final class Settings {
* Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.) * Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.)
*/ */
public final Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList( public final Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList(
Blocks.DIRT.asItem(), Item.getItemFromBlock(Blocks.DIRT),
Blocks.COBBLESTONE.asItem(), Item.getItemFromBlock(Blocks.COBBLESTONE),
Blocks.NETHERRACK.asItem(), Item.getItemFromBlock(Blocks.NETHERRACK),
Blocks.STONE.asItem() Item.getItemFromBlock(Blocks.STONE)
))); )));
/** /**
@@ -177,12 +177,27 @@ public final class Settings {
public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet? public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet?
Blocks.CRAFTING_TABLE, Blocks.CRAFTING_TABLE,
Blocks.FURNACE, Blocks.FURNACE,
Blocks.LIT_FURNACE,
Blocks.CHEST, Blocks.CHEST,
Blocks.TRAPPED_CHEST, Blocks.TRAPPED_CHEST,
Blocks.SIGN, Blocks.STANDING_SIGN,
Blocks.WALL_SIGN Blocks.WALL_SIGN
))); )));
/**
* A list of blocks to be treated as if they're air.
* <p>
* If a schematic asks for air at a certain position, and that position currently contains a block on this list, it will be treated as correct.
*/
public final Setting<List<Block>> buildIgnoreBlocks = new Setting<>(new ArrayList<>(Arrays.asList(
)));
/**
* If this is true, the builder will treat all non-air blocks as correct. It will only place new blocks.
*/
public final Setting<Boolean> buildIgnoreExisting = new Setting<>(false);
/** /**
* If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block. * If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
* <p> * <p>
@@ -233,7 +248,7 @@ public final class Settings {
/** /**
* If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway. * If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway.
* <p> * <p>
* This helps with speed at >=20m/s * This helps with speed exceeding 20m/s
*/ */
public final Setting<Boolean> overshootTraverse = new Setting<>(true); public final Setting<Boolean> overshootTraverse = new Setting<>(true);
@@ -248,9 +263,9 @@ public final class Settings {
public final Setting<Integer> rightClickSpeed = new Setting<>(4); public final Setting<Integer> rightClickSpeed = new Setting<>(4);
/** /**
* How many degrees to randomize the yaw every tick. Set to 0 to disable * Block reach distance
*/ */
public final Setting<Double> randomLooking113 = new Setting<>(2d); public final Setting<Float> blockReachDistance = new Setting<>(4.5f);
/** /**
* How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable * How many degrees to randomize the pitch and yaw every tick. Set to 0 to disable
@@ -742,6 +757,11 @@ public final class Settings {
*/ */
public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0)); public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
/**
* How many times to buildrepeat. -1 for infinite.
*/
public final Setting<Integer> buildRepeatCount = new Setting<>(-1);
/** /**
* Allow standing above a block while mining it, in BuilderProcess * Allow standing above a block while mining it, in BuilderProcess
* <p> * <p>
@@ -791,6 +811,12 @@ public final class Settings {
*/ */
public final Setting<Boolean> schematicOrientationZ = new Setting<>(false); public final Setting<Boolean> schematicOrientationZ = new Setting<>(false);
/**
* The fallback used by the build command when no extension is specified. This may be useful if schematics of a
* particular format are used often, and the user does not wish to have to specify the extension with every usage.
*/
public final Setting<String> schematicFallbackExtension = new Setting<>("schematic");
/** /**
* Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above) * Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above)
* is only necessary in very large schematics where rescanning the whole thing is costly. * is only necessary in very large schematics where rescanning the whole thing is costly.
@@ -928,7 +954,7 @@ public final class Settings {
* via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting * via {@link Consumer#andThen(Consumer)} or it can completely be overriden via setting
* {@link Setting#value}; * {@link Setting#value};
*/ */
public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage); public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getMinecraft().ingameGUI.getChatGUI()::printChatMessage);
/** /**
* The size of the box that is rendered when the current goal is a GoalYLevel * The size of the box that is rendered when the current goal is a GoalYLevel
@@ -0,0 +1,80 @@
/*
* 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.bot;
import baritone.api.IBaritone;
import baritone.api.utils.IPlayerController;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.util.Session;
/**
* @author Brady
* @since 10/23/2018
*/
public interface IBaritoneUser {
/**
* @return The network manager that is responsible for the current connection.
*/
NetworkManager getNetworkManager();
/**
* Returns the current play network handler. Can also be acquired via
* {@link NetworkManager#getNetHandler()} from {@link #getNetworkManager()},
* and checking if the {@link INetHandler} is an instance of {@link INetHandlerPlayClient}.
*
* @return The current play network handler
*/
INetHandlerPlayClient getConnection();
/**
* @return The locally managed entity for this user.
*/
EntityPlayerSP getEntity();
/**
* @return The bot player controller
*/
IPlayerController getPlayerController();
/**
* Returns the user login session. Should never be {@code null}, as this should be set when the
* user is constructed.
*
* @return This users's login session
*/
Session getSession();
/**
* Returns the game profile for the account represented by this user.
*
* @return This users's profile.
*/
GameProfile getProfile();
/**
* @return The manager that spawned this {@link IBaritoneUser}.
*/
IUserManager getManager();
IBaritone getBaritone();
}
@@ -0,0 +1,73 @@
/*
* 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.bot;
import baritone.api.bot.connect.IConnectionResult;
import com.mojang.authlib.GameProfile;
import net.minecraft.util.Session;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
/**
* @author Brady
* @since 1/17/2019
*/
public interface IUserManager {
/**
* Connects a new user with the specified {@link Session} to the current server.
*
* @param session The user session
* @return The result of the attempted connection
*/
IConnectionResult connect(Session session);
/**
* Disconnects the specified {@link IBaritoneUser} from its current server.
*
* @param user The user to disconnect
*/
void disconnect(IBaritoneUser user);
/**
* Finds the {@link IBaritoneUser} associated with the specified {@link GameProfile}
*
* @param profile The game profile of the user
* @return The user, {@link Optional#empty()} if no match or {@code profile} is {@code null}
*/
default Optional<IBaritoneUser> getUserByProfile(GameProfile profile) {
return profile == null ? Optional.empty() : users().stream().filter(user -> user.getProfile().equals(profile)).findFirst();
}
/**
* Finds the {@link IBaritoneUser} associated with the specified {@link UUID}
*
* @param uuid The uuid of the user
* @return The user, {@link Optional#empty()} if no match or {@code uuid} is {@code null}
*/
default Optional<IBaritoneUser> getUserByUUID(UUID uuid) {
return uuid == null ? Optional.empty() : users().stream().filter(user -> user.getProfile().getId().equals(uuid)).findFirst();
}
/**
* @return All of the users held by this manager
*/
List<IBaritoneUser> users();
}
@@ -0,0 +1,45 @@
/*
* 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.bot.connect;
/**
* @author Brady
* @since 11/6/2018
*/
public enum ConnectionStatus {
/**
* The local player is not connected to a server, therefore, there is no target server to connect to.
*/
NO_CURRENT_CONNECTION,
/**
* The IP of the targetted address to connect to could not be resolved.
*/
CANT_RESOLVE_HOST,
/**
* The connection initialization failed.
*/
CONNECTION_FAILED,
/**
* The connection was a success
*/
SUCCESS
}
@@ -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.bot.connect;
import baritone.api.bot.IBaritoneUser;
import java.util.Optional;
/**
* @author Brady
* @since 1/17/2019
*/
public interface IConnectionResult {
/**
* @return The actual status of the connection attempt.
* @see ConnectionStatus
*/
ConnectionStatus getStatus();
/**
* Returns the user that was created in this connection this result reflects, if
* {@link #getStatus()} is {@link ConnectionStatus#SUCCESS}, otherwise it will
* return {@link Optional#empty()}.
*
* @return The user created in the connection
*/
Optional<IBaritoneUser> getUser();
}
-2
View File
@@ -81,6 +81,4 @@ public interface ICachedWorld {
* in a new thread by default. * in a new thread by default.
*/ */
void save(); void save();
} }
+13 -3
View File
@@ -77,10 +77,20 @@ public interface IWorldScanner {
} }
/** /**
* Repacks 40 chunks around the player. * Overload of {@link #repack(IPlayerContext, int)} where the value of the {@code range} parameter is {@code 40}.
* *
* @param ctx The player context for that player. * @param ctx The player, describing the origin
* @return The number of chunks queued for repacking. * @return The amount of chunks successfully queued for repacking
*/ */
int repack(IPlayerContext ctx); int repack(IPlayerContext ctx);
/**
* Queues the chunks in a square formation around the specified player, using the specified
* range, which represents 1/2 the square's dimensions, where the player is in the center.
*
* @param ctx The player, describing the origin
* @param range The range to repack
* @return The amount of chunks successfully queued for repacking
*/
int repack(IPlayerContext ctx, int range);
} }
@@ -22,7 +22,6 @@ import baritone.api.command.exception.CommandException;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -33,7 +32,7 @@ public enum BlockById implements IDatatypeFor<Block> {
public Block get(IDatatypeContext ctx) throws CommandException { public Block get(IDatatypeContext ctx) throws CommandException {
ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString()); ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString());
Block block; Block block;
if ((block = IRegistry.BLOCK.get(id)) == Blocks.AIR) { if ((block = Block.REGISTRY.getObject(id)) == Blocks.AIR) {
throw new IllegalArgumentException("no block found by that id"); throw new IllegalArgumentException("no block found by that id");
} }
return block; return block;
@@ -43,7 +42,7 @@ public enum BlockById implements IDatatypeFor<Block> {
public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException { public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException {
return new TabCompleteHelper() return new TabCompleteHelper()
.append( .append(
IRegistry.BLOCK.keySet() Block.REGISTRY.getKeys()
.stream() .stream()
.map(Object::toString) .map(Object::toString)
) )
@@ -17,22 +17,22 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.EntityType; import baritone.api.command.exception.CommandException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import java.util.stream.Stream; import java.util.stream.Stream;
public enum EntityClassById implements IDatatypeFor<EntityType> { public enum EntityClassById implements IDatatypeFor<Class<? extends Entity>> {
INSTANCE; INSTANCE;
@Override @Override
public EntityType get(IDatatypeContext ctx) throws CommandException { public Class<? extends Entity> get(IDatatypeContext ctx) throws CommandException {
ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString()); ResourceLocation id = new ResourceLocation(ctx.getConsumer().getString());
EntityType entity; Class<? extends Entity> entity;
if ((entity = IRegistry.ENTITY_TYPE.get(id)) == null) { if ((entity = EntityList.REGISTRY.getObject(id)) == null) {
throw new IllegalArgumentException("no entity found by that id"); throw new IllegalArgumentException("no entity found by that id");
} }
return entity; return entity;
@@ -41,7 +41,7 @@ public enum EntityClassById implements IDatatypeFor<EntityType> {
@Override @Override
public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException { public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException {
return new TabCompleteHelper() return new TabCompleteHelper()
.append(IRegistry.ENTITY_TYPE.stream().map(Object::toString)) .append(EntityList.getEntityNameList().stream().map(Object::toString))
.filterPrefixNamespaced(ctx.getConsumer().getString()) .filterPrefixNamespaced(ctx.getConsumer().getString())
.sortAlphabetically() .sortAlphabetically()
.stream(); .stream();
@@ -18,10 +18,9 @@
package baritone.api.command.datatypes; package baritone.api.command.datatypes;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.ITextComponent;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -37,14 +36,14 @@ public enum NearbyPlayer implements IDatatypeFor<EntityPlayer> {
public EntityPlayer get(IDatatypeContext ctx) throws CommandException { public EntityPlayer get(IDatatypeContext ctx) throws CommandException {
final String username = ctx.getConsumer().getString(); final String username = ctx.getConsumer().getString();
return getPlayers(ctx).stream() return getPlayers(ctx).stream()
.filter(s -> s.getName().getString().equalsIgnoreCase(username)) .filter(s -> s.getName().equalsIgnoreCase(username))
.findFirst().orElse(null); .findFirst().orElse(null);
} }
@Override @Override
public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException { public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException {
return new TabCompleteHelper() return new TabCompleteHelper()
.append(getPlayers(ctx).stream().map(EntityPlayer::getName).map(ITextComponent::getString)) .append(getPlayers(ctx).stream().map(EntityPlayer::getName))
.filterPrefix(ctx.getConsumer().getString()) .filterPrefix(ctx.getConsumer().getString())
.sortAlphabetically() .sortAlphabetically()
.stream(); .stream();
@@ -38,38 +38,26 @@ public enum RelativeGoal implements IDatatypePost<Goal, BetterBlockPos> {
if (origin == null) { if (origin == null) {
origin = BetterBlockPos.ORIGIN; origin = BetterBlockPos.ORIGIN;
} }
final IArgConsumer consumer = ctx.getConsumer(); final IArgConsumer consumer = ctx.getConsumer();
List<IDatatypePostFunction<Double, Double>> coords = new ArrayList<>(); GoalBlock goalBlock = consumer.peekDatatypePostOrNull(RelativeGoalBlock.INSTANCE, origin);
final IArgConsumer copy = consumer.copy(); // This is a hack and should be fixed in the future probably if (goalBlock != null) {
for (int i = 0; i < 3; i++) { return goalBlock;
if (copy.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
coords.add(o -> consumer.getDatatypePost(RelativeCoordinate.INSTANCE, o));
copy.get(); // Consume so we actually decrement the remaining arguments
}
} }
switch (coords.size()) { GoalXZ goalXZ = consumer.peekDatatypePostOrNull(RelativeGoalXZ.INSTANCE, origin);
case 0: if (goalXZ != null) {
return new GoalBlock(origin); return goalXZ;
case 1:
return new GoalYLevel(
MathHelper.floor(coords.get(0).apply((double) origin.y))
);
case 2:
return new GoalXZ(
MathHelper.floor(coords.get(0).apply((double) origin.x)),
MathHelper.floor(coords.get(1).apply((double) origin.z))
);
case 3:
return new GoalBlock(
MathHelper.floor(coords.get(0).apply((double) origin.x)),
MathHelper.floor(coords.get(1).apply((double) origin.y)),
MathHelper.floor(coords.get(2).apply((double) origin.z))
);
default:
throw new IllegalStateException("Unexpected coords size: " + coords.size());
} }
GoalYLevel goalYLevel = consumer.peekDatatypePostOrNull(RelativeGoalYLevel.INSTANCE, origin);
if (goalYLevel != null) {
return goalYLevel;
}
// when the user doesn't input anything, default to the origin
return new GoalBlock(origin);
} }
@Override @Override
@@ -22,4 +22,8 @@ public abstract class CommandErrorMessageException extends CommandException {
protected CommandErrorMessageException(String reason) { protected CommandErrorMessageException(String reason) {
super(reason); super(reason);
} }
protected CommandErrorMessageException(String reason, Throwable cause) {
super(reason, cause);
}
} }
@@ -22,4 +22,8 @@ public abstract class CommandException extends Exception implements ICommandExce
protected CommandException(String reason) { protected CommandException(String reason) {
super(reason); super(reason);
} }
protected CommandException(String reason, Throwable cause) {
super(reason, cause);
}
} }
@@ -23,12 +23,21 @@ public abstract class CommandInvalidArgumentException extends CommandErrorMessag
public final ICommandArgument arg; public final ICommandArgument arg;
protected CommandInvalidArgumentException(ICommandArgument arg, String reason) { protected CommandInvalidArgumentException(ICommandArgument arg, String message) {
super(String.format( super(formatMessage(arg, message));
"Error at argument #%s: %s",
arg.getIndex() == -1 ? "<unknown>" : Integer.toString(arg.getIndex() + 1),
reason
));
this.arg = arg; this.arg = arg;
} }
protected CommandInvalidArgumentException(ICommandArgument arg, String message, Throwable cause) {
super(formatMessage(arg, message), cause);
this.arg = arg;
}
private static String formatMessage(ICommandArgument arg, String message) {
return String.format(
"Error at argument #%s: %s",
arg.getIndex() == -1 ? "<unknown>" : Integer.toString(arg.getIndex() + 1),
message
);
}
} }
@@ -26,7 +26,7 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
} }
public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) { public CommandInvalidTypeException(ICommandArgument arg, String expected, Throwable cause) {
super(arg, String.format("Expected %s.\nMore details: %s", expected, cause.getMessage())); super(arg, String.format("Expected %s", expected), cause);
} }
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) { public CommandInvalidTypeException(ICommandArgument arg, String expected, String got) {
@@ -34,6 +34,6 @@ public class CommandInvalidTypeException extends CommandInvalidArgumentException
} }
public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) { public CommandInvalidTypeException(ICommandArgument arg, String expected, String got, Throwable cause) {
super(arg, String.format("Expected %s, but got %s instead.\nMore details: %s", expected, got, cause.getMessage())); super(arg, String.format("Expected %s, but got %s instead", expected, got), cause);
} }
} }
@@ -23,7 +23,7 @@ import baritone.api.event.events.type.Overrideable;
/** /**
* @author LoganDark * @author LoganDark
*/ */
public final class TabCompleteEvent extends Cancellable { public class TabCompleteEvent extends Cancellable {
public final String prefix; public final String prefix;
public String[] completions; public String[] completions;
@@ -19,22 +19,20 @@ package baritone.api.event.events;
import baritone.api.event.events.type.EventState; import baritone.api.event.events.type.EventState;
import java.util.function.BiFunction;
public final class TickEvent { public final class TickEvent {
private static int overallTickCount;
private final EventState state; private final EventState state;
private final Type type; private final Type type;
private final int count; private final int count;
private static int overallTickCount; public TickEvent(EventState state, Type type, int count) {
public TickEvent(EventState state, Type type) {
this.state = state; this.state = state;
this.type = type; this.type = type;
this.count = incrementCount(); this.count = count;
}
private static synchronized int incrementCount() {
return overallTickCount++;
} }
public int getCount() { public int getCount() {
@@ -49,6 +47,10 @@ public final class TickEvent {
return state; return state;
} }
public static synchronized BiFunction<EventState, Type, TickEvent> createNextProvider() {
final int count = overallTickCount++;
return (state, type) -> new TickEvent(state, type, count);
}
public enum Type { public enum Type {
/** /**
@@ -18,11 +18,12 @@
package baritone.api.event.listener; package baritone.api.event.listener;
import baritone.api.event.events.*; import baritone.api.event.events.*;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiGameOver; import net.minecraft.client.gui.GuiGameOver;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
@@ -44,7 +45,7 @@ public interface IGameEventListener {
* Run once per game tick from before and after the player rotation is sent to the server. * Run once per game tick from before and after the player rotation is sent to the server.
* *
* @param event The event * @param event The event
* @see EntityPlayerSP#tick() * @see EntityPlayerSP#onUpdate()
*/ */
void onPlayerUpdate(PlayerUpdateEvent event); void onPlayerUpdate(PlayerUpdateEvent event);
@@ -67,11 +68,14 @@ public interface IGameEventListener {
* Runs before and after whenever a chunk is either loaded, unloaded, or populated. * Runs before and after whenever a chunk is either loaded, unloaded, or populated.
* *
* @param event The event * @param event The event
* @see WorldClient#doPreChunk(int, int, boolean)
*/ */
void onChunkEvent(ChunkEvent event); void onChunkEvent(ChunkEvent event);
/** /**
* Runs once per world render pass. * Runs once per world render pass. Two passes are made when {@link GameSettings#anaglyph} is on.
* <p>
* <b>Note:</b> {@link GameSettings#anaglyph} has been removed in Minecraft 1.13
* *
* @param event The event * @param event The event
*/ */
@@ -81,7 +85,7 @@ public interface IGameEventListener {
* Runs before and after whenever a new world is loaded * Runs before and after whenever a new world is loaded
* *
* @param event The event * @param event The event
* @see Minecraft#loadWorld(WorldClient, GuiScreen) * @see Minecraft#loadWorld(WorldClient, String)
*/ */
void onWorldEvent(WorldEvent event); void onWorldEvent(WorldEvent event);
@@ -90,6 +94,7 @@ public interface IGameEventListener {
* *
* @param event The event * @param event The event
* @see Packet * @see Packet
* @see GenericFutureListener
*/ */
void onSendPacket(PacketEvent event); void onSendPacket(PacketEvent event);
@@ -98,6 +103,7 @@ public interface IGameEventListener {
* *
* @param event The event * @param event The event
* @see Packet * @see Packet
* @see GenericFutureListener
*/ */
void onReceivePacket(PacketEvent event); void onReceivePacket(PacketEvent event);
@@ -111,10 +117,10 @@ public interface IGameEventListener {
void onPlayerRotationMove(RotationMoveEvent event); void onPlayerRotationMove(RotationMoveEvent event);
/** /**
* Called whenever the sprint keybind state is checked in {@link EntityPlayerSP#livingTick} * Called whenever the sprint keybind state is checked in {@link EntityPlayerSP#onLivingUpdate}
* *
* @param event The event * @param event The event
* @see EntityPlayerSP#livingTick() * @see EntityPlayerSP#onLivingUpdate()
*/ */
void onPlayerSprintState(SprintStateEvent event); void onPlayerSprintState(SprintStateEvent event);
@@ -105,7 +105,7 @@ public interface IPath {
* Returns the estimated number of ticks to complete the path from the given node index. * Returns the estimated number of ticks to complete the path from the given node index.
* *
* @param pathPosition The index of the node we're calculating from * @param pathPosition The index of the node we're calculating from
* @return The estimated number of ticks remaining frm the given position * @return The estimated number of ticks remaining from the given position
*/ */
default double ticksRemainingFrom(int pathPosition) { default double ticksRemainingFrom(int pathPosition) {
double sum = 0; double sum = 0;
@@ -117,6 +117,15 @@ public interface IPath {
return sum; return sum;
} }
/**
* Returns the estimated amount of time needed to complete this path from start to finish
*
* @return The estimated amount of time, in ticks
*/
default double totalTicks() {
return ticksRemainingFrom(0);
}
/** /**
* Cuts off this path at the loaded chunk border, and returns the resulting path. Default * Cuts off this path at the loaded chunk border, and returns the resulting path. Default
* implementation just returns this path, without the intended functionality. * implementation just returns this path, without the intended functionality.
@@ -52,7 +52,7 @@ public interface IBuilderProcess extends IBaritoneProcess {
boolean build(String name, File schematic, Vec3i origin); boolean build(String name, File schematic, Vec3i origin);
default boolean build(String schematicFile, BlockPos origin) { default boolean build(String schematicFile, BlockPos origin) {
File file = new File(new File(Minecraft.getInstance().gameDir, "schematics"), schematicFile); File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile);
return build(schematicFile, file, origin); return build(schematicFile, file, origin);
} }
@@ -23,6 +23,10 @@ public abstract class AbstractSchematic implements ISchematic {
protected int y; protected int y;
protected int z; protected int z;
public AbstractSchematic() {
this(0, 0, 0);
}
public AbstractSchematic(int x, int y, int z) { public AbstractSchematic(int x, int y, int z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -32,6 +32,10 @@ public class FillSchematic extends AbstractSchematic {
this.bom = bom; this.bom = bom;
} }
public FillSchematic(int x, int y, int z, IBlockState state) {
this(x, y, z, new BlockOptionalMeta(state.getBlock(), state.getBlock().getMetaFromState(state)));
}
public BlockOptionalMeta getBom() { public BlockOptionalMeta getBom() {
return bom; return bom;
} }
@@ -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.schematic;
import baritone.api.command.registry.Registry;
import baritone.api.schematic.format.ISchematicFormat;
import java.io.File;
import java.util.Optional;
/**
* @author Brady
* @since 12/23/2019
*/
public interface ISchematicSystem {
/**
* @return The registry of supported schematic formats
*/
Registry<ISchematicFormat> getRegistry();
/**
* Attempts to find an {@link ISchematicFormat} that supports the specified schematic file.
*
* @param file A schematic file
* @return The corresponding format for the file, {@link Optional#empty()} if no candidates were found.
*/
Optional<ISchematicFormat> getByFile(File file);
}
@@ -0,0 +1,60 @@
/*
* 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.schematic;
import net.minecraft.block.state.IBlockState;
/**
* A static schematic is capable of providing the desired state at a given position without
* additional context. Schematics of this type are expected to have non-varying contents.
*
* @see #getDirect(int, int, int)
*
* @author Brady
* @since 12/24/2019
*/
public interface IStaticSchematic extends ISchematic {
/**
* Gets the {@link IBlockState} for a given position in this schematic. It should be guaranteed
* that the return value of this method will not change given that the parameters are the same.
*
* @param x The X block position
* @param y The Y block position
* @param z The Z block position
* @return The desired state at the specified position.
*/
IBlockState getDirect(int x, int y, int z);
/**
* Returns an {@link IBlockState} array of size {@link #heightY()} which contains all
* desired block states in the specified vertical column. The index of {@link IBlockState}s
* in the array are equivalent to their Y position in the schematic.
*
* @param x The X column position
* @param z The Z column position
* @return An {@link IBlockState} array
*/
default IBlockState[] getColumn(int x, int z) {
IBlockState[] column = new IBlockState[this.heightY()];
for (int i = 0; i < this.heightY(); i++) {
column[i] = getDirect(x, i, z);
}
return column;
}
}
@@ -0,0 +1,45 @@
/*
* 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.schematic.format;
import baritone.api.schematic.ISchematic;
import baritone.api.schematic.IStaticSchematic;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* The base of a {@link ISchematic} file format
*
* @author Brady
* @since 12/23/2019
*/
public interface ISchematicFormat {
/**
* @return The parser for creating schematics of this format
*/
IStaticSchematic parse(InputStream input) throws IOException;
/**
* @param file The file to check against
* @return Whether or not the specified file matches this schematic format
*/
boolean isFileType(File file);
}
@@ -20,37 +20,45 @@ package baritone.api.utils;
import baritone.api.utils.accessor.IItemStack; import baritone.api.utils.accessor.IItemStack;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.IProperty;
import net.minecraft.state.properties.*;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*; import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.MatchResult; import java.util.regex.MatchResult;
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;
public final class BlockOptionalMeta { public final class BlockOptionalMeta {
private final Block block; private final Block block;
private final int meta;
private final boolean noMeta;
private final Set<IBlockState> blockstates; private final Set<IBlockState> blockstates;
private final ImmutableSet<Integer> stateHashes; private final ImmutableSet<Integer> stateHashes;
private final ImmutableSet<Integer> stackHashes; private final ImmutableSet<Integer> stackHashes;
private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$"); private static final Pattern pattern = Pattern.compile("^(.+?)(?::(\\d+))?$");
private static final Map<Object, Object> normalizations; private static final Map<Object, Object> normalizations;
public BlockOptionalMeta(@Nonnull Block block) { public BlockOptionalMeta(@Nonnull Block block, @Nullable Integer meta) {
this.block = block; this.block = block;
this.blockstates = getStates(block); this.noMeta = meta == null;
this.meta = noMeta ? 0 : meta;
this.blockstates = getStates(block, meta);
this.stateHashes = getStateHashes(blockstates); this.stateHashes = getStateHashes(blockstates);
this.stackHashes = getStackHashes(blockstates); this.stackHashes = getStackHashes(blockstates);
} }
public BlockOptionalMeta(@Nonnull Block block) {
this(block, null);
}
public BlockOptionalMeta(@Nonnull String selector) { public BlockOptionalMeta(@Nonnull String selector) {
Matcher matcher = pattern.matcher(selector); Matcher matcher = pattern.matcher(selector);
@@ -59,15 +67,17 @@ public final class BlockOptionalMeta {
} }
MatchResult matchResult = matcher.toMatchResult(); MatchResult matchResult = matcher.toMatchResult();
noMeta = matchResult.group(2) == null;
ResourceLocation id = new ResourceLocation(matchResult.group(1)); ResourceLocation id = new ResourceLocation(matchResult.group(1));
if (!IRegistry.BLOCK.containsKey(id)) { if (!Block.REGISTRY.containsKey(id)) {
throw new IllegalArgumentException("Invalid block ID"); throw new IllegalArgumentException("Invalid block ID");
} }
block = IRegistry.BLOCK.get(id); block = Block.REGISTRY.getObject(id);
blockstates = getStates(block); meta = noMeta ? 0 : Integer.parseInt(matchResult.group(2));
blockstates = getStates(block, getMeta());
stateHashes = getStateHashes(blockstates); stateHashes = getStateHashes(blockstates);
stackHashes = getStackHashes(blockstates); stackHashes = getStackHashes(blockstates);
} }
@@ -77,14 +87,17 @@ public final class BlockOptionalMeta {
Consumer<Enum> put = instance -> _normalizations.put(instance.getClass(), instance); Consumer<Enum> put = instance -> _normalizations.put(instance.getClass(), instance);
put.accept(EnumFacing.NORTH); put.accept(EnumFacing.NORTH);
put.accept(EnumFacing.Axis.Y); put.accept(EnumFacing.Axis.Y);
put.accept(Half.BOTTOM); put.accept(BlockLog.EnumAxis.Y);
put.accept(StairsShape.STRAIGHT); put.accept(BlockStairs.EnumHalf.BOTTOM);
put.accept(AttachFace.FLOOR); put.accept(BlockStairs.EnumShape.STRAIGHT);
put.accept(DoubleBlockHalf.UPPER); put.accept(BlockLever.EnumOrientation.DOWN_X);
put.accept(SlabType.BOTTOM); put.accept(BlockDoublePlant.EnumBlockHalf.LOWER);
put.accept(DoorHingeSide.LEFT); put.accept(BlockSlab.EnumBlockHalf.BOTTOM);
put.accept(BedPart.HEAD); put.accept(BlockDoor.EnumDoorHalf.LOWER);
put.accept(RailShape.NORTH_SOUTH); put.accept(BlockDoor.EnumHingePosition.LEFT);
put.accept(BlockBed.EnumPartType.HEAD);
put.accept(BlockRailBase.EnumRailDirection.NORTH_SOUTH);
put.accept(BlockTrapDoor.DoorHalf.BOTTOM);
_normalizations.put(BlockBanner.ROTATION, 0); _normalizations.put(BlockBanner.ROTATION, 0);
_normalizations.put(BlockBed.OCCUPIED, false); _normalizations.put(BlockBed.OCCUPIED, false);
_normalizations.put(BlockBrewingStand.HAS_BOTTLE[0], false); _normalizations.put(BlockBrewingStand.HAS_BOTTLE[0], false);
@@ -102,7 +115,7 @@ public final class BlockOptionalMeta {
_normalizations.put(BlockChorusPlant.DOWN, false); _normalizations.put(BlockChorusPlant.DOWN, false);
// _normalizations.put(BlockCocoa.AGE, 0); // _normalizations.put(BlockCocoa.AGE, 0);
// _normalizations.put(BlockCrops.AGE, 0); // _normalizations.put(BlockCrops.AGE, 0);
_normalizations.put(BlockDirtSnowy.SNOWY, false); _normalizations.put(BlockDirt.SNOWY, false);
_normalizations.put(BlockDoor.OPEN, false); _normalizations.put(BlockDoor.OPEN, false);
_normalizations.put(BlockDoor.POWERED, false); _normalizations.put(BlockDoor.POWERED, false);
// _normalizations.put(BlockFarmland.MOISTURE, 0); // _normalizations.put(BlockFarmland.MOISTURE, 0);
@@ -117,7 +130,7 @@ public final class BlockOptionalMeta {
_normalizations.put(BlockFire.EAST, false); _normalizations.put(BlockFire.EAST, false);
_normalizations.put(BlockFire.SOUTH, false); _normalizations.put(BlockFire.SOUTH, false);
_normalizations.put(BlockFire.WEST, false); _normalizations.put(BlockFire.WEST, false);
_normalizations.put(BlockFire.UP, false); _normalizations.put(BlockFire.UPPER, false);
// _normalizations.put(BlockFrostedIce.AGE, 0); // _normalizations.put(BlockFrostedIce.AGE, 0);
_normalizations.put(BlockGrass.SNOWY, false); _normalizations.put(BlockGrass.SNOWY, false);
// _normalizations.put(BlockHopper.ENABLED, true); // _normalizations.put(BlockHopper.ENABLED, true);
@@ -125,7 +138,7 @@ public final class BlockOptionalMeta {
// _normalizations.put(BlockLiquid.LEVEL, 0); // _normalizations.put(BlockLiquid.LEVEL, 0);
// _normalizations.put(BlockMycelium.SNOWY, false); // _normalizations.put(BlockMycelium.SNOWY, false);
// _normalizations.put(BlockNetherWart.AGE, false); // _normalizations.put(BlockNetherWart.AGE, false);
_normalizations.put(BlockLeaves.DISTANCE, false); _normalizations.put(BlockLeaves.CHECK_DECAY, false);
// _normalizations.put(BlockLeaves.DECAYABLE, false); // _normalizations.put(BlockLeaves.DECAYABLE, false);
// _normalizations.put(BlockObserver.POWERED, false); // _normalizations.put(BlockObserver.POWERED, false);
_normalizations.put(BlockPane.NORTH, false); _normalizations.put(BlockPane.NORTH, false);
@@ -135,6 +148,8 @@ public final class BlockOptionalMeta {
// _normalizations.put(BlockPistonBase.EXTENDED, false); // _normalizations.put(BlockPistonBase.EXTENDED, false);
// _normalizations.put(BlockPressurePlate.POWERED, false); // _normalizations.put(BlockPressurePlate.POWERED, false);
// _normalizations.put(BlockPressurePlateWeighted.POWER, false); // _normalizations.put(BlockPressurePlateWeighted.POWER, false);
_normalizations.put(BlockQuartz.EnumType.LINES_X, BlockQuartz.EnumType.LINES_Y);
_normalizations.put(BlockQuartz.EnumType.LINES_Z, BlockQuartz.EnumType.LINES_Y);
// _normalizations.put(BlockRailDetector.POWERED, false); // _normalizations.put(BlockRailDetector.POWERED, false);
// _normalizations.put(BlockRailPowered.POWERED, false); // _normalizations.put(BlockRailPowered.POWERED, false);
_normalizations.put(BlockRedstoneWire.NORTH, false); _normalizations.put(BlockRedstoneWire.NORTH, false);
@@ -143,6 +158,7 @@ public final class BlockOptionalMeta {
_normalizations.put(BlockRedstoneWire.WEST, false); _normalizations.put(BlockRedstoneWire.WEST, false);
// _normalizations.put(BlockReed.AGE, false); // _normalizations.put(BlockReed.AGE, false);
_normalizations.put(BlockSapling.STAGE, 0); _normalizations.put(BlockSapling.STAGE, 0);
_normalizations.put(BlockSkull.NODROP, false);
_normalizations.put(BlockStandingSign.ROTATION, 0); _normalizations.put(BlockStandingSign.ROTATION, 0);
_normalizations.put(BlockStem.AGE, 0); _normalizations.put(BlockStem.AGE, 0);
_normalizations.put(BlockTripWire.NORTH, false); _normalizations.put(BlockTripWire.NORTH, false);
@@ -162,38 +178,49 @@ public final class BlockOptionalMeta {
normalizations = Collections.unmodifiableMap(_normalizations); normalizations = Collections.unmodifiableMap(_normalizations);
} }
private static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) { public static <C extends Comparable<C>, P extends IProperty<C>> P castToIProperty(Object value) {
//noinspection unchecked //noinspection unchecked
return (P) value; return (P) value;
} }
private static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) { public static <C extends Comparable<C>, P extends IProperty<C>> C castToIPropertyValue(P iproperty, Object value) {
//noinspection unchecked //noinspection unchecked
return (C) value; return (C) value;
} }
/**
* Normalizes the specified blockstate by setting meta-affecting properties which
* are not being targeted by the meta parameter to their default values.
* <p>
* For example, block variant/color is the primary target for the meta value, so properties
* such as rotation/facing direction will be set to default values in order to nullify
* the effect that they have on the state's meta value.
*
* @param state The state to normalize
* @return The normalized block state
*/
public static IBlockState normalize(IBlockState state) { public static IBlockState normalize(IBlockState state) {
IBlockState newState = state; IBlockState newState = state;
for (IProperty<?> property : state.getProperties()) { for (IProperty<?> property : state.getProperties().keySet()) {
Class<?> valueClass = property.getValueClass(); Class<?> valueClass = property.getValueClass();
if (normalizations.containsKey(property)) { if (normalizations.containsKey(property)) {
try { try {
newState = newState.with( newState = newState.withProperty(
castToIProperty(property), castToIProperty(property),
castToIPropertyValue(property, normalizations.get(property)) castToIPropertyValue(property, normalizations.get(property))
); );
} catch (IllegalArgumentException ignored) {} } catch (IllegalArgumentException ignored) {}
} else if (normalizations.containsKey(state.get(property))) { } else if (normalizations.containsKey(state.getValue(property))) {
try { try {
newState = newState.with( newState = newState.withProperty(
castToIProperty(property), castToIProperty(property),
castToIPropertyValue(property, normalizations.get(state.get(property))) castToIPropertyValue(property, normalizations.get(state.getValue(property)))
); );
} catch (IllegalArgumentException ignored) {} } catch (IllegalArgumentException ignored) {}
} else if (normalizations.containsKey(valueClass)) { } else if (normalizations.containsKey(valueClass)) {
try { try {
newState = newState.with( newState = newState.withProperty(
castToIProperty(property), castToIProperty(property),
castToIPropertyValue(property, normalizations.get(valueClass)) castToIPropertyValue(property, normalizations.get(valueClass))
); );
@@ -204,12 +231,23 @@ public final class BlockOptionalMeta {
return newState; return newState;
} }
/**
* Evaluate the target meta value for the specified state. The target meta value is
* most often that which is influenced by the variant/color property of the block state.
*
* @see #normalize(IBlockState)
*
* @param state The state to check
* @return The target meta of the state
*/
public static int stateMeta(IBlockState state) { public static int stateMeta(IBlockState state) {
return state.hashCode(); return state.getBlock().getMetaFromState(normalize(state));
} }
private static Set<IBlockState> getStates(@Nonnull Block block) { private static Set<IBlockState> getStates(@Nonnull Block block, @Nullable Integer meta) {
return new HashSet<>(block.getStateContainer().getValidStates()); return block.getBlockState().getValidStates().stream()
.filter(blockstate -> meta == null || stateMeta(blockstate) == meta)
.collect(Collectors.toSet());
} }
private static ImmutableSet<Integer> getStateHashes(Set<IBlockState> blockstates) { private static ImmutableSet<Integer> getStateHashes(Set<IBlockState> blockstates) {
@@ -225,8 +263,8 @@ public final class BlockOptionalMeta {
return ImmutableSet.copyOf( return ImmutableSet.copyOf(
blockstates.stream() blockstates.stream()
.map(state -> new ItemStack( .map(state -> new ItemStack(
state.getBlock().getItemDropped(state, null, null, 0).asItem(), state.getBlock().getItemDropped(state, new Random(), 0),
1 state.getBlock().damageDropped(state)
)) ))
.map(stack -> ((IItemStack) (Object) stack).getBaritoneHash()) .map(stack -> ((IItemStack) (Object) stack).getBaritoneHash())
.toArray(Integer[]::new) .toArray(Integer[]::new)
@@ -237,6 +275,10 @@ public final class BlockOptionalMeta {
return block; return block;
} }
public Integer getMeta() {
return noMeta ? null : meta;
}
public boolean matches(@Nonnull Block block) { public boolean matches(@Nonnull Block block) {
return block == this.block; return block == this.block;
} }
@@ -250,14 +292,21 @@ public final class BlockOptionalMeta {
//noinspection ConstantConditions //noinspection ConstantConditions
int hash = ((IItemStack) (Object) stack).getBaritoneHash(); int hash = ((IItemStack) (Object) stack).getBaritoneHash();
hash -= stack.getDamage(); if (noMeta) {
hash -= stack.getItemDamage();
}
return stackHashes.contains(hash); return stackHashes.contains(hash);
} }
@Override @Override
public String toString() { public String toString() {
return String.format("BlockOptionalMeta{block=%s}", block); return String.format("BlockOptionalMeta{block=%s,meta=%s}", block, getMeta());
}
public static IBlockState blockStateFromStack(ItemStack stack) {
//noinspection deprecation
return Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getMetadata());
} }
public IBlockState getAnyBlockState() { public IBlockState getAnyBlockState() {
@@ -19,7 +19,6 @@ package baritone.api.utils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -29,7 +28,7 @@ public class BlockUtils {
private static transient Map<String, Block> resourceCache = new HashMap<>(); private static transient Map<String, Block> resourceCache = new HashMap<>();
public static String blockToString(Block block) { public static String blockToString(Block block) {
ResourceLocation loc = IRegistry.BLOCK.getKey(block); ResourceLocation loc = Block.REGISTRY.getNameForObject(block);
String name = loc.getPath(); // normally, only write the part after the minecraft: String name = loc.getPath(); // normally, only write the part after the minecraft:
if (!loc.getNamespace().equals("minecraft")) { if (!loc.getNamespace().equals("minecraft")) {
// Baritone is running on top of forge with mods installed, perhaps? // Baritone is running on top of forge with mods installed, perhaps?
@@ -57,7 +56,7 @@ public class BlockUtils {
if (resourceCache.containsKey(name)) { if (resourceCache.containsKey(name)) {
return null; // cached as null return null; // cached as null
} }
block = IRegistry.BLOCK.get(ResourceLocation.tryCreate(name.contains(":") ? name : "minecraft:" + name)); block = Block.getBlockFromName(name.contains(":") ? name : "minecraft:" + name);
Map<String, Block> copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification Map<String, Block> copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification
copy.put(name, block); copy.put(name, block);
resourceCache = copy; resourceCache = copy;
+2 -2
View File
@@ -43,7 +43,7 @@ public interface Helper {
/** /**
* Instance of the game * Instance of the game
*/ */
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getMinecraft();
static ITextComponent getPrefix() { static ITextComponent getPrefix() {
// Inner text component // Inner text component
@@ -84,7 +84,7 @@ public interface Helper {
component.appendSibling(getPrefix()); component.appendSibling(getPrefix());
component.appendSibling(new TextComponentString(" ")); component.appendSibling(new TextComponentString(" "));
Arrays.asList(components).forEach(component::appendSibling); Arrays.asList(components).forEach(component::appendSibling);
mc.addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component)); Minecraft.getMinecraft().addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component));
} }
/** /**
@@ -84,7 +84,7 @@ public interface IPlayerContext {
*/ */
default Optional<BlockPos> getSelectedBlock() { default Optional<BlockPos> getSelectedBlock() {
RayTraceResult result = objectMouseOver(); RayTraceResult result = objectMouseOver();
if (result != null && result.type == RayTraceResult.Type.BLOCK) { if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
return Optional.of(result.getBlockPos()); return Optional.of(result.getBlockPos());
} }
return Optional.empty(); return Optional.empty();
@@ -101,8 +101,8 @@ public interface IPlayerContext {
*/ */
default Optional<Entity> getSelectedEntity() { default Optional<Entity> getSelectedEntity() {
RayTraceResult result = objectMouseOver(); RayTraceResult result = objectMouseOver();
if (result != null && result.type == RayTraceResult.Type.ENTITY) { if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) {
return Optional.of(result.entity); return Optional.of(result.entityHit);
} }
return Optional.empty(); return Optional.empty();
} }
@@ -17,6 +17,7 @@
package baritone.api.utils; package baritone.api.utils;
import baritone.api.BaritoneAPI;
import net.minecraft.client.entity.EntityPlayerSP; 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;
@@ -45,6 +46,8 @@ public interface IPlayerController {
ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player); ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player);
void setGameType(GameType type);
GameType getGameType(); GameType getGameType();
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand); EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
@@ -56,6 +59,6 @@ public interface IPlayerController {
void setHittingBlock(boolean hittingBlock); void setHittingBlock(boolean hittingBlock);
default double getBlockReachDistance() { default double getBlockReachDistance() {
return this.getGameType().isCreative() ? 5.0F : 4.5F; return this.getGameType().isCreative() ? 5.0F : BaritoneAPI.getSettings().blockReachDistance.value;
} }
} }
@@ -18,7 +18,6 @@
package baritone.api.utils; package baritone.api.utils;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.RayTraceFluidMode;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@@ -41,13 +40,13 @@ public final class RayTraceUtils {
* @return The calculated raytrace result * @return The calculated raytrace result
*/ */
public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) { public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) {
Vec3d start = entity.getEyePosition(1.0F); Vec3d start = entity.getPositionEyes(1.0F);
Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation); Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation);
Vec3d end = start.add( Vec3d end = start.add(
direction.x * blockReachDistance, direction.x * blockReachDistance,
direction.y * blockReachDistance, direction.y * blockReachDistance,
direction.z * blockReachDistance direction.z * blockReachDistance
); );
return entity.world.rayTraceBlocks(start, end, RayTraceFluidMode.NEVER, false, true); return entity.world.rayTraceBlocks(start, end, false, false, true);
} }
} }
@@ -36,9 +36,6 @@ public class Rotation {
public Rotation(float yaw, float pitch) { public Rotation(float yaw, float pitch) {
this.yaw = yaw; this.yaw = yaw;
this.pitch = pitch; this.pitch = pitch;
if (Float.isInfinite(yaw) || Float.isNaN(yaw) || Float.isInfinite(pitch) || Float.isNaN(pitch)) {
throw new IllegalStateException(yaw + " " + pitch);
}
} }
/** /**
@@ -23,13 +23,7 @@ import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.math.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import java.util.Optional; import java.util.Optional;
@@ -180,14 +174,11 @@ public final class RotationUtils {
} }
IBlockState state = entity.world.getBlockState(pos); IBlockState state = entity.world.getBlockState(pos);
VoxelShape shape = state.getShape(entity.world, pos); AxisAlignedBB aabb = state.getBoundingBox(entity.world, pos);
if (shape.isEmpty()) {
shape = VoxelShapes.fullCube();
}
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) { for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = shape.getStart(EnumFacing.Axis.X) * sideOffset.x + shape.getEnd(EnumFacing.Axis.X) * (1 - sideOffset.x); double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x);
double yDiff = shape.getStart(EnumFacing.Axis.Y) * sideOffset.y + shape.getEnd(EnumFacing.Axis.Y) * (1 - sideOffset.y); double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = shape.getStart(EnumFacing.Axis.Z) * sideOffset.z + shape.getEnd(EnumFacing.Axis.Z) * (1 - sideOffset.z); double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance); possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance);
if (possibleRotation.isPresent()) { if (possibleRotation.isPresent()) {
return possibleRotation; return possibleRotation;
@@ -208,10 +199,10 @@ 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.getEyePosition(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch)); 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.type == RayTraceResult.Type.BLOCK) { if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
if (result.getBlockPos().equals(pos)) { if (result.getBlockPos().equals(pos)) {
return Optional.of(rotation); return Optional.of(rotation);
} }
@@ -20,12 +20,9 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.Settings; import baritone.api.Settings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.IRegistry;
import java.awt.*; import java.awt.*;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -46,13 +43,13 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static net.minecraft.client.Minecraft.getMinecraft;
public class SettingsUtil { public class SettingsUtil {
private static final Path SETTINGS_PATH = Minecraft.getInstance().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>.+)"); // key and value split by the first space private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>.+)"); // key and value split by the first space
private static boolean isComment(String line) { private static boolean isComment(String line) {
return line.startsWith("#") || line.startsWith("//"); return line.startsWith("#") || line.startsWith("//");
} }
@@ -236,14 +233,15 @@ public class SettingsUtil {
), ),
ITEM( ITEM(
Item.class, Item.class,
str -> IRegistry.ITEM.get(new ResourceLocation(str.trim())), str -> Item.getByNameOrId(str.trim()),
item -> IRegistry.ITEM.getKey(item).toString() item -> Item.REGISTRY.getNameForObject(item).toString()
), ),
LIST() { LIST() {
@Override @Override
public Object parse(ParserContext context, String raw) { public Object parse(ParserContext context, String raw) {
Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0]; Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0];
Parser parser = Parser.getParser(type); Parser parser = Parser.getParser(type);
return Stream.of(raw.split(",")) return Stream.of(raw.split(","))
.map(s -> parser.parse(context, s)) .map(s -> parser.parse(context, s))
.collect(Collectors.toList()); .collect(Collectors.toList());
+5 -12
View File
@@ -20,10 +20,9 @@ package baritone.api.utils;
import net.minecraft.block.BlockFire; import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB;
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 net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
@@ -44,16 +43,10 @@ public final class VecUtils {
*/ */
public static Vec3d calculateBlockCenter(World world, BlockPos pos) { public static Vec3d calculateBlockCenter(World world, BlockPos pos) {
IBlockState b = world.getBlockState(pos); IBlockState b = world.getBlockState(pos);
VoxelShape shape = b.getCollisionShape(world, pos); AxisAlignedBB bbox = b.getBoundingBox(world, pos);
if (shape.isEmpty()) { double xDiff = (bbox.minX + bbox.maxX) / 2;
return getBlockPosCenter(pos); double yDiff = (bbox.minY + bbox.maxY) / 2;
} double zDiff = (bbox.minZ + bbox.maxZ) / 2;
double xDiff = (shape.getStart(EnumFacing.Axis.X) + shape.getEnd(EnumFacing.Axis.X)) / 2;
double yDiff = (shape.getStart(EnumFacing.Axis.Y) + shape.getEnd(EnumFacing.Axis.Y)) / 2;
double zDiff = (shape.getStart(EnumFacing.Axis.Z) + shape.getEnd(EnumFacing.Axis.Z)) / 2;
if (Double.isNaN(xDiff) || Double.isNaN(yDiff) || Double.isNaN(zDiff)) {
throw new IllegalStateException(b + " " + pos + " " + shape);
}
if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out if (b.getBlock() instanceof BlockFire) {//look at bottom of fire when putting it out
yDiff = 0; yDiff = 0;
} }
@@ -1,105 +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;
import com.google.common.base.Strings;
import com.google.gson.GsonBuilder;
import com.mojang.authlib.Agent;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication;
import net.minecraft.launchwrapper.Launch;
import java.io.File;
import java.lang.reflect.Field;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Based on GradleStart from ForgeGradle 2.3
*
* @author Brady
* @since 3/11/2019
*/
public class LaunchTesting {
public static void main(String[] args) {
Map<String, String> arguments = new HashMap<>();
hackNatives();
arguments.put("version", "BaritownedDeveloperEnvironment");
arguments.put("assetIndex", System.getenv("assetIndex"));
arguments.put("assetsDir", System.getenv().getOrDefault("assetDirectory", "assets"));
arguments.put("accessToken", "FML");
arguments.put("userProperties", "{}");
arguments.put("tweakClass", System.getenv("tweakClass"));
String password = System.getenv("password");
if (password != null && !password.isEmpty()) {
attemptLogin(arguments, System.getenv("username"), System.getenv("password"));
}
List<String> argsArray = new ArrayList<>();
arguments.forEach((k, v) -> {
argsArray.add("--" + k);
argsArray.add(v);
});
Launch.main(argsArray.toArray(new String[0]));
}
private static void hackNatives() {
String paths = System.getProperty("java.library.path");
String nativesDir = System.getenv().get("nativesDirectory");
if (Strings.isNullOrEmpty(paths))
paths = nativesDir;
else
paths += File.pathSeparator + nativesDir;
System.setProperty("java.library.path", paths);
// hack the classloader now.
try {
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
sysPathsField.setAccessible(true);
sysPathsField.set(null, null);
} catch (Throwable ignored) {}
}
private static void attemptLogin(Map<String, String> argMap, String username, String password) {
YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) (new YggdrasilAuthenticationService(Proxy.NO_PROXY, "1")).createUserAuthentication(Agent.MINECRAFT);
auth.setUsername(username);
auth.setPassword(password);
try {
auth.logIn();
} catch (AuthenticationException var4) {
throw new RuntimeException(var4);
}
argMap.put("accessToken", auth.getAuthenticatedToken());
argMap.put("uuid", auth.getSelectedProfile().getId().toString().replace("-", ""));
argMap.put("username", auth.getSelectedProfile().getName());
argMap.put("userType", auth.getUserType().getName());
argMap.put("userProperties", (new GsonBuilder()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create().toJson(auth.getUserProperties()));
}
}
@@ -33,11 +33,11 @@ public abstract class MixinBlockStateContainer implements IBlockStateContainer {
protected BitArray storage; protected BitArray storage;
@Shadow @Shadow
protected IBlockStatePalette<IBlockState> palette; protected IBlockStatePalette palette;
@Override @Override
public IBlockState getAtPalette(int index) { public IBlockState getAtPalette(int index) {
return palette.get(index); return palette.getBlockState(index);
} }
@Override @Override
@@ -17,31 +17,23 @@
package baritone.launch.mixins; package baritone.launch.mixins;
import baritone.Baritone; import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.chunk.RenderChunkCache;
import net.minecraft.world.chunk.Chunk;
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;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(RenderChunkCache.class) @Mixin(GuiChat.ChatTabCompleter.class)
public class MixinRenderChunkCache { public abstract class MixinChatTabCompleter extends MixinTabCompleter {
@Redirect( @Inject(
method = "generateCache", method = "complete",
at = @At( at = @At("HEAD"),
value = "INVOKE", cancellable = true
target = "net/minecraft/world/chunk/Chunk.isEmptyBetween(II)Z"
) )
) private void onComplete(CallbackInfo ci) {
private static boolean isEmpty(Chunk chunk, int yStart, int yEnd) { if (dontComplete) {
if (!chunk.isEmptyBetween(yStart, yEnd)) { ci.cancel();
return false; }
}
if (chunk.isEmpty() && Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null) {
return false;
}
return true;
} }
} }
@@ -28,10 +28,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import static org.lwjgl.opengl.GL11.GL_ONE; import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL11.GL_ZERO;
import static org.lwjgl.opengl.GL14.GL_CONSTANT_ALPHA;
import static org.lwjgl.opengl.GL14.GL_ONE_MINUS_CONSTANT_ALPHA;
@Mixin(ChunkRenderContainer.class) @Mixin(ChunkRenderContainer.class)
public class MixinChunkRenderContainer { public class MixinChunkRenderContainer {
@@ -44,11 +41,11 @@ public class MixinChunkRenderContainer {
) )
) )
private BlockPos getPosition(RenderChunk renderChunkIn) { private BlockPos getPosition(RenderChunk renderChunkIn) {
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getInstance().isSingleplayer() && Minecraft.getInstance().world.getChunk(renderChunkIn.getPosition()).isEmpty()) { if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer() && Minecraft.getMinecraft().world.getChunk(renderChunkIn.getPosition()).isEmpty()) {
GlStateManager.enableAlphaTest(); GlStateManager.enableAlpha();
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.value); GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.value);
GlStateManager.blendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO); GlStateManager.tryBlendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO);
} }
return renderChunkIn.getPosition(); return renderChunkIn.getPosition();
} }
@@ -43,7 +43,7 @@ public abstract class MixinChunkRenderWorker {
) )
) )
private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) { private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) {
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getInstance().isSingleplayer()) { if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone(); Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext(); IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
@@ -23,7 +23,6 @@ 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;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EntityType;
import net.minecraft.world.World; import net.minecraft.world.World;
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;
@@ -45,8 +44,9 @@ public abstract class MixinEntityLivingBase extends Entity {
*/ */
private RotationMoveEvent jumpRotationEvent; private RotationMoveEvent jumpRotationEvent;
public MixinEntityLivingBase(EntityType<?> entityTypeIn, World worldIn) { public MixinEntityLivingBase(World worldIn, RotationMoveEvent jumpRotationEvent) {
super(entityTypeIn, worldIn); super(worldIn);
this.jumpRotationEvent = jumpRotationEvent;
} }
@Inject( @Inject(
@@ -58,10 +58,10 @@ public class MixinEntityPlayerSP {
} }
@Inject( @Inject(
method = "tick", method = "onUpdate",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.isPassenger()Z", target = "net/minecraft/client/entity/EntityPlayerSP.isRiding()Z",
shift = At.Shift.BY, shift = At.Shift.BY,
by = -3 by = -3
) )
@@ -74,7 +74,7 @@ public class MixinEntityPlayerSP {
} }
@Inject( @Inject(
method = "tick", method = "onUpdate",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.onUpdateWalkingPlayer()V", target = "net/minecraft/client/entity/EntityPlayerSP.onUpdateWalkingPlayer()V",
@@ -90,7 +90,7 @@ public class MixinEntityPlayerSP {
} }
@Redirect( @Redirect(
method = "livingTick", method = "onLivingUpdate",
at = @At( at = @At(
value = "FIELD", value = "FIELD",
target = "net/minecraft/entity/player/PlayerCapabilities.allowFlying:Z" target = "net/minecraft/entity/player/PlayerCapabilities.allowFlying:Z"
@@ -105,7 +105,7 @@ public class MixinEntityPlayerSP {
} }
@Redirect( @Redirect(
method = "livingTick", method = "onLivingUpdate",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z" target = "net/minecraft/client/settings/KeyBinding.isKeyDown()Z"
@@ -20,24 +20,24 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.event.events.RenderEvent; import baritone.api.event.events.RenderEvent;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.EntityRenderer;
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;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(GameRenderer.class) @Mixin(EntityRenderer.class)
public class MixinGameRenderer { public class MixinEntityRenderer {
@Inject( @Inject(
method = "updateCameraAndRender(FJ)V", method = "renderWorldPass",
at = @At( at = @At(
value = "INVOKE_STRING", value = "INVOKE_STRING",
target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V", target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V",
args = {"ldc=hand"} args = {"ldc=hand"}
) )
) )
private void renderWorldPass(float partialTicks, long finishTimeNano, CallbackInfo ci) { private void renderWorldPass(int pass, float partialTicks, long finishTimeNano, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks)); ibaritone.getGameEventHandler().onRenderPass(new RenderEvent(partialTicks));
} }
@@ -1,99 +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.TabCompleteEvent;
import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiTextField;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfo;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author Brady
* @since 10/9/2019
*/
@Mixin(GuiChat.class)
public class MixinGuiChat {
@Shadow
protected GuiTextField inputField;
@Shadow
@Final
protected List<String> commandUsage;
@Shadow
private CompletableFuture<Suggestions> pendingSuggestions;
@Inject(
method = "updateSuggestion",
at = @At("HEAD"),
cancellable = true
)
private void preUpdateSuggestion(CallbackInfo ci) {
// Anything that is present in the input text before the cursor position
String prefix = this.inputField.getText().substring(0, Math.min(this.inputField.getText().length(), this.inputField.getCursorPosition()));
TabCompleteEvent event = new TabCompleteEvent(prefix);
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onPreTabComplete(event);
if (event.isCancelled()) {
ci.cancel();
return;
}
if (event.completions != null) {
ci.cancel();
// TODO: Support populating the command usage
this.commandUsage.clear();
if (event.completions.length == 0) {
this.pendingSuggestions = Suggestions.empty();
} else {
int offset = this.inputField.getText().endsWith(" ")
? this.inputField.getCursorPosition()
: this.inputField.getText().lastIndexOf(" ") + 1; // If there is no space this is still 0 haha yes
List<Suggestion> suggestionList = Stream.of(event.completions)
.map(s -> new Suggestion(StringRange.between(offset, offset + s.length()), s))
.collect(Collectors.toList());
Suggestions suggestions = new Suggestions(
StringRange.between(offset, offset + suggestionList.stream().mapToInt(s -> s.getText().length()).max().orElse(0)),
suggestionList);
this.pendingSuggestions = new CompletableFuture<>();
this.pendingSuggestions.complete(suggestions);
}
}
}
}
@@ -35,14 +35,14 @@ public abstract class MixinItemStack implements IItemStack {
@Final @Final
private Item item; private Item item;
@Shadow
private int itemDamage;
@Unique @Unique
private int baritoneHash; private int baritoneHash;
@Shadow
protected abstract int getDamage();
private void recalculateHash() { private void recalculateHash() {
baritoneHash = item == null ? -1 : item.hashCode() + getDamage(); baritoneHash = item == null ? -1 : item.hashCode() + itemDamage;
} }
@Inject( @Inject(
@@ -54,7 +54,7 @@ public abstract class MixinItemStack implements IItemStack {
} }
@Inject( @Inject(
method = "setDamage", method = "setItemDamage",
at = @At("TAIL") at = @At("TAIL")
) )
private void onItemDamageSet(CallbackInfo ci) { private void onItemDamageSet(CallbackInfo ci) {
@@ -41,6 +41,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.BiFunction;
/** /**
* @author Brady * @author Brady
* @since 7/31/2018 * @since 7/31/2018
@@ -84,22 +86,24 @@ public class MixinMinecraft {
) )
) )
private void runTick(CallbackInfo ci) { private void runTick(CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { final BiFunction<EventState, TickEvent.Type, TickEvent> tickProvider = TickEvent.createNextProvider();
TickEvent.Type type = ibaritone.getPlayerContext().player() != null && ibaritone.getPlayerContext().world() != null for (IBaritone baritone : BaritoneAPI.getProvider().getAllBaritones()) {
TickEvent.Type type = baritone.getPlayerContext().player() != null && baritone.getPlayerContext().world() != null
? TickEvent.Type.IN ? TickEvent.Type.IN
: TickEvent.Type.OUT; : TickEvent.Type.OUT;
ibaritone.getGameEventHandler().onTick(new TickEvent(EventState.PRE, type)); baritone.getGameEventHandler().onTick(tickProvider.apply(EventState.PRE, type));
} }
} }
@Inject( @Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/gui/GuiScreen;)V", method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
at = @At("HEAD") at = @At("HEAD")
) )
private void preLoadWorld(WorldClient world, GuiScreen loadingScreen, CallbackInfo ci) { private void preLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it // If we're unloading the world but one doesn't exist, ignore it
if (this.world == null && world == null) { if (this.world == null && world == null) {
return; return;
@@ -116,10 +120,10 @@ public class MixinMinecraft {
} }
@Inject( @Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/gui/GuiScreen;)V", method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
at = @At("RETURN") at = @At("RETURN")
) )
private void postLoadWorld(WorldClient world, GuiScreen loadingScreen, CallbackInfo ci) { private void postLoadWorld(WorldClient world, String loadingMessage, CallbackInfo ci) {
// still fire event for both null, as that means we've just finished exiting a world // still fire event for both null, as that means we've just finished exiting a world
// mc.world changing is only the primary baritone // mc.world changing is only the primary baritone
@@ -24,7 +24,6 @@ import baritone.api.event.events.type.EventState;
import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.network.play.server.SPacketCombatEvent; import net.minecraft.network.play.server.SPacketCombatEvent;
import net.minecraft.network.play.server.SPacketUnloadChunk;
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;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -41,7 +40,7 @@ public class MixinNetHandlerPlayClient {
method = "handleChunkData", method = "handleChunkData",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/multiplayer/ChunkProviderClient.func_212474_a(IILnet/minecraft/network/PacketBuffer;IZ)Lnet/minecraft/world/chunk/Chunk;" target = "net/minecraft/world/chunk/Chunk.read(Lnet/minecraft/network/PacketBuffer;IZ)V"
) )
) )
private void preRead(SPacketChunkData packetIn, CallbackInfo ci) { private void preRead(SPacketChunkData packetIn, CallbackInfo ci) {
@@ -78,34 +77,6 @@ public class MixinNetHandlerPlayClient {
} }
} }
@Inject(
method = "processChunkUnload",
at = @At("HEAD")
)
private void preChunkUnload(SPacketUnloadChunk packet, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.PRE, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
);
}
}
}
@Inject(
method = "processChunkUnload",
at = @At("RETURN")
)
private void postChunkUnload(SPacketUnloadChunk packet, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.POST, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
);
}
}
}
@Inject( @Inject(
method = "handleCombatEvent", method = "handleCombatEvent",
at = @At( at = @At(
@@ -53,7 +53,7 @@ public class MixinNetworkManager {
method = "dispatchPacket", method = "dispatchPacket",
at = @At("HEAD") at = @At("HEAD")
) )
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) { private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>>[] futureListeners, CallbackInfo ci) {
if (this.direction != EnumPacketDirection.CLIENTBOUND) { if (this.direction != EnumPacketDirection.CLIENTBOUND) {
return; return;
} }
@@ -69,7 +69,7 @@ public class MixinNetworkManager {
method = "dispatchPacket", method = "dispatchPacket",
at = @At("RETURN") at = @At("RETURN")
) )
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) { private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>>[] futureListeners, CallbackInfo ci) {
if (this.direction != EnumPacketDirection.CLIENTBOUND) { if (this.direction != EnumPacketDirection.CLIENTBOUND) {
return; return;
} }
@@ -85,7 +85,7 @@ public class MixinNetworkManager {
method = "channelRead0", method = "channelRead0",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/network/NetworkManager.processPacket(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;)V" target = "net/minecraft/network/Packet.processPacket(Lnet/minecraft/network/INetHandler;)V"
) )
) )
private void preProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) { private void preProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
@@ -23,8 +23,8 @@ import baritone.api.utils.IPlayerContext;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.chunk.RenderChunk; import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.client.renderer.chunk.RenderChunkCache;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ChunkCache;
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;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
@@ -40,11 +40,43 @@ public class MixinRenderChunk {
method = "rebuildChunk", method = "rebuildChunk",
at = @At( at = @At(
value = "INVOKE", value = "INVOKE",
target = "net/minecraft/client/renderer/chunk/RenderChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;" target = "net/minecraft/world/ChunkCache.isEmpty()Z"
) )
) )
private IBlockState getBlockState(RenderChunkCache chunkCache, BlockPos pos) { private boolean isEmpty(ChunkCache chunkCache) {
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getInstance().isSingleplayer()) { 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(); Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext(); IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) { if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
@@ -38,9 +38,9 @@ public class MixinRenderList {
) )
) )
private void popMatrix() { private void popMatrix() {
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getInstance().isSingleplayer()) { if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
// reset the blend func to normal (not dependent on constant alpha) // reset the blend func to normal (not dependent on constant alpha)
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
} }
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@@ -0,0 +1,60 @@
/*
* 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 com.google.common.collect.ImmutableMap;
import net.minecraft.block.properties.IProperty;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(targets = "net.minecraft.block.state.BlockStateContainer$StateImplementation")
public abstract class MixinStateImplementation {
@Shadow
@Final
private ImmutableMap<IProperty<?>, Comparable<?>> properties;
/**
* Block states are fucking immutable
*/
@Unique
private int hashCode;
@Inject(
method = "<init>*",
at = @At("RETURN")
)
private void onInit(CallbackInfo ci) {
hashCode = properties.hashCode();
}
/**
* Cache this instead of using the fucking map every time
*
* @author LoganDark
* @reason Regular IBlockState generates a new hash every fucking time. This is not needed when scanning millions
* per second
*/
@Override
@Overwrite
public int hashCode() {
return hashCode;
}
}
@@ -0,0 +1,83 @@
/*
* 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.IBaritone;
import baritone.api.event.events.TabCompleteEvent;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.util.TabCompleter;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(TabCompleter.class)
public abstract class MixinTabCompleter {
@Shadow
@Final
protected GuiTextField textField;
@Shadow
protected boolean requestedCompletions;
@Shadow
public abstract void setCompletions(String... newCompl);
@Unique
protected boolean dontComplete = false;
@Inject(
method = "requestCompletions",
at = @At("HEAD"),
cancellable = true
)
private void onRequestCompletions(String prefix, CallbackInfo ci) {
if (!((Object) this instanceof GuiChat.ChatTabCompleter)) {
return;
}
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
TabCompleteEvent event = new TabCompleteEvent(prefix);
baritone.getGameEventHandler().onPreTabComplete(event);
if (event.isCancelled()) {
ci.cancel();
return;
}
if (event.completions != null) {
ci.cancel();
this.dontComplete = true;
try {
this.requestedCompletions = true;
setCompletions(event.completions);
} finally {
this.dontComplete = false;
}
}
}
}
@@ -38,9 +38,9 @@ public class MixinVboRenderList {
) )
) )
private void popMatrix() { private void popMatrix() {
if (Baritone.settings().renderCachedChunks.value && !Minecraft.getInstance().isSingleplayer()) { if (Baritone.settings().renderCachedChunks.value && !Minecraft.getMinecraft().isSingleplayer()) {
// reset the blend func to normal (not dependent on constant alpha) // reset the blend func to normal (not dependent on constant alpha)
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
} }
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@@ -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.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.ChunkEvent;
import baritone.api.event.events.type.EventState;
import net.minecraft.client.multiplayer.WorldClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* @author Brady
* @since 8/2/2018
*/
@Mixin(WorldClient.class)
public class MixinWorldClient {
@Inject(
method = "doPreChunk",
at = @At("HEAD")
)
private void preDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().world() == (WorldClient) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.PRE,
loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD,
chunkX,
chunkZ
)
);
}
}
}
@Inject(
method = "doPreChunk",
at = @At("RETURN")
)
private void postDoPreChunk(int chunkX, int chunkZ, boolean loadChunk, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().world() == (WorldClient) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
loadChunk ? ChunkEvent.Type.LOAD : ChunkEvent.Type.UNLOAD,
chunkX,
chunkZ
)
);
}
}
}
}
+6 -4
View File
@@ -11,14 +11,14 @@
"MixinAnvilChunkLoader", "MixinAnvilChunkLoader",
"MixinBitArray", "MixinBitArray",
"MixinBlockStateContainer", "MixinBlockStateContainer",
"MixinChatTabCompleter",
"MixinChunkProviderClient", "MixinChunkProviderClient",
"MixinChunkProviderServer", "MixinChunkProviderServer",
"MixinChunkRenderContainer", "MixinChunkRenderContainer",
"MixinChunkRenderWorker", "MixinChunkRenderWorker",
"MixinEntityLivingBase", "MixinEntityLivingBase",
"MixinEntityPlayerSP", "MixinEntityPlayerSP",
"MixinGameRenderer", "MixinEntityRenderer",
"MixinGuiChat",
"MixinGuiScreen", "MixinGuiScreen",
"MixinItemStack", "MixinItemStack",
"MixinMinecraft", "MixinMinecraft",
@@ -26,8 +26,10 @@
"MixinNetworkManager", "MixinNetworkManager",
"MixinPlayerControllerMP", "MixinPlayerControllerMP",
"MixinRenderChunk", "MixinRenderChunk",
"MixinRenderChunkCache",
"MixinRenderList", "MixinRenderList",
"MixinVboRenderList" "MixinStateImplementation",
"MixinTabCompleter",
"MixinVboRenderList",
"MixinWorldClient"
] ]
} }
+4 -5
View File
@@ -25,12 +25,11 @@ 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.command.manager.CommandManager;
import baritone.event.GameEventHandler; import baritone.event.GameEventHandler;
import baritone.process.*; import baritone.process.*;
import baritone.selection.SelectionManager; import baritone.selection.SelectionManager;
import baritone.utils.*; import baritone.utils.*;
import baritone.command.manager.CommandManager;
import baritone.utils.player.PrimaryPlayerContext;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import java.io.File; import java.io.File;
@@ -53,7 +52,7 @@ public class Baritone implements IBaritone {
static { static {
threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());
dir = new File(Minecraft.getInstance().gameDir, "baritone"); dir = new File(Minecraft.getMinecraft().gameDir, "baritone");
if (!Files.exists(dir.toPath())) { if (!Files.exists(dir.toPath())) {
try { try {
Files.createDirectories(dir.toPath()); Files.createDirectories(dir.toPath());
@@ -87,11 +86,11 @@ public class Baritone implements IBaritone {
public BlockStateInterface bsi; public BlockStateInterface bsi;
Baritone() { public Baritone(IPlayerContext playerContext) {
this.gameEventHandler = new GameEventHandler(this); this.gameEventHandler = new GameEventHandler(this);
// 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 = playerContext;
{ {
// 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
+24 -5
View File
@@ -19,13 +19,19 @@ package baritone;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.IBaritoneProvider; import baritone.api.IBaritoneProvider;
import baritone.api.bot.IBaritoneUser;
import baritone.api.bot.IUserManager;
import baritone.api.cache.IWorldScanner; import baritone.api.cache.IWorldScanner;
import baritone.api.command.ICommandSystem; import baritone.api.command.ICommandSystem;
import baritone.bot.UserManager;
import baritone.api.schematic.ISchematicSystem;
import baritone.command.BaritoneChatControl; import baritone.command.BaritoneChatControl;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
import baritone.command.CommandSystem; import baritone.command.CommandSystem;
import baritone.utils.player.PrimaryPlayerContext;
import baritone.utils.schematic.SchematicSystem;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@@ -35,11 +41,9 @@ import java.util.List;
public final class BaritoneProvider implements IBaritoneProvider { public final class BaritoneProvider implements IBaritoneProvider {
private final Baritone primary; private final Baritone primary;
private final List<IBaritone> all;
{ {
this.primary = new Baritone(); this.primary = new Baritone(PrimaryPlayerContext.INSTANCE);
this.all = Collections.singletonList(this.primary);
// Setup chat control, just for the primary instance // Setup chat control, just for the primary instance
new BaritoneChatControl(this.primary); new BaritoneChatControl(this.primary);
@@ -52,7 +56,12 @@ public final class BaritoneProvider implements IBaritoneProvider {
@Override @Override
public List<IBaritone> getAllBaritones() { public List<IBaritone> getAllBaritones() {
return all; List<IBaritone> baritones = new ArrayList<>();
baritones.add(getPrimaryBaritone());
for (IBaritoneUser ibu : UserManager.INSTANCE.users()) {
baritones.add(ibu.getBaritone());
}
return baritones;
} }
@Override @Override
@@ -60,8 +69,18 @@ public final class BaritoneProvider implements IBaritoneProvider {
return WorldScanner.INSTANCE; return WorldScanner.INSTANCE;
} }
@Override
public IUserManager getUserManager() {
return UserManager.INSTANCE;
}
@Override @Override
public ICommandSystem getCommandSystem() { public ICommandSystem getCommandSystem() {
return CommandSystem.INSTANCE; return CommandSystem.INSTANCE;
} }
@Override
public ISchematicSystem getSchematicSystem() {
return SchematicSystem.INSTANCE;
}
} }
@@ -134,7 +134,7 @@ public final class InventoryBehavior extends Behavior {
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) { public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z, baritone.bsi.get0(x, y, z)); IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z, baritone.bsi.get0(x, y, z));
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && maybe.equals(((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.player(), stack, ctx.playerFeet(), EnumFacing.UP, (float) ctx.player().posX, (float) ctx.player().posY, (float) ctx.player().posZ)))))) { if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && maybe.equals(((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(ctx.world(), ctx.playerFeet(), EnumFacing.UP, (float) ctx.player().posX, (float) ctx.player().posY, (float) ctx.player().posZ, stack.getItem().getMetadata(stack.getMetadata()), ctx.player())))) {
return true; // gotem return true; // gotem
} }
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) { if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
@@ -28,6 +28,9 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
/** /**
* Target's values are as follows: * Target's values are as follows:
* <p>
* getFirst() -> yaw
* getSecond() -> pitch
*/ */
private Rotation target; private Rotation target;
@@ -50,13 +53,6 @@ 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;
if (!force) {
double rand = Math.random() - 0.5;
if (Math.abs(rand) < 0.1) {
rand *= 4;
}
this.target = new Rotation(this.target.getYaw() + (float) (rand * Baritone.settings().randomLooking113.value), this.target.getPitch());
}
this.force = force || !Baritone.settings().freeLook.value; this.force = force || !Baritone.settings().freeLook.value;
} }
@@ -32,6 +32,7 @@ import net.minecraft.block.BlockBed;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketClickWindow;
import net.minecraft.network.play.client.CPacketCloseWindow; import net.minecraft.network.play.client.CPacketCloseWindow;
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock; import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
import net.minecraft.network.play.server.SPacketCloseWindow; import net.minecraft.network.play.server.SPacketCloseWindow;
@@ -117,6 +118,11 @@ public final class MemoryBehavior extends Behavior {
if (p instanceof CPacketCloseWindow) { if (p instanceof CPacketCloseWindow) {
getCurrent().save(); getCurrent().save();
} }
if (p instanceof CPacketClickWindow) {
CPacketClickWindow c = event.cast();
System.out.println("CLICK " + c.getWindowId() + " " + c.getSlotId() + " " + c.getUsedButton() + " " + c.getClickType());
}
} }
} }
@@ -154,7 +160,19 @@ public final class MemoryBehavior extends Behavior {
if (p instanceof SPacketCloseWindow) { if (p instanceof SPacketCloseWindow) {
getCurrent().save(); getCurrent().save();
} }
// apparently doesn't happen
/*if (p instanceof SPacketWindowItems) {
SPacketWindowItems meme = (SPacketWindowItems) p;
if (meme.getWindowId() == ctx.player().openContainer.windowId && enderChestWindowId != null && meme.getWindowId() == enderChestWindowId) {
System.out.println("RECEIVED GUARANTEED ECHEST CONTENTS" + meme.getItemStacks());
} }
}*/
}
}
public boolean eChestOpen() {
return enderChestWindowId != null && ctx.player().openContainer.windowId == enderChestWindowId;
} }
@Override @Override
@@ -0,0 +1,110 @@
/*
* 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.bot;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.bot.IBaritoneUser;
import baritone.api.bot.IUserManager;
import baritone.api.utils.IPlayerController;
import baritone.bot.spec.BotWorld;
import baritone.bot.spec.EntityBot;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.util.Session;
/**
* Implementation of {@link IBaritoneUser}
*
* @author Brady
* @since 11/6/2018
*/
public class BaritoneUser implements IBaritoneUser {
private final UserManager manager;
private final NetworkManager networkManager;
private final Session session;
private GameProfile profile;
private INetHandlerPlayClient netHandlerPlayClient;
private BotWorld world;
private EntityBot player;
private IPlayerController playerController;
private final Baritone baritone;
BaritoneUser(UserManager manager, NetworkManager networkManager, Session session) {
this.manager = manager;
this.networkManager = networkManager;
this.session = session;
this.baritone = new Baritone(new BotPlayerContext(this));
}
public void onLoginSuccess(GameProfile profile, INetHandlerPlayClient netHandlerPlayClient) {
this.profile = profile;
this.netHandlerPlayClient = netHandlerPlayClient;
}
public void onWorldLoad(BotWorld world, EntityBot player, IPlayerController playerController) {
this.world = world;
this.player = player;
this.playerController = playerController;
}
@Override
public NetworkManager getNetworkManager() {
return this.networkManager;
}
@Override
public INetHandlerPlayClient getConnection() {
return this.netHandlerPlayClient;
}
@Override
public EntityBot getEntity() {
return this.player;
}
@Override
public IPlayerController getPlayerController() {
return this.playerController;
}
@Override
public Session getSession() {
return this.session;
}
@Override
public GameProfile getProfile() {
return this.profile;
}
@Override
public UserManager getManager() {
return this.manager;
}
@Override
public IBaritone getBaritone() {
return baritone;
}
}
@@ -0,0 +1,80 @@
/*
* 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.bot;
import baritone.api.bot.IBaritoneUser;
import baritone.api.cache.IWorldData;
import baritone.api.utils.IPlayerContext;
import baritone.api.utils.IPlayerController;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class BotPlayerContext implements IPlayerContext {
/**
* The backing {@link IBaritoneUser}
*/
private final IBaritoneUser bot;
public BotPlayerContext(IBaritoneUser bot) {
this.bot = bot;
}
@Override
public EntityPlayerSP player() {
if (bot.getEntity() == null) {
return null;
}
return bot.getEntity();
}
@Override
public IPlayerController playerController() {
if (bot.getEntity() == null) {
return null;
}
return bot.getPlayerController();
}
@Override
public World world() {
if (bot.getEntity() == null) {
return null;
}
return bot.getEntity().world;
}
@Override
public IWorldData worldData() {
return bot.getBaritone().getWorldProvider().getCurrentWorld();
}
@Override
public RayTraceResult objectMouseOver() {
Entity entity = this.bot.getEntity();
if (entity != null) {
double blockReachDistance = this.bot.getPlayerController().getBlockReachDistance();
return entity.rayTrace(blockReachDistance, 1.0F);
}
return null;
}
}
@@ -0,0 +1,66 @@
/*
* 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.bot;
import baritone.bot.spec.BotWorld;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.world.GameType;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.WorldType;
/**
* @author Brady
* @since 11/7/2018
*/
public class BotWorldProvider {
/**
* Generic world settings for a typical survival world.
*/
private static final WorldSettings GENERIC_WORLD_SETTINGS = new WorldSettings(0L, GameType.SURVIVAL, true, false, WorldType.DEFAULT);
/**
* All of the dimensions mapped to their respective worlds.
*/
private final Int2ObjectMap<BotWorld> worlds = new Int2ObjectArrayMap<>();
/**
* Gets or creates the {@link BotWorld} for the specified dimension
*
* @param dimension The dimension id
* @return The world
*/
public BotWorld getWorld(int dimension) {
return worlds.computeIfAbsent(dimension, this::createWorldForDim);
}
/**
* Creates a new {@link BotWorld} for the given dimension id.
*
* @param dimension The dimension id
* @return The new world
*/
private BotWorld createWorldForDim(int dimension) {
return new BotWorld(GENERIC_WORLD_SETTINGS, dimension);
}
public void tick() {
this.worlds.forEach((dim, world) -> world.updateEntities());
}
}
+164
View File
@@ -0,0 +1,164 @@
/*
* 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.bot;
import baritone.api.BaritoneAPI;
import baritone.api.bot.IBaritoneUser;
import baritone.api.bot.IUserManager;
import baritone.api.bot.connect.IConnectionResult;
import baritone.api.event.events.TickEvent;
import baritone.api.event.events.type.EventState;
import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.utils.Helper;
import baritone.bot.connect.ConnectionResult;
import baritone.bot.handler.BotNetHandlerLoginClient;
import net.minecraft.client.multiplayer.ServerAddress;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.handshake.client.C00Handshake;
import net.minecraft.network.login.client.CPacketLoginStart;
import net.minecraft.util.Session;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import static baritone.api.bot.connect.ConnectionStatus.*;
/**
* @author Brady
* @since 11/6/2018
*/
public final class UserManager implements IUserManager, Helper {
public static final UserManager INSTANCE = new UserManager();
private final List<IBaritoneUser> users = new CopyOnWriteArrayList<>();
private final BotWorldProvider worldProvider;
private UserManager() {
// Setup an event listener that automatically disconnects bots when we're not in-game
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().registerEventListener(new AbstractGameEventListener() {
@Override
public final void onTick(TickEvent event) {
if (event.getState() == EventState.PRE) {
if (event.getType() == TickEvent.Type.OUT)
UserManager.this.users.forEach(UserManager.this::disconnect);
UserManager.this.worldProvider.tick();
}
}
});
this.worldProvider = new BotWorldProvider();
}
/**
* Connects a new user with the specified {@link Session} to the current server.
*
* @param session The user session
* @return The result of the attempted connection
*/
@Override
public final IConnectionResult connect(Session session) {
ServerData data = mc.getCurrentServerData();
if (data == null) {
return ConnectionResult.failed(NO_CURRENT_CONNECTION);
}
// Connect to the server from the parsed server data
return connect0(session, ServerAddress.fromString(data.serverIP));
}
/**
* Connects a new user with the specified {@link Session} to the specified server.
* <p>
* Hi Mickey :)
*
* @param session The user session
* @param address The address of the server to connect to
* @return The result of the attempted connection
*/
private IConnectionResult connect0(Session session, ServerAddress address) {
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName(address.getIP());
} catch (UnknownHostException e) {
return ConnectionResult.failed(CANT_RESOLVE_HOST);
}
try {
// Initialize Connection
NetworkManager networkManager = NetworkManager.createNetworkManagerAndConnect(
inetAddress,
address.getPort(),
mc.gameSettings.isUsingNativeTransport()
);
// Create User
BaritoneUser user = new BaritoneUser(this, networkManager, session);
this.users.add(user);
// Setup login handler and send connection packets
networkManager.setNetHandler(new BotNetHandlerLoginClient(networkManager, user));
networkManager.sendPacket(new C00Handshake(address.getIP(), address.getPort(), EnumConnectionState.LOGIN));
networkManager.sendPacket(new CPacketLoginStart(session.getProfile()));
return ConnectionResult.success(user);
} catch (Exception e) {
return ConnectionResult.failed(CONNECTION_FAILED);
}
}
/**
* Notifies the manager of an {@link IBaritoneUser} disconnect, and
* removes the {@link IBaritoneUser} from the list of users.
*
* @param user The user that disconnected
* @param state The connection state at the time of disconnect
*/
public final void notifyDisconnect(IBaritoneUser user, EnumConnectionState state) {
this.users.remove(user);
}
/**
* @return The bot world provider
*/
public final BotWorldProvider getWorldProvider() {
return this.worldProvider;
}
@Override
public final void disconnect(IBaritoneUser user) {
// It's probably fine to pass null to this, because the handlers aren't doing anything with it
// noinspection ConstantConditions
user.getNetworkManager().closeChannel(null);
this.users.remove(user);
}
@Override
public final List<IBaritoneUser> users() {
return Collections.unmodifiableList(this.users);
}
}
@@ -0,0 +1,87 @@
/*
* 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.bot.connect;
import baritone.api.bot.IBaritoneUser;
import baritone.api.bot.connect.ConnectionStatus;
import baritone.api.bot.connect.IConnectionResult;
import java.util.Objects;
import java.util.Optional;
import static baritone.api.bot.connect.ConnectionStatus.SUCCESS;
/**
* @author Brady
* @since 11/6/2018
*/
public final class ConnectionResult implements IConnectionResult {
/**
* The result status
*/
private final ConnectionStatus status;
/**
* The user created, if the status is {@link ConnectionStatus#SUCCESS}
*/
private final IBaritoneUser user;
private ConnectionResult(ConnectionStatus status, IBaritoneUser user) {
this.status = status;
this.user = user;
}
@Override
public ConnectionStatus getStatus() {
return this.status;
}
@Override
public Optional<IBaritoneUser> getUser() {
return Optional.ofNullable(user);
}
/**
* Creates a new failed {@link ConnectionResult}.
*
* @param status The failed connection status
* @return The connection result
* @throws IllegalArgumentException if {@code status} is {@link ConnectionStatus#SUCCESS}
*/
public static ConnectionResult failed(ConnectionStatus status) {
if (status == SUCCESS) {
throw new IllegalArgumentException("Status must be a failure type");
}
return new ConnectionResult(status, null);
}
/**
* Creates a new success {@link ConnectionResult}.
*
* @param user The user created
* @return The connection result
* @throws IllegalArgumentException if {@code user} is {@code null}
*/
public static ConnectionResult success(IBaritoneUser user) {
Objects.requireNonNull(user);
return new ConnectionResult(SUCCESS, user);
}
}
@@ -0,0 +1,118 @@
/*
* 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.bot.handler;
import baritone.bot.BaritoneUser;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.exceptions.AuthenticationException;
import com.mojang.authlib.exceptions.AuthenticationUnavailableException;
import com.mojang.authlib.exceptions.InvalidCredentialsException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerLoginClient;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.login.client.CPacketEncryptionResponse;
import net.minecraft.network.login.server.SPacketEncryptionRequest;
import net.minecraft.network.login.server.SPacketLoginSuccess;
import net.minecraft.util.CryptManager;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import javax.annotation.Nonnull;
import javax.crypto.SecretKey;
import java.math.BigInteger;
import java.security.PublicKey;
/**
* Handles the login stage when connecting to a server.
*
* @author Brady
* @since 10/29/2018
*/
public class BotNetHandlerLoginClient extends NetHandlerLoginClient {
/**
* The {@link NetworkManager} that is managing the connection with the server.
*/
private final NetworkManager networkManager;
/**
* The {@link Minecraft} game instance
*/
private final Minecraft mc;
/**
* The bot of this connection
*/
private final BaritoneUser user;
public BotNetHandlerLoginClient(NetworkManager networkManager, BaritoneUser user) {
super(networkManager, Minecraft.getMinecraft(), null);
this.networkManager = networkManager;
this.mc = Minecraft.getMinecraft();
this.user = user;
}
@Override
public void handleEncryptionRequest(SPacketEncryptionRequest packetIn) {
SecretKey secretkey = CryptManager.createNewSharedKey();
PublicKey publicKey = packetIn.getPublicKey();
// Setup joinServer payload info
GameProfile profile = this.user.getSession().getProfile();
String authenticationToken = this.user.getSession().getToken();
String serverId = new BigInteger(CryptManager.getServerIdHash(packetIn.getServerId(), publicKey, secretkey)).toString(16);
if (this.mc.getCurrentServerData() != null && this.mc.getCurrentServerData().isOnLAN()) {
try {
this.mc.getSessionService().joinServer(profile, authenticationToken, serverId);
} catch (AuthenticationException e) {
// Couldn't connect to auth servers but will continue to join LAN
}
} else {
try {
this.mc.getSessionService().joinServer(profile, authenticationToken, serverId);
} catch (AuthenticationUnavailableException e) {
this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new TextComponentTranslation("disconnect.loginFailedInfo.serversUnavailable")));
return;
} catch (InvalidCredentialsException e) {
this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", new TextComponentTranslation("disconnect.loginFailedInfo.invalidSession")));
return;
} catch (AuthenticationException e) {
this.networkManager.closeChannel(new TextComponentTranslation("disconnect.loginFailedInfo", e.getMessage()));
return;
}
}
// noinspection unchecked
this.networkManager.sendPacket(new CPacketEncryptionResponse(secretkey, publicKey, packetIn.getVerifyToken()),
future -> BotNetHandlerLoginClient.this.networkManager.enableEncryption(secretkey));
}
@Override
public void handleLoginSuccess(SPacketLoginSuccess packetIn) {
this.networkManager.setConnectionState(EnumConnectionState.PLAY);
this.networkManager.setNetHandler(new BotNetHandlerPlayClient(this.networkManager, this.user, Minecraft.getMinecraft(), packetIn.getProfile()));
}
@Override
public void onDisconnect(@Nonnull ITextComponent reason) {
// It's important that we don't call the superclass method because that would mess up GUIs and make us upset
this.user.getManager().notifyDisconnect(this.user, EnumConnectionState.LOGIN);
}
}
@@ -0,0 +1,706 @@
/*
* 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.bot.handler;
import baritone.api.utils.Helper;
import baritone.bot.BaritoneUser;
import baritone.bot.spec.BotPlayerController;
import baritone.bot.spec.BotWorld;
import baritone.bot.spec.EntityBot;
import com.mojang.authlib.GameProfile;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.ClientAdvancementManager;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.util.RecipeBookClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.entity.player.PlayerCapabilities;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.PacketThreadUtil;
import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.network.play.client.*;
import net.minecraft.network.play.server.*;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatisticsManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.Explosion;
import net.minecraft.world.chunk.Chunk;
import javax.annotation.Nonnull;
// Notes
// - Make some sort of system that prevents repetition of entity info updating
// - For some packets, such as ones that modify position, we can check if the existing server state matches the packet proposed state
// - For other things, we'll actually need the system
/**
* This class would effectively operate the same if we directly implemented {@link INetHandlerPlayClient},
* however, the {@link EntityPlayerSP} constructor requires an actual implementation of
* {@link NetHandlerPlayClient} in order to access the {@link GameProfile}.
*
* @author Brady
* @since 10/22/2018
*/
public class BotNetHandlerPlayClient extends NetHandlerPlayClient {
/**
* The {@link NetworkManager} that is managing the connection with the server.
*/
private final NetworkManager networkManager;
/**
* This is the {@link Minecraft} game instance, however, to prevent unwanted references
* to the game instance fields, we refer to it as a {@link IThreadListener}.
*/
private final IThreadListener client;
/**
* The bot of this connection
*/
private final BaritoneUser user;
/**
* The bot entity
*/
private EntityBot player;
/**
* The current world.
*/
private BotWorld world;
/**
* The current player controller
*/
private BotPlayerController playerController;
public BotNetHandlerPlayClient(NetworkManager networkManager, BaritoneUser user, Minecraft client, GameProfile profile) {
// noinspection ConstantConditions
super(client, null, networkManager, profile);
this.networkManager = networkManager;
this.client = client;
this.user = user;
// Notify the user that we're ingame
this.user.onLoginSuccess(profile, this);
}
@Override
public void handleSpawnObject(@Nonnull SPacketSpawnObject packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleSpawnExperienceOrb(@Nonnull SPacketSpawnExperienceOrb packetIn) { /* We will want to know this if we want Tenor to collect XP */ }
@Override
public void handleSpawnGlobalEntity(@Nonnull SPacketSpawnGlobalEntity packetIn) { /* Only lightning bolts, this may change in the future */ }
@Override
public void handleSpawnMob(@Nonnull SPacketSpawnMob packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleScoreboardObjective(@Nonnull SPacketScoreboardObjective packetIn) {}
@Override
public void handleSpawnPainting(@Nonnull SPacketSpawnPainting packetIn) {}
@Override
public void handleSpawnPlayer(@Nonnull SPacketSpawnPlayer packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleAnimation(@Nonnull SPacketAnimation packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
if (entity != null) {
switch (packetIn.getAnimationType()) {
case 0: {
((EntityLivingBase) entity).swingArm(EnumHand.MAIN_HAND);
break;
}
case 1: {
entity.performHurtAnimation();
break;
}
case 2: {
((EntityPlayer) entity).wakeUpPlayer(false, false, false);
break;
}
case 3: {
((EntityLivingBase) entity).swingArm(EnumHand.OFF_HAND);
break;
}
}
}
}
@Override
public void handleStatistics(@Nonnull SPacketStatistics packetIn) { /* Lol global bot stats when?? */ }
@Override
public void handleRecipeBook(@Nonnull SPacketRecipeBook packetIn) {}
@Override
public void handleBlockBreakAnim(@Nonnull SPacketBlockBreakAnim packetIn) {}
@Override
public void handleSignEditorOpen(@Nonnull SPacketSignEditorOpen packetIn) {}
@Override
public void handleUpdateTileEntity(@Nonnull SPacketUpdateTileEntity packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleBlockAction(@Nonnull SPacketBlockAction packetIn) {}
@Override
public void handleBlockChange(@Nonnull SPacketBlockChange packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.world.setBlockState(packetIn.getBlockPosition(), packetIn.getBlockState());
}
@Override
public void handleChat(@Nonnull SPacketChat packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleTabComplete(@Nonnull SPacketTabComplete packetIn) {}
@Override
public void handleMultiBlockChange(@Nonnull SPacketMultiBlockChange packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
for (SPacketMultiBlockChange.BlockUpdateData data : packetIn.getChangedBlocks()) {
this.world.setBlockState(data.getPos(), data.getBlockState());
}
}
@Override
public void handleMaps(@Nonnull SPacketMaps packetIn) {}
@Override
public void handleConfirmTransaction(@Nonnull SPacketConfirmTransaction packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleCloseWindow(@Nonnull SPacketCloseWindow packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.player.closeScreenAndDropStack();
}
@Override
public void handleWindowItems(@Nonnull SPacketWindowItems packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
(packetIn.getWindowId() == 0 ? this.player.inventoryContainer : this.player.openContainer).setAll(packetIn.getItemStacks());
}
@Override
public void handleOpenWindow(@Nonnull SPacketOpenWindow packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleWindowProperty(@Nonnull SPacketWindowProperty packetIn) {}
@Override
public void handleSetSlot(@Nonnull SPacketSetSlot packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
ItemStack stack = packetIn.getStack();
int slot = packetIn.getSlot();
switch (packetIn.getWindowId()) {
case -1: {
this.player.inventory.setItemStack(stack);
break;
}
case -2: {
this.player.inventory.setInventorySlotContents(slot, stack);
break;
}
default: {
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= 36 && slot < 45) {
this.player.inventoryContainer.putStackInSlot(slot, stack);
} else if (packetIn.getWindowId() == this.player.openContainer.windowId && packetIn.getWindowId() != 0) {
this.player.openContainer.putStackInSlot(slot, stack);
}
}
}
}
@Override
public void handleCustomPayload(@Nonnull SPacketCustomPayload packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleDisconnect(@Nonnull SPacketDisconnect packetIn) {
this.networkManager.closeChannel(packetIn.getReason());
}
@Override
public void handleUseBed(@Nonnull SPacketUseBed packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleEntityStatus(@Nonnull SPacketEntityStatus packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleEntityAttach(@Nonnull SPacketEntityAttach packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleSetPassengers(@Nonnull SPacketSetPassengers packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleExplosion(@Nonnull SPacketExplosion packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
// noinspection ConstantConditions
new Explosion(this.world, null, packetIn.getX(), packetIn.getY(), packetIn.getZ(), packetIn.getStrength(), packetIn.getAffectedBlockPositions()).doExplosionB(true);
this.player.motionX += (double) packetIn.getMotionX();
this.player.motionY += (double) packetIn.getMotionY();
this.player.motionZ += (double) packetIn.getMotionZ();
}
@Override
public void handleChangeGameState(@Nonnull SPacketChangeGameState packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleKeepAlive(@Nonnull SPacketKeepAlive packetIn) {
this.networkManager.sendPacket(new CPacketKeepAlive(packetIn.getId()));
}
@Override
public void handleChunkData(@Nonnull SPacketChunkData packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
if (packetIn.isFullChunk()) {
this.world.doPreChunk(packetIn.getChunkX(), packetIn.getChunkZ(), true);
}
Chunk chunk = this.world.getChunk(packetIn.getChunkX(), packetIn.getChunkZ());
chunk.read(packetIn.getReadBuffer(), packetIn.getExtractedSize(), packetIn.isFullChunk());
for (NBTTagCompound tag : packetIn.getTileEntityTags()) {
BlockPos pos = new BlockPos(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"));
TileEntity tileEntity = this.world.getTileEntity(pos);
if (tileEntity != null) {
tileEntity.readFromNBT(tag);
}
}
}
@Override
public void processChunkUnload(@Nonnull SPacketUnloadChunk packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
// TODO Unload chunks
}
@Override
public void handleEffect(@Nonnull SPacketEffect packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleJoinGame(@Nonnull SPacketJoinGame packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.playerController = new BotPlayerController(this.user);
this.world = this.user.getManager().getWorldProvider().getWorld(packetIn.getDimension());
this.player = new EntityBot(this.user, (Minecraft) this.client, this.world, this, new StatisticsManager(), new RecipeBookClient());
this.user.onWorldLoad(this.world, this.player, this.playerController);
this.player.preparePlayerToSpawn();
this.world.spawnEntity(this.player);
this.player.setEntityId(packetIn.getPlayerId());
this.player.dimension = packetIn.getDimension();
this.playerController.setGameType(packetIn.getGameType());
packetIn.getGameType().configurePlayerCapabilities(this.player.capabilities);
this.networkManager.sendPacket(new CPacketClientSettings("en_us", 8, EntityPlayer.EnumChatVisibility.FULL, true, 0, EnumHandSide.RIGHT));
this.networkManager.sendPacket(new CPacketCustomPayload("MC|Brand", new PacketBuffer(Unpooled.buffer()).writeString("vanilla")));
this.world.registerBot(packetIn.getPlayerId(), this.player);
Helper.HELPER.logDirect("Initialized Player and World");
}
@Override
public void handleEntityMovement(@Nonnull SPacketEntity packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handlePlayerPosLook(@Nonnull SPacketPlayerPosLook packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
EntityPlayer player = this.player;
double d0 = packetIn.getX();
double d1 = packetIn.getY();
double d2 = packetIn.getZ();
float f = packetIn.getYaw();
float f1 = packetIn.getPitch();
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X)) {
d0 += player.posX;
} else {
player.motionX = 0.0D;
}
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y)) {
d1 += player.posY;
} else {
player.motionY = 0.0D;
}
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Z)) {
d2 += player.posZ;
} else {
player.motionZ = 0.0D;
}
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X_ROT)) {
f1 += player.rotationPitch;
}
if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y_ROT)) {
f += player.rotationYaw;
}
player.setPositionAndRotation(d0, d1, d2, f, f1);
this.networkManager.sendPacket(new CPacketConfirmTeleport(packetIn.getTeleportId()));
this.networkManager.sendPacket(new CPacketPlayer.PositionRotation(player.posX, player.getEntityBoundingBox().minY, player.posZ, player.rotationYaw, player.rotationPitch, false));
this.player.prevPosX = this.player.posX;
this.player.prevPosY = this.player.posY;
this.player.prevPosZ = this.player.posZ;
}
@Override
public void handleParticles(@Nonnull SPacketParticles packetIn) {}
@Override
public void handlePlayerAbilities(@Nonnull SPacketPlayerAbilities packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
PlayerCapabilities c = this.player.capabilities;
c.disableDamage = packetIn.isInvulnerable();
c.isFlying = packetIn.isFlying();
c.allowFlying = packetIn.isAllowFlying();
c.isCreativeMode = packetIn.isCreativeMode();
c.setFlySpeed(packetIn.getFlySpeed());
c.setPlayerWalkSpeed(packetIn.getWalkSpeed());
}
@Override
public void handlePlayerListItem(@Nonnull SPacketPlayerListItem packetIn) {
// okay now this is awesome
super.handlePlayerListItem(packetIn);
}
@Override
public void handleDestroyEntities(@Nonnull SPacketDestroyEntities packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
for (int i = 0; i < packetIn.getEntityIDs().length; ++i) {
this.world.removeEntityFromWorld(packetIn.getEntityIDs()[i]);
}
}
@Override
public void handleRemoveEntityEffect(@Nonnull SPacketRemoveEntityEffect packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
Entity entity = packetIn.getEntity(this.world);
if (entity instanceof EntityLivingBase) {
((EntityLivingBase) entity).removeActivePotionEffect(packetIn.getPotion());
}
}
@Override
public void handleRespawn(@Nonnull SPacketRespawn packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
if (packetIn.getDimensionID() != this.player.dimension) {
this.world.removeEntity(this.player);
this.world = this.user.getManager().getWorldProvider().getWorld(packetIn.getDimensionID());
}
EntityBot prev = this.player;
this.player = new EntityBot(this.user, (Minecraft) this.client, this.world, this, prev.getStatFileWriter(), prev.getRecipeBook());
this.user.onWorldLoad(this.world, this.player, this.playerController);
// noinspection ConstantConditions
this.player.getDataManager().setEntryValues(prev.getDataManager().getAll());
this.player.preparePlayerToSpawn();
this.world.spawnEntity(this.player);
this.player.setEntityId(prev.getEntityId());
this.player.dimension = packetIn.getDimensionID();
this.player.setServerBrand(prev.getServerBrand());
this.playerController.setGameType(packetIn.getGameType());
}
@Override
public void handleEntityHeadLook(@Nonnull SPacketEntityHeadLook packetIn) {}
@Override
public void handleHeldItemChange(@Nonnull SPacketHeldItemChange packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
if (InventoryPlayer.isHotbar(packetIn.getHeldItemHotbarIndex())) {
this.player.inventory.currentItem = packetIn.getHeldItemHotbarIndex();
}
}
@Override
public void handleDisplayObjective(@Nonnull SPacketDisplayObjective packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleEntityMetadata(@Nonnull SPacketEntityMetadata packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
Entity entity = this.world.getEntityByID(packetIn.getEntityId());
if (entity != null && packetIn.getDataManagerEntries() != null) {
entity.getDataManager().setEntryValues(packetIn.getDataManagerEntries());
}
}
@Override
public void handleEntityVelocity(@Nonnull SPacketEntityVelocity packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
if (entity != null) {
entity.setVelocity(
(double) packetIn.getMotionX() / 8000.0D,
(double) packetIn.getMotionY() / 8000.0D,
(double) packetIn.getMotionZ() / 8000.0D
);
}
}
@Override
public void handleEntityEquipment(@Nonnull SPacketEntityEquipment packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
Entity entity = this.world.getEntityByID(packetIn.getEntityID());
if (entity != null) {
entity.setItemStackToSlot(packetIn.getEquipmentSlot(), packetIn.getItemStack());
}
}
@Override
public void handleSetExperience(@Nonnull SPacketSetExperience packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.player.setXPStats(packetIn.getExperienceBar(), packetIn.getTotalExperience(), packetIn.getLevel());
}
@Override
public void handleUpdateHealth(@Nonnull SPacketUpdateHealth packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.player.setPlayerSPHealth(packetIn.getHealth());
this.player.getFoodStats().setFoodLevel(packetIn.getFoodLevel());
this.player.getFoodStats().setFoodSaturationLevel(packetIn.getSaturationLevel());
}
@Override
public void handleTeams(@Nonnull SPacketTeams packetIn) {}
@Override
public void handleUpdateScore(@Nonnull SPacketUpdateScore packetIn) {}
@Override
public void handleSpawnPosition(@Nonnull SPacketSpawnPosition packetIn) { /* We probably don't need to know this, the server handles everything related to spawn psoition? */ }
@Override
public void handleTimeUpdate(@Nonnull SPacketTimeUpdate packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
this.world.setTotalWorldTime(packetIn.getTotalWorldTime());
this.world.setWorldTime(packetIn.getWorldTime());
// TODO: Calculate World TPS
}
@Override
public void handleSoundEffect(@Nonnull SPacketSoundEffect packetIn) {}
@Override
public void handleCustomSound(@Nonnull SPacketCustomSound packetIn) {}
@Override
public void handleCollectItem(@Nonnull SPacketCollectItem packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleEntityTeleport(@Nonnull SPacketEntityTeleport packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleEntityProperties(@Nonnull SPacketEntityProperties packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
}
@Override
public void handleEntityEffect(@Nonnull SPacketEntityEffect packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
Entity entity = this.world.getEntityByID(packetIn.getEntityId());
if (entity instanceof EntityLivingBase) {
Potion potion = Potion.getPotionById(packetIn.getEffectId());
if (potion != null) {
PotionEffect effect = new PotionEffect(potion, packetIn.getDuration(), packetIn.getAmplifier(), packetIn.getIsAmbient(), packetIn.doesShowParticles());
effect.setPotionDurationMax(packetIn.isMaxDuration());
((EntityLivingBase) entity).addPotionEffect(effect);
}
}
}
@Override
public void handleCombatEvent(@Nonnull SPacketCombatEvent packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
// We only care if we died
if (packetIn.eventType == SPacketCombatEvent.Event.ENTITY_DIED) {
if (packetIn.playerId == this.player.getEntityId()) {
// Perform an instantaneous respawn
this.networkManager.sendPacket(new CPacketClientStatus(CPacketClientStatus.State.PERFORM_RESPAWN));
}
}
}
@Override
public void handleServerDifficulty(@Nonnull SPacketServerDifficulty packetIn) {}
@Override
public void handleCamera(SPacketCamera packetIn) {}
@Override
public void handleWorldBorder(@Nonnull SPacketWorldBorder packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
packetIn.apply(this.world.getWorldBorder());
}
@Override
public void handleTitle(@Nonnull SPacketTitle packetIn) {}
@Override
public void handlePlayerListHeaderFooter(@Nonnull SPacketPlayerListHeaderFooter packetIn) {}
@Override
public void handleResourcePack(@Nonnull SPacketResourcePackSend packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
// Lie to the server and tell them we accepted it in response
this.networkManager.sendPacket(new CPacketResourcePackStatus(CPacketResourcePackStatus.Action.ACCEPTED));
this.networkManager.sendPacket(new CPacketResourcePackStatus(CPacketResourcePackStatus.Action.SUCCESSFULLY_LOADED));
}
@Override
public void handleUpdateBossInfo(@Nonnull SPacketUpdateBossInfo packetIn) {}
@Override
public void handleCooldown(@Nonnull SPacketCooldown packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
if (packetIn.getTicks() == 0) { // There is no cooldown
this.player.getCooldownTracker().removeCooldown(packetIn.getItem());
} else {
this.player.getCooldownTracker().setCooldown(packetIn.getItem(), packetIn.getTicks());
}
}
@Override
public void handleMoveVehicle(@Nonnull SPacketMoveVehicle packetIn) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.client);
/* Atm Baritone doesn't even work on vehicles that well at all, so this is a major TODO */
}
@Override
public void handleAdvancementInfo(@Nonnull SPacketAdvancementInfo packetIn) {}
@Override
public void handleSelectAdvancementsTab(@Nonnull SPacketSelectAdvancementsTab packetIn) { /* Lol global bot achievements when? */ }
@Override
public void func_194307_a(@Nonnull SPacketPlaceGhostRecipe p_194307_1_) {}
@Override
public void onDisconnect(@Nonnull ITextComponent reason) {
// TODO Maybe more world unloadinde
this.world.removeEntity(this.player);
this.user.getManager().notifyDisconnect(this.user, EnumConnectionState.PLAY);
}
@Nonnull
@Override
public ClientAdvancementManager getAdvancementManager() {
throw new UnsupportedOperationException("This method shouldn't have been called; That is unepic!");
}
public EntityBot player() {
return player;
}
public BotWorld world() {
return world;
}
}
@@ -0,0 +1,260 @@
/*
* 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.bot.spec;
import baritone.api.bot.IBaritoneUser;
import baritone.api.utils.IPlayerController;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCommandBlock;
import net.minecraft.block.BlockStructure;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketClickWindow;
import net.minecraft.network.play.client.CPacketHeldItemChange;
import net.minecraft.network.play.client.CPacketPlayerDigging;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameType;
import net.minecraft.world.World;
/**
* @author Brady
* @since 11/14/2018
*/
public class BotPlayerController implements IPlayerController {
private final IBaritoneUser user;
private GameType gameType;
private BlockPos currentBlock;
private ItemStack currentHittingItem;
private boolean hittingBlock;
private float blockDamage;
private int blockHitDelay;
private int heldItemServer;
public BotPlayerController(IBaritoneUser user) {
this.user = user;
this.currentHittingItem = ItemStack.EMPTY;
}
@Override
public boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side) {
this.syncHeldItem();
EntityPlayerSP player = this.user.getEntity();
World world = player.world;
if (this.blockHitDelay > 0) {
this.blockHitDelay--;
return true;
}
if (!this.isHittingPosition(pos)) {
return this.clickBlock(pos, side);
}
IBlockState state = world.getBlockState(pos);
if (state.getMaterial() == Material.AIR) {
this.hittingBlock = false;
return false;
}
this.blockDamage += state.getPlayerRelativeBlockHardness(player, world, pos);
if (this.blockDamage >= 1.0F) {
this.hittingBlock = false;
this.blockDamage = 0.0F;
this.blockHitDelay = 5;
player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side));
this.handleBreak(pos);
}
world.sendBlockBreakProgress(player.getEntityId(), this.currentBlock, (int) (this.blockDamage * 10.0F) - 1);
return true;
}
@Override
public void resetBlockRemoving() {
if (this.hittingBlock) {
this.hittingBlock = false;
this.blockDamage = 0.0F;
this.user.getEntity().resetCooldown();
this.user.getEntity().connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, EnumFacing.DOWN));
}
}
@Override
public ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player) {
short transactionID = player.openContainer.getNextTransactionID(player.inventory);
ItemStack stack = player.openContainer.slotClick(slotId, mouseButton, type, player);
this.user.getEntity().connection.sendPacket(new CPacketClickWindow(windowId, slotId, mouseButton, type, stack, transactionID));
return stack;
}
@Override
public void setGameType(GameType type) {
this.gameType = type;
this.gameType.configurePlayerCapabilities(this.user.getEntity().capabilities);
}
@Override
public GameType getGameType() {
return this.gameType;
}
@Override
public boolean clickBlock(BlockPos pos, EnumFacing side) {
EntityPlayerSP player = this.user.getEntity();
World world = player.world;
if (!canBreak(player, pos)) {
return false;
}
if (!this.hittingBlock || !this.isHittingPosition(pos)) {
if (this.hittingBlock) {
player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, side));
}
IBlockState state = world.getBlockState(pos);
player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side));
if (state.getMaterial() != Material.AIR) {
if (this.blockDamage == 0.0F) {
state.getBlock().onBlockClicked(world, pos, player);
}
if (state.getPlayerRelativeBlockHardness(player, player.world, pos) >= 1.0F) {
this.handleBreak(pos);
}
} else {
this.hittingBlock = true;
this.currentBlock = pos;
this.blockDamage = 0.0F;
this.currentHittingItem = player.getHeldItemMainhand();
world.sendBlockBreakProgress(player.getEntityId(), this.currentBlock, (int) (this.blockDamage * 10.0F) - 1);
}
}
return true;
}
private void handleBreak(BlockPos pos) {
EntityPlayerSP player = this.user.getEntity();
World world = player.world;
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
return;
}
if (state.getMaterial() == Material.AIR) {
return;
}
block.onBlockHarvested(world, pos, state, player);
if (world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11)) {
block.onPlayerDestroy(world, pos, state);
}
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
ItemStack stack = player.getHeldItemMainhand();
if (!stack.isEmpty()) {
stack.onBlockDestroyed(world, state, pos, player);
if (stack.isEmpty()) {
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
}
}
private boolean canBreak(EntityPlayer player, BlockPos pos) {
if (this.gameType.isCreative() || this.gameType == GameType.SPECTATOR) {
return false;
}
if (!player.world.getWorldBorder().contains(pos)) {
return false;
}
if (this.gameType.hasLimitedInteractions() && !player.isAllowEdit()) {
ItemStack stack = player.getHeldItemMainhand();
return !stack.isEmpty() && stack.canDestroy(player.world.getBlockState(pos).getBlock());
}
return true;
}
private boolean isHittingPosition(BlockPos pos) {
ItemStack stack = this.user.getEntity().getHeldItemMainhand();
boolean itemUnchanged = this.currentHittingItem.isEmpty() && stack.isEmpty();
if (!this.currentHittingItem.isEmpty() && !stack.isEmpty()) {
itemUnchanged = stack.getItem() == this.currentHittingItem.getItem()
&& ItemStack.areItemStackTagsEqual(stack, this.currentHittingItem)
&& (stack.isItemStackDamageable() || stack.getMetadata() == this.currentHittingItem.getMetadata());
}
return pos.equals(this.currentBlock) && itemUnchanged;
}
@Override
public void syncHeldItem() {
int heldItemClient = this.user.getEntity().inventory.currentItem;
if (heldItemClient != this.heldItemServer) {
this.heldItemServer = heldItemClient;
this.user.getEntity().connection.sendPacket(new CPacketHeldItemChange(this.heldItemServer));
}
}
@Override
public boolean hasBrokenBlock() {
return this.currentBlock.getY() == -1;
}
@Override
public EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand) {
throw new AbstractMethodError("Lol");
}
@Override
public EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand) {
throw new AbstractMethodError("Lol");
}
@Override
public void setHittingBlock(boolean hittingBlock) {
this.hittingBlock = hittingBlock;
}
}
@@ -0,0 +1,84 @@
/*
* 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.bot.spec;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.entity.Entity;
import net.minecraft.profiler.Profiler;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.storage.SaveHandlerMP;
import net.minecraft.world.storage.WorldInfo;
import javax.annotation.Nonnull;
/**
* @author Brady
* @since 11/7/2018
*/
public class BotWorld extends World {
private static Profiler BOT_WORLD_PROFILER = new Profiler();
private static int worldNum = 0;
private ChunkProviderClient chunkProviderClient;
public BotWorld(WorldSettings settings, int dimension) {
super(
new SaveHandlerMP(),
new WorldInfo(settings, "BotWorld" + ++worldNum),
DimensionType.getById(dimension).createDimension(),
BOT_WORLD_PROFILER,
true
);
this.provider.setWorld(this);
this.chunkProvider = this.createChunkProvider();
}
@Override
@Nonnull
protected IChunkProvider createChunkProvider() {
return (this.chunkProviderClient = new ChunkProviderClient(this));
}
@Override
protected boolean isChunkLoaded(int x, int z, boolean allowEmpty) {
return allowEmpty || !this.chunkProviderClient.provideChunk(x, z).isEmpty();
}
public void registerBot(int entityID, EntityBot entity) {
this.entitiesById.addKey(entityID, entity);
}
public void removeEntityFromWorld(int entityID) {
Entity entity = this.entitiesById.removeObject(entityID);
if (entity != null) {
this.removeEntity(entity);
}
}
public void doPreChunk(int chunkX, int chunkZ, boolean loadChunk) {
if (loadChunk) {
this.chunkProviderClient.loadChunk(chunkX, chunkZ);
} else {
this.chunkProviderClient.unloadChunk(chunkX, chunkZ);
}
}
}
@@ -0,0 +1,170 @@
/*
* 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.bot.spec;
import baritone.api.bot.IBaritoneUser;
import baritone.utils.PlayerMovementInput;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IMerchant;
import net.minecraft.entity.passive.AbstractHorse;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.RecipeBook;
import net.minecraft.stats.StatisticsManager;
import net.minecraft.tileentity.CommandBlockBaseLogic;
import net.minecraft.tileentity.TileEntityCommandBlock;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.tileentity.TileEntityStructure;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.GameType;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;
import javax.annotation.Nullable;
// Some Notes:
// startRiding references the sound manager
// onUpdateWalkingPlayer references the gameSettings autoJump flag
// notifyDataManagerChange references the sound manager
// onLivingUpdate makes a lot of references to mc fields
// - playerController
// - currentScreen
// - gameSettings
// - tutorial
// What needs to be considered
// - The server tells us what our entity id should be, the bot entity should respect this.
/**
* @author Brady
* @since 10/23/2018
*/
@SuppressWarnings("EntityConstructor")
public class EntityBot extends EntityPlayerSP {
private final IBaritoneUser user;
private NetworkPlayerInfo playerInfo;
public EntityBot(IBaritoneUser user, Minecraft mc, World world, NetHandlerPlayClient netHandlerPlayClient, StatisticsManager statisticsManager, RecipeBook recipeBook) {
super(mc, world, netHandlerPlayClient, statisticsManager, recipeBook);
this.user = user;
this.movementInput = new PlayerMovementInput(this.user.getBaritone().getInputOverrideHandler());
}
@Override
public void closeScreenAndDropStack() {
this.inventory.setItemStack(ItemStack.EMPTY);
// EntityPlayer#closeScreen
this.openContainer = this.inventoryContainer;
}
@Override
public void sendStatusMessage(ITextComponent chatComponent, boolean actionBar) {
// TODO: Custom message handling
}
@Override
public void sendMessage(ITextComponent component) {
// TODO: Custom message handling
}
@Override
public void openEditSign(TileEntitySign signTile) {
// TODO: Custom GUI handling
}
@Override
public void displayGuiEditCommandCart(CommandBlockBaseLogic commandBlock) {
// TODO: Custom GUI handling
}
@Override
public void displayGuiCommandBlock(TileEntityCommandBlock commandBlock) {
// TODO: Custom GUI handling
}
@Override
public void openEditStructure(TileEntityStructure structure) {
// TODO: Custom GUI handling
}
@Override
public void openBook(ItemStack stack, EnumHand hand) {
// TODO: Custom GUI handling
}
@Override
public void displayGUIChest(IInventory chestInventory) {
// TODO: Custom GUI handling
}
@Override
public void openGuiHorseInventory(AbstractHorse horse, IInventory inventoryIn) {
// TODO: Custom GUI handling
}
@Override
public void displayGui(IInteractionObject guiOwner) {
// TODO: Custom GUI handling
}
@Override
public void displayVillagerTradeGui(IMerchant villager) {
// TODO: Custom GUI handling
}
@Override
public void onCriticalHit(Entity entityHit) {
// Don't render
}
@Override
public void onEnchantmentCritical(Entity entityHit) {
// Don't render
}
@Override
protected boolean isCurrentViewEntity() {
return true;
}
@Override
public boolean isSpectator() {
NetworkPlayerInfo networkplayerinfo = this.connection.getPlayerInfo(this.getGameProfile().getId());
// noinspection ConstantConditions
return networkplayerinfo != null && networkplayerinfo.getGameType() == GameType.SPECTATOR;
}
@Override
public boolean isCreative() {
NetworkPlayerInfo networkplayerinfo = this.connection.getPlayerInfo(this.getGameProfile().getId());
// noinspection ConstantConditions
return networkplayerinfo != null && networkplayerinfo.getGameType() == GameType.CREATIVE;
}
@Nullable
@Override
protected NetworkPlayerInfo getPlayerInfo() {
return this.playerInfo == null ? (this.playerInfo = this.connection.getPlayerInfo(this.getUniqueID())) : null;
}
}
+20 -37
View File
@@ -38,13 +38,23 @@ import java.util.Map;
public final class CachedChunk { public final class CachedChunk {
public static final ImmutableSet<Block> BLOCKS_TO_KEEP_TRACK_OF = ImmutableSet.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,
Blocks.ENDER_CHEST, Blocks.ENDER_CHEST,
Blocks.FURNACE, Blocks.FURNACE,
Blocks.CHEST, Blocks.CHEST,
Blocks.TRAPPED_CHEST, Blocks.TRAPPED_CHEST,
Blocks.END_PORTAL, Blocks.END_PORTAL,
Blocks.END_PORTAL_FRAME, Blocks.END_PORTAL_FRAME,
Blocks.SPAWNER, Blocks.MOB_SPAWNER,
Blocks.BARRIER, Blocks.BARRIER,
Blocks.OBSERVER, Blocks.OBSERVER,
Blocks.WHITE_SHULKER_BOX, Blocks.WHITE_SHULKER_BOX,
@@ -55,7 +65,7 @@ public final class CachedChunk {
Blocks.LIME_SHULKER_BOX, Blocks.LIME_SHULKER_BOX,
Blocks.PINK_SHULKER_BOX, Blocks.PINK_SHULKER_BOX,
Blocks.GRAY_SHULKER_BOX, Blocks.GRAY_SHULKER_BOX,
Blocks.LIGHT_GRAY_SHULKER_BOX, Blocks.SILVER_SHULKER_BOX,
Blocks.CYAN_SHULKER_BOX, Blocks.CYAN_SHULKER_BOX,
Blocks.PURPLE_SHULKER_BOX, Blocks.PURPLE_SHULKER_BOX,
Blocks.BLUE_SHULKER_BOX, Blocks.BLUE_SHULKER_BOX,
@@ -63,52 +73,25 @@ public final class CachedChunk {
Blocks.GREEN_SHULKER_BOX, Blocks.GREEN_SHULKER_BOX,
Blocks.RED_SHULKER_BOX, Blocks.RED_SHULKER_BOX,
Blocks.BLACK_SHULKER_BOX, Blocks.BLACK_SHULKER_BOX,
Blocks.NETHER_PORTAL, Blocks.PORTAL,
Blocks.HOPPER, Blocks.HOPPER,
Blocks.BEACON, Blocks.BEACON,
Blocks.BREWING_STAND, Blocks.BREWING_STAND,
Blocks.SKULL,
// TODO: Maybe add a predicate for blocks to keep track of?
// This should really not need to happen
Blocks.CREEPER_HEAD,
Blocks.CREEPER_WALL_HEAD,
Blocks.DRAGON_HEAD,
Blocks.DRAGON_WALL_HEAD,
Blocks.PLAYER_HEAD,
Blocks.PLAYER_WALL_HEAD,
Blocks.ZOMBIE_HEAD,
Blocks.ZOMBIE_WALL_HEAD,
Blocks.SKELETON_SKULL,
Blocks.SKELETON_WALL_SKULL,
Blocks.WITHER_SKELETON_SKULL,
Blocks.WITHER_SKELETON_WALL_SKULL,
Blocks.ENCHANTING_TABLE, Blocks.ENCHANTING_TABLE,
Blocks.ANVIL, Blocks.ANVIL,
Blocks.WHITE_BED, Blocks.LIT_FURNACE,
Blocks.ORANGE_BED, Blocks.BED,
Blocks.MAGENTA_BED,
Blocks.LIGHT_BLUE_BED,
Blocks.YELLOW_BED,
Blocks.LIME_BED,
Blocks.PINK_BED,
Blocks.GRAY_BED,
Blocks.LIGHT_GRAY_BED,
Blocks.CYAN_BED,
Blocks.PURPLE_BED,
Blocks.BLUE_BED,
Blocks.BROWN_BED,
Blocks.GREEN_BED,
Blocks.RED_BED,
Blocks.BLACK_BED,
Blocks.DRAGON_EGG, Blocks.DRAGON_EGG,
Blocks.JUKEBOX, Blocks.JUKEBOX,
Blocks.END_GATEWAY, Blocks.END_GATEWAY,
Blocks.COBWEB, Blocks.WEB,
Blocks.NETHER_WART, Blocks.NETHER_WART,
Blocks.LADDER, Blocks.LADDER,
Blocks.VINE Blocks.VINE
); );
/** /**
* The size of the chunk data in bits. Equal to 16 KiB. * The size of the chunk data in bits. Equal to 16 KiB.
* <p> * <p>
@@ -187,8 +170,8 @@ public final class CachedChunk {
// 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.getInstance().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())) {
throw new IllegalStateException("failed " + Minecraft.getInstance().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16)); throw new IllegalStateException("failed " + Minecraft.getMinecraft().world.getBlockState(new BlockPos(x + this.x * 16, y, z + this.z * 16)).getBlock() + " " + state.getBlock() + " " + (x + this.x * 16) + " " + y + " " + (z + this.z * 16));
}*/ }*/
return overview[internalPos]; return overview[internalPos];
} }
+9 -10
View File
@@ -24,10 +24,9 @@ import net.minecraft.block.*;
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.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.BlockStateContainer;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import java.util.*; import java.util.*;
@@ -45,9 +44,9 @@ public final class ChunkPacker {
Map<String, List<BlockPos>> specialBlocks = new HashMap<>(); Map<String, List<BlockPos>> specialBlocks = new HashMap<>();
BitSet bitSet = new BitSet(CachedChunk.SIZE); BitSet bitSet = new BitSet(CachedChunk.SIZE);
try { try {
ChunkSection[] chunkInternalStorageArray = chunk.getSections(); ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray();
for (int y0 = 0; y0 < 16; y0++) { for (int y0 = 0; y0 < 16; y0++) {
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0]; ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0];
if (extendedblockstorage == null) { if (extendedblockstorage == null) {
// any 16x16x16 area that's all air will have null storage // any 16x16x16 area that's all air will have null storage
// for example, in an ocean biome, with air from y=64 to y=256 // for example, in an ocean biome, with air from y=64 to y=256
@@ -59,7 +58,7 @@ public final class ChunkPacker {
// since a bitset is initialized to all zero, and air is saved as zeros // since a bitset is initialized to all zero, and air is saved as zeros
continue; continue;
} }
BlockStateContainer<IBlockState> bsc = extendedblockstorage.getData(); BlockStateContainer bsc = extendedblockstorage.getData();
int yReal = y0 << 4; int yReal = y0 << 4;
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x; // the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order // for better cache locality, iterate in that order
@@ -106,9 +105,10 @@ 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());
} }
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) { private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
Block block = state.getBlock(); Block block = state.getBlock();
if (MovementHelper.isWater(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 // FLOWING_WATER is a waterfall, it doesn't really matter and caching it as AVOID just makes it look wrong
if (MovementHelper.possiblyFlowing(state)) { if (MovementHelper.possiblyFlowing(state)) {
@@ -123,8 +123,7 @@ public final class ChunkPacker {
return PathingBlockType.AVOID; return PathingBlockType.AVOID;
} }
if (x == 0 || x == 15 || z == 0 || z == 15) { if (x == 0 || x == 15 || z == 0 || z == 15) {
Vec3d flow = state.getFluidState().getFlow(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4)); if (BlockLiquid.getSlopeAngle(chunk.getWorld(), new BlockPos(x + chunk.x << 4, y, z + chunk.z << 4), state.getMaterial(), state) == -1000.0F) {
if (flow.x != 0.0 || flow.z != 0.0) {
return PathingBlockType.WATER; return PathingBlockType.WATER;
} }
return PathingBlockType.AVOID; return PathingBlockType.AVOID;
@@ -132,14 +131,14 @@ public final class ChunkPacker {
return PathingBlockType.WATER; return PathingBlockType.WATER;
} }
if (MovementHelper.avoidWalkingInto(state) || 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
// however, this failed in the nether when you were near a nether fortress // however, this failed in the nether when you were near a nether fortress
// because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape // because fences check their adjacent blocks in the world for their fence connection status to determine AABB shape
// this caused a nullpointerexception when we saved chunks on unload, because they were unable to check their neighbors // this caused a nullpointerexception when we saved chunks on unload, because they were unable to check their neighbors
if (block instanceof BlockAir || block instanceof BlockTallGrass || block instanceof BlockDoublePlant || block instanceof BlockFlower) { if (block == Blocks.AIR || block instanceof BlockTallGrass || block instanceof BlockDoublePlant || block instanceof BlockFlower) {
return PathingBlockType.AIR; return PathingBlockType.AIR;
} }
+3 -4
View File
@@ -24,7 +24,6 @@ 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 net.minecraft.world.dimension.DimensionType;
import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.SystemUtils;
import java.io.File; import java.io.File;
@@ -56,7 +55,7 @@ public class WorldProvider implements IWorldProvider, Helper {
* *
* @param dimension The ID of the world's dimension * @param dimension The ID of the world's dimension
*/ */
public final void initWorld(DimensionType dimension) { public final void initWorld(int dimension) {
File directory; File directory;
File readme; File readme;
@@ -93,7 +92,7 @@ public class WorldProvider implements IWorldProvider, Helper {
} catch (IOException ignored) {} } catch (IOException ignored) {}
// We will actually store the world data in a subfolder: "DIM<id>" // We will actually store the world data in a subfolder: "DIM<id>"
Path dir = new File(directory, "DIM" + dimension.getId()).toPath(); Path dir = new File(directory, "DIM" + dimension).toPath();
if (!Files.exists(dir)) { if (!Files.exists(dir)) {
try { try {
Files.createDirectories(dir); Files.createDirectories(dir);
@@ -102,7 +101,7 @@ public class WorldProvider implements IWorldProvider, Helper {
System.out.println("Baritone world data dir: " + dir); System.out.println("Baritone world data dir: " + dir);
synchronized (worldCache) { synchronized (worldCache) {
this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension.getId())); this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension));
} }
} }
+40 -27
View File
@@ -28,8 +28,8 @@ import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import java.util.*; import java.util.*;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@@ -72,7 +72,7 @@ public enum WorldScanner implements IWorldScanner {
foundChunks = true; foundChunks = true;
int chunkX = xoff + playerChunkX; int chunkX = xoff + playerChunkX;
int chunkZ = zoff + playerChunkZ; int chunkZ = zoff + playerChunkZ;
Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, false, false); Chunk chunk = chunkProvider.getLoadedChunk(chunkX, chunkZ);
if (chunk == null) { if (chunk == null) {
continue; continue;
} }
@@ -99,7 +99,7 @@ public enum WorldScanner implements IWorldScanner {
} }
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider(); ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, false, false); Chunk chunk = chunkProvider.getLoadedChunk(pos.x, pos.z);
int playerY = ctx.playerFeet().getY(); int playerY = ctx.playerFeet().getY();
if (chunk == null || chunk.isEmpty()) { if (chunk == null || chunk.isEmpty()) {
@@ -111,12 +111,47 @@ public enum WorldScanner implements IWorldScanner {
return res; return res;
} }
@Override
public int repack(IPlayerContext ctx) {
return this.repack(ctx, 40);
}
@Override
public int repack(IPlayerContext ctx, int range) {
IChunkProvider chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
int playerChunkX = playerPos.getX() >> 4;
int playerChunkZ = playerPos.getZ() >> 4;
int minX = playerChunkX - range;
int minZ = playerChunkZ - range;
int maxX = playerChunkX + range;
int maxZ = playerChunkZ + range;
int queued = 0;
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
Chunk chunk = chunkProvider.getLoadedChunk(x, z);
if (chunk != null && !chunk.isEmpty()) {
queued++;
cachedWorld.queueForPacking(chunk);
}
}
}
return queued;
}
private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, BlockOptionalMetaLookup filter, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) { private boolean scanChunkInto(int chunkX, int chunkZ, Chunk chunk, BlockOptionalMetaLookup filter, Collection<BlockPos> result, int max, int yLevelThreshold, int playerY, int[] coordinateIterationOrder) {
ChunkSection[] chunkInternalStorageArray = chunk.getSections(); ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray();
boolean foundWithinY = false; boolean foundWithinY = false;
for (int yIndex = 0; yIndex < 16; yIndex++) { for (int yIndex = 0; yIndex < 16; yIndex++) {
int y0 = coordinateIterationOrder[yIndex]; int y0 = coordinateIterationOrder[yIndex];
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0]; ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0];
if (extendedblockstorage == null) { if (extendedblockstorage == null) {
continue; continue;
} }
@@ -147,26 +182,4 @@ public enum WorldScanner implements IWorldScanner {
} }
return foundWithinY; return foundWithinY;
} }
public int repack(IPlayerContext ctx) {
IChunkProvider chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
int playerChunkX = playerPos.getX() >> 4;
int playerChunkZ = playerPos.getZ() >> 4;
int queued = 0;
for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) {
for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) {
Chunk chunk = chunkProvider.getChunk(x, z, false, false);
if (chunk != null && !chunk.isEmpty()) {
queued++;
cachedWorld.queueForPacking(chunk);
}
}
}
return queued;
}
} }
@@ -68,7 +68,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
event.cancel(); event.cancel();
String commandStr = msg.substring(forceRun ? FORCE_COMMAND_PREFIX.length() : prefix.length()); String commandStr = msg.substring(forceRun ? FORCE_COMMAND_PREFIX.length() : prefix.length());
if (!runCommand(commandStr) && !commandStr.trim().isEmpty()) { if (!runCommand(commandStr) && !commandStr.trim().isEmpty()) {
new CommandNotFoundException(CommandManager.expand(commandStr).getA()).handle(null, null); new CommandNotFoundException(CommandManager.expand(commandStr).getFirst()).handle(null, null);
} }
} else if ((settings.chatControl.value || settings.chatControlAnyway.value) && runCommand(msg)) { } else if ((settings.chatControl.value || settings.chatControlAnyway.value) && runCommand(msg)) {
event.cancel(); event.cancel();
@@ -108,9 +108,9 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
return this.runCommand("help"); return this.runCommand("help");
} }
Tuple<String, List<ICommandArgument>> pair = CommandManager.expand(msg); Tuple<String, List<ICommandArgument>> pair = CommandManager.expand(msg);
String command = pair.getA(); String command = pair.getFirst();
String rest = msg.substring(pair.getA().length()); String rest = msg.substring(pair.getFirst().length());
ArgConsumer argc = new ArgConsumer(this.manager, pair.getB()); ArgConsumer argc = new ArgConsumer(this.manager, pair.getSecond());
if (!argc.hasAny()) { if (!argc.hasAny()) {
Settings.Setting setting = settings.byLowerName.get(command.toLowerCase(Locale.US)); Settings.Setting setting = settings.byLowerName.get(command.toLowerCase(Locale.US));
if (setting != null) { if (setting != null) {
@@ -127,7 +127,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
if (setting.getName().equals("logger")) { if (setting.getName().equals("logger")) {
continue; continue;
} }
if (setting.getName().equalsIgnoreCase(pair.getA())) { if (setting.getName().equalsIgnoreCase(pair.getFirst())) {
logRanCommand(command, rest); logRanCommand(command, rest);
try { try {
this.manager.execute(String.format("set %s %s", setting.getName(), argc.getString())); this.manager.execute(String.format("set %s %s", setting.getName(), argc.getString()));
@@ -138,7 +138,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
} }
// If the command exists, then handle echoing the input // If the command exists, then handle echoing the input
if (this.manager.getCommand(pair.getA()) != null) { if (this.manager.getCommand(pair.getFirst()) != null) {
logRanCommand(command, rest); logRanCommand(command, rest);
} }
@@ -316,8 +316,7 @@ public class ArgConsumer implements IArgConsumer {
try { try {
return datatype.apply(this.context, original); return datatype.apply(this.context, original);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName());
} }
} }
@@ -346,7 +345,7 @@ public class ArgConsumer implements IArgConsumer {
try { try {
return datatype.get(this.context); return datatype.get(this.context);
} catch (Exception e) { } catch (Exception e) {
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName()); throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getClass().getSimpleName(), e);
} }
} }
@@ -17,6 +17,7 @@
package baritone.command.defaults; package baritone.command.defaults;
import baritone.Baritone;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command; import baritone.api.command.Command;
@@ -26,16 +27,16 @@ import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException; import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.argument.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import org.apache.commons.io.FilenameUtils;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.stream.Stream; import java.util.stream.Stream;
public class BuildCommand extends Command { public class BuildCommand extends Command {
private static final File schematicsDir = new File(mc.gameDir, "schematics"); private static final File schematicsDir = new File(Minecraft.getMinecraft().gameDir, "schematics");
public BuildCommand(IBaritone baritone) { public BuildCommand(IBaritone baritone) {
super(baritone, "build"); super(baritone, "build");
@@ -44,8 +45,8 @@ public class BuildCommand extends Command {
@Override @Override
public void execute(String label, IArgConsumer args) throws CommandException { public void execute(String label, IArgConsumer args) throws CommandException {
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile(); File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) { if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) {
file = new File(file.getAbsolutePath() + ".schematic"); file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension);
} }
BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos origin = ctx.playerFeet();
BetterBlockPos buildOrigin; BetterBlockPos buildOrigin;
@@ -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.command.defaults;
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class CancelCommand extends Command {
public CancelCommand(IBaritone baritone) {
super(baritone, "cancel", "stop");
}
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
baritone.getPathingBehavior().cancelEverything();
logDirect("ok canceled");
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Cancel what Baritone is currently doing";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The cancel command tells Baritone to stop whatever it's currently doing.",
"",
"Usage:",
"> cancel"
);
}
}
@@ -24,7 +24,8 @@ import java.util.*;
public final class DefaultCommands { public final class DefaultCommands {
private DefaultCommands() {} private DefaultCommands() {
}
public static List<ICommand> createAll(IBaritone baritone) { public static List<ICommand> createAll(IBaritone baritone) {
Objects.requireNonNull(baritone); Objects.requireNonNull(baritone);
@@ -43,7 +44,6 @@ public final class DefaultCommands {
new SchematicaCommand(baritone), new SchematicaCommand(baritone),
new ComeCommand(baritone), new ComeCommand(baritone),
new AxisCommand(baritone), new AxisCommand(baritone),
new CancelCommand(baritone),
new ForceCancelCommand(baritone), new ForceCancelCommand(baritone),
new GcCommand(baritone), new GcCommand(baritone),
new InvertCommand(baritone), new InvertCommand(baritone),
@@ -66,10 +66,11 @@ public final class DefaultCommands {
new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"), new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"),
new SelCommand(baritone) new SelCommand(baritone)
)); ));
PauseResumeCommands prc = new PauseResumeCommands(baritone); ExecutionControlCommands prc = new ExecutionControlCommands(baritone);
commands.add(prc.pauseCommand); commands.add(prc.pauseCommand);
commands.add(prc.resumeCommand); commands.add(prc.resumeCommand);
commands.add(prc.pausedCommand); commands.add(prc.pausedCommand);
commands.add(prc.cancelCommand);
return Collections.unmodifiableList(commands); return Collections.unmodifiableList(commands);
} }
} }
@@ -18,13 +18,13 @@
package baritone.command.defaults; package baritone.command.defaults;
import baritone.api.IBaritone; import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.process.IBaritoneProcess; import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType; import baritone.api.process.PathingCommandType;
import baritone.api.command.Command;
import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.argument.IArgConsumer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -37,13 +37,14 @@ import java.util.stream.Stream;
* TO USE THIS to pause and resume Baritone. Make your own process that returns {@link PathingCommandType#REQUEST_PAUSE * TO USE THIS to pause and resume Baritone. Make your own process that returns {@link PathingCommandType#REQUEST_PAUSE
* REQUEST_PAUSE} as needed. * REQUEST_PAUSE} as needed.
*/ */
public class PauseResumeCommands { public class ExecutionControlCommands {
Command pauseCommand; Command pauseCommand;
Command resumeCommand; Command resumeCommand;
Command pausedCommand; Command pausedCommand;
Command cancelCommand;
public PauseResumeCommands(IBaritone baritone) { public ExecutionControlCommands(IBaritone baritone) {
// array for mutability, non-field so reflection can't touch it // array for mutability, non-field so reflection can't touch it
final boolean[] paused = {false}; final boolean[] paused = {false};
baritone.getPathingControlManager().registerProcess( baritone.getPathingControlManager().registerProcess(
@@ -64,7 +65,8 @@ public class PauseResumeCommands {
} }
@Override @Override
public void onLostControl() {} public void onLostControl() {
}
@Override @Override
public double priority() { public double priority() {
@@ -169,5 +171,36 @@ public class PauseResumeCommands {
); );
} }
}; };
cancelCommand = new Command(baritone, "cancel", "stop") {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
args.requireMax(0);
if (paused[0]) {
paused[0] = false;
}
baritone.getPathingBehavior().cancelEverything();
logDirect("ok canceled");
}
@Override
public Stream<String> tabComplete(String label, IArgConsumer args) {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Cancel what Baritone is currently doing";
}
@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The cancel command tells Baritone to stop whatever it's currently doing.",
"",
"Usage:",
"> cancel"
);
}
};
} }
} }
@@ -24,7 +24,6 @@ import baritone.api.command.datatypes.BlockById;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.argument.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.util.registry.IRegistry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -47,7 +46,7 @@ public class FindCommand extends Command {
toFind.stream() toFind.stream()
.flatMap(block -> .flatMap(block ->
ctx.worldData().getCachedWorld().getLocationsOf( ctx.worldData().getCachedWorld().getLocationsOf(
IRegistry.BLOCK.getKey(block).getPath(), Block.REGISTRY.getNameForObject(block).getPath(),
Integer.MAX_VALUE, Integer.MAX_VALUE,
origin.x, origin.x,
origin.y, origin.y,
@@ -26,11 +26,10 @@ import baritone.api.command.exception.CommandException;
import baritone.api.command.argument.IArgConsumer; import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import java.util.*; import java.util.*;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -48,7 +47,7 @@ public class FollowCommand extends Command {
FollowGroup group; FollowGroup group;
FollowList list; FollowList list;
List<Entity> entities = new ArrayList<>(); List<Entity> entities = new ArrayList<>();
List<EntityType> classes = new ArrayList<>(); List<Class<? extends Entity>> classes = new ArrayList<>();
if (args.hasExactlyOne()) { if (args.hasExactlyOne()) {
baritone.getFollowProcess().follow((group = args.getEnum(FollowGroup.class)).filter); baritone.getFollowProcess().follow((group = args.getEnum(FollowGroup.class)).filter);
} else { } else {
@@ -57,9 +56,9 @@ public class FollowCommand extends Command {
list = args.getEnum(FollowList.class); list = args.getEnum(FollowList.class);
while (args.hasAny()) { while (args.hasAny()) {
Object gotten = args.getDatatypeFor(list.datatype); Object gotten = args.getDatatypeFor(list.datatype);
if (gotten instanceof EntityType) { if (gotten instanceof Class) {
//noinspection unchecked //noinspection unchecked
classes.add((EntityType) gotten); classes.add((Class<? extends Entity>) gotten);
} else { } else {
entities.add((Entity) gotten); entities.add((Entity) gotten);
} }
@@ -67,7 +66,7 @@ public class FollowCommand extends Command {
baritone.getFollowProcess().follow( baritone.getFollowProcess().follow(
classes.isEmpty() classes.isEmpty()
? entities::contains ? entities::contains
: e -> classes.stream().anyMatch(c -> c.getEntityClass().isInstance(e)) : e -> classes.stream().anyMatch(c -> c.isInstance(e))
); );
} }
if (group != null) { if (group != null) {
@@ -80,7 +79,7 @@ public class FollowCommand extends Command {
.forEach(this::logDirect); .forEach(this::logDirect);
} else { } else {
classes.stream() classes.stream()
.map(IRegistry.ENTITY_TYPE::getKey) .map(EntityList::getKey)
.map(Objects::requireNonNull) .map(Objects::requireNonNull)
.map(ResourceLocation::toString) .map(ResourceLocation::toString)
.forEach(this::logDirect); .forEach(this::logDirect);
@@ -41,9 +41,13 @@ public class GotoCommand extends Command {
@Override @Override
public void execute(String label, IArgConsumer args) throws CommandException { public void execute(String label, IArgConsumer args) throws CommandException {
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) { // if we have a numeric first argument... // If we have a numeric first argument, then parse arguments as coordinates.
// Note: There is no reason to want to go where you're already at so there
// is no need to handle the case of empty arguments.
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
args.requireMax(3);
BetterBlockPos origin = baritone.getPlayerContext().playerFeet(); BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
Goal goal = args.getDatatypePostOrNull(RelativeGoal.INSTANCE, origin); Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
logDirect(String.format("Going to: %s", goal.toString())); logDirect(String.format("Going to: %s", goal.toString()));
baritone.getCustomGoalProcess().setGoalAndPath(goal); baritone.getCustomGoalProcess().setGoalAndPath(goal);
return; return;
@@ -38,7 +38,7 @@ public class RenderCommand extends Command {
args.requireMax(0); args.requireMax(0);
BetterBlockPos origin = ctx.playerFeet(); BetterBlockPos origin = ctx.playerFeet();
int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16; int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16;
mc.worldRenderer.markBlockRangeForRenderUpdate( mc.renderGlobal.markBlockRangeForRenderUpdate(
origin.x - renderDistance, origin.x - renderDistance,
0, 0,
origin.z - renderDistance, origin.z - renderDistance,
@@ -23,10 +23,10 @@ import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument; import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.exception.CommandUnhandledException; import baritone.api.command.exception.CommandUnhandledException;
import baritone.api.command.exception.ICommandException; import baritone.api.command.exception.ICommandException;
import baritone.command.argument.ArgConsumer;
import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.manager.ICommandManager; import baritone.api.command.manager.ICommandManager;
import baritone.api.command.registry.Registry; import baritone.api.command.registry.Registry;
import baritone.command.argument.ArgConsumer;
import baritone.command.argument.CommandArguments; import baritone.command.argument.CommandArguments;
import baritone.command.defaults.DefaultCommands; import baritone.command.defaults.DefaultCommands;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
@@ -35,7 +35,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* The default, internal implementation of {@link ICommandManager} * The default, internal implementation of {@link ICommandManager}
* *
@@ -95,8 +94,8 @@ public class CommandManager implements ICommandManager {
@Override @Override
public Stream<String> tabComplete(String prefix) { public Stream<String> tabComplete(String prefix) {
Tuple<String, List<ICommandArgument>> pair = expand(prefix, true); Tuple<String, List<ICommandArgument>> pair = expand(prefix, true);
String label = pair.getA(); String label = pair.getFirst();
List<ICommandArgument> args = pair.getB(); List<ICommandArgument> args = pair.getSecond();
if (args.isEmpty()) { if (args.isEmpty()) {
return new TabCompleteHelper() return new TabCompleteHelper()
.addCommands(this.baritone.getCommandManager()) .addCommands(this.baritone.getCommandManager())
@@ -108,8 +107,8 @@ public class CommandManager implements ICommandManager {
} }
private ExecutionWrapper from(Tuple<String, List<ICommandArgument>> expanded) { private ExecutionWrapper from(Tuple<String, List<ICommandArgument>> expanded) {
String label = expanded.getA(); String label = expanded.getFirst();
ArgConsumer args = new ArgConsumer(this, expanded.getB()); ArgConsumer args = new ArgConsumer(this, expanded.getSecond());
ICommand command = this.getCommand(label); ICommand command = this.getCommand(label);
return command == null ? null : new ExecutionWrapper(command, label, args); return command == null ? null : new ExecutionWrapper(command, label, args);
@@ -126,7 +125,6 @@ public class CommandManager implements ICommandManager {
} }
private static final class ExecutionWrapper { private static final class ExecutionWrapper {
private ICommand command; private ICommand command;
private String label; private String label;
private ArgConsumer args; private ArgConsumer args;
@@ -22,6 +22,7 @@ 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.bot.UserManager;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import baritone.cache.WorldProvider; import baritone.cache.WorldProvider;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
@@ -29,6 +30,7 @@ import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
/** /**
@@ -66,6 +68,9 @@ public final class GameEventHandler implements IEventBus, Helper {
@Override @Override
public final void onSendChatMessage(ChatEvent event) { public final void onSendChatMessage(ChatEvent event) {
// Ensure UserManager is created to prevent a ConcurrentModificationException
Objects.requireNonNull(UserManager.INSTANCE);
listeners.forEach(l -> l.onSendChatMessage(event)); listeners.forEach(l -> l.onSendChatMessage(event));
} }
@@ -89,7 +94,7 @@ public final class GameEventHandler implements IEventBus, Helper {
// to make sure the chunk being unloaded is already loaded. // to make sure the chunk being unloaded is already loaded.
boolean isPreUnload = state == EventState.PRE boolean isPreUnload = state == EventState.PRE
&& type == ChunkEvent.Type.UNLOAD && type == ChunkEvent.Type.UNLOAD
&& world.getChunkProvider().getChunk(event.getX(), event.getZ(), false, false) != null; && world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ());
if (isPostPopulate || isPreUnload) { if (isPostPopulate || isPreUnload) {
baritone.getWorldProvider().ifWorldLoaded(worldData -> { baritone.getWorldProvider().ifWorldLoaded(worldData -> {
@@ -114,7 +119,7 @@ public final class GameEventHandler implements IEventBus, Helper {
if (event.getState() == EventState.POST) { if (event.getState() == EventState.POST) {
cache.closeWorld(); cache.closeWorld();
if (event.getWorld() != null) { if (event.getWorld() != null) {
cache.initWorld(event.getWorld().getDimension().getType()); cache.initWorld(event.getWorld().provider.getDimensionType().getId());
} }
} }

Some files were not shown because too many files have changed in this diff Show More