Compare commits

..

179 Commits

Author SHA1 Message Date
Leijurv
0bb148844d Merge branch '1.13.2' into 1.14.4 2019-08-17 16:10:59 -07:00
Leijurv
7c9b812a5b Merge branch 'master' into 1.13.2 2019-08-17 16:07:26 -07:00
Leijurv
9046eb500b crucial performance optimization 2019-08-16 21:16:41 -07:00
Leijurv
011b7427e2 fine lmao 2019-08-15 23:03:16 -07:00
Leijurv
13caaf6fa7 ok fine optifine 2019-08-15 19:27:46 -07:00
Brady
a98677dbda crucial performance optimization 2019-08-15 03:19:19 -05:00
Leijurv
afc639ab4b bypass 2019-08-14 22:31:46 -07:00
Leijurv
6c1f0d3711 Merge pull request #764 from Scribblefoxx/master
Just a little fix, you know was coding away and thought, "hey! here is something cool!"
2019-08-10 08:20:50 -10:00
Scribblefoxx
e1e6a08eb2 Update Settings.java 2019-08-11 03:39:29 +10:00
Leijurv
7b21b0401d Merge pull request #712 from IronException/master
dimensional coords extension
2019-08-08 21:47:28 -10:00
Leijurv
4c935fc447 epicer cached bedrock level pathing 2019-08-08 18:09:25 -10:00
Leijurv
3d221dcda4 antiquated and does more harm than good 2019-08-08 18:04:49 -10:00
Friedolin2000
ac6c413fb8 dimensional coords extension 2019-08-08 22:45:18 +02:00
Leijurv
17a07ba85e better render 2019-08-08 09:56:06 -10:00
Leijurv
ca6f7003a5 Merge pull request #752 from cabaletta/raytrace-shaders
Disable lighting on path renderer
2019-08-08 09:55:16 -10:00
Howard Stark
d402ba61cc Disable lighting on path render 2019-08-08 09:36:55 -10:00
Leijurv
081fae98c4 1 year later 2019-08-01 23:47:32 -07:00
Leijurv
014d3b3a99 goal can never be null 2019-08-01 23:47:12 -07:00
Leijurv
19fe29ad1e i am stupid 2019-07-31 22:17:44 -07:00
Leijurv
8bcbd0231e bye 2019-07-31 21:45:57 -07:00
Leijurv
01c0e321b5 what was i THINKING 2019-07-31 20:58:45 -07:00
Leijurv
5f721b544e smh conner, imagine getting the same block position 2x without caching 2019-07-31 20:47:46 -07:00
Leijurv
57d4a79496 Merge pull request #701 from c0nn3r/master
Add parkour ascend
2019-07-30 21:55:37 -07:00
Conner
9541a45451 Resolve comments 2019-07-30 21:37:50 -07:00
Conner
bba4c09195 Add parkour ascend 2019-07-30 21:07:26 -07:00
Leijurv
06c62029c5 not iffy 2019-07-30 20:04:50 -07:00
Leijurv
6f251b64f1 i am very stupid 2019-07-29 17:35:06 -07:00
Leijurv
551b6b88d2 EXTREMELY old comment that is no longer true 2019-07-28 00:19:14 -07:00
Leijurv
07cbc47fb2 extra line 2019-07-27 23:51:23 -07:00
Leijurv
fe6ca97f21 whoops 2019-07-26 15:14:35 -07:00
Leijurv
1b481c6765 aristois badge 2019-07-26 15:14:04 -07:00
Leijurv
1c5e0b4d68 bump impact badge 2019-07-25 23:02:44 -07:00
Leijurv
afebdce1f8 fix crash and ice behavior 2019-07-25 16:02:29 -07:00
Leijurv
2ca4c3042a fix realms 2019-07-25 15:50:58 -07:00
Leijurv
a8226ba4c8 v1.3.4 2019-07-24 15:43:37 -07:00
Leijurv
bc849daccb v1.2.8 2019-07-24 15:38:14 -07:00
Leijurv
e34b2d1392 Merge branch 'master' into 1.13.2 2019-07-24 15:36:20 -07:00
Leijurv
f5b4de023f update usage stuff 2019-07-24 15:33:39 -07:00
Leijurv
6dc7a7788e install for 1.14.4 2019-07-23 22:30:04 -07:00
Leijurv
6bee5828a0 thank you brigadier very cool 2019-07-23 21:38:42 -07:00
Leijurv
8a5cc5b17d should be peaceful anyway 2019-07-23 20:54:00 -07:00
Leijurv
4e563c6130 could this be the worst possible way to copy a chunk array 2019-07-23 20:44:07 -07:00
Leijurv
01cf3c67a6 whatever this works lol 2019-07-23 19:25:48 -07:00
Leijurv
36315c5151 working for realsies 2019-07-23 15:47:18 -07:00
Leijurv
9f951f261d fixes 2019-07-23 15:39:19 -07:00
Leijurv
4c8907c629 it launches 2019-07-23 14:12:44 -07:00
Leijurv
223791cea7 Merge branch '1.13.2' into 1.14.2 2019-07-23 12:09:39 -07:00
Leijurv
de6e96b952 Merge branch 'master' into 1.13.2 2019-07-23 11:58:45 -07:00
Leijurv
0e51a73149 instanceof BlockLiquid checks this 2019-07-23 11:53:21 -07:00
Leijurv
44a092cd94 Merge pull request #622 from babbaj/schematica
fix crash
2019-07-22 23:57:54 -07:00
Babbaj
7000b6cda2 fix crash 2019-07-23 02:56:24 -04:00
Leijurv
7a17f7d253 Merge pull request #607 from babbaj/schematica
build the schematic schematica has open
2019-07-22 23:53:09 -07:00
Babbaj
821e73c1d3 fix usage.md 2019-07-23 02:48:40 -04:00
Babbaj
784bc52d6d add to usage.md 2019-07-23 02:46:53 -04:00
Leijurv
4338e34734 while this is cool, nothing will ever conceivably use it 2019-07-22 23:37:43 -07:00
Babbaj
61147536e5 ok 2019-07-22 16:51:09 -04:00
Leijurv
6b9737eb3f fix double jump on paused overshot sprint ascend 2019-07-21 22:04:15 -07:00
Babbaj
fe54372a53 resolve the issue 2019-07-21 22:33:22 -04:00
Babbaj
21e9c0b7c1 add get functions 2019-07-21 22:17:21 -04:00
Babbaj
8bf977060e dont need the fields 2019-07-21 22:06:36 -04:00
Babbaj
074ec333cf clean up a bit 2019-07-21 21:57:59 -04:00
Babbaj
d505ec4f9f build the schematic schematica has open 2019-07-21 21:05:43 -04:00
Leijurv
9dd6856872 get called out 2019-07-21 14:36:02 -07:00
Leijurv
4d127acb9a reformat 2019-07-20 23:47:51 -07:00
Leijurv
ed4753e968 now that impact locks to specific baritone versions this hack can finally be removed yay 2019-07-19 22:33:08 -07:00
Leijurv
df900c9e64 use origin 2019-07-19 18:55:32 -07:00
Leijurv
93a090c56e Merge pull request #588 from StijnSimons/master
I forgot players and items were entities too
2019-07-19 17:06:48 -07:00
StijnSimons
8b43d93259 i forgot players and items were entities too 2019-07-20 01:37:43 +02:00
Leijurv
053662d0af Merge pull request #554 from StijnSimons/master
FollowEntity and FollowEntities
2019-07-19 16:31:04 -07:00
Brady
af943a8253 Fix issue opening fence gates in some scenarios
If there are 2 fence gates at the player height, and they are approached
diagonally, there is a slight chance that Baritone will be caught in an
infinite loop of opening and closing the upper fence gate, being unable
to interact with the bottom one.
2019-07-18 21:18:02 -05:00
Leijurv
8151444671 privatize this too 2019-07-18 14:15:53 -07:00
Leijurv
f32147d9d5 privatize 2019-07-17 22:41:09 -07:00
Leijurv
515e0364f7 Merge pull request #564 from ZakME/patch-1
PICKUP_DROPPED - Remove 2nd Items.WHEAT
2019-07-16 23:01:09 -07:00
ZakME
09239f8180 PICKUP_DROPPED - Remove 2nd Items.WHEAT
PICKUP_DROPPED:
Remove 2nd Items.WHEAT
Re-order a few items for neatness
2019-07-16 23:50:03 -06:00
Brady
0d9f233e33 Add question template 2019-07-15 18:00:51 -05:00
Brady
e034437c63 Separate templates 2019-07-15 17:55:15 -05:00
Leijurv
72be046f34 Update ISSUE_TEMPLATE.md 2019-07-15 15:26:58 -07:00
StijnSimons
3ba8824eb0 More copy paste 2019-07-15 22:34:52 +02:00
StijnSimons
b51a261bd1 Added entityfollow
Hey look i can cntrl + c v
2019-07-15 22:31:55 +02:00
Leijurv
38602dd141 verify top side of block, fixes #541 2019-07-14 11:13:51 -07:00
Leijurv
cdbec60da0 Merge pull request #531 from StijnSimons/master
Added Spider, PigZombie and Enderman conditions
2019-07-13 09:15:53 -07:00
StijnSimons
2b41012c5b Enderman angry condition 2019-07-13 17:17:10 +02:00
Leijurv
6bb87d0a64 address an absolutely critical gap in documentation 2019-07-12 23:27:02 -07:00
Baddeveloper
b16f9edd2c Added EntitySpider and EntityPigZombie conditions 2019-07-12 19:12:00 +02:00
Leijurv
ce4b1e09ed fix parkour and multithread farm 2019-07-11 14:39:10 -07:00
Leijurv
1a4635df16 v1.3.3 2019-07-11 12:47:44 -07:00
Leijurv
1390af20b6 fix parkour and multithread farm 2019-07-11 12:46:24 -07:00
Leijurv
1427cf57a8 randomlooking 2019-07-11 11:56:44 -07:00
Leijurv
d70243b4c0 leijurv would never do this 2019-07-11 11:08:45 -07:00
Leijurv
8f63dd4ba6 Merge branch 'master' into 1.13.2 2019-07-11 10:51:29 -07:00
Leijurv
01658286af detect allowbreak false 2019-07-11 10:41:24 -07:00
Leijurv
aa90c8b7cd address encapsulation conccerns 2019-07-10 22:18:11 -07:00
Leijurv
eba1011fd6 remove scuff 2019-07-09 23:47:42 -07:00
Brady
96a424c25a Merge pull request #445 from SylveonBottle/patch-1
Speed up production
2019-07-09 14:23:37 -05:00
Leijurv
f4dd100345 fix indexof 2019-07-08 23:16:26 -07:00
Brady
c7e1c917c3 Fix Baritone thinking it can walk through wall-placed skulls
Fixes #485
2019-07-08 19:21:09 -05:00
Leijurv
cd4205c361 v1.2.7 2019-07-07 12:07:00 -07:00
Leijurv
b81bcf8c6d fix path start in diagonal and downward 2019-07-07 11:44:56 -07:00
Leijurv
4259764b70 thank you off by one errors very cool 2019-07-07 11:12:32 -07:00
Leijurv
8f761f7dff better skip ahead 2019-07-07 11:03:43 -07:00
Leijurv
cbbaf2aa2f unscuff 2019-07-06 20:38:59 -07:00
Leijurv
dd9b84646a disgraceful 2019-07-06 17:07:16 -07:00
Leijurv
94131fd705 too many newlines 2019-07-05 21:19:18 -07:00
Leijurv
6d8914e6c9 spell it out even more 2019-07-04 15:52:09 -07:00
Leijurv
63ee687cee shill EVEN harder 2019-07-03 23:47:47 -07:00
Leijurv
ab779dc850 increase shilling 2019-07-02 22:13:17 -07:00
Leijurv
c2f35ae46f dawn of the final month 2019-07-01 10:21:58 -07:00
Leijurv
199e0e5ed3 better comparison 2019-06-30 21:55:32 -07:00
Leijurv
a8155b4b0b privatize 2019-06-29 11:56:02 -07:00
Leijurv
fdd78cf110 codcacy wants these to be combined 2019-06-28 22:17:31 -07:00
Leijurv
afff6395d1 codcacy wants a default 2019-06-27 21:02:44 -07:00
Leijurv
4d3d48e962 crucial documentation oversight 2019-06-26 23:58:22 -07:00
Leijurv
36290e4e53 crucial encapsulation improvement 2019-06-25 22:54:24 -07:00
Leijurv
fd6923dd28 ok i forgot falling into water 2019-06-24 20:38:17 -07:00
Leijurv
9c64067d49 vastly improve resilience to lagbacks, fixes #446 2019-06-24 17:53:25 -07:00
Leijurv
f4d2ea7923 fix path canceling at edge of loaded chunks hopefully 2019-06-24 10:43:49 -07:00
Leijurv
ce3d3bb244 literally no reason to have this 2019-06-23 22:49:33 -07:00
Leijurv
fa71e7d84f reduce stupidity 2019-06-22 21:11:09 -07:00
Leijurv
b0115b8b4c Merge pull request #447 from babbaj/master
daily commit
2019-06-21 23:59:32 -07:00
Babbaj
3902b2db3b increase line count and improve readability 2019-06-21 23:01:37 -04:00
SylveonBottle
4ff61f96df wow times infinity 2019-06-21 03:59:10 -05:00
Leijurv
f998dce614 wow wow 2019-06-20 23:48:02 -07:00
Leijurv
2b9084d2f3 wow 2019-06-19 20:41:21 -07:00
Leijurv
b3605546ac golly another missing slash wow 2019-06-18 23:15:47 -07:00
Leijurv
96097ab726 this counts as a commit 2019-06-17 22:44:38 -07:00
Leijurv
be142d79bc link to the code 2019-06-16 23:06:57 -07:00
Leijurv
0fd241a9ba crucial performance optimization 2019-06-15 11:04:05 -07:00
Leijurv
7b192f17e8 privatize 2019-06-14 21:42:11 -07:00
Leijurv
cc015846d2 explain 2019-06-13 23:13:40 -07:00
Leijurv
e785bd13f5 sanity check 2019-06-12 16:41:05 -07:00
Leijurv
eb6c0a39ea codacy wants this 2019-06-11 23:46:04 -07:00
Leijurv
86525f98ec fix scuffed jumping, fixes #426 2019-06-10 23:12:37 -07:00
Leijurv
8758c77ac0 most of the way there 2019-06-10 18:25:20 -07:00
Leijurv
dba496471e api sourceset done 2019-06-10 12:43:02 -07:00
Leijurv
125facfbb6 Merge branch 'master' into 1.13.2 2019-06-10 11:50:14 -07:00
Leijurv
94bf703dde this counts as a commit 2019-06-09 23:56:54 -07:00
Leijurv
14bb0a0a80 alt text 2019-06-08 23:13:27 -07:00
Leijurv
1ee6e04f00 this counts as a commit 2019-06-07 21:29:31 -07:00
Brady
ee6796d5e2 crucial performance optimization (pt. 2) 2019-06-07 03:52:46 -05:00
Brady
81d7f3c319 crucial performance optimization 2019-06-07 03:19:23 -05:00
Leijurv
9822962d98 it is tbh 2019-06-06 23:55:12 -07:00
Brady
ce606f826b consistency 2019-06-06 19:05:13 -05:00
Brady
4c4bc8058b Some clean ups 2019-06-06 04:15:43 -05:00
Leijurv
f0210f7c5f add an additional underscore 2019-06-05 22:12:28 -07:00
Leijurv
aef84eceb8 fix a rare crash when the view is occluded by falling sand, fixes #443 2019-06-05 14:26:26 -07:00
Leijurv
a6ea9ed3a6 👶 2019-06-05 12:47:18 -07:00
Leijurv
0815e3c195 thank u intellij very cool suggestion 2019-06-05 12:08:19 -07:00
Leijurv
a1c03eb601 another tool selection fix 2019-06-05 12:04:09 -07:00
Leijurv
1e43563cc3 fix weird backfill behavior 2019-06-04 20:55:31 -07:00
Leijurv
63f3f9123a Merge pull request #409 from babbaj/master
use ImmutableSet
2019-06-03 22:17:14 -07:00
Leijurv
4860d3bd18 Merge pull request #439 from ImpcatDevelopment/delete-user-defined-waypoints
Added the command delete. Allows you to remove a user defined waypoint.
2019-06-03 22:09:08 -07:00
0x22
7fa6593bdc Added the command delete. Allows you to remove a user defined waypoint. Fixes #334 2019-06-04 01:04:13 -04:00
Leijurv
e1dd580df8 fix improper singleplayer check after quitting singleplayer 2019-06-03 15:27:24 -07:00
Leijurv
f19e63d6e9 mc version support is important 2019-06-03 13:43:32 -07:00
Leijurv
130873d91d 1.13.2 2019-06-02 21:33:10 -07:00
Leijurv
9611cb9057 1.13.2 is supported 2019-06-01 17:54:16 -07:00
Leijurv
023aa78d8b yay 2019-06-01 15:36:52 -07:00
Leijurv
39a231eae0 crucial performance optimization 2019-06-01 10:56:24 -07:00
Leijurv
aca6922be0 there is no actual integration 2019-05-31 23:01:16 -07:00
Leijurv
1a52537d0c badges 2019-05-30 20:49:04 -08:00
Leijurv
479b4e3349 releases download count 2019-05-29 10:45:59 -07:00
Leijurv
a1e2b018a2 very good suggestion 2019-05-28 14:17:54 -07:00
Leijurv
aa0f664cda just for debugging purposes 😉 2019-05-27 22:48:06 -07:00
Brady
2e2f4aee1b critical performance enhancement 2019-05-27 02:31:28 -05:00
Leijurv
18474d872c unused 2019-05-26 12:14:08 -07:00
Leijurv
44327c009a Merge pull request #427 from babbaj/master
yet another meaningless commit
2019-05-25 14:30:10 -07:00
Babbaj
de554655a5 yet another meaningless commit 2019-05-25 17:27:06 -04:00
Babbaj
bd0c7b9391 yet another meaningless commit 2019-05-25 17:25:23 -04:00
Babbaj
8d32db5206 Merge branch 'master' of https://github.com/cabaletta/baritone 2019-05-25 17:23:47 -04:00
Leijurv
a6954aa719 bye 2 2019-05-24 10:36:01 -07:00
Leijurv
b4d203ab99 bye 2019-05-23 20:47:22 -08:00
Leijurv
bb924ad83f thank you intellij very cool 2019-05-22 23:41:02 -07:00
Leijurv
79da32cc60 unused 2019-05-21 15:07:05 -07:00
Leijurv
c7fe9c3171 finalize 2019-05-20 22:37:51 -07:00
Leijurv
d70da4f37d finalize these 2019-05-19 21:53:09 -08:00
Leijurv
ccc1b04e81 crucial spacing 2019-05-18 17:11:16 -07:00
Leijurv
352e428890 explicitly set serialized name post obf 2019-05-17 22:21:40 -08:00
Leijurv
4679e12588 better usage 2019-05-16 15:20:52 -07:00
Babbaj
0f61aaafb8 use ImmutableSet 2019-04-28 21:27:11 -04:00
118 changed files with 2048 additions and 1924 deletions

View File

@@ -1 +0,0 @@
<!-- No UwU's or OwO's allowed -->

25
.github/ISSUE_TEMPLATE/bug.md vendored Normal file
View File

@@ -0,0 +1,25 @@
---
name: Bug report
about: Please file a separate report for each issue
title: Please add a brief but descriptive title
labels: bug
assignees: ''
---
## Some information
Operating system:
Java version:
Minecraft version:
Baritone version:
Forge mods (if used):
## Exception, error or logs
You can find your logs in `%appdata%/.minecraft/logs/` (Windows) or `/Library/Application\ Support/minecraft/logs` (Mac).
## How to reproduce
Add your steps to reproduce the issue/bug experienced here.
## Final checklist
- [ ] I have included the version of Minecraft I'm running, baritone's version and forge mods (if used).
- [ ] I have included logs, exceptions and / or steps to reproduce the issue.
- [ ] I have not used any OwO's or UwU's in this issue.

13
.github/ISSUE_TEMPLATE/question.md vendored Normal file
View File

@@ -0,0 +1,13 @@
---
name: Question
about: Please file a separate report for each question
title: Please add a brief but descriptive title
labels: question
assignees: ''
---
## What do you need help with?
With as much detail as possible, describe your question and what you may need help with.
## Final checklist
- [ ] I have not used any OwO's or UwU's in this issue.

19
.github/ISSUE_TEMPLATE/suggestion.md vendored Normal file
View File

@@ -0,0 +1,19 @@
---
name: Suggestion
about: Please file a separate report for each suggestion
title: Please add a brief but descriptive title
labels: enhancement
assignees: ''
---
## Describe your suggestion
With as much detail as possible, describe what your suggestion would do for Baritone.
## Settings
If applicable, what settings/customizability should be offered to tweak the functionality of your suggestion.
## Context
Describe how your suggestion would improve Baritone, or the reason behind it being added.
## Final checklist
- [ ] I have not used any OwO's or UwU's in this issue.

View File

@@ -1,37 +1,44 @@
# Baritone
[![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone)
[![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases)
[![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone/)
[![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases/)
[![License](https://img.shields.io/badge/license-LGPL--3.0%20with%20anime%20exception-green.svg)](LICENSE)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a73d037823b64a5faf597a18d71e3400)](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=cabaletta/baritone&amp;utm_campaign=Badge_Grade)
[![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone)
[![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone/)
[![GitHub All Releases](https://img.shields.io/github/downloads/cabaletta/baritone/total.svg)](https://github.com/cabaletta/baritone/releases/)
[![Minecraft](https://img.shields.io/badge/MC-1.12.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/master/)
[![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.13.2/)
[![Minecraft](https://img.shields.io/badge/MC-1.14.4-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.14.4/)
[![Code of Conduct](https://img.shields.io/badge/%E2%9D%A4-code%20of%20conduct-blue.svg?style=flat)](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md)
[![Known Vulnerabilities](https://snyk.io/test/github/cabaletta/baritone/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle)
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues)
[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues/)
[![Issues](https://img.shields.io/github/issues/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/issues/)
[![GitHub issues-closed](https://img.shields.io/github/issues-closed/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed)
[![Pull Requests](https://img.shields.io/github/issues-pr/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/pulls/)
![Code size](https://img.shields.io/github/languages/code-size/cabaletta/baritone.svg)
![GitHub repo size](https://img.shields.io/github/repo-size/cabaletta/baritone.svg)
![](https://tokei.rs/b1/github/cabaletta/baritone?category=code)
[![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://minecraft.gamepedia.com/1.13.2)
![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 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.5%20/%20v1.3.0-brightgreen.svg)](https://impactdevelopment.github.io/)
[![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.8%20/%20v1.3.4-brightgreen.svg)](https://impactdevelopment.github.io/)
[![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-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/)
[![KAMI integration](https://img.shields.io/badge/KAMI%20integration-v1.0.0-red.svg)](https://github.com/zeroeightysix/KAMI/)
[![Future integration](https://img.shields.io/badge/Future%20integration-Soon™%3F%3F%3F-red.svg)](https://futureclient.net/)
[![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20integration-Soon™-red.svg)](https://github.com/fr1kin/ForgeHax)
[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/)
[![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com/)
A Minecraft pathfinder bot.
Baritone is the pathfinding system used in [Impact](https://impactdevelopment.github.io/) since 4.4. There's a [showcase video](https://www.youtube.com/watch?v=yI8hgW_m6dQ) made by @Adovin#3153 on Baritone's integration into Impact. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do.
This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/),
the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths).
The easiest way to install Baritone is to install [Impact](https://impactdevelopment.github.io/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the v1.2.* forge api jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it.
Have committed at least once a day for the last 8 months =D 🦀
For 1.14.4, [click here](https://www.dropbox.com/s/rkml3hjokd3qv0m/1.14.4-Baritone.zip?dl=1). Or [with optifine](https://github.com/cabaletta/baritone/issues/797).
This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/),
the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 and 1.13.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths).
Have committed at least once a day from Aug 1 2018 to Aug 1 2019.
1Leijurv3DWTrGAfmmiTphjhXLvQiHg7K2
@@ -43,15 +50,15 @@ Here are some links to help to get started:
- [Installation & setup](SETUP.md)
- [API Javadocs](https://baritone.leijurv.com)
- [API Javadocs](https://baritone.leijurv.com/)
- [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail)
- [Baritone chat control usage](USAGE.md)
- [Usage (chat control)](USAGE.md)
# API
The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com).
The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/).
Please note that usage of anything located outside of the ``baritone.api`` package is not supported by the API release
jar.
@@ -68,11 +75,11 @@ BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAnd
## Can I use Baritone as a library in my custom utility client?
That's what it's for, sure! (As long as usage is in compliance with the LGPL 3 License)
That's what it's for, sure! (As long as usage is in compliance with the LGPL 3.0 License)
## How is it so fast?
Magic. (Hours of [leijurv](https://github.com/leijurv) enduring excruciating pain)
Magic. (Hours of [leijurv](https://github.com/leijurv/) enduring excruciating pain)
## Why is it called Baritone?

View File

@@ -1,10 +1,18 @@
# Installation
The easiest way to install Baritone is to install [Impact](https://impactdevelopment.github.io/), which comes with Baritone.
For 1.14.4, [click here](https://www.dropbox.com/s/rkml3hjokd3qv0m/1.14.4-Baritone.zip?dl=1).
Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it.
## Prebuilt official releases
These releases are not always completely up to date with latest features, and are only released from `master`. (so if you want `backfill-2` branch for example, you'll have to build it yourself)
Link to the releases page: [Releases](https://github.com/cabaletta/baritone/releases)
v1.2.* is for 1.12.2, v1.3.* is for 1.13.2
Any official release will be GPG signed by leijurv (44A3EA646EADAC6A) and ZeroMemes (73A788379A197567). Please verify that the hash of the file you download is in `checksums.txt` and that `checksums_signed.asc` is a valid signature by those two public keys of `checksums.txt`.
The build is fully deterministic and reproducible, and you can verify Travis did it properly by running `docker build --no-cache -t cabaletta/baritone .` yourself and comparing the shasum. This works identically on Travis, Mac, and Linux (if you have docker on Windows, I'd be grateful if you could let me know if it works there too).

View File

@@ -2,42 +2,34 @@
# Prefix
Baritone commands can by default be typed in the chatbox. However if you make a typo, like typing "gola 10000 10000" instead of goal it goes into public chat, which is bad.
Therefore you can use a prefix before your messages.
On Baritone v1.1.0 and newer: The prefix is `#` by default. Anything beginning with `#` isn't sent, and is only interpreted by Baritone.
For older than v1.1.0, `#` must be enabled by toggling on the `prefix` setting.
**Only** in Impact is `.b` also a valid prefix. In 4.4, `#` does **not** work, neither does saying the commands directly in chat. `#` works by default in 4.5 (not 4.4).
Other clients like Kami and Asuna have their own custom things (like `-path`), and can disable direct chat control entirely.
Baritone's chat control prefix is `#` by default. In Impact, you can also use `.b` as a prefix. (for example, `.b click` instead of `#click`)
Baritone commands can also by default be typed in the chatbox. However if you make a typo, like typing "gola 10000 10000" instead of "goal" it goes into public chat, which is bad, so using `#` is suggested.
To disable direct chat control (with no prefix), turn off the `chatControl` setting. To disable chat control with the `#` prefix, turn off the `prefixControl` setting. In Impact, `.b` cannot be disabled. Be careful that you don't leave yourself with all control methods disabled (if you do, reset your settings by deleting the file `minecraft/baritone/settings.txt` and relaunching).
# Commands
**All** of these commands may need a prefix before them, as above ^.
`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java#L53).
`help` for (rudimentary) help. You can see what it says [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java#L47).
To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`.
Some common examples:
- `thisway 1000` then `path` to go in the direction you're facing for a thousand blocks
- `goal x y z` or `goal x z` or `goal y`, then `path` to go to a certain coordinate
- `goal x y z` or `goal x z` or `goal y`, then `path` to set a goal to a certain coordinate then path to it
- `goto x y z` or `goto x z` or `goto y` to go to a certain coordinate (in a single step, starts going immediately)
- `goal` to set the goal to your player's feet
- `goal clear` to clear the goal
- `cancel` or `stop` to stop everything
- `goto portal` or `goto ender_chest` or `goto block_type` to go to a block. (in Impact, `.goto` is an alias for `.b goto` for the most part)
- `mine diamond_ore` to mine diamond ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.)
- `click` to click your destination on the screen. Right click path to on top of the block, left click to path into it (either at foot level or eye level), and left click and drag to clear all blocks from an area.
- `follow playerName` to follow a player. `follow` to follow the entity you're looking at (only works if it hitting range). `followplayers` to follow any players in range (combine with Kill Aura for a fun time).
- `follow playerName` to follow a player. `followplayers` to follow any players in range (combine with Kill Aura for a fun time). `followentities` to follow any entities. `followentity pig` to follow entities of a specific type.
- `save waypointName` to save a waypoint. `goto waypointName` to go to it.
- `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420).
- `schematica` to build the schematic that is currently open in schematica
- `tunnel` to dig just straight ahead and make a tunnel
- `farm` to automatically harvest, replant, or bone meal crops
- `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120).
@@ -47,7 +39,7 @@ Some common examples:
- `damn` daniel
For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/main/java/baritone/utils/ExampleBaritoneControl.java).
For the rest of the commands, you can take a look at the code [here](https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/utils/ExampleBaritoneControl.java).
All the settings and documentation are <a href="https://github.com/cabaletta/baritone/blob/master/src/api/java/baritone/api/Settings.java">here</a>. If you find HTML easier to read than Javadoc, you can look <a href="https://baritone.leijurv.com/baritone/api/Settings.html#field.detail">here</a>.

View File

@@ -16,7 +16,7 @@
*/
group 'baritone'
version '1.3.2'
version '1.4.0'
buildscript {
repositories {
@@ -66,6 +66,14 @@ sourceSets {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
schematica_api {
compileClasspath += main.compileClasspath
}
main {
compileClasspath += schematica_api.output
}
}
task sourceJar(type: Jar, dependsOn: classes) {
@@ -74,7 +82,7 @@ task sourceJar(type: Jar, dependsOn: classes) {
}
minecraft {
mappings channel: 'snapshot', version: '20190307-1.13.1'
mappings channel: 'snapshot', version: '20190814-1.14.3'
reobfMappings 'notch'
runs {
@@ -130,7 +138,7 @@ repositories {
}
dependencies {
minecraft 'com.github.ImpactDevelopment:Vanilla:1.13.2'
minecraft 'com.github.ImpactDevelopment:Vanilla:1.14.4'
runtime launchCompile('net.minecraft:launchwrapper:1.12') {
exclude module: 'lwjgl'

View File

@@ -33,6 +33,12 @@
# need to keep mixin names
-keep class baritone.launch.** { *; }
#try to keep usage of schematica in separate classes
-keep class baritone.utils.schematic.schematica.**
#proguard doesnt like it when it cant find our fake schematica classes
-dontwarn baritone.utils.schematic.schematica.**
# Keep - Applications. Keep all application classes, along with their 'main'
# methods.
-keepclasseswithmembers public class * {

View File

@@ -128,5 +128,8 @@ public interface IBaritone {
*/
IEventBus getGameEventHandler();
/**
* Open click
*/
void openClick();
}

View File

@@ -18,7 +18,7 @@
package baritone.api;
import baritone.api.cache.IWorldScanner;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import java.util.List;
@@ -43,19 +43,19 @@ public interface IBaritoneProvider {
* returned by {@link #getPrimaryBaritone()}.
*
* @return All active {@link IBaritone} instances.
* @see #getBaritoneForPlayer(EntityPlayerSP)
* @see #getBaritoneForPlayer(ClientPlayerEntity)
*/
List<IBaritone> getAllBaritones();
/**
* Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be
* Provides the {@link IBaritone} instance for a given {@link ClientPlayerEntity}. This will likely be
* replaced with or be overloaded in addition to {@code #getBaritoneForUser(IBaritoneUser)} when
* {@code bot-system} is merged into {@code master}.
*
* @param player The player
* @return The {@link IBaritone} instance.
*/
default IBaritone getBaritoneForPlayer(EntityPlayerSP player) {
default IBaritone getBaritoneForPlayer(ClientPlayerEntity player) {
for (IBaritone baritone : getAllBaritones()) {
if (player.equals(baritone.getPlayerContext().player())) {
return baritone;

View File

@@ -20,8 +20,8 @@ package baritone.api;
import baritone.api.utils.SettingsUtil;
import baritone.api.utils.TypeUtils;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.text.ITextComponent;
@@ -124,6 +124,13 @@ public final class Settings {
*/
public final Setting<Boolean> allowJumpAt256 = new Setting<>(false);
/**
* This should be monetized it's so good
* <p>
* Defaults to true, but only actually takes effect if allowParkour is also true
*/
public final Setting<Boolean> allowParkourAscend = new Setting<>(true);
/**
* Allow descending diagonally
* <p>
@@ -178,7 +185,7 @@ public final class Settings {
* Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real
* pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario.
* <p>
* Never turn this on lol
* Almost never turn this on lol
*/
public final Setting<Boolean> allowVines = new Setting<>(false);
@@ -231,6 +238,11 @@ public final class Settings {
*/
public final Setting<Integer> rightClickSpeed = new Setting<>(4);
/**
* How many degrees to randomize the yaw every tick. Set to 0 to disable
*/
public final Setting<Double> randomLooking = new Setting<>(2d);
/**
* This is the big A* setting.
* As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path.

View File

@@ -17,7 +17,7 @@
package baritone.api.cache;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
/**
@@ -26,9 +26,9 @@ import net.minecraft.util.math.BlockPos;
*/
public interface IBlockTypeAccess {
IBlockState getBlock(int x, int y, int z);
BlockState getBlock(int x, int y, int z);
default IBlockState getBlock(BlockPos pos) {
default BlockState getBlock(BlockPos pos) {
return getBlock(pos.getX(), pos.getY(), pos.getZ());
}
}

View File

@@ -19,7 +19,7 @@ package baritone.api.event.events;
import baritone.api.event.events.type.EventState;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.IPacket;
/**
* @author Brady
@@ -31,9 +31,9 @@ public final class PacketEvent {
private final EventState state;
private final Packet<?> packet;
private final IPacket<?> packet;
public PacketEvent(NetworkManager networkManager, EventState state, Packet<?> packet) {
public PacketEvent(NetworkManager networkManager, EventState state, IPacket<?> packet) {
this.networkManager = networkManager;
this.state = state;
this.packet = packet;
@@ -47,12 +47,12 @@ public final class PacketEvent {
return this.state;
}
public final Packet<?> getPacket() {
public final IPacket<?> getPacket() {
return this.packet;
}
@SuppressWarnings("unchecked")
public final <T extends Packet<?>> T cast() {
public final <T extends IPacket<?>> T cast() {
return (T) this.packet;
}
}

View File

@@ -18,7 +18,6 @@
package baritone.api.event.events;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
/**
* @author Brady
@@ -76,7 +75,7 @@ public final class RotationMoveEvent {
/**
* Called when the player jumps.
*
* @see EntityLivingBase#jump
* @see LivingEntity#jump
*/
JUMP
}

View File

@@ -18,7 +18,7 @@
package baritone.api.event.events;
import baritone.api.event.events.type.EventState;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.world.ClientWorld;
/**
* @author Brady
@@ -29,14 +29,14 @@ public final class WorldEvent {
/**
* The new world that is being loaded. {@code null} if being unloaded.
*/
private final WorldClient world;
private final ClientWorld world;
/**
* The state of the event
*/
private final EventState state;
public WorldEvent(WorldClient world, EventState state) {
public WorldEvent(ClientWorld world, EventState state) {
this.world = world;
this.state = state;
}
@@ -44,7 +44,7 @@ public final class WorldEvent {
/**
* @return The new world that is being loaded. {@code null} if being unloaded.
*/
public final WorldClient getWorld() {
public final ClientWorld getWorld() {
return this.world;
}

View File

@@ -19,12 +19,11 @@ package baritone.api.event.listener;
import baritone.api.event.events.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiGameOver;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.network.Packet;
/**
* @author Brady
@@ -44,7 +43,7 @@ public interface IGameEventListener {
* Run once per game tick from before and after the player rotation is sent to the server.
*
* @param event The event
* @see EntityPlayerSP#tick()
* @see ClientPlayerEntity#tick()
*/
void onPlayerUpdate(PlayerUpdateEvent event);
@@ -52,7 +51,7 @@ public interface IGameEventListener {
* Runs whenever the client player sends a message to the server.
*
* @param event The event
* @see EntityPlayerSP#sendChatMessage(String)
* @see ClientPlayerEntity#sendChatMessage(String)
*/
void onSendChatMessage(ChatEvent event);
@@ -74,7 +73,7 @@ public interface IGameEventListener {
* Runs before and after whenever a new world is loaded
*
* @param event The event
* @see Minecraft#loadWorld(WorldClient, GuiScreen)
* @see Minecraft#loadWorld(ClientWorld, Screen)
*/
void onWorldEvent(WorldEvent event);
@@ -104,10 +103,10 @@ public interface IGameEventListener {
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 ClientPlayerEntity#livingTick}
*
* @param event The event
* @see EntityPlayerSP#livingTick()
* @see ClientPlayerEntity#livingTick()
*/
void onPlayerSprintState(SprintStateEvent event);

View File

@@ -17,7 +17,7 @@
package baritone.api.pathing.goals;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
/**
@@ -30,7 +30,7 @@ public class GoalStrictDirection implements Goal {
public final int dx;
public final int dz;
public GoalStrictDirection(BlockPos origin, EnumFacing direction) {
public GoalStrictDirection(BlockPos origin, Direction direction) {
x = origin.getX();
y = origin.getY();
z = origin.getZ();

View File

@@ -54,6 +54,8 @@ public interface IBuilderProcess extends IBaritoneProcess {
return build(schematicFile, file, origin);
}
void buildOpenSchematic();
void pause();
void resume();

View File

@@ -17,7 +17,7 @@
package baritone.api.utils;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3i;
@@ -101,10 +101,10 @@ public final class BetterBlockPos extends BlockPos {
// this is unimaginably faster than blockpos.up
// that literally calls
// this.up(1)
// which calls this.offset(EnumFacing.UP, 1)
// which calls this.offset(Direction.UP, 1)
// which does return n == 0 ? this : new BlockPos(this.getX() + facing.getXOffset() * n, this.getY() + facing.getYOffset() * n, this.getZ() + facing.getZOffset() * n);
// how many function calls is that? up(), up(int), offset(EnumFacing, int), new BlockPos, getX, getXOffset, getY, getYOffset, getZ, getZOffset
// how many function calls is that? up(), up(int), offset(Direction, int), new BlockPos, getX, getXOffset, getY, getYOffset, getZ, getZOffset
// that's ten.
// this is one function call.
return new BetterBlockPos(x, y + 1, z);
@@ -129,13 +129,13 @@ public final class BetterBlockPos extends BlockPos {
}
@Override
public BetterBlockPos offset(EnumFacing dir) {
public BetterBlockPos offset(Direction dir) {
Vec3i vec = dir.getDirectionVec();
return new BetterBlockPos(x + vec.getX(), y + vec.getY(), z + vec.getZ());
}
@Override
public BetterBlockPos offset(EnumFacing dir, int dist) {
public BetterBlockPos offset(Direction dir, int dist) {
if (dist == 0) {
return this;
}

View File

@@ -17,9 +17,10 @@
package baritone.api.utils;
import net.minecraft.block.AirBlock;
import net.minecraft.block.Block;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraft.util.registry.Registry;
import java.util.HashMap;
import java.util.Map;
@@ -29,7 +30,7 @@ public class BlockUtils {
private static transient Map<String, Block> resourceCache = new HashMap<>();
public static String blockToString(Block block) {
ResourceLocation loc = IRegistry.BLOCK.getKey(block);
ResourceLocation loc = Registry.BLOCK.getKey(block);
String name = loc.getPath(); // normally, only write the part after the minecraft:
if (!loc.getNamespace().equals("minecraft")) {
// Baritone is running on top of forge with mods installed, perhaps?
@@ -39,9 +40,6 @@ public class BlockUtils {
}
public static Block stringToBlockRequired(String name) {
if (name.equals("lit_redstone_ore")) { // workaround for Impact 4.6 only
return stringToBlockRequired("redstone_ore");
}
Block block = stringToBlockNullable(name);
Objects.requireNonNull(block);
return block;
@@ -56,7 +54,10 @@ public class BlockUtils {
if (resourceCache.containsKey(name)) {
return null; // cached as null
}
block = IRegistry.BLOCK.get(ResourceLocation.tryCreate(name.contains(":") ? name : "minecraft:" + name));
block = Registry.BLOCK.getOrDefault(ResourceLocation.tryCreate(name.contains(":") ? name : "minecraft:" + name));
if (block instanceof AirBlock && !name.equals("air")) {
block = null;
}
Map<String, Block> copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification
copy.put(name, block);
resourceCache = copy;

View File

@@ -32,48 +32,26 @@ import baritone.api.process.ICustomGoalProcess;
import baritone.api.process.IGetToBlockProcess;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.crash.CrashReport;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.DimensionType;
import java.nio.file.Path;
import java.util.*;
import static org.apache.commons.lang3.StringUtils.isNumeric;
public class ExampleBaritoneControl implements Helper, AbstractGameEventListener {
private static final String HELP_MSG =
"baritone - Output settings into chat\n" +
"settings - Same as baritone\n" +
"goal - Create a goal (one number is '<Y>', two is '<X> <Z>', three is '<X> <Y> <Z>, 'clear' to clear)\n" +
"path - Go towards goal\n" +
"repack - (debug) Repacks chunk cache\n" +
"rescan - (debug) Same as repack\n" +
"axis - Paths towards the closest axis or diagonal axis, at y=120\n" +
"cancel - Cancels current path\n" +
"forcecancel - sudo cancel (only use if very glitched, try toggling 'pause' first)\n" +
"gc - Calls System.gc();\n" +
"invert - Runs away from the goal instead of towards it\n" +
"follow - Follows a player 'follow username'\n" +
"reloadall - (debug) Reloads chunk cache\n" +
"saveall - (debug) Saves chunk cache\n" +
"find - (debug) outputs how many blocks of a certain type are within the cache\n" +
"mine - Paths to and mines specified blocks 'mine x_ore y_ore ...'\n" +
"thisway - Creates a goal X blocks where you're facing\n" +
"list - Lists waypoints under a category\n" +
"get - Same as list\n" +
"show - Same as list\n" +
"save - Saves a waypoint (works but don't try to make sense of it)\n" +
"goto - Paths towards specified block or waypoint\n" +
"spawn - Paths towards world spawn or your most recent bed right-click\n" +
"sethome - Sets \"home\"\n" +
"home - Paths towards \"home\" \n" +
"costs - (debug) all movement costs from current location\n" +
"damn - Daniel\n" +
"Go to https://github.com/cabaletta/baritone/blob/master/USAGE.md for more information";
private static final String COMMAND_PREFIX = "#";
public final IBaritone baritone;
@@ -144,9 +122,12 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
return true;
}
if (msg.equals("") || msg.equals("help") || msg.equals("?")) {
for (String line : HELP_MSG.split("\n")) {
logDirect(line);
}
ITextComponent component = MESSAGE_PREFIX.shallowCopy();
component.getStyle().setColor(TextFormatting.GRAY);
StringTextComponent helpLink = new StringTextComponent(" Click here for instructions on how to use Baritone (https://github.com/cabaletta/baritone/blob/master/USAGE.md)");
helpLink.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/cabaletta/baritone/blob/master/USAGE.md"));
component.appendSibling(helpLink);
BaritoneAPI.getSettings().logger.value.accept(component);
return true;
}
if (msg.contains(" ")) {
@@ -195,6 +176,16 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
logDirect("Goal: " + goal);
return true;
}
if (msg.equals("crash")) {
StringBuilder meme = new StringBuilder();
CrashReport rep = new CrashReport("Manually triggered debug crash", new Throwable());
mc.addGraphicsAndWorldToCrashReport(rep);
rep.getSectionsInStringBuilder(meme);
System.out.println(meme);
logDirect(meme.toString());
logDirect("ok");
return true;
}
if (msg.equals("path")) {
if (pathingBehavior.getGoal() == null) {
logDirect("No goal.");
@@ -207,23 +198,6 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
return true;
}
/*if (msg.equals("fullpath")) {
if (pathingBehavior.getGoal() == null) {
logDirect("No goal.");
} else {
logDirect("Started segmented calculator");
SegmentedCalculator.calculateSegmentsThreaded(pathingBehavior.pathStart(), pathingBehavior.getGoal(), new CalculationContext(baritone, true), ipath -> {
logDirect("Found a path");
logDirect("Ends at " + ipath.getDest());
logDirect("Length " + ipath.length());
logDirect("Estimated time " + ipath.ticksRemainingFrom(0));
pathingBehavior.secretCursedFunctionDoNotCall(ipath); // it's okay when *I* do it
}, () -> {
logDirect("Path calculation failed, no path");
});
}
return true;
}*/
if (msg.equals("proc")) {
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
if (!proc.isPresent()) {
@@ -248,13 +222,13 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
return true;
}
if (msg.equals("repack") || msg.equals("rescan")) {
ChunkProviderClient cli = (ChunkProviderClient) ctx.world().getChunkProvider();
ClientChunkProvider cli = (ClientChunkProvider) ctx.world().getChunkProvider();
int playerChunkX = ctx.playerFeet().getX() >> 4;
int playerChunkZ = ctx.playerFeet().getZ() >> 4;
int count = 0;
for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) {
for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) {
Chunk chunk = cli.getChunk(x, z, false, false);
Chunk chunk = cli.getChunk(x, z, null, false);
if (chunk != null) {
count++;
baritone.getWorldProvider().getCurrentWorld().getCachedWorld().queueForPacking(chunk);
@@ -270,7 +244,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
try {
String[] coords = msg.substring("build".length()).trim().split(" ");
file = coords[0] + ".schematic";
origin = new BlockPos(parseOrDefault(coords[1], ctx.playerFeet().x), parseOrDefault(coords[2], ctx.playerFeet().y), parseOrDefault(coords[3], ctx.playerFeet().z));
origin = new BlockPos(parseOrDefault(coords[1], ctx.playerFeet().x, 1), parseOrDefault(coords[2], ctx.playerFeet().y, 1), parseOrDefault(coords[3], ctx.playerFeet().z, 1));
} catch (Exception ex) {
file = msg.substring(5).trim() + ".schematic";
origin = ctx.playerFeet();
@@ -280,6 +254,10 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
logDirect(success ? "Loaded" : "Unable to load");
return true;
}
if (msg.startsWith("schematica")) {
baritone.getBuilderProcess().buildOpenSchematic();
return true;
}
if (msg.equals("come")) {
customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity())));
logDirect("Coming");
@@ -332,7 +310,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
if (suffix.isEmpty()) {
// clear the area from the current goal to here
Goal goal = baritone.getPathingBehavior().getGoal();
if (goal == null || !(goal instanceof GoalBlock)) {
if (!(goal instanceof GoalBlock)) {
logDirect("Need to specify goal of opposite corner");
return true;
}
@@ -376,7 +354,8 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
if (msg.equals("render")) {
BetterBlockPos pf = ctx.playerFeet();
Minecraft.getInstance().worldRenderer.markBlockRangeForRenderUpdate(pf.x - 500, pf.y - 500, pf.z - 500, pf.x + 500, pf.y + 500, pf.z + 500);
int dist = (Minecraft.getInstance().gameSettings.renderDistanceChunks + 1) * 16;
Minecraft.getInstance().worldRenderer.markBlockRangeForRenderUpdate(pf.x - dist, pf.y - 256, pf.z - dist, pf.x + dist, pf.y + 256, pf.z + dist);
logDirect("okay");
return true;
}
@@ -385,17 +364,6 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
logDirect("farming");
return true;
}
// this literally doesn't work, memory is disabled lol
/*if (msg.equals("echest")) {
Optional<List<ItemStack>> contents = baritone.getMemoryBehavior().echest();
if (contents.isPresent()) {
logDirect("echest contents:");
log(contents.get());
} else {
logDirect("echest contents unknown");
}
return true;
}*/
if (msg.equals("chests")) {
for (Map.Entry<BlockPos, IRememberedInventory> entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) {
logDirect(entry.getKey() + "");
@@ -403,18 +371,41 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
return true;
}
if (msg.startsWith("followentities")) {
baritone.getFollowProcess().follow(Entity.class::isInstance);
logDirect("Following any entities");
return true;
}
if (msg.startsWith("followplayers")) {
baritone.getFollowProcess().follow(EntityPlayer.class::isInstance); // O P P A
baritone.getFollowProcess().follow(PlayerEntity.class::isInstance); // O P P A
logDirect("Following any players");
return true;
}
if (msg.startsWith("followentity")) {
String name = msg.substring(12).trim();
Optional<Entity> toFollow = Optional.empty();
for (Entity entity : ctx.entities()) {
String entityName = entity.getName().getFormattedText().trim().toLowerCase();
if ((entityName.contains(name) || name.contains(entityName)) && !(entity instanceof ItemEntity || entity instanceof PlayerEntity)) { // We dont want it following players while `#follow` exists.
toFollow = Optional.of(entity);
}
}
if (!toFollow.isPresent()) {
logDirect("Entity not found");
return true;
}
Entity effectivelyFinal = toFollow.get();
baritone.getFollowProcess().follow(effectivelyFinal::equals);
logDirect("Following entity " + toFollow.get());
return true;
}
if (msg.startsWith("follow")) {
String name = msg.substring(6).trim();
Optional<Entity> toFollow = Optional.empty();
if (name.length() == 0) {
toFollow = ctx.getSelectedEntity();
} else {
for (EntityPlayer pl : ctx.world().playerEntities) {
for (PlayerEntity pl : ctx.world().getPlayers()) {
String theirName = pl.getName().getString().trim().toLowerCase();
if (!theirName.equals(ctx.player().getName().getString().trim().toLowerCase()) && (theirName.contains(name) || name.contains(theirName))) { // don't follow ourselves lol
toFollow = Optional.of(pl);
@@ -426,7 +417,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
return true;
}
Entity effectivelyFinal = toFollow.get();
baritone.getFollowProcess().follow(x -> effectivelyFinal.equals(x));
baritone.getFollowProcess().follow(effectivelyFinal::equals);
logDirect("Following " + toFollow.get());
return true;
}
@@ -581,6 +572,17 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints.");
return true;
}
if (msg.startsWith("delete")) {
String name = msg.substring(6).trim();
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getTag() == IWaypoint.Tag.USER && w.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
if (waypoint == null) {
logDirect("No user defined position under the name '" + name + "' found.");
return true;
}
baritone.getWorldProvider().getCurrentWorld().getWaypoints().removeWaypoint(waypoint);
logDirect("Deleted user defined position under name '" + name + "'.");
return true;
}
if (msg.startsWith("goto")) {
String waypointType = msg.substring(4).trim();
if (waypointType.endsWith("s") && IWaypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
@@ -649,32 +651,14 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
return true;
}
// this is completely impossible from api
/*if (msg.equals("costs")) {
List<Movement> moves = Stream.of(Moves.values()).map(x -> x.apply0(new CalculationContext(baritone), ctx.playerFeet())).collect(Collectors.toCollection(ArrayList::new));
while (moves.contains(null)) {
moves.remove(null);
}
moves.sort(Comparator.comparingDouble(move -> move.getCost(new CalculationContext(baritone))));
for (Movement move : moves) {
String[] parts = move.getClass().toString().split("\\.");
double cost = move.getCost();
String strCost = cost + "";
if (cost >= ActionCosts.COST_INF) {
strCost = "IMPOSSIBLE";
}
logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
}
return true;
}*/
if (msg.equals("damn")) {
logDirect("daniel");
}
return false;
}
private int parseOrDefault(String str, int i) {
return str.equals("~") ? i : str.startsWith("~") ? Integer.parseInt(str.substring(1)) + i : Integer.parseInt(str);
private int parseOrDefault(String str, int i, double dimensionFactor) {
return str.equals("~") ? i : str.startsWith("~") ? (int) (Integer.parseInt(str.substring(1)) * dimensionFactor) + i : (int) (Integer.parseInt(str) * dimensionFactor);
}
private void log(List<ItemStack> stacks) {
@@ -689,19 +673,23 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
Goal goal;
try {
BetterBlockPos playerFeet = ctx.playerFeet();
switch (params.length) {
int length = params.length - 1; // length has to be smaller when a dimension parameter is added
if (params.length < 1 || (isNumeric(params[params.length - 1]) || params[params.length - 1].startsWith("~"))) {
length = params.length;
}
switch (length) {
case 0:
goal = new GoalBlock(playerFeet);
break;
case 1:
goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y));
goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y, 1));
break;
case 2:
goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.z));
goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x, calculateDimensionFactor(params[params.length - 1])), parseOrDefault(params[1], playerFeet.z, calculateDimensionFactor(params[params.length - 1])));
break;
case 3:
goal = new GoalBlock(new BlockPos(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.y), parseOrDefault(params[2], playerFeet.z)));
goal = new GoalBlock(new BlockPos(parseOrDefault(params[0], playerFeet.x, calculateDimensionFactor(params[params.length - 1])), parseOrDefault(params[1], playerFeet.y, 1), parseOrDefault(params[2], playerFeet.z, calculateDimensionFactor(params[params.length - 1]))));
break;
default:
logDirect("unable to understand lol");
@@ -713,4 +701,23 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
return goal;
}
private double calculateDimensionFactor(String to) {
return Math.pow(8, ctx.world().dimension.getType().getId() - getDimensionByName(to.toLowerCase()).getId());
}
private DimensionType getDimensionByName(String name) {
if ("the_end".contains(name)) {
return DimensionType.THE_END;
}
if ("the_overworld".contains(name) || "surface".contains(name)) {
return DimensionType.OVERWORLD;
}
if ("the_nether".contains(name) || "hell".contains(name)) {
return DimensionType.THE_NETHER;
}
return ctx.world().dimension.getType();
}
}

View File

@@ -20,7 +20,7 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
/**
@@ -34,7 +34,7 @@ public interface Helper {
*/
Helper HELPER = new Helper() {};
ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format(
ITextComponent MESSAGE_PREFIX = new StringTextComponent(String.format(
"%s[%sBaritone%s]%s",
TextFormatting.DARK_PURPLE,
TextFormatting.LIGHT_PURPLE,
@@ -66,7 +66,7 @@ public interface Helper {
default void logDirect(String message) {
ITextComponent component = MESSAGE_PREFIX.shallowCopy();
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(new TextComponentString(" " + message));
Minecraft.getInstance().addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component));
component.appendSibling(new StringTextComponent(" " + message));
Minecraft.getInstance().execute(() -> BaritoneAPI.getSettings().logger.value.accept(component));
}
}

View File

@@ -18,15 +18,16 @@
package baritone.api.utils;
import baritone.api.cache.IWorldData;
import net.minecraft.block.BlockSlab;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.block.SlabBlock;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* @author Brady
@@ -34,12 +35,21 @@ import java.util.Optional;
*/
public interface IPlayerContext {
EntityPlayerSP player();
ClientPlayerEntity player();
IPlayerController playerController();
World world();
default Iterable<Entity> entities() {
return ((ClientWorld) world()).getAllEntities();
}
default Stream<Entity> entitiesStream() {
return StreamSupport.stream(entities().spliterator(), false);
}
IWorldData worldData();
RayTraceResult objectMouseOver();
@@ -47,7 +57,7 @@ public interface IPlayerContext {
default BetterBlockPos playerFeet() {
// TODO find a better way to deal with soul sand!!!!!
BetterBlockPos feet = new BetterBlockPos(player().posX, player().posY + 0.1251, player().posZ);
if (world().getBlockState(feet).getBlock() instanceof BlockSlab) {
if (world().getBlockState(feet).getBlock() instanceof SlabBlock) {
return feet.up();
}
return feet;
@@ -72,8 +82,8 @@ public interface IPlayerContext {
*/
default Optional<BlockPos> getSelectedBlock() {
RayTraceResult result = objectMouseOver();
if (result != null && result.type == RayTraceResult.Type.BLOCK) {
return Optional.of(result.getBlockPos());
if (result != null && result.getType() == RayTraceResult.Type.BLOCK) {
return Optional.of(((BlockRayTraceResult) result).getPos());
}
return Optional.empty();
}
@@ -89,8 +99,8 @@ public interface IPlayerContext {
*/
default Optional<Entity> getSelectedEntity() {
RayTraceResult result = objectMouseOver();
if (result != null && result.type == RayTraceResult.Type.ENTITY) {
return Optional.of(result.entity);
if (result != null && result.getType() == RayTraceResult.Type.ENTITY) {
return Optional.of(((EntityRayTraceResult) result).getEntity());
}
return Optional.empty();
}

View File

@@ -17,14 +17,15 @@
package baritone.api.utils;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameType;
import net.minecraft.world.World;
@@ -35,11 +36,11 @@ import net.minecraft.world.World;
*/
public interface IPlayerController {
boolean onPlayerDamageBlock(BlockPos pos, EnumFacing side);
boolean onPlayerDamageBlock(BlockPos pos, Direction side);
void resetBlockRemoving();
ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, EntityPlayer player);
ItemStack windowClick(int windowId, int slotId, int mouseButton, ClickType type, PlayerEntity player);
void setGameType(GameType type);
@@ -49,7 +50,7 @@ public interface IPlayerController {
return this.getGameType().isCreative() ? 5.0F : 4.5F;
}
EnumActionResult processRightClickBlock(EntityPlayerSP player, World world, BlockPos pos, EnumFacing direction, Vec3d vec, EnumHand hand);
ActionResultType processRightClickBlock(ClientPlayerEntity player, World world, Hand hand, BlockRayTraceResult result);
EnumActionResult processRightClick(EntityPlayerSP player, World world, EnumHand hand);
ActionResultType processRightClick(ClientPlayerEntity player, World world, Hand hand);
}

View File

@@ -17,8 +17,8 @@
package baritone.api.utils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.block.BlockState;
import net.minecraft.util.Direction;
/**
* Basic representation of a schematic. Provides the dimensions and
@@ -45,7 +45,7 @@ public interface ISchematic {
return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ();
}
default int size(EnumFacing.Axis axis) {
default int size(Direction.Axis axis) {
switch (axis) {
case X:
return widthX();
@@ -66,7 +66,7 @@ public interface ISchematic {
* @param z The z position of the block, relative to the origin
* @return The desired block state at the specified position
*/
IBlockState desiredState(int x, int y, int z);
BlockState desiredState(int x, int y, int z);
/**
* @return The width (X axis length) of this schematic
@@ -82,4 +82,4 @@ public interface ISchematic {
* @return The length (Z axis length) of this schematic
*/
int lengthZ();
}
}

View File

@@ -17,15 +17,21 @@
package baritone.api.utils;
import com.google.gson.annotations.SerializedName;
/**
* Need a non obfed chunkpos that we can load using GSON
*/
public class MyChunkPos {
@SerializedName("x")
public int x;
@SerializedName("z")
public int z;
@Override
public String toString() {
return x + ", " + z;
}
}
}

View File

@@ -18,7 +18,7 @@
package baritone.api.utils;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.RayTraceFluidMode;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
@@ -48,6 +48,6 @@ public final class RayTraceUtils {
direction.y * blockReachDistance,
direction.z * blockReachDistance
);
return entity.world.rayTraceBlocks(start, end, RayTraceFluidMode.NEVER, false, true);
return entity.world.rayTraceBlocks(new RayTraceContext(start, end, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, entity));
}
}

View File

@@ -19,15 +19,12 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.block.BlockState;
import net.minecraft.block.FireBlock;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
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.Direction;
import net.minecraft.util.math.*;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
@@ -140,7 +137,7 @@ public final class RotationUtils {
* @param ctx Context for the viewing entity
* @param pos The target block position
* @return The optional rotation
* @see #reachable(EntityPlayerSP, BlockPos, double)
* @see #reachable(ClientPlayerEntity, BlockPos, double)
*/
public static Optional<Rotation> reachable(IPlayerContext ctx, BlockPos pos) {
return reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
@@ -158,7 +155,7 @@ public final class RotationUtils {
* @param blockReachDistance The block reach distance of the entity
* @return The optional rotation
*/
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
public static Optional<Rotation> reachable(ClientPlayerEntity entity, BlockPos pos, double blockReachDistance) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
if (baritone.getPlayerContext().isLookingAt(pos)) {
/*
@@ -179,15 +176,15 @@ public final class RotationUtils {
return possibleRotation;
}
IBlockState state = entity.world.getBlockState(pos);
BlockState state = entity.world.getBlockState(pos);
VoxelShape shape = state.getShape(entity.world, pos);
if (shape.isEmpty()) {
shape = VoxelShapes.fullCube();
}
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = shape.getStart(EnumFacing.Axis.X) * sideOffset.x + shape.getEnd(EnumFacing.Axis.X) * (1 - sideOffset.x);
double yDiff = shape.getStart(EnumFacing.Axis.Y) * sideOffset.y + shape.getEnd(EnumFacing.Axis.Y) * (1 - sideOffset.y);
double zDiff = shape.getStart(EnumFacing.Axis.Z) * sideOffset.z + shape.getEnd(EnumFacing.Axis.Z) * (1 - sideOffset.z);
double xDiff = shape.getStart(Direction.Axis.X) * sideOffset.x + shape.getEnd(Direction.Axis.X) * (1 - sideOffset.x);
double yDiff = shape.getStart(Direction.Axis.Y) * sideOffset.y + shape.getEnd(Direction.Axis.Y) * (1 - sideOffset.y);
double zDiff = shape.getStart(Direction.Axis.Z) * sideOffset.z + shape.getEnd(Direction.Axis.Z) * (1 - sideOffset.z);
possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance);
if (possibleRotation.isPresent()) {
return possibleRotation;
@@ -211,11 +208,11 @@ public final class RotationUtils {
Rotation rotation = calcRotationFromVec3d(entity.getEyePosition(1.0F), offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch));
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance);
//System.out.println(result);
if (result != null && result.type == RayTraceResult.Type.BLOCK) {
if (result.getBlockPos().equals(pos)) {
if (result != null && result.getType() == RayTraceResult.Type.BLOCK) {
if (((BlockRayTraceResult) result).getPos().equals(pos)) {
return Optional.of(rotation);
}
if (entity.world.getBlockState(pos).getBlock() instanceof BlockFire && result.getBlockPos().equals(pos.down())) {
if (entity.world.getBlockState(pos).getBlock() instanceof FireBlock && ((BlockRayTraceResult) result).getPos().equals(pos.down())) {
return Optional.of(rotation);
}
}

View File

@@ -21,10 +21,10 @@ import baritone.api.Settings;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.Registry;
import java.awt.*;
import java.io.BufferedReader;
@@ -160,11 +160,11 @@ public class SettingsUtil {
private final Settings.Setting<?> setting;
public ParserContext(Settings.Setting<?> setting) {
private ParserContext(Settings.Setting<?> setting) {
this.setting = setting;
}
final Settings.Setting<?> getSetting() {
private Settings.Setting<?> getSetting() {
return this.setting;
}
}
@@ -176,7 +176,7 @@ public class SettingsUtil {
INTEGER(Integer.class, Integer::parseInt),
FLOAT(Float.class, Float::parseFloat),
LONG(Long.class, Long::parseLong),
ENUMFACING(EnumFacing.class, EnumFacing::byName),
ENUMFACING(Direction.class, Direction::byName),
COLOR(
Color.class,
str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])),
@@ -194,8 +194,8 @@ public class SettingsUtil {
),
ITEM(
Item.class,
str -> IRegistry.ITEM.get(new ResourceLocation(str.trim())),
item -> IRegistry.ITEM.getKey(item).toString()
str -> Registry.ITEM.getOrDefault(new ResourceLocation(str.trim())), // TODO this now returns AIR on failure instead of null, is that an issue?
item -> Registry.ITEM.getKey(item).toString()
),
LIST() {
@Override

View File

@@ -17,10 +17,10 @@
package baritone.api.utils;
import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.FireBlock;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.VoxelShape;
@@ -43,18 +43,18 @@ public final class VecUtils {
* @see #getBlockPosCenter(BlockPos)
*/
public static Vec3d calculateBlockCenter(World world, BlockPos pos) {
IBlockState b = world.getBlockState(pos);
BlockState b = world.getBlockState(pos);
VoxelShape shape = b.getCollisionShape(world, pos);
if (shape.isEmpty()) {
return getBlockPosCenter(pos);
}
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;
double xDiff = (shape.getStart(Direction.Axis.X) + shape.getEnd(Direction.Axis.X)) / 2;
double yDiff = (shape.getStart(Direction.Axis.Y) + shape.getEnd(Direction.Axis.Y)) / 2;
double zDiff = (shape.getStart(Direction.Axis.Z) + shape.getEnd(Direction.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 FireBlock) {//look at bottom of fire when putting it out
yDiff = 0;
}
return new Vec3d(

View File

@@ -0,0 +1,92 @@
/*
* 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.utils.accessor.IChunkArray;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.concurrent.atomic.AtomicReferenceArray;
@Mixin(targets = "net.minecraft.client.multiplayer.ClientChunkProvider$ChunkArray")
public abstract class MixinChunkArray implements IChunkArray {
@Shadow
private AtomicReferenceArray<Chunk> chunks;
@Shadow
private int viewDistance;
@Shadow
private int sideLength;
@Shadow
private int centerX;
@Shadow
private int centerZ;
@Shadow
private int loaded;
@Shadow
protected abstract boolean inView(int x, int z);
@Shadow
protected abstract int getIndex(int x, int z);
@Shadow
protected abstract void replace(int index, Chunk chunk);
@Override
public int centerX() {
return centerX;
}
@Override
public int centerZ() {
return centerZ;
}
@Override
public int viewDistance() {
return viewDistance;
}
@Override
public AtomicReferenceArray<Chunk> getChunks() {
return chunks;
}
@Override
public void copyFrom(IChunkArray other) {
centerX = other.centerX();
centerZ = other.centerZ();
AtomicReferenceArray<Chunk> copyingFrom = other.getChunks();
for (int k = 0; k < copyingFrom.length(); ++k) {
Chunk chunk = copyingFrom.get(k);
if (chunk != null) {
ChunkPos chunkpos = chunk.getPos();
if (inView(chunkpos.x, chunkpos.z)) {
int index = getIndex(chunkpos.x, chunkpos.z);
if (chunks.get(index) != null) {
throw new IllegalStateException("Doing this would mutate the client's REAL loaded chunks?!");
}
replace(index, chunk);
}
}
}
}
}

View File

@@ -1,42 +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.utils.accessor.IChunkProviderServer;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.world.gen.ChunkProviderServer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
/**
* @author Brady
* @since 9/4/2018
*/
@Mixin(ChunkProviderServer.class)
public class MixinChunkProviderServer implements IChunkProviderServer {
@Shadow
@Final
private IChunkLoader chunkLoader;
@Override
public IChunkLoader getChunkLoader() {
return this.chunkLoader;
}
}

View File

@@ -1,55 +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.Baritone;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ChunkRenderContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.util.math.BlockPos;
import org.lwjgl.opengl.GL14;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import static org.lwjgl.opengl.GL11.GL_ONE;
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)
public class MixinChunkRenderContainer {
@Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
method = "preRenderChunk",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/renderer/chunk/RenderChunk.getPosition()Lnet/minecraft/util/math/BlockPos;"
)
)
private BlockPos getPosition(RenderChunk renderChunkIn) {
if (Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null && Minecraft.getInstance().world.getChunk(renderChunkIn.getPosition()).isEmpty()) {
GlStateManager.enableAlphaTest();
GlStateManager.enableBlend();
GL14.glBlendColor(0, 0, 0, Baritone.settings().cachedChunksOpacity.value);
GlStateManager.blendFuncSeparate(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_ONE, GL_ZERO);
}
return renderChunkIn.getPosition();
}
}

View File

@@ -1,57 +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.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.utils.IPlayerContext;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.chunk.ChunkRenderWorker;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ChunkRenderWorker.class)
public abstract class MixinChunkRenderWorker {
@Shadow
protected abstract boolean isChunkExisting(BlockPos pos, World worldIn);
@Redirect(
method = "processTask",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/renderer/chunk/ChunkRenderWorker.isChunkExisting(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/World;)Z"
)
)
private boolean isChunkExisting(ChunkRenderWorker worker, BlockPos pos, World world) {
if (Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null) {
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
return baritone.bsi.isLoaded(pos.getX(), pos.getZ()) || this.isChunkExisting(pos, world);
}
}
return this.isChunkExisting(pos, world);
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.utils.accessor.IChunkArray;
import baritone.utils.accessor.IClientChunkProvider;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.lang.reflect.Field;
import java.util.Arrays;
@Mixin(ClientChunkProvider.class)
public class MixinClientChunkProvider implements IClientChunkProvider {
@Shadow
private ClientWorld world;
@Override
public ClientChunkProvider createThreadSafeCopy() {
IChunkArray arr = extractReferenceArray();
ClientChunkProvider result = new ClientChunkProvider(world, arr.viewDistance() - 3); // -3 because its adds 3 for no reason lmao
IChunkArray copyArr = ((IClientChunkProvider) result).extractReferenceArray();
copyArr.copyFrom(arr);
if (copyArr.viewDistance() != arr.viewDistance()) {
throw new IllegalStateException(copyArr.viewDistance() + " " + arr.viewDistance());
}
return result;
}
@Override
public IChunkArray extractReferenceArray() {
for (Field f : ClientChunkProvider.class.getDeclaredFields()) {
if (IChunkArray.class.isAssignableFrom(f.getType())) {
try {
return (IChunkArray) f.get(this);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
throw new RuntimeException(Arrays.toString(ClientChunkProvider.class.getDeclaredFields()));
}
}

View File

@@ -21,10 +21,10 @@ 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.network.NetHandlerPlayClient;
import net.minecraft.network.play.server.SPacketChunkData;
import net.minecraft.network.play.server.SPacketCombatEvent;
import net.minecraft.network.play.server.SPacketUnloadChunk;
import net.minecraft.client.network.play.ClientPlayNetHandler;
import net.minecraft.network.play.server.SChunkDataPacket;
import net.minecraft.network.play.server.SCombatPacket;
import net.minecraft.network.play.server.SUnloadChunkPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -34,10 +34,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* @author Brady
* @since 8/3/2018
*/
@Mixin(NetHandlerPlayClient.class)
public class MixinNetHandlerPlayClient {
@Mixin(ClientPlayNetHandler.class)
public class MixinClientPlayNetHandler {
@Inject(
// unused lol
/*@Inject(
method = "handleChunkData",
at = @At(
value = "INVOKE",
@@ -57,15 +58,15 @@ public class MixinNetHandlerPlayClient {
);
}
}
}
}*/
@Inject(
method = "handleChunkData",
at = @At("RETURN")
)
private void postHandleChunkData(SPacketChunkData packetIn, CallbackInfo ci) {
private void postHandleChunkData(SChunkDataPacket packetIn, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(
EventState.POST,
@@ -82,9 +83,9 @@ public class MixinNetHandlerPlayClient {
method = "processChunkUnload",
at = @At("HEAD")
)
private void preChunkUnload(SPacketUnloadChunk packet, CallbackInfo ci) {
private void preChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.PRE, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
);
@@ -96,9 +97,9 @@ public class MixinNetHandlerPlayClient {
method = "processChunkUnload",
at = @At("RETURN")
)
private void postChunkUnload(SPacketUnloadChunk packet, CallbackInfo ci) {
private void postChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) {
ibaritone.getGameEventHandler().onChunkEvent(
new ChunkEvent(EventState.POST, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ())
);
@@ -110,12 +111,12 @@ public class MixinNetHandlerPlayClient {
method = "handleCombatEvent",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/Minecraft.displayGuiScreen(Lnet/minecraft/client/gui/GuiScreen;)V"
target = "net/minecraft/client/Minecraft.displayGuiScreen(Lnet/minecraft/client/gui/screen/Screen;)V"
)
)
private void onPlayerDeath(SPacketCombatEvent packetIn, CallbackInfo ci) {
private void onPlayerDeath(SCombatPacket packetIn, CallbackInfo ci) {
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) {
if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) {
ibaritone.getGameEventHandler().onPlayerDeath();
}
}

View File

@@ -24,9 +24,9 @@ import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.SprintStateEvent;
import baritone.api.event.events.type.EventState;
import baritone.behavior.LookBehavior;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.PlayerCapabilities;
import net.minecraft.entity.player.PlayerAbilities;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@@ -37,8 +37,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* @author Brady
* @since 8/1/2018
*/
@Mixin(EntityPlayerSP.class)
public class MixinEntityPlayerSP {
@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity {
@Inject(
method = "sendChatMessage",
@@ -47,7 +47,7 @@ public class MixinEntityPlayerSP {
)
private void sendChatMessage(String msg, CallbackInfo ci) {
ChatEvent event = new ChatEvent(msg);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone == null) {
return;
}
@@ -61,13 +61,13 @@ public class MixinEntityPlayerSP {
method = "tick",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.isPassenger()Z",
target = "net/minecraft/client/entity/player/ClientPlayerEntity.isPassenger()Z",
shift = At.Shift.BY,
by = -3
)
)
private void onPreUpdate(CallbackInfo ci) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone != null) {
baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.PRE));
}
@@ -77,13 +77,13 @@ public class MixinEntityPlayerSP {
method = "tick",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.onUpdateWalkingPlayer()V",
target = "net/minecraft/client/entity/player/ClientPlayerEntity.onUpdateWalkingPlayer()V",
shift = At.Shift.BY,
by = 2
)
)
private void onPostUpdate(CallbackInfo ci) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone != null) {
baritone.getGameEventHandler().onPlayerUpdate(new PlayerUpdateEvent(EventState.POST));
}
@@ -93,11 +93,11 @@ public class MixinEntityPlayerSP {
method = "livingTick",
at = @At(
value = "FIELD",
target = "net/minecraft/entity/player/PlayerCapabilities.allowFlying:Z"
target = "net/minecraft/entity/player/PlayerAbilities.allowFlying:Z"
)
)
private boolean isAllowFlying(PlayerCapabilities capabilities) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
private boolean isAllowFlying(PlayerAbilities capabilities) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone == null) {
return capabilities.allowFlying;
}
@@ -112,7 +112,7 @@ public class MixinEntityPlayerSP {
)
)
private boolean isKeyDown(KeyBinding keyBinding) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone == null) {
return keyBinding.isKeyDown();
}
@@ -135,7 +135,7 @@ public class MixinEntityPlayerSP {
)
)
private void updateRidden(CallbackInfo cb) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone != null) {
((LookBehavior) baritone.getLookBehavior()).pig();
}

View 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.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.event.events.RotationMoveEvent;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Entity.class)
public class MixinEntity {
@Shadow
private float rotationYaw;
float yawRestore;
@Inject(
method = "moveRelative",
at = @At("HEAD")
)
private void moveRelativeHead(CallbackInfo info) {
this.yawRestore = this.rotationYaw;
// noinspection ConstantConditions
if (!ClientPlayerEntity.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this) == null) {
return;
}
RotationMoveEvent motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw);
BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this).getGameEventHandler().onPlayerRotationMove(motionUpdateRotationEvent);
this.rotationYaw = motionUpdateRotationEvent.getYaw();
}
@Inject(
method = "moveRelative",
at = @At("RETURN")
)
private void moveRelativeReturn(CallbackInfo info) {
this.rotationYaw = this.yawRestore;
}
}

View File

@@ -17,27 +17,32 @@
package baritone.launch.mixins;
import baritone.utils.accessor.IAnvilChunkLoader;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import org.spongepowered.asm.mixin.Final;
import baritone.utils.accessor.IEntityRenderManager;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.io.File;
/**
* @author Brady
* @since 9/4/2018
*/
@Mixin(AnvilChunkLoader.class)
public class MixinAnvilChunkLoader implements IAnvilChunkLoader {
@Mixin(EntityRendererManager.class)
public class MixinEntityRenderManager implements IEntityRenderManager {
@Shadow
@Final
private File chunkSaveLocation;
private double renderPosX;
@Shadow
private double renderPosY;
@Shadow
private double renderPosZ;
@Override
public File getChunkSaveLocation() {
return this.chunkSaveLocation;
public double renderPosX() {
return renderPosX;
}
@Override
public double renderPosY() {
return renderPosY;
}
@Override
public double renderPosZ() {
return renderPosZ;
}
}

View File

@@ -33,7 +33,7 @@ public class MixinGameRenderer {
method = "updateCameraAndRender(FJ)V",
at = @At(
value = "INVOKE_STRING",
target = "Lnet/minecraft/profiler/Profiler;endStartSection(Ljava/lang/String;)V",
target = "Lnet/minecraft/profiler/IProfiler;endStartSection(Ljava/lang/String;)V",
args = {"ldc=hand"}
)
)

View File

@@ -20,10 +20,11 @@ package baritone.launch.mixins;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.event.events.RotationMoveEvent;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -37,15 +38,15 @@ import static org.spongepowered.asm.lib.Opcodes.GETFIELD;
* @author Brady
* @since 9/10/2018
*/
@Mixin(EntityLivingBase.class)
public abstract class MixinEntityLivingBase extends Entity {
@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends Entity {
/**
* Event called to override the movement direction when jumping
*/
private RotationMoveEvent jumpRotationEvent;
public MixinEntityLivingBase(EntityType<?> entityTypeIn, World worldIn) {
public MixinLivingEntity(EntityType<?> entityTypeIn, World worldIn) {
super(entityTypeIn, worldIn);
}
@@ -55,8 +56,8 @@ public abstract class MixinEntityLivingBase extends Entity {
)
private void preMoveRelative(CallbackInfo ci) {
// noinspection ConstantConditions
if (EntityPlayerSP.class.isInstance(this)) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this);
if (ClientPlayerEntity.class.isInstance(this)) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this);
if (baritone != null) {
this.jumpRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.JUMP, this.rotationYaw);
baritone.getGameEventHandler().onPlayerRotationMove(this.jumpRotationEvent);
@@ -69,34 +70,15 @@ public abstract class MixinEntityLivingBase extends Entity {
at = @At(
value = "FIELD",
opcode = GETFIELD,
target = "net/minecraft/entity/EntityLivingBase.rotationYaw:F"
target = "net/minecraft/entity/LivingEntity.rotationYaw:F"
)
)
private float overrideYaw(EntityLivingBase self) {
if (self instanceof EntityPlayerSP && BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) != null) {
private float overrideYaw(LivingEntity self) {
if (self instanceof ClientPlayerEntity && BaritoneAPI.getProvider().getBaritoneForPlayer((ClientPlayerEntity) (Object) this) != null) {
return this.jumpRotationEvent.getYaw();
}
return self.rotationYaw;
}
@Redirect(
method = "travel",
at = @At(
value = "INVOKE",
target = "net/minecraft/entity/EntityLivingBase.moveRelative(FFFF)V"
)
)
private void travel(EntityLivingBase self, float strafe, float up, float forward, float friction) {
// noinspection ConstantConditions
if (!EntityPlayerSP.class.isInstance(this) || BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this) == null) {
moveRelative(strafe, up, forward, friction);
return;
}
RotationMoveEvent motionUpdateRotationEvent = new RotationMoveEvent(RotationMoveEvent.Type.MOTION_UPDATE, this.rotationYaw);
BaritoneAPI.getProvider().getBaritoneForPlayer((EntityPlayerSP) (Object) this).getGameEventHandler().onPlayerRotationMove(motionUpdateRotationEvent);
float originalYaw = this.rotationYaw;
this.rotationYaw = motionUpdateRotationEvent.getYaw();
this.moveRelative(strafe, up, forward, friction);
this.rotationYaw = originalYaw;
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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.process.MineProcess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTableManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(LootContext.Builder.class)
public class MixinLootContext {
@Redirect(
method = "build",
at = @At(
value = "INVOKE",
target = "net/minecraft/world/server/ServerWorld.getServer()Lnet/minecraft/server/MinecraftServer;"
)
)
private MinecraftServer getServer(ServerWorld world) {
if (world == null) {
return null;
}
return world.getServer();
}
@Redirect(
method = "build",
at = @At(
value = "INVOKE",
target = "net/minecraft/server/MinecraftServer.getLootTableManager()Lnet/minecraft/world/storage/loot/LootTableManager;"
)
)
private LootTableManager getLootTableManager(MinecraftServer server) {
if (server == null) {
return MineProcess.getManager();
}
return server.getLootTableManager();
}
}

View File

@@ -26,13 +26,13 @@ import baritone.api.event.events.WorldEvent;
import baritone.api.event.events.type.EventState;
import baritone.utils.BaritoneAutoTest;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockRayTraceResult;
import org.spongepowered.asm.lib.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -50,9 +50,9 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
public class MixinMinecraft {
@Shadow
public EntityPlayerSP player;
public ClientPlayerEntity player;
@Shadow
public WorldClient world;
public ClientWorld world;
@Inject(
method = "init",
@@ -78,7 +78,7 @@ public class MixinMinecraft {
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "net/minecraft/client/Minecraft.currentScreen:Lnet/minecraft/client/gui/GuiScreen;",
target = "net/minecraft/client/Minecraft.currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
ordinal = 5,
shift = At.Shift.BY,
by = -3
@@ -97,10 +97,10 @@ public class MixinMinecraft {
}
@Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/gui/GuiScreen;)V",
method = "loadWorld(Lnet/minecraft/client/world/ClientWorld;)V",
at = @At("HEAD")
)
private void preLoadWorld(WorldClient world, GuiScreen loadingScreen, CallbackInfo ci) {
private void preLoadWorld(ClientWorld world, CallbackInfo ci) {
// If we're unloading the world but one doesn't exist, ignore it
if (this.world == null && world == null) {
return;
@@ -117,10 +117,10 @@ public class MixinMinecraft {
}
@Inject(
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/gui/GuiScreen;)V",
method = "loadWorld(Lnet/minecraft/client/world/ClientWorld;)V",
at = @At("RETURN")
)
private void postLoadWorld(WorldClient world, GuiScreen loadingScreen, CallbackInfo ci) {
private void postLoadWorld(ClientWorld world, CallbackInfo ci) {
// still fire event for both null, as that means we've just finished exiting a world
// mc.world changing is only the primary baritone
@@ -137,37 +137,24 @@ public class MixinMinecraft {
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "net/minecraft/client/gui/GuiScreen.allowUserInput:Z"
target = "net/minecraft/client/gui/screen/Screen.passEvents:Z"
)
)
private boolean isAllowUserInput(GuiScreen screen) {
private boolean passEvents(Screen screen) {
// allow user input is only the primary baritone
return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.allowUserInput;
}
@Inject(
method = "clickMouse",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/multiplayer/PlayerControllerMP.clickBlock(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;)Z"
),
locals = LocalCapture.CAPTURE_FAILHARD
)
private void onBlockBreak(CallbackInfo ci, BlockPos pos) {
// clickMouse is only for the main player
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(pos, BlockInteractEvent.Type.START_BREAK));
return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.passEvents;
}
@Inject(
method = "rightClickMouse",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/entity/EntityPlayerSP.swingArm(Lnet/minecraft/util/EnumHand;)V"
target = "net/minecraft/client/entity/player/ClientPlayerEntity.swingArm(Lnet/minecraft/util/Hand;)V"
),
locals = LocalCapture.CAPTURE_FAILHARD
)
private void onBlockUse(CallbackInfo ci, EnumHand var1[], int var2, int var3, EnumHand enumhand, ItemStack itemstack, BlockPos blockpos, int i, EnumActionResult enumactionresult) {
private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand enumhand, ItemStack itemstack, BlockRayTraceResult raytrace, int i, ActionResultType enumactionresult) {
// rightClickMouse is only for the main player
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(blockpos, BlockInteractEvent.Type.USE));
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onBlockInteract(new BlockInteractEvent(raytrace.getPos(), BlockInteractEvent.Type.USE));
}
}

View File

@@ -25,9 +25,9 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.EnumPacketDirection;
import net.minecraft.network.IPacket;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketDirection;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -47,14 +47,14 @@ public class MixinNetworkManager {
@Shadow
@Final
private EnumPacketDirection direction;
private PacketDirection direction;
@Inject(
method = "dispatchPacket",
at = @At("HEAD")
)
private void preDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != EnumPacketDirection.CLIENTBOUND) {
private void preDispatchPacket(IPacket<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != PacketDirection.CLIENTBOUND) {
return;
}
@@ -69,8 +69,8 @@ public class MixinNetworkManager {
method = "dispatchPacket",
at = @At("RETURN")
)
private void postDispatchPacket(Packet<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != EnumPacketDirection.CLIENTBOUND) {
private void postDispatchPacket(IPacket<?> inPacket, final GenericFutureListener<? extends Future<? super Void>> futureListeners, CallbackInfo ci) {
if (this.direction != PacketDirection.CLIENTBOUND) {
return;
}
@@ -85,11 +85,11 @@ public class MixinNetworkManager {
method = "channelRead0",
at = @At(
value = "INVOKE",
target = "net/minecraft/network/NetworkManager.processPacket(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;)V"
target = "net/minecraft/network/NetworkManager.processPacket(Lnet/minecraft/network/IPacket;Lnet/minecraft/network/INetHandler;)V"
)
)
private void preProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
if (this.direction != EnumPacketDirection.CLIENTBOUND) {
private void preProcessPacket(ChannelHandlerContext context, IPacket<?> packet, CallbackInfo ci) {
if (this.direction != PacketDirection.CLIENTBOUND) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {
@@ -103,8 +103,8 @@ public class MixinNetworkManager {
method = "channelRead0",
at = @At("RETURN")
)
private void postProcessPacket(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
if (!this.channel.isOpen() || this.direction != EnumPacketDirection.CLIENTBOUND) {
private void postProcessPacket(ChannelHandlerContext context, IPacket<?> packet, CallbackInfo ci) {
if (!this.channel.isOpen() || this.direction != PacketDirection.CLIENTBOUND) {
return;
}
for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) {

View File

@@ -1,57 +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.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.utils.IPlayerContext;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.chunk.RenderChunk;
import net.minecraft.client.renderer.chunk.RenderChunkCache;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
/**
* @author Brady
* @since 1/29/2019
*/
@Mixin(RenderChunk.class)
public class MixinRenderChunk {
@Redirect(
method = "rebuildChunk",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/renderer/chunk/RenderChunkCache.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"
)
)
private IBlockState getBlockState(RenderChunkCache chunkCache, BlockPos pos) {
if (Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null) {
Baritone baritone = (Baritone) BaritoneAPI.getProvider().getPrimaryBaritone();
IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.player() != null && ctx.world() != null && baritone.bsi != null) {
return baritone.bsi.get0(pos);
}
}
return chunkCache.getBlockState(pos);
}
}

View File

@@ -1,47 +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.Baritone;
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.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(RenderChunkCache.class)
public class MixinRenderChunkCache {
@Redirect(
method = "generateCache",
at = @At(
value = "INVOKE",
target = "net/minecraft/world/chunk/Chunk.isEmptyBetween(II)Z"
)
)
private static boolean isEmpty(Chunk chunk, int yStart, int yEnd) {
if (!chunk.isEmptyBetween(yStart, yEnd)) {
return false;
}
if (chunk.isEmpty() && Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null) {
return false;
}
return true;
}
}

View File

@@ -1,47 +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.Baritone;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import static org.lwjgl.opengl.GL11.*;
@Mixin(RenderList.class)
public class MixinRenderList {
@Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
method = "renderChunkLayer",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V"
)
)
private void popMatrix() {
if (Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null) {
// 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.popMatrix();
}
}

View File

@@ -1,47 +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.Baritone;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.VboRenderList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import static org.lwjgl.opengl.GL11.*;
@Mixin(VboRenderList.class)
public class MixinVboRenderList {
@Redirect( // avoid creating CallbackInfo at all costs; this is called 40k times per second
method = "renderChunkLayer",
at = @At(
value = "INVOKE",
target = "net/minecraft/client/renderer/GlStateManager.popMatrix()V"
)
)
private void popMatrix() {
if (Baritone.settings().renderCachedChunks.value && Minecraft.getInstance().getIntegratedServer() == null) {
// 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.popMatrix();
}
}

View File

@@ -8,21 +8,17 @@
"maxShiftBy": 2
},
"client": [
"MixinAnvilChunkLoader",
"MixinBlockPos",
"MixinChunkProviderClient",
"MixinChunkProviderServer",
"MixinChunkRenderContainer",
"MixinChunkRenderWorker",
"MixinEntityLivingBase",
"MixinEntityPlayerSP",
"MixinChunkArray",
"MixinClientChunkProvider",
"MixinClientPlayerEntity",
"MixinClientPlayNetHandler",
"MixinEntity",
"MixinEntityRenderManager",
"MixinGameRenderer",
"MixinLivingEntity",
"MixinLootContext",
"MixinMinecraft",
"MixinNetHandlerPlayClient",
"MixinNetworkManager",
"MixinRenderChunk",
"MixinRenderChunkCache",
"MixinRenderList",
"MixinVboRenderList"
"MixinNetworkManager"
]
}

View File

@@ -148,12 +148,12 @@ public class Baritone implements IBaritone {
}
@Override
public CustomGoalProcess getCustomGoalProcess() { // Iffy
public CustomGoalProcess getCustomGoalProcess() {
return this.customGoalProcess;
}
@Override
public GetToBlockProcess getGetToBlockProcess() { // Iffy
public GetToBlockProcess getGetToBlockProcess() {
return this.getToBlockProcess;
}
@@ -218,7 +218,7 @@ public class Baritone implements IBaritone {
new Thread(() -> {
try {
Thread.sleep(100);
Helper.mc.addScheduledTask(() -> Helper.mc.displayGuiScreen(new GuiClick()));
Helper.mc.execute(() -> Helper.mc.displayGuiScreen(new GuiClick()));
} catch (Exception ignored) {}
}).start();
}
@@ -234,4 +234,4 @@ public class Baritone implements IBaritone {
public static Executor getExecutor() {
return threadPool;
}
}
}

View File

@@ -32,6 +32,7 @@ import java.util.List;
public final class BaritoneProvider implements IBaritoneProvider {
private final Baritone primary = new Baritone();
private final List<IBaritone> all = Collections.singletonList(primary);
@Override
public IBaritone getPrimaryBaritone() {
@@ -40,8 +41,7 @@ public final class BaritoneProvider implements IBaritoneProvider {
@Override
public List<IBaritone> getAllBaritones() {
// TODO return a CopyOnWriteArrayList
return Collections.singletonList(primary);
return all;
}
@Override

View File

@@ -21,10 +21,10 @@ import baritone.Baritone;
import baritone.api.event.events.TickEvent;
import baritone.utils.ToolSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ClickType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.item.*;
import net.minecraft.util.NonNullList;
@@ -33,7 +33,7 @@ import java.util.OptionalInt;
import java.util.Random;
import java.util.function.Predicate;
public class InventoryBehavior extends Behavior {
public final class InventoryBehavior extends Behavior {
public InventoryBehavior(Baritone baritone) {
super(baritone);
}
@@ -46,14 +46,14 @@ public class InventoryBehavior extends Behavior {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
if (ctx.player().openContainer != ctx.player().inventoryContainer) {
if (ctx.player().openContainer != ctx.player().container) {
// we have a crafting table or a chest or something open
return;
}
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
swapWithHotBar(firstValidThrowaway(), 8);
}
int pick = bestToolAgainst(Blocks.STONE, ItemPickaxe.class);
int pick = bestToolAgainst(Blocks.STONE, PickaxeItem.class);
if (pick >= 9) {
swapWithHotBar(pick, 0);
}
@@ -88,7 +88,7 @@ public class InventoryBehavior extends Behavior {
}
private void swapWithHotBar(int inInventory, int inHotbar) {
ctx.playerController().windowClick(ctx.player().inventoryContainer.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
ctx.playerController().windowClick(ctx.player().container.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
}
private int firstValidThrowaway() { // TODO offhand idk
@@ -101,7 +101,7 @@ public class InventoryBehavior extends Behavior {
return -1;
}
private int bestToolAgainst(Block against, Class<? extends ItemTool> klass) {
private int bestToolAgainst(Block against, Class<? extends ToolItem> klass) {
NonNullList<ItemStack> invy = ctx.player().inventory.mainInventory;
int bestInd = -1;
double bestSpeed = -1;
@@ -131,8 +131,8 @@ public class InventoryBehavior extends Behavior {
}
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
BlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof BlockItem && ((BlockItem) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
return true; // gotem
}
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
@@ -144,7 +144,7 @@ public class InventoryBehavior extends Behavior {
}
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
EntityPlayerSP p = ctx.player();
ClientPlayerEntity p = ctx.player();
NonNullList<ItemStack> inv = p.inventory.mainInventory;
for (byte i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
@@ -168,7 +168,7 @@ public class InventoryBehavior extends Behavior {
// so not a shovel, not a hoe, not a block, etc
for (byte i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
if (item.isEmpty() || item.getItem() instanceof ItemPickaxe) {
if (item.isEmpty() || item.getItem() instanceof PickaxeItem) {
if (select) {
p.inventory.currentItem = i;
}

View File

@@ -50,6 +50,13 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
@Override
public void updateTarget(Rotation target, boolean force) {
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().randomLooking.value), this.target.getPitch());
}
this.force = force || !Baritone.settings().freeLook.value;
}

View File

@@ -20,26 +20,10 @@ package baritone.behavior;
import baritone.Baritone;
import baritone.api.cache.Waypoint;
import baritone.api.event.events.BlockInteractEvent;
import baritone.api.event.events.PacketEvent;
import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.TickEvent;
import baritone.api.event.events.type.EventState;
import baritone.cache.ContainerMemory;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBed;
import net.minecraft.init.Blocks;
import net.minecraft.block.BedBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketCloseWindow;
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
import net.minecraft.network.play.server.SPacketCloseWindow;
import net.minecraft.network.play.server.SPacketOpenWindow;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import java.io.IOException;
import java.nio.file.Files;
@@ -54,111 +38,13 @@ import java.util.*;
*/
public final class MemoryBehavior extends Behavior {
private final List<FutureInventory> futureInventories = new ArrayList<>(); // this is per-bot
private Integer enderChestWindowId; // nae nae
public MemoryBehavior(Baritone baritone) {
super(baritone);
}
@Override
public synchronized void onTick(TickEvent event) {
if (!Baritone.settings().containerMemory.value) {
return;
}
if (event.getType() == TickEvent.Type.OUT) {
enderChestWindowId = null;
futureInventories.clear();
}
}
@Override
public synchronized void onPlayerUpdate(PlayerUpdateEvent event) {
if (event.getState() == EventState.PRE) {
updateInventory();
}
}
@Override
public synchronized void onSendPacket(PacketEvent event) {
if (!Baritone.settings().containerMemory.value) {
return;
}
Packet p = event.getPacket();
if (event.getState() == EventState.PRE) {
if (p instanceof CPacketPlayerTryUseItemOnBlock) {
CPacketPlayerTryUseItemOnBlock packet = event.cast();
TileEntity tileEntity = ctx.world().getTileEntity(packet.getPos());
// if tileEntity is an ender chest, we don't need to do anything. ender chests are treated the same regardless of what coordinate right clicked
// Ensure the TileEntity is a container of some sort
if (tileEntity instanceof TileEntityLockable) {
TileEntityLockable lockable = (TileEntityLockable) tileEntity;
int size = lockable.getSizeInventory();
BlockPos position = tileEntity.getPos();
BlockPos adj = neighboringConnectedBlock(position);
System.out.println(position + " " + adj);
if (adj != null) {
size *= 2; // double chest or double trapped chest
if (adj.getX() < position.getX() || adj.getZ() < position.getZ()) {
position = adj; // standardize on the lower coordinate, regardless of which side of the large chest we right clicked
}
}
this.futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), position));
}
}
if (p instanceof CPacketCloseWindow) {
getCurrent().save();
}
}
}
@Override
public synchronized void onReceivePacket(PacketEvent event) {
if (!Baritone.settings().containerMemory.value) {
return;
}
Packet p = event.getPacket();
if (event.getState() == EventState.PRE) {
if (p instanceof SPacketOpenWindow) {
SPacketOpenWindow packet = event.cast();
// Remove any entries that were created over a second ago, this should make up for INSANE latency
futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000);
System.out.println("Received packet " + packet.getGuiId() + " " + packet.getEntityId() + " " + packet.getSlotCount() + " " + packet.getWindowId());
System.out.println(packet.getWindowTitle());
if (packet.getWindowTitle() instanceof TextComponentTranslation && ((TextComponentTranslation) packet.getWindowTitle()).getKey().equals("container.enderchest")) {
// title is not customized (i.e. this isn't just a renamed shulker)
enderChestWindowId = packet.getWindowId();
return;
}
futureInventories.stream()
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
.findFirst().ifPresent(matched -> {
// Remove the future inventory
futureInventories.remove(matched);
// Setup the remembered inventory
getCurrentContainer().setup(matched.pos, packet.getWindowId(), packet.getSlotCount());
});
}
if (p instanceof SPacketCloseWindow) {
getCurrent().save();
}
}
}
@Override
public void onBlockInteract(BlockInteractEvent event) {
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BlockBed) {
if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(ctx, event.getPos()) instanceof BedBlock) {
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos()));
}
}
@@ -168,85 +54,6 @@ public final class MemoryBehavior extends Behavior {
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, ctx.playerFeet()));
}
private void updateInventory() {
if (!Baritone.settings().containerMemory.value) {
return;
}
int windowId = ctx.player().openContainer.windowId;
if (enderChestWindowId != null) {
if (windowId == enderChestWindowId) {
getCurrent().contents = ctx.player().openContainer.getInventory().subList(0, 27);
} else {
getCurrent().save();
enderChestWindowId = null;
}
}
if (getCurrentContainer() != null) {
getCurrentContainer().getInventoryFromWindow(windowId).ifPresent(inventory -> inventory.updateFromOpenWindow(ctx));
}
}
private ContainerMemory getCurrentContainer() {
if (baritone.getWorldProvider().getCurrentWorld() == null) {
return null;
}
return (ContainerMemory) baritone.getWorldProvider().getCurrentWorld().getContainerMemory();
}
private BlockPos neighboringConnectedBlock(BlockPos in) {
BlockStateInterface bsi = baritone.bsi;
Block block = bsi.get0(in).getBlock();
if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
return null; // other things that have contents, but can be placed adjacent without combining
}
for (int i = 0; i < 4; i++) {
BlockPos adj = in.offset(EnumFacing.byHorizontalIndex(i));
if (bsi.get0(adj).getBlock() == block) {
return adj;
}
}
return null;
}
/**
* An inventory that we are not yet fully aware of, but are expecting to exist at some point in the future.
*/
private static final class FutureInventory {
/**
* The time that we initially expected the inventory to be provided, in milliseconds
*/
private final long time;
/**
* The amount of slots in the inventory
*/
private final int slots;
/**
* The type of inventory
*/
private final String type;
/**
* The position of the inventory container
*/
private final BlockPos pos;
private FutureInventory(long time, int slots, String type, BlockPos pos) {
this.time = time;
this.slots = slots;
this.type = type;
this.pos = pos;
System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + pos);
}
}
public Optional<List<ItemStack>> echest() {
return Optional.ofNullable(getCurrent().contents).map(Collections::unmodifiableList);
}
public EnderChestMemory getCurrent() {
Path path = baritone.getWorldProvider().getCurrentWorld().directory;
return EnderChestMemory.getByServerAndPlayer(path.getParent(), ctx.player().getUniqueID());

View File

@@ -65,7 +65,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
private boolean lastAutoJump;
private BlockPos expectedSegmentStart;
private BetterBlockPos expectedSegmentStart;
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
@@ -135,7 +135,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
) {
// when it was *just* started, currentBest will be empty so we need to also check calcFrom since that's always present
inProgress.cancel(); // cancellation doesn't dispatch any events
inProgress = null; // this is safe since we hold both locks
}
}
}
@@ -339,7 +338,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
}
// just cancel the current path
public void secretInternalSegmentCancel() {
private void secretInternalSegmentCancel() {
queuePathEvent(PathEvent.CANCELED);
synchronized (pathPlanLock) {
getInProgress().ifPresent(AbstractNodeCostSearch::cancel);
@@ -361,12 +360,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
}
}
/*public void secretCursedFunctionDoNotCall(IPath path) {
synchronized (pathPlanLock) {
current = new PathExecutor(this, path);
}
}*/
public CalculationContext secretInternalGetCalculationContext() {
return context;
}
@@ -495,7 +488,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
}
}
if (talkAboutIt && current != null && current.getPath() != null) {
if (goal == null || goal.isInGoal(current.getPath().getDest())) {
if (goal.isInGoal(current.getPath().getDest())) {
logDebug("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
} else {
logDebug("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered");
@@ -508,7 +501,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
});
}
public static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) {
private static AbstractNodeCostSearch createPathfinder(BlockPos start, Goal goal, IPath previous, CalculationContext context) {
Goal transformed = goal;
if (Baritone.settings().simplifyUnloadedYCoord.value && goal instanceof IGoalRenderPos) {
BlockPos pos = ((IGoalRenderPos) goal).getGoalPos();

View File

@@ -19,13 +19,17 @@ package baritone.cache;
import baritone.api.utils.BlockUtils;
import baritone.utils.pathing.PathingBlockType;
import com.google.common.collect.ImmutableSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import java.util.*;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Map;
/**
* @author Brady
@@ -33,99 +37,77 @@ import java.util.*;
*/
public final class CachedChunk {
public static final Set<Block> BLOCKS_TO_KEEP_TRACK_OF;
public static final ImmutableSet<Block> BLOCKS_TO_KEEP_TRACK_OF = ImmutableSet.of(
Blocks.ENDER_CHEST,
Blocks.FURNACE,
Blocks.CHEST,
Blocks.TRAPPED_CHEST,
Blocks.END_PORTAL,
Blocks.END_PORTAL_FRAME,
Blocks.SPAWNER,
Blocks.BARRIER,
Blocks.OBSERVER,
Blocks.WHITE_SHULKER_BOX,
Blocks.ORANGE_SHULKER_BOX,
Blocks.MAGENTA_SHULKER_BOX,
Blocks.LIGHT_BLUE_SHULKER_BOX,
Blocks.YELLOW_SHULKER_BOX,
Blocks.LIME_SHULKER_BOX,
Blocks.PINK_SHULKER_BOX,
Blocks.GRAY_SHULKER_BOX,
Blocks.LIGHT_GRAY_SHULKER_BOX,
Blocks.CYAN_SHULKER_BOX,
Blocks.PURPLE_SHULKER_BOX,
Blocks.BLUE_SHULKER_BOX,
Blocks.BROWN_SHULKER_BOX,
Blocks.GREEN_SHULKER_BOX,
Blocks.RED_SHULKER_BOX,
Blocks.BLACK_SHULKER_BOX,
Blocks.NETHER_PORTAL,
Blocks.HOPPER,
Blocks.BEACON,
Blocks.BREWING_STAND,
static {
HashSet<Block> temp = new HashSet<>();
//temp.add(Blocks.DIAMOND_ORE);
temp.add(Blocks.DIAMOND_BLOCK);
//temp.add(Blocks.COAL_ORE);
temp.add(Blocks.COAL_BLOCK);
//temp.add(Blocks.IRON_ORE);
temp.add(Blocks.IRON_BLOCK);
//temp.add(Blocks.GOLD_ORE);
temp.add(Blocks.GOLD_BLOCK);
temp.add(Blocks.EMERALD_ORE);
temp.add(Blocks.EMERALD_BLOCK);
temp.add(Blocks.ENDER_CHEST);
temp.add(Blocks.FURNACE);
temp.add(Blocks.CHEST);
temp.add(Blocks.TRAPPED_CHEST);
temp.add(Blocks.END_PORTAL);
temp.add(Blocks.END_PORTAL_FRAME);
temp.add(Blocks.SPAWNER);
temp.add(Blocks.BARRIER);
temp.add(Blocks.OBSERVER);
temp.add(Blocks.WHITE_SHULKER_BOX);
temp.add(Blocks.ORANGE_SHULKER_BOX);
temp.add(Blocks.MAGENTA_SHULKER_BOX);
temp.add(Blocks.LIGHT_BLUE_SHULKER_BOX);
temp.add(Blocks.YELLOW_SHULKER_BOX);
temp.add(Blocks.LIME_SHULKER_BOX);
temp.add(Blocks.PINK_SHULKER_BOX);
temp.add(Blocks.GRAY_SHULKER_BOX);
temp.add(Blocks.LIGHT_GRAY_SHULKER_BOX);
temp.add(Blocks.CYAN_SHULKER_BOX);
temp.add(Blocks.PURPLE_SHULKER_BOX);
temp.add(Blocks.BLUE_SHULKER_BOX);
temp.add(Blocks.BROWN_SHULKER_BOX);
temp.add(Blocks.GREEN_SHULKER_BOX);
temp.add(Blocks.RED_SHULKER_BOX);
temp.add(Blocks.BLACK_SHULKER_BOX);
temp.add(Blocks.NETHER_PORTAL);
temp.add(Blocks.HOPPER);
temp.add(Blocks.BEACON);
temp.add(Blocks.BREWING_STAND);
// TODO: Maybe add a predicate for blocks to keep track of?
// This should really not need to happen
temp.add(Blocks.CREEPER_HEAD);
temp.add(Blocks.CREEPER_WALL_HEAD);
temp.add(Blocks.DRAGON_HEAD);
temp.add(Blocks.DRAGON_WALL_HEAD);
temp.add(Blocks.PLAYER_HEAD);
temp.add(Blocks.PLAYER_WALL_HEAD);
temp.add(Blocks.ZOMBIE_HEAD);
temp.add(Blocks.ZOMBIE_WALL_HEAD);
temp.add(Blocks.SKELETON_SKULL);
temp.add(Blocks.SKELETON_WALL_SKULL);
temp.add(Blocks.WITHER_SKELETON_SKULL);
temp.add(Blocks.WITHER_SKELETON_WALL_SKULL);
temp.add(Blocks.ENCHANTING_TABLE);
temp.add(Blocks.ANVIL);
temp.add(Blocks.WHITE_BED);
temp.add(Blocks.ORANGE_BED);
temp.add(Blocks.MAGENTA_BED);
temp.add(Blocks.LIGHT_BLUE_BED);
temp.add(Blocks.YELLOW_BED);
temp.add(Blocks.LIME_BED);
temp.add(Blocks.PINK_BED);
temp.add(Blocks.GRAY_BED);
temp.add(Blocks.LIGHT_GRAY_BED);
temp.add(Blocks.CYAN_BED);
temp.add(Blocks.PURPLE_BED);
temp.add(Blocks.BLUE_BED);
temp.add(Blocks.BROWN_BED);
temp.add(Blocks.GREEN_BED);
temp.add(Blocks.RED_BED);
temp.add(Blocks.BLACK_BED);
temp.add(Blocks.DRAGON_EGG);
temp.add(Blocks.JUKEBOX);
temp.add(Blocks.END_GATEWAY);
temp.add(Blocks.COBWEB);
temp.add(Blocks.NETHER_WART);
temp.add(Blocks.LADDER);
temp.add(Blocks.VINE);
BLOCKS_TO_KEEP_TRACK_OF = Collections.unmodifiableSet(temp);
// TODO: Lit Furnaces
}
// 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.ANVIL,
Blocks.WHITE_BED,
Blocks.ORANGE_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.JUKEBOX,
Blocks.END_GATEWAY,
Blocks.COBWEB,
Blocks.NETHER_WART,
Blocks.LADDER,
Blocks.VINE
);
/**
* The size of the chunk data in bits. Equal to 16 KiB.
@@ -161,7 +143,7 @@ public final class CachedChunk {
/**
* The block names of each surface level block for generating an overview
*/
private final IBlockState[] overview;
private final BlockState[] overview;
private final int[] heightMap;
@@ -169,7 +151,7 @@ public final class CachedChunk {
public final long cacheTimestamp;
CachedChunk(int x, int z, BitSet data, IBlockState[] overview, Map<String, List<BlockPos>> specialBlockLocations, long cacheTimestamp) {
CachedChunk(int x, int z, BitSet data, BlockState[] overview, Map<String, List<BlockPos>> specialBlockLocations, long cacheTimestamp) {
validateSize(data);
this.x = x;
@@ -196,7 +178,7 @@ public final class CachedChunk {
}
}
public final IBlockState getBlock(int x, int y, int z, int dimension) {
public final BlockState getBlock(int x, int y, int z, int dimension) {
int index = getPositionIndex(x, y, z);
PathingBlockType type = getType(index);
int internalPos = z << 4 | x;
@@ -217,8 +199,17 @@ public final class CachedChunk {
}
}
if (type == PathingBlockType.SOLID && y == 127 && dimension == -1) {
return Blocks.BEDROCK.getDefaultState();
if (type == PathingBlockType.SOLID) {
if (y == 127 && dimension == -1) {
// nether roof is always unbreakable
return Blocks.BEDROCK.getDefaultState();
}
if (y < 5 && dimension == 0) {
// solid blocks below 5 are commonly bedrock
// however, returning bedrock always would be a little yikes
// discourage paths that include breaking blocks below 5 a little more heavily just so that it takes paths breaking what's known to be stone (at 5 or above) instead of what could maybe be bedrock (below 5)
return Blocks.OBSIDIAN.getDefaultState();
}
}
return ChunkPacker.pathingTypeToBlock(type, dimension);
}
@@ -243,7 +234,7 @@ public final class CachedChunk {
}
}
public final IBlockState[] getOverview() {
public final BlockState[] getOverview() {
return overview;
}

View File

@@ -20,7 +20,7 @@ package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.ICachedRegion;
import baritone.api.utils.BlockUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import java.io.*;
@@ -75,7 +75,7 @@ public final class CachedRegion implements ICachedRegion {
}
@Override
public final IBlockState getBlock(int x, int y, int z) {
public final BlockState getBlock(int x, int y, int z) {
CachedChunk chunk = chunks[x >> 4][z >> 4];
if (chunk != null) {
return chunk.getBlock(x & 15, y, z & 15, dimension);
@@ -216,7 +216,7 @@ public final class CachedRegion implements ICachedRegion {
boolean[][] present = new boolean[32][32];
BitSet[][] bitSets = new BitSet[32][32];
Map<String, List<BlockPos>>[][] location = new Map[32][32];
IBlockState[][][] overview = new IBlockState[32][32][];
BlockState[][][] overview = new BlockState[32][32][];
long[][] cacheTimestamp = new long[32][32];
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
@@ -227,7 +227,7 @@ public final class CachedRegion implements ICachedRegion {
in.readFully(bytes);
bitSets[x][z] = BitSet.valueOf(bytes);
location[x][z] = new HashMap<>();
overview[x][z] = new IBlockState[256];
overview[x][z] = new BlockState[256];
present[x][z] = true;
break;
case CHUNK_NOT_PRESENT:

View File

@@ -303,6 +303,9 @@ public final class CachedWorld implements ICachedWorld, Helper {
} catch (InterruptedException e) {
e.printStackTrace();
break;
} catch (Throwable th) {
// in the case of an exception, keep consuming from the queue so as not to leak memory
th.printStackTrace();
}
}
}

View File

@@ -21,8 +21,6 @@ import baritone.api.utils.BlockUtils;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.pathing.PathingBlockType;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.chunk.BlockStateContainer;
@@ -31,6 +29,8 @@ import net.minecraft.world.chunk.ChunkSection;
import java.util.*;
import static baritone.utils.BlockStateInterface.getFromChunk;
/**
* @author Brady
* @since 8/3/2018
@@ -59,7 +59,7 @@ public final class ChunkPacker {
// since a bitset is initialized to all zero, and air is saved as zeros
continue;
}
BlockStateContainer<IBlockState> bsc = extendedblockstorage.getData();
BlockStateContainer<BlockState> bsc = extendedblockstorage.getData();
int yReal = y0 << 4;
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order
@@ -68,7 +68,7 @@ public final class ChunkPacker {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int index = CachedChunk.getPositionIndex(x, y, z);
IBlockState state = bsc.get(x, y1, z);
BlockState state = bsc.get(x, y1, z);
boolean[] bits = getPathingBlockType(state, chunk, x, y, z).getBits();
bitSet.set(index, bits[0]);
bitSet.set(index + 1, bits[1]);
@@ -86,25 +86,26 @@ public final class ChunkPacker {
}
//long end = System.nanoTime() / 1000000L;
//System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z);
IBlockState[] blocks = new IBlockState[256];
BlockState[] blocks = new BlockState[256];
for (int z = 0; z < 16; z++) {
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
https:
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
for (int x = 0; x < 16; x++) {
for (int y = 255; y >= 0; y--) {
int index = CachedChunk.getPositionIndex(x, y, z);
if (bitSet.get(index) || bitSet.get(index + 1)) {
blocks[z << 4 | x] = chunk.getBlockState(x, y, z);
blocks[z << 4 | x] = getFromChunk(chunk, x, y, z);
continue https;
}
}
blocks[z << 4 | x] = Blocks.AIR.getDefaultState();
}
}
return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
return new CachedChunk(chunk.getPos().x, chunk.getPos().z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
}
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
private static PathingBlockType getPathingBlockType(BlockState state, Chunk chunk, int x, int y, int z) {
Block block = state.getBlock();
if (MovementHelper.isWater(state)) {
// only water source blocks are plausibly usable, flowing water should be avoid
@@ -113,15 +114,15 @@ public final class ChunkPacker {
return PathingBlockType.AVOID;
}
if (
(x != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)))
|| (x != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)))
|| (z != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)))
|| (z != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1)))
(x != 15 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x + 1, y, z)))
|| (x != 0 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x - 1, y, z)))
|| (z != 15 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x, y, z + 1)))
|| (z != 0 && MovementHelper.possiblyFlowing(getFromChunk(chunk, x, y, z - 1)))
) {
return PathingBlockType.AVOID;
}
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));
Vec3d flow = state.getFluidState().getFlow(chunk.getWorld(), new BlockPos(x + chunk.getPos().x << 4, y, z + chunk.getPos().z << 4));
if (flow.x != 0.0 || flow.z != 0.0) {
return PathingBlockType.WATER;
}
@@ -137,14 +138,14 @@ public final class ChunkPacker {
// 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
// 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 instanceof AirBlock || block instanceof TallGrassBlock || block instanceof DoublePlantBlock || block instanceof FlowerBlock) {
return PathingBlockType.AIR;
}
return PathingBlockType.SOLID;
}
public static IBlockState pathingTypeToBlock(PathingBlockType type, int dimension) {
public static BlockState pathingTypeToBlock(PathingBlockType type, int dimension) {
switch (type) {
case AIR:
return Blocks.AIR.getDefaultState();

View File

@@ -20,11 +20,9 @@ package baritone.cache;
import baritone.Baritone;
import baritone.api.cache.IWorldProvider;
import baritone.api.utils.Helper;
import baritone.utils.accessor.IAnvilChunkLoader;
import baritone.utils.accessor.IChunkProviderServer;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.world.WorldServer;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld;
import org.apache.commons.lang3.SystemUtils;
import java.io.File;
@@ -63,11 +61,9 @@ public class WorldProvider implements IWorldProvider, Helper {
IntegratedServer integratedServer = mc.getIntegratedServer();
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
if (integratedServer != null) {
WorldServer localServerWorld = integratedServer.getWorld(dimension);
IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider();
IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader();
directory = loader.getChunkSaveLocation();
if (mc.isSingleplayer()) {
ServerWorld localServerWorld = integratedServer.getWorld(dimension);
directory = dimension.getDirectory(localServerWorld.getSaveHandler().getWorldDirectory());
// Gets the "depth" of this directory relative the the game's run directory, 2 is the location of the world
if (directory.toPath().relativize(mc.gameDir.toPath()).getNameCount() != 2) {
@@ -78,7 +74,7 @@ public class WorldProvider implements IWorldProvider, Helper {
directory = new File(directory, "baritone");
readme = directory;
} else { // Otherwise, the server must be remote...
String folderName = mc.getCurrentServerData().serverIP;
String folderName = mc.isConnectedToRealms() ? "realms" : mc.getCurrentServerData().serverIP;
if (SystemUtils.IS_OS_WINDOWS) {
folderName = folderName.replace(":", "_");
}

View File

@@ -20,8 +20,8 @@ package baritone.cache;
import baritone.api.cache.IWorldScanner;
import baritone.api.utils.IPlayerContext;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.block.BlockState;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.BlockStateContainer;
@@ -46,7 +46,7 @@ public enum WorldScanner implements IWorldScanner {
if (blocks.isEmpty()) {
return res;
}
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
ClientChunkProvider chunkProvider = (ClientChunkProvider) ctx.world().getChunkProvider();
int maxSearchRadiusSq = maxSearchRadius * maxSearchRadius;
int playerChunkX = ctx.playerFeet().getX() >> 4;
@@ -70,7 +70,7 @@ public enum WorldScanner implements IWorldScanner {
foundChunks = true;
int chunkX = xoff + playerChunkX;
int chunkZ = zoff + playerChunkZ;
Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, false, false);
Chunk chunk = chunkProvider.getChunk(chunkX, chunkZ, null, false);
if (chunk == null) {
continue;
}
@@ -96,8 +96,8 @@ public enum WorldScanner implements IWorldScanner {
return Collections.emptyList();
}
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, false, false);
ClientChunkProvider chunkProvider = (ClientChunkProvider) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getChunk(pos.x, pos.z, null, false);
int playerY = ctx.playerFeet().getY();
if (chunk == null || chunk.isEmpty()) {
@@ -114,18 +114,18 @@ public enum WorldScanner implements IWorldScanner {
boolean foundWithinY = false;
for (int yIndex = 0; yIndex < 16; yIndex++) {
int y0 = coordinateIterationOrder[yIndex];
ChunkSection extendedblockstorage = chunkInternalStorageArray[y0];
if (extendedblockstorage == null) {
ChunkSection section = chunkInternalStorageArray[y0];
if (section == null || ChunkSection.isEmpty(section)) {
continue;
}
int yReal = y0 << 4;
BlockStateContainer<IBlockState> bsc = extendedblockstorage.getData();
BlockStateContainer<BlockState> bsc = section.getData();
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
// for better cache locality, iterate in that order
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
IBlockState state = bsc.get(x, y, z);
BlockState state = bsc.get(x, y, z);
if (search.contains(state.getBlock())) {
int yy = yReal | y;
if (result.size() >= max) {

View File

@@ -51,6 +51,7 @@ public final class GameEventHandler implements IEventBus, Helper {
try {
baritone.bsi = new BlockStateInterface(baritone.getPlayerContext(), true);
} catch (Exception ex) {
ex.printStackTrace();
baritone.bsi = null;
}
} else {
@@ -84,7 +85,7 @@ public final class GameEventHandler implements IEventBus, Helper {
// to make sure the chunk being unloaded is already loaded.
boolean isPreUnload = state == EventState.PRE
&& type == ChunkEvent.Type.UNLOAD
&& world.getChunkProvider().getChunk(event.getX(), event.getZ(), false, false) != null;
&& world.getChunkProvider().getChunk(event.getX(), event.getZ(), null, false) != null;
if (isPostPopulate || isPreUnload) {
baritone.getWorldProvider().ifWorldLoaded(worldData -> {

View File

@@ -76,6 +76,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch {
int timeCheckInterval = 1 << 6;
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.value; // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
double minimumImprovement = Baritone.settings().minimumImprovementRepropagation.value ? MIN_IMPROVEMENT : 0;
Moves[] allMoves = Moves.values();
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
@@ -86,8 +87,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch {
if (slowPath) {
try {
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.value);
} catch (InterruptedException ex) {
}
} catch (InterruptedException ignored) {}
}
PathNode currentNode = openSet.removeLowest();
mostRecentConsidered = currentNode;
@@ -96,7 +96,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch {
logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext));
}
for (Moves moves : Moves.values()) {
for (Moves moves : allMoves) {
int newX = currentNode.x + moves.xOffset;
int newZ = currentNode.z + moves.zOffset;
if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !calcContext.isLoaded(newX, newZ)) {

View File

@@ -127,7 +127,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper {
return new PathCalculationResult(PathCalculationResult.Type.SUCCESS_SEGMENT, path);
}
} catch (Exception e) {
Helper.HELPER.logDebug("Pathing exception: " + e);
Helper.HELPER.logDirect("Pathing exception: " + e);
e.printStackTrace();
return new PathCalculationResult(PathCalculationResult.Type.EXCEPTION);
} finally {

View File

@@ -72,31 +72,12 @@ class Path extends PathBase {
this.start = new BetterBlockPos(start.x, start.y, start.z);
this.end = new BetterBlockPos(end.x, end.y, end.z);
this.numNodes = numNodes;
this.path = new ArrayList<>();
this.movements = new ArrayList<>();
this.nodes = new ArrayList<>();
this.goal = goal;
this.context = context;
assemblePath(end);
}
@Override
public Goal getGoal() {
return goal;
}
/**
* Assembles this path given the end node.
*
* @param end The end node
*/
private void assemblePath(PathNode end) {
if (!path.isEmpty() || !movements.isEmpty()) {
throw new IllegalStateException();
}
PathNode current = end;
LinkedList<BetterBlockPos> tempPath = new LinkedList<>();
LinkedList<PathNode> tempNodes = new LinkedList();
LinkedList<PathNode> tempNodes = new LinkedList<>();
// Repeatedly inserting to the beginning of an arraylist is O(n^2)
// Instead, do it into a linked list, then convert at the end
while (current != null) {
@@ -107,8 +88,13 @@ class Path extends PathBase {
// Can't directly convert from the PathNode pseudo linked list to an array because we don't know how long it is
// inserting into a LinkedList<E> keeps track of length, then when we addall (which calls .toArray) it's able
// to performantly do that conversion since it knows the length.
path.addAll(tempPath);
nodes.addAll(tempNodes);
this.path = new ArrayList<>(tempPath);
this.nodes = new ArrayList<>(tempNodes);
}
@Override
public Goal getGoal() {
return goal;
}
private boolean assembleMovements() {

View File

@@ -25,12 +25,12 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.ToolSet;
import baritone.utils.pathing.BetterWorldBorder;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -58,6 +58,7 @@ public class CalculationContext {
public final boolean allowParkour;
public final boolean allowParkourPlace;
public final boolean allowJumpAt256;
public final boolean allowParkourAscend;
public final boolean assumeWalkOnWater;
public final boolean allowDiagonalDescend;
public final boolean allowDownward;
@@ -77,19 +78,20 @@ public class CalculationContext {
public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
this.safeForThreadedUse = forUseOnAnotherThread;
this.baritone = baritone;
EntityPlayerSP player = baritone.getPlayerContext().player();
ClientPlayerEntity player = baritone.getPlayerContext().player();
this.world = baritone.getPlayerContext().world();
this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread);
this.toolSet = new ToolSet(player);
this.hasThrowaway = Baritone.settings().allowPlace.value && ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway();
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.getDimension().isNether();
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && PlayerInventory.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.getDimension().isNether();
this.canSprint = Baritone.settings().allowSprint.value && player.getFoodStats().getFoodLevel() > 6;
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.value;
this.allowBreak = Baritone.settings().allowBreak.value;
this.allowParkour = Baritone.settings().allowParkour.value;
this.allowParkourPlace = Baritone.settings().allowParkourPlace.value;
this.allowJumpAt256 = Baritone.settings().allowJumpAt256.value;
this.allowParkourAscend = Baritone.settings().allowParkourAscend.value;
this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.value;
this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.value;
this.allowDownward = Baritone.settings().allowDownward.value;
@@ -115,7 +117,7 @@ public class CalculationContext {
return baritone;
}
public IBlockState get(int x, int y, int z) {
public BlockState get(int x, int y, int z) {
return bsi.get0(x, y, z); // laughs maniacally
}
@@ -123,7 +125,7 @@ public class CalculationContext {
return bsi.isLoaded(x, z);
}
public IBlockState get(BlockPos pos) {
public BlockState get(BlockPos pos) {
return get(pos.getX(), pos.getY(), pos.getZ());
}

View File

@@ -23,19 +23,18 @@ import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.*;
import baritone.api.utils.input.Input;
import baritone.behavior.PathingBehavior;
import baritone.utils.BlockStateInterface;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.util.EnumFacing;
import net.minecraft.entity.item.FallingBlockEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
public abstract class Movement implements IMovement, MovementHelper {
public static final EnumFacing[] HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.DOWN};
public static final Direction[] HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.DOWN};
protected final IBaritone baritone;
protected final IPlayerContext ctx;
@@ -62,6 +61,8 @@ public abstract class Movement implements IMovement, MovementHelper {
public List<BlockPos> toPlaceCached = null;
public List<BlockPos> toWalkIntoCached = null;
private Set<BetterBlockPos> validPositionsCached = null;
private Boolean calculatedWhileLoaded;
protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
@@ -99,6 +100,20 @@ public abstract class Movement implements IMovement, MovementHelper {
this.cost = cost;
}
protected abstract Set<BetterBlockPos> calculateValidPositions();
public Set<BetterBlockPos> getValidPositions() {
if (validPositionsCached == null) {
validPositionsCached = calculateValidPositions();
Objects.requireNonNull(validPositionsCached);
}
return validPositionsCached;
}
protected boolean playerInValidPosition() {
return getValidPositions().contains(ctx.playerFeet()) || getValidPositions().contains(((PathingBehavior) baritone.getPathingBehavior()).pathStart());
}
/**
* Handles the execution of the latest Movement
* State, and offers a Status to the calling class.
@@ -113,6 +128,7 @@ public abstract class Movement implements IMovement, MovementHelper {
currentState.setInput(Input.JUMP, true);
}
if (ctx.player().isEntityInsideOpaqueBlock()) {
ctx.getSelectedBlock().ifPresent(pos -> MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, pos)));
currentState.setInput(Input.CLICK_LEFT, true);
}
@@ -141,15 +157,15 @@ public abstract class Movement implements IMovement, MovementHelper {
}
boolean somethingInTheWay = false;
for (BetterBlockPos blockPos : positionsToBreak) {
if (!ctx.world().getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(0, 0, 0, 1, 1.1, 1).offset(blockPos)).isEmpty() && Baritone.settings().pauseMiningForFallingBlocks.value) {
if (!ctx.world().getEntitiesWithinAABB(FallingBlockEntity.class, new AxisAlignedBB(0, 0, 0, 1, 1.1, 1).offset(blockPos)).isEmpty() && Baritone.settings().pauseMiningForFallingBlocks.value) {
return false;
}
if (!MovementHelper.canWalkThrough(ctx, blockPos)) { // can't break air, so don't try
somethingInTheWay = true;
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
if (reachable.isPresent()) {
Rotation rotTowardsBlock = reachable.get();
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
if (ctx.isLookingAt(blockPos) || ctx.playerRotations().isReallyCloseTo(rotTowardsBlock)) {
state.setInput(Input.CLICK_LEFT, true);

View File

@@ -27,24 +27,19 @@ import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.BlockStateInterface;
import baritone.utils.ToolSet;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.fluid.FlowingFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.IFluidState;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.init.Fluids;
import net.minecraft.fluid.*;
import net.minecraft.pathfinding.PathType;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import java.util.Optional;
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP;
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
/**
* Static helpers for cost calculation
@@ -53,10 +48,10 @@ import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN____SO
*/
public interface MovementHelper extends ActionCosts, Helper {
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
static boolean avoidBreaking(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block b = state.getBlock();
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|| b instanceof BlockSilverfish // obvious reasons
|| b instanceof SilverfishBlock // obvious reasons
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|| avoidAdjacentBreaking(bsi, x, y + 1, z, true)
|| avoidAdjacentBreaking(bsi, x + 1, y, z, false)
@@ -69,13 +64,13 @@ public interface MovementHelper extends ActionCosts, Helper {
// returns true if you should avoid breaking a block that's adjacent to this one (e.g. lava that will start flowing if you give it a path)
// this is only called for north, south, east, west, and up. this is NOT called for down.
// we assume that it's ALWAYS okay to break the block thats ABOVE liquid
IBlockState state = bsi.get0(x, y, z);
BlockState state = bsi.get0(x, y, z);
Block block = state.getBlock();
if (!directlyAbove // it is fine to mine a block that has a falling block directly above, this (the cost of breaking the stacked fallings) is included in cost calculations
// therefore if directlyAbove is true, we will actually ignore if this is falling
&& block instanceof BlockFalling // obviously, this check is only valid for falling blocks
&& block instanceof FallingBlock // obviously, this check is only valid for falling blocks
&& Baritone.settings().avoidUpdatingFallingBlocks.value // and if the setting is enabled
&& BlockFalling.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported)
&& FallingBlock.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported)
return true; // dont break a block that is adjacent to unsupported gravel because it can cause really weird stuff
}
return !state.getFluidState().isEmpty();
@@ -89,27 +84,27 @@ public interface MovementHelper extends ActionCosts, Helper {
return canWalkThrough(bsi, x, y, z, bsi.get0(x, y, z));
}
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
static boolean canWalkThrough(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block block = state.getBlock();
if (block instanceof BlockAir) { // early return for most common case
if (block instanceof AirBlock) { // early return for most common case
return true;
}
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof BlockSkull || block == Blocks.BUBBLE_COLUMN || block instanceof BlockShulkerBox || block instanceof BlockSlab || block instanceof BlockTrapDoor) {
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof AbstractSkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock) {
return false;
}
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
return false;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
if (block instanceof DoorBlock || block instanceof FenceGateBlock) {
// Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume
// that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't
// be opened by just interacting.
return block != Blocks.IRON_DOOR;
}
if (block instanceof BlockCarpet) {
if (block instanceof CarpetBlock) {
return canWalkOn(bsi, x, y - 1, z);
}
if (block instanceof BlockSnowLayer) {
if (block instanceof SnowBlock) {
// we've already checked doors and fence gates
// so the only remaining dynamic isPassables are snow and trapdoor
// if they're cached as a top block, we don't know their metadata
@@ -119,7 +114,7 @@ public interface MovementHelper extends ActionCosts, Helper {
}
// the check in BlockSnow.isPassable is layers < 5
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
if (state.get(BlockSnowLayer.LAYERS) >= 3) {
if (state.get(SnowBlock.LAYERS) >= 3) {
return false;
}
// ok, it's low enough we could walk through it, but is it supported?
@@ -133,8 +128,8 @@ public interface MovementHelper extends ActionCosts, Helper {
if (Baritone.settings().assumeWalkOnWater.value) {
return false;
}
IBlockState up = bsi.get0(x, y + 1, z);
if (!up.getFluidState().isEmpty() || up.getBlock() instanceof BlockLilyPad) {
BlockState up = bsi.get0(x, y + 1, z);
if (!up.getFluidState().isEmpty() || up.getBlock() instanceof LilyPadBlock) {
return false;
}
return true;
@@ -142,7 +137,7 @@ public interface MovementHelper extends ActionCosts, Helper {
// every block that overrides isPassable with anything more complicated than a "return true;" or "return false;"
// has already been accounted for above
// therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null
return state.allowsMovement(null, null, PathType.LAND);
return state.allowsMovement(null, BlockPos.ZERO, PathType.LAND); // workaround for future compatibility =P
}
/**
@@ -159,9 +154,9 @@ public interface MovementHelper extends ActionCosts, Helper {
return fullyPassable(context.get(x, y, z));
}
static boolean fullyPassable(IBlockState state) {
static boolean fullyPassable(BlockState state) {
Block block = state.getBlock();
if (block instanceof BlockAir) { // early return for most common case
if (block instanceof AirBlock) { // early return for most common case
return true;
}
// exceptions - blocks that are isPassable true, but we can't actually jump through
@@ -171,21 +166,21 @@ public interface MovementHelper extends ActionCosts, Helper {
|| block == Blocks.VINE
|| block == Blocks.LADDER
|| block == Blocks.COCOA
|| block instanceof BlockDoor
|| block instanceof BlockFenceGate
|| block instanceof BlockSnow
|| block instanceof DoorBlock
|| block instanceof FenceGateBlock
|| block instanceof SnowBlock
|| !state.getFluidState().isEmpty()
|| block instanceof BlockTrapDoor
|| block instanceof BlockEndPortal
|| block instanceof BlockSkull
|| block instanceof BlockShulkerBox) {
|| block instanceof TrapDoorBlock
|| block instanceof EndPortalBlock
|| block instanceof SkullBlock
|| block instanceof ShulkerBoxBlock) {
return false;
}
// door, fence gate, liquid, trapdoor have been accounted for, nothing else uses the world or pos parameters
return state.allowsMovement(null, null, PathType.LAND);
}
static boolean isReplacable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
static boolean isReplacable(int x, int y, int z, BlockState state, BlockStateInterface bsi) {
// for MovementTraverse and MovementAscend
// block double plant defaults to true when the block doesn't match, so don't need to check that case
// all other overrides just return true or false
@@ -197,16 +192,16 @@ public interface MovementHelper extends ActionCosts, Helper {
* }
*/
Block block = state.getBlock();
if (block instanceof BlockAir) {
if (block instanceof AirBlock) {
// early return for common cases hehe
return true;
}
if (block instanceof BlockSnowLayer) {
if (block instanceof SnowBlock) {
// as before, default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible)
if (!bsi.worldContainsLoadedChunk(x, z)) {
return true;
}
return state.get(BlockSnowLayer.LAYERS) == 1;
return state.get(SnowBlock.LAYERS) == 1;
}
if (block == Blocks.LARGE_FERN || block == Blocks.TALL_GRASS) {
return true;
@@ -219,12 +214,12 @@ public interface MovementHelper extends ActionCosts, Helper {
return false;
}
IBlockState state = BlockStateInterface.get(ctx, doorPos);
if (!(state.getBlock() instanceof BlockDoor)) {
BlockState state = BlockStateInterface.get(ctx, doorPos);
if (!(state.getBlock() instanceof DoorBlock)) {
return true;
}
return isHorizontalBlockPassable(doorPos, state, playerPos, BlockDoor.OPEN);
return isHorizontalBlockPassable(doorPos, state, playerPos, DoorBlock.OPEN);
}
static boolean isGatePassable(IPlayerContext ctx, BlockPos gatePos, BlockPos playerPos) {
@@ -232,27 +227,27 @@ public interface MovementHelper extends ActionCosts, Helper {
return false;
}
IBlockState state = BlockStateInterface.get(ctx, gatePos);
if (!(state.getBlock() instanceof BlockFenceGate)) {
BlockState state = BlockStateInterface.get(ctx, gatePos);
if (!(state.getBlock() instanceof FenceGateBlock)) {
return true;
}
return state.get(BlockFenceGate.OPEN);
return state.get(FenceGateBlock.OPEN);
}
static boolean isHorizontalBlockPassable(BlockPos blockPos, IBlockState blockState, BlockPos playerPos, BooleanProperty propertyOpen) {
static boolean isHorizontalBlockPassable(BlockPos blockPos, BlockState blockState, BlockPos playerPos, BooleanProperty propertyOpen) {
if (playerPos.equals(blockPos)) {
return false;
}
EnumFacing.Axis facing = blockState.get(BlockHorizontal.HORIZONTAL_FACING).getAxis();
Direction.Axis facing = blockState.get(HorizontalBlock.HORIZONTAL_FACING).getAxis();
boolean open = blockState.get(propertyOpen);
EnumFacing.Axis playerFacing;
Direction.Axis playerFacing;
if (playerPos.north().equals(blockPos) || playerPos.south().equals(blockPos)) {
playerFacing = EnumFacing.Axis.Z;
playerFacing = Direction.Axis.Z;
} else if (playerPos.east().equals(blockPos) || playerPos.west().equals(blockPos)) {
playerFacing = EnumFacing.Axis.X;
playerFacing = Direction.Axis.X;
} else {
return true;
}
@@ -260,7 +255,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return (facing == playerFacing) == open;
}
static boolean avoidWalkingInto(IBlockState state) {
static boolean avoidWalkingInto(BlockState state) {
Block block = state.getBlock();
return !state.getFluidState().isEmpty()
|| block == Blocks.MAGMA_BLOCK
@@ -283,14 +278,14 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param state The state of the block at the specified location
* @return Whether or not the specified block can be walked on
*/
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
static boolean canWalkOn(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
Block block = state.getBlock();
if (block instanceof BlockAir || block == Blocks.MAGMA_BLOCK || block == Blocks.BUBBLE_COLUMN) {
if (block instanceof AirBlock || block == Blocks.MAGMA_BLOCK || block == Blocks.BUBBLE_COLUMN) {
// early return for most common case (air)
// plus magma, which is a normal cube but it hurts you
return false;
}
if (state.isBlockNormalCube()) {
if (isBlockNormalCube(state)) {
return true;
}
if (block == Blocks.LADDER || (block == Blocks.VINE && Baritone.settings().allowVines.value)) { // TODO reconsider this
@@ -305,9 +300,9 @@ public interface MovementHelper extends ActionCosts, Helper {
if (isWater(state)) {
// since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()"
// BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability
IBlockState upState = bsi.get0(x, y + 1, z);
BlockState upState = bsi.get0(x, y + 1, z);
Block up = upState.getBlock();
if (up == Blocks.LILY_PAD || up instanceof BlockCarpet) {
if (up == Blocks.LILY_PAD || up instanceof CarpetBlock) {
return true;
}
if (isFlowing(x, y, z, state, bsi) || upState.getFluidState().getFluid() == Fluids.FLOWING_WATER) {
@@ -321,19 +316,19 @@ public interface MovementHelper extends ActionCosts, Helper {
if (Baritone.settings().assumeWalkOnLava.value && isLava(state) && !isFlowing(x, y, z, state, bsi)) {
return true;
}
if (block == Blocks.GLASS || block instanceof BlockStainedGlass) {
if (block == Blocks.GLASS || block instanceof StainedGlassBlock) {
return true;
}
if (block instanceof BlockSlab) {
if (block instanceof SlabBlock) {
if (!Baritone.settings().allowWalkOnBottomSlab.value) {
return state.isTopSolid();
return state.get(SlabBlock.TYPE) != SlabType.BOTTOM;
}
return true;
}
return block instanceof BlockStairs;
return block instanceof StairsBlock;
}
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, IBlockState state) {
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos, BlockState state) {
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state);
}
@@ -361,18 +356,18 @@ public interface MovementHelper extends ActionCosts, Helper {
return canPlaceAgainst(new BlockStateInterface(ctx), pos);
}
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z, IBlockState state) {
static boolean canPlaceAgainst(BlockStateInterface bsi, int x, int y, int z, BlockState state) {
// can we look at the center of a side face of this block and likely be able to place?
// (thats how this check is used)
// therefore dont include weird things that we technically could place against (like carpet) but practically can't
return state.isBlockNormalCube() || state.isFullCube() || state.getBlock() == Blocks.GLASS || state.getBlock() instanceof BlockStainedGlass;
return isBlockNormalCube(state) || state.getBlock() == Blocks.GLASS || state.getBlock() instanceof StainedGlassBlock;
}
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) {
return getMiningDurationTicks(context, x, y, z, context.get(x, y, z), includeFalling);
}
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, BlockState state, boolean includeFalling) {
Block block = state.getBlock();
if (!canWalkThrough(context.bsi, x, y, z, state)) {
if (!state.getFluidState().isEmpty()) {
@@ -393,8 +388,8 @@ public interface MovementHelper extends ActionCosts, Helper {
result += context.breakBlockAdditionalCost;
result *= mult;
if (includeFalling) {
IBlockState above = context.get(x, y + 1, z);
if (above.getBlock() instanceof BlockFalling) {
BlockState above = context.get(x, y + 1, z);
if (above.getBlock() instanceof FallingBlock) {
result += getMiningDurationTicks(context, x, y + 1, z, above, true);
}
}
@@ -403,9 +398,9 @@ public interface MovementHelper extends ActionCosts, Helper {
return 0; // we won't actually mine it, so don't check fallings above
}
static boolean isBottomSlab(IBlockState state) {
return state.getBlock() instanceof BlockSlab
&& state.get(BlockSlab.TYPE) == SlabType.BOTTOM;
static boolean isBottomSlab(BlockState state) {
return state.getBlock() instanceof SlabBlock
&& state.get(SlabBlock.TYPE) == SlabType.BOTTOM;
}
/**
@@ -414,7 +409,7 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param ctx The player context
* @param b the blockstate to mine
*/
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b) {
static void switchToBestToolFor(IPlayerContext ctx, BlockState b) {
switchToBestToolFor(ctx, b, new ToolSet(ctx.player()));
}
@@ -425,7 +420,7 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param b the blockstate to mine
* @param ts previously calculated ToolSet
*/
static void switchToBestToolFor(IPlayerContext ctx, IBlockState b, ToolSet ts) {
static void switchToBestToolFor(IPlayerContext ctx, BlockState b, ToolSet ts) {
ctx.player().inventory.currentItem = ts.getBestSlot(b.getBlock());
}
@@ -445,7 +440,7 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param state The block state
* @return Whether or not the block is water
*/
static boolean isWater(IBlockState state) {
static boolean isWater(BlockState state) {
Fluid f = state.getFluidState().getFluid();
return f == Fluids.WATER || f == Fluids.FLOWING_WATER;
}
@@ -462,7 +457,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return isWater(BlockStateInterface.get(ctx, bp));
}
static boolean isLava(IBlockState state) {
static boolean isLava(BlockState state) {
Fluid f = state.getFluidState().getFluid();
return f == Fluids.LAVA || f == Fluids.FLOWING_LAVA;
}
@@ -478,17 +473,17 @@ public interface MovementHelper extends ActionCosts, Helper {
return isLiquid(BlockStateInterface.get(ctx, p));
}
static boolean isLiquid(IBlockState blockState) {
static boolean isLiquid(BlockState blockState) {
return !blockState.getFluidState().isEmpty();
}
static boolean possiblyFlowing(IBlockState state) {
static boolean possiblyFlowing(BlockState state) {
IFluidState fluidState = state.getFluidState();
return fluidState.getFluid() instanceof FlowingFluid
&& fluidState.getFluid().getLevel(fluidState) != 8;
}
static boolean isFlowing(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
static boolean isFlowing(int x, int y, int z, BlockState state, BlockStateInterface bsi) {
IFluidState fluidState = state.getFluidState();
if (!(fluidState.getFluid() instanceof FlowingFluid)) {
return false;
@@ -502,6 +497,16 @@ public interface MovementHelper extends ActionCosts, Helper {
|| possiblyFlowing(bsi.get0(x, y, z - 1));
}
static boolean isBlockNormalCube(BlockState state) {
Block block = state.getBlock();
if (block instanceof BambooBlock
|| block instanceof MovingPistonBlock
|| block instanceof ScaffoldingBlock
|| block instanceof ShulkerBoxBlock) {
return false;
}
return Block.isOpaque(state.getCollisionShape(null, null));
}
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) {
IPlayerContext ctx = baritone.getPlayerContext();
@@ -512,7 +517,7 @@ public interface MovementHelper extends ActionCosts, Helper {
found = true;
}
for (int i = 0; i < 5; i++) {
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(false, placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
@@ -520,11 +525,11 @@ public interface MovementHelper extends ActionCosts, Helper {
return PlaceResult.NO_OPTION;
}
double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D;
double faceY = (placeAt.getY() + against1.getY() + 1.0D) * 0.5D;
double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D;
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance());
if (res != null && res.type == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) {
if (res != null && res.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) res).getPos().equals(against1) && ((BlockRayTraceResult) res).getPos().offset(((BlockRayTraceResult) res).getFace()).equals(placeAt)) {
state.setTarget(new MovementState.MovementTarget(place, true));
found = true;
@@ -538,7 +543,7 @@ public interface MovementHelper extends ActionCosts, Helper {
}
if (ctx.getSelectedBlock().isPresent()) {
BlockPos selectedBlock = ctx.getSelectedBlock().get();
EnumFacing side = ctx.objectMouseOver().sideHit;
Direction side = ((BlockRayTraceResult) ctx.objectMouseOver()).getFace();
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());

View File

@@ -20,6 +20,8 @@ package baritone.pathing.movement;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.Rotation;
import baritone.api.utils.input.Input;
import net.minecraft.client.Minecraft;
import net.minecraft.util.registry.Registry;
import java.util.HashMap;
import java.util.Map;

View File

@@ -20,7 +20,7 @@ package baritone.pathing.movement;
import baritone.api.utils.BetterBlockPos;
import baritone.pathing.movement.movements.*;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
/**
* An enum of all possible movements attached to all possible directions they could be taken in
@@ -225,7 +225,7 @@ public enum Moves {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.EAST, res.y - src.y);
return new MovementDiagonal(context.getBaritone(), src, Direction.NORTH, Direction.EAST, res.y - src.y);
}
@Override
@@ -239,7 +239,7 @@ public enum Moves {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.NORTH, EnumFacing.WEST, res.y - src.y);
return new MovementDiagonal(context.getBaritone(), src, Direction.NORTH, Direction.WEST, res.y - src.y);
}
@Override
@@ -253,7 +253,7 @@ public enum Moves {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.EAST, res.y - src.y);
return new MovementDiagonal(context.getBaritone(), src, Direction.SOUTH, Direction.EAST, res.y - src.y);
}
@Override
@@ -267,7 +267,7 @@ public enum Moves {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(context, src.x, src.y, src.z, res);
return new MovementDiagonal(context.getBaritone(), src, EnumFacing.SOUTH, EnumFacing.WEST, res.y - src.y);
return new MovementDiagonal(context.getBaritone(), src, Direction.SOUTH, Direction.WEST, res.y - src.y);
}
@Override
@@ -276,51 +276,51 @@ public enum Moves {
}
},
PARKOUR_NORTH(0, 0, -4, true, false) {
PARKOUR_NORTH(0, 0, -4, true, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.NORTH);
return MovementParkour.cost(context, src, Direction.NORTH);
}
@Override
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementParkour.cost(context, x, y, z, EnumFacing.NORTH, result);
MovementParkour.cost(context, x, y, z, Direction.NORTH, result);
}
},
PARKOUR_SOUTH(0, 0, +4, true, false) {
PARKOUR_SOUTH(0, 0, +4, true, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.SOUTH);
return MovementParkour.cost(context, src, Direction.SOUTH);
}
@Override
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementParkour.cost(context, x, y, z, EnumFacing.SOUTH, result);
MovementParkour.cost(context, x, y, z, Direction.SOUTH, result);
}
},
PARKOUR_EAST(+4, 0, 0, true, false) {
PARKOUR_EAST(+4, 0, 0, true, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.EAST);
return MovementParkour.cost(context, src, Direction.EAST);
}
@Override
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementParkour.cost(context, x, y, z, EnumFacing.EAST, result);
MovementParkour.cost(context, x, y, z, Direction.EAST, result);
}
},
PARKOUR_WEST(-4, 0, 0, true, false) {
PARKOUR_WEST(-4, 0, 0, true, true) {
@Override
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.WEST);
return MovementParkour.cost(context, src, Direction.WEST);
}
@Override
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
MovementParkour.cost(context, x, y, z, EnumFacing.WEST, result);
MovementParkour.cost(context, x, y, z, Direction.WEST, result);
}
};

View File

@@ -27,10 +27,12 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.util.Direction;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
public class MovementAscend extends Movement {
@@ -51,8 +53,19 @@ public class MovementAscend extends Movement {
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
BetterBlockPos prior = new BetterBlockPos(src.subtract(getDirection()).up()); // sometimes we back up to place the block, also sprint ascends, also skip descend to straight ascend
return ImmutableSet.of(src,
src.up(),
dest,
prior,
prior.up()
);
}
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
IBlockState toPlace = context.get(destX, y, destZ);
BlockState toPlace = context.get(destX, y, destZ);
double additionalPlacementCost = 0;
if (!MovementHelper.canWalkOn(context.bsi, destX, y, destZ, toPlace)) {
additionalPlacementCost = context.costOfPlacingAt(destX, y, destZ);
@@ -64,9 +77,9 @@ public class MovementAscend extends Movement {
}
boolean foundPlaceOption = false;
for (int i = 0; i < 5; i++) {
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
if (againstX == x && againstZ == z) { // we might be able to backplace now, but it doesn't matter because it will have been broken by the time we'd need to use it
continue;
}
@@ -79,26 +92,26 @@ public class MovementAscend extends Movement {
return COST_INF;
}
}
IBlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway
if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us
BlockState srcUp2 = context.get(x, y + 2, z); // used lower down anyway
if (context.get(x, y + 3, z).getBlock() instanceof FallingBlock && (MovementHelper.canWalkThrough(context.bsi, x, y + 1, z) || !(srcUp2.getBlock() instanceof FallingBlock))) {//it would fall on us and possibly suffocate us
// HOWEVER, we assume that we're standing in the start position
// that means that src and src.up(1) are both air
// maybe they aren't now, but they will be by the time this starts
// if the lower one is can't walk through and the upper one is falling, that means that by standing on src
// (the presupposition of this Movement)
// we have necessarily already cleared the entire BlockFalling stack
// we have necessarily already cleared the entire FallingBlock stack
// on top of our head
// as in, if we have a block, then two BlockFallings on top of it
// as in, if we have a block, then two FallingBlocks on top of it
// and that block is x, y+1, z, and we'd have to clear it to even start this movement
// we don't need to worry about those BlockFallings because we've already cleared them
// we don't need to worry about those FallingBlocks because we've already cleared them
return COST_INF;
// you may think we only need to check srcUp2, not srcUp
// however, in the scenario where glitchy world gen where unsupported sand / gravel generates
// it's possible srcUp is AIR from the start, and srcUp2 is falling
// and in that scenario, when we arrive and break srcUp2, that lets srcUp3 fall on us and suffocate us
}
IBlockState srcDown = context.get(x, y - 1, z);
BlockState srcDown = context.get(x, y - 1, z);
if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) {
return COST_INF;
}
@@ -143,6 +156,10 @@ public class MovementAscend extends Movement {
@Override
public MovementState updateState(MovementState state) {
if (ctx.playerFeet().y < src.y) {
// this check should run even when in preparing state (breaking blocks)
return state.setStatus(MovementStatus.UNREACHABLE);
}
super.updateState(state);
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
@@ -150,15 +167,11 @@ public class MovementAscend extends Movement {
return state;
}
if (ctx.playerFeet().equals(dest)) {
if (ctx.playerFeet().equals(dest) || ctx.playerFeet().equals(dest.add(getDirection().down()))) {
return state.setStatus(MovementStatus.SUCCESS);
}
if (ctx.playerFeet().y < src.y) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
BlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
ticksWithoutPlacement++;
if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false) == PlaceResult.READY_TO_PLACE) {
@@ -189,7 +202,7 @@ public class MovementAscend extends Movement {
double flatDistToNext = xAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + zAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
double sideDist = zAxis * Math.abs((dest.getX() + 0.5D) - ctx.player().posX) + xAxis * Math.abs((dest.getZ() + 0.5D) - ctx.player().posZ);
double lateralMotion = xAxis * ctx.player().motionZ + zAxis * ctx.player().motionX;
double lateralMotion = xAxis * ctx.player().getMotion().z + zAxis * ctx.player().getMotion().x;
if (Math.abs(lateralMotion) > 0.1) {
return state;
}
@@ -211,7 +224,7 @@ public class MovementAscend extends Movement {
public boolean headBonkClear() {
BetterBlockPos startUp = src.up(2);
for (int i = 0; i < 4; i++) {
BetterBlockPos check = startUp.offset(EnumFacing.byHorizontalIndex(i));
BetterBlockPos check = startUp.offset(Direction.byHorizontalIndex(i));
if (!MovementHelper.canWalkThrough(ctx, check)) {
// We might bonk our head
return false;

View File

@@ -29,14 +29,17 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import java.util.Set;
public class MovementDescend extends Movement {
private int numTicks = 0;
@@ -61,9 +64,14 @@ public class MovementDescend extends Movement {
return result.cost;
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
return ImmutableSet.of(src, dest.up(), dest);
}
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
double totalCost = 0;
IBlockState destDown = context.get(destX, y - 1, destZ);
BlockState destDown = context.get(destX, y - 1, destZ);
totalCost += MovementHelper.getMiningDurationTicks(context, destX, y - 1, destZ, destDown, false);
if (totalCost >= COST_INF) {
return;
@@ -92,7 +100,7 @@ public class MovementDescend extends Movement {
//A is plausibly breakable by either descend or fall
//C, D, etc determine the length of the fall
IBlockState below = context.get(destX, y - 2, destZ);
BlockState below = context.get(destX, y - 2, destZ);
if (!MovementHelper.canWalkOn(context.bsi, destX, y - 2, destZ, below)) {
dynamicFallCost(context, x, y, z, destX, destZ, totalCost, below, res);
return;
@@ -115,8 +123,8 @@ public class MovementDescend extends Movement {
res.cost = totalCost;
}
public static boolean dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below, MutableMoveResult res) {
if (frontBreak != 0 && context.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) {
public static boolean dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, BlockState below, MutableMoveResult res) {
if (frontBreak != 0 && context.get(destX, y + 2, destZ).getBlock() instanceof FallingBlock) {
// if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall
// but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column,
// and potentially replace the water we're going to fall into
@@ -134,7 +142,7 @@ public class MovementDescend extends Movement {
// this check prevents it from getting the block at y=-1 and crashing
return false;
}
IBlockState ontoBlock = context.get(destX, newY, destZ);
BlockState ontoBlock = context.get(destX, newY, destZ);
int unprotectedFallHeight = fallHeight - (y - effectiveStartHeight); // equal to fallHeight - y + effectiveFallHeight, which is equal to -newY + effectiveFallHeight, which is equal to effectiveFallHeight - newY
double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[unprotectedFallHeight] + frontBreak + costSoFar;
if (MovementHelper.isWater(ontoBlock)) {
@@ -214,7 +222,7 @@ public class MovementDescend extends Movement {
if (safeMode()) {
double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83;
double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83;
EntityPlayerSP player = ctx.player();
ClientPlayerEntity player = ctx.player();
state.setTarget(new MovementState.MovementTarget(
new Rotation(RotationUtils.calcRotationFromVec3d(player.getEyePosition(1.0F),
new Vec3d(destX, dest.getY(), destZ),

View File

@@ -28,25 +28,27 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MovementDiagonal extends Movement {
private static final double SQRT_2 = Math.sqrt(2);
public MovementDiagonal(IBaritone baritone, BetterBlockPos start, EnumFacing dir1, EnumFacing dir2, int dy) {
public MovementDiagonal(IBaritone baritone, BetterBlockPos start, Direction dir1, Direction dir2, int dy) {
this(baritone, start, start.offset(dir1), start.offset(dir2), dir2, dy);
// super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
}
private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2, int dy) {
private MovementDiagonal(IBaritone baritone, BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, Direction drr2, int dy) {
this(baritone, start, dir1.offset(drr2).up(dy), dir1, dir2);
}
@@ -64,12 +66,22 @@ public class MovementDiagonal extends Movement {
return result.cost;
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
BetterBlockPos diagA = new BetterBlockPos(src.x, src.y, dest.z);
BetterBlockPos diagB = new BetterBlockPos(dest.x, src.y, src.z);
if (dest.y != src.y) { // only if allowDiagonalDescend
return ImmutableSet.of(src, dest.up(), diagA, diagB, dest, diagA.down(), diagB.down());
}
return ImmutableSet.of(src, dest, diagA, diagB);
}
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
IBlockState destInto = context.get(destX, y, destZ);
BlockState destInto = context.get(destX, y, destZ);
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) {
return;
}
IBlockState destWalkOn = context.get(destX, y - 1, destZ);
BlockState destWalkOn = context.get(destX, y - 1, destZ);
boolean descend = false;
if (!MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destWalkOn)) {
descend = true;
@@ -91,16 +103,16 @@ public class MovementDiagonal extends Movement {
if (fromDown == Blocks.SOUL_SAND) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
}
IBlockState cuttingOver1 = context.get(x, y - 1, destZ);
BlockState cuttingOver1 = context.get(x, y - 1, destZ);
if (cuttingOver1.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver1)) {
return;
}
IBlockState cuttingOver2 = context.get(destX, y - 1, z);
BlockState cuttingOver2 = context.get(destX, y - 1, z);
if (cuttingOver2.getBlock() == Blocks.MAGMA_BLOCK || MovementHelper.isLava(cuttingOver2)) {
return;
}
IBlockState pb0 = context.get(x, y, destZ);
IBlockState pb2 = context.get(destX, y, z);
BlockState pb0 = context.get(x, y, destZ);
BlockState pb2 = context.get(destX, y, z);
double optionA = MovementHelper.getMiningDurationTicks(context, x, y, destZ, pb0, false);
double optionB = MovementHelper.getMiningDurationTicks(context, destX, y, z, pb2, false);
if (optionA != 0 && optionB != 0) {
@@ -108,13 +120,13 @@ public class MovementDiagonal extends Movement {
// so no need to check pb1 as well, might as well return early here
return;
}
IBlockState pb1 = context.get(x, y + 1, destZ);
BlockState pb1 = context.get(x, y + 1, destZ);
optionA += MovementHelper.getMiningDurationTicks(context, x, y + 1, destZ, pb1, true);
if (optionA != 0 && optionB != 0) {
// same deal, if pb1 makes optionA nonzero and option B already was nonzero, pb3 can't affect the result
return;
}
IBlockState pb3 = context.get(destX, y + 1, z);
BlockState pb3 = context.get(destX, y + 1, z);
if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2) && pb2.getBlock() != Blocks.WATER) || MovementHelper.avoidWalkingInto(pb3))) {
// at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction
return;
@@ -129,7 +141,7 @@ public class MovementDiagonal extends Movement {
return;
}
boolean water = false;
IBlockState startState = context.get(x, y, z);
BlockState startState = context.get(x, y, z);
Block startIn = startState.getBlock();
if (MovementHelper.isWater(startState) || MovementHelper.isWater(destInto)) {
// Ignore previous multiplier
@@ -172,8 +184,9 @@ public class MovementDiagonal extends Movement {
}
if (ctx.playerFeet().equals(dest)) {
state.setStatus(MovementStatus.SUCCESS);
return state;
return state.setStatus(MovementStatus.SUCCESS);
} else if (!playerInValidPosition() && !(MovementHelper.isLiquid(ctx, src) && getValidPositions().contains(ctx.playerFeet().up()))) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
if (sprint()) {
state.setInput(Input.SPRINT, true);
@@ -182,7 +195,7 @@ public class MovementDiagonal extends Movement {
return state;
}
public boolean sprint() {
private boolean sprint() {
if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && !Baritone.settings().sprintInWater.value) {
return false;
}

View File

@@ -24,9 +24,12 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import java.util.Set;
public class MovementDownward extends Movement {
@@ -47,6 +50,11 @@ public class MovementDownward extends Movement {
return cost(context, src.x, src.y, src.z);
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
return ImmutableSet.of(src, dest);
}
public static double cost(CalculationContext context, int x, int y, int z) {
if (!context.allowDownward) {
return COST_INF;
@@ -54,7 +62,7 @@ public class MovementDownward extends Movement {
if (!MovementHelper.canWalkOn(context.bsi, x, y - 2, z)) {
return COST_INF;
}
IBlockState down = context.get(x, y - 1, z);
BlockState down = context.get(x, y - 1, z);
Block downBlock = down.getBlock();
if (downBlock == Blocks.LADDER || downBlock == Blocks.VINE) {
return LADDER_DOWN_ONE_COST;
@@ -73,6 +81,8 @@ public class MovementDownward extends Movement {
if (ctx.playerFeet().equals(dest)) {
return state.setStatus(MovementStatus.SUCCESS);
} else if (!playerInValidPosition()) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
double diffX = ctx.player().posX - (dest.getX() + 0.5);
double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);

View File

@@ -31,19 +31,21 @@ import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.LadderBlock;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.item.Items;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class MovementFall extends Movement {
@@ -64,6 +66,16 @@ public class MovementFall extends Movement {
return result.cost;
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
Set<BetterBlockPos> set = new HashSet<>();
set.add(src);
for (int y = src.y - dest.y; y >= 0; y--) {
set.add(dest.up(y));
}
return set;
}
private boolean willPlaceBucket() {
CalculationContext context = new CalculationContext(baritone);
MutableMoveResult result = new MutableMoveResult();
@@ -80,11 +92,11 @@ public class MovementFall extends Movement {
BlockPos playerFeet = ctx.playerFeet();
Rotation toDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations());
Rotation targetRotation = null;
IBlockState destState = ctx.world().getBlockState(dest);
BlockState destState = ctx.world().getBlockState(dest);
Block destBlock = destState.getBlock();
boolean isWater = destState.getFluidState().getFluid() instanceof WaterFluid;
if (!isWater && willPlaceBucket() && !playerFeet.equals(dest)) {
if (!InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().getDimension().isNether()) {
if (!PlayerInventory.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_WATER)) || ctx.world().getDimension().isNether()) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
@@ -105,15 +117,15 @@ public class MovementFall extends Movement {
}
if (playerFeet.equals(dest) && (ctx.player().posY - playerFeet.getY() < 0.094 || isWater)) { // 0.094 because lilypads
if (isWater) { // only match water, not flowing water (which we cannot pick up with a bucket)
if (InventoryPlayer.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
if (PlayerInventory.isHotbar(ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY))) {
ctx.player().inventory.currentItem = ctx.player().inventory.getSlotFor(STACK_BUCKET_EMPTY);
if (ctx.player().motionY >= 0) {
if (ctx.player().getMotion().y >= 0) {
return state.setInput(Input.CLICK_RIGHT, true);
} else {
return state;
}
} else {
if (ctx.player().motionY >= 0) {
if (ctx.player().getMotion().y >= 0) {
return state.setStatus(MovementStatus.SUCCESS);
} // don't else return state; we need to stay centered because this water might be flowing under the surface
}
@@ -122,13 +134,13 @@ public class MovementFall extends Movement {
}
}
Vec3d destCenter = VecUtils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder)
if (Math.abs(ctx.player().posX + ctx.player().motionX - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().motionZ - destCenter.z) > 0.1) {
if (!ctx.player().onGround && Math.abs(ctx.player().motionY) > 0.4) {
if (Math.abs(ctx.player().posX + ctx.player().getMotion().x - destCenter.x) > 0.1 || Math.abs(ctx.player().posZ + ctx.player().getMotion().z - destCenter.z) > 0.1) {
if (!ctx.player().onGround && Math.abs(ctx.player().getMotion().y) > 0.4) {
state.setInput(Input.SNEAK, true);
}
state.setInput(Input.MOVE_FORWARD, true);
}
Vec3i avoid = Optional.ofNullable(avoid()).map(EnumFacing::getDirectionVec).orElse(null);
Vec3i avoid = Optional.ofNullable(avoid()).map(Direction::getDirectionVec).orElse(null);
if (avoid == null) {
avoid = src.subtract(dest);
} else {
@@ -146,11 +158,11 @@ public class MovementFall extends Movement {
return state;
}
private EnumFacing avoid() {
private Direction avoid() {
for (int i = 0; i < 15; i++) {
IBlockState state = ctx.world().getBlockState(ctx.playerFeet().down(i));
BlockState state = ctx.world().getBlockState(ctx.playerFeet().down(i));
if (state.getBlock() == Blocks.LADDER) {
return state.get(BlockLadder.FACING);
return state.get(LadderBlock.FACING);
}
}
return null;

View File

@@ -28,34 +28,39 @@ import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.StairsBlock;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.init.Fluids;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import java.util.HashSet;
import java.util.Set;
public class MovementParkour extends Movement {
private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
private final EnumFacing direction;
private final Direction direction;
private final int dist;
private final boolean ascend;
private MovementParkour(IBaritone baritone, BetterBlockPos src, int dist, EnumFacing dir) {
super(baritone, src, src.offset(dir, dist), EMPTY, src.offset(dir, dist).down());
private MovementParkour(IBaritone baritone, BetterBlockPos src, int dist, Direction dir, boolean ascend) {
super(baritone, src, src.offset(dir, dist).up(ascend ? 1 : 0), EMPTY, src.offset(dir, dist).down(ascend ? 0 : 1));
this.direction = dir;
this.dist = dist;
this.ascend = ascend;
}
public static MovementParkour cost(CalculationContext context, BetterBlockPos src, EnumFacing direction) {
public static MovementParkour cost(CalculationContext context, BetterBlockPos src, Direction direction) {
MutableMoveResult res = new MutableMoveResult();
cost(context, src.x, src.y, src.z, direction, res);
int dist = Math.abs(res.x - src.x) + Math.abs(res.z - src.z);
return new MovementParkour(context.getBaritone(), src, dist, direction);
return new MovementParkour(context.getBaritone(), src, dist, direction, res.y > src.y);
}
public static void cost(CalculationContext context, int x, int y, int z, EnumFacing dir, MutableMoveResult res) {
public static void cost(CalculationContext context, int x, int y, int z, Direction dir, MutableMoveResult res) {
if (!context.allowParkour) {
return;
}
@@ -69,7 +74,7 @@ public class MovementParkour extends Movement {
// most common case at the top -- the adjacent block isn't air
return;
}
IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff);
BlockState adj = context.get(x + xDiff, y - 1, z + zDiff);
if (MovementHelper.canWalkOn(context.bsi, x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now)
// second most common case -- we could just traverse not parkour
return;
@@ -86,8 +91,8 @@ public class MovementParkour extends Movement {
if (!MovementHelper.fullyPassable(context, x, y + 2, z)) {
return;
}
IBlockState standingOn = context.get(x, y - 1, z);
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn) || standingOn.getFluidState().getFluid() != Fluids.EMPTY) {
BlockState standingOn = context.get(x, y - 1, z);
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof StairsBlock || MovementHelper.isBottomSlab(standingOn) || standingOn.getFluidState().getFluid() != Fluids.EMPTY) {
return;
}
int maxJump;
@@ -101,19 +106,36 @@ public class MovementParkour extends Movement {
}
}
for (int i = 2; i <= maxJump; i++) {
// TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly?
for (int y2 = 0; y2 < 4; y2++) {
if (!MovementHelper.fullyPassable(context, x + xDiff * i, y + y2, z + zDiff * i)) {
return;
}
int destX = x + xDiff * i;
int destZ = z + zDiff * i;
if (!MovementHelper.fullyPassable(context, destX, y + 1, destZ)) {
return;
}
IBlockState landingOn = context.bsi.get0(x + xDiff * i, y - 1, z + zDiff * i);
if (!MovementHelper.fullyPassable(context, destX, y + 2, destZ)) {
return;
}
BlockState destInto = context.bsi.get0(destX, y, destZ);
if (!MovementHelper.fullyPassable(destInto)) {
if (i <= 3 && context.allowParkourAscend && context.canSprint && MovementHelper.canWalkOn(context.bsi, destX, y, destZ, destInto) && checkOvershootSafety(context.bsi, destX + xDiff, y + 1, destZ + zDiff)) {
res.x = destX;
res.y = y + 1;
res.z = destZ;
res.cost = i * SPRINT_ONE_BLOCK_COST + context.jumpPenalty;
}
return;
}
BlockState landingOn = context.bsi.get0(destX, y - 1, destZ);
// farmland needs to be canwalkon otherwise farm can never work at all, but we want to specifically disallow ending a jumy on farmland haha
if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i, landingOn)) {
res.x = x + xDiff * i;
res.y = y;
res.z = z + zDiff * i;
res.cost = costFromJumpDistance(i) + context.jumpPenalty;
if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, landingOn)) {
if (checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) {
res.x = destX;
res.y = y;
res.z = destZ;
res.cost = costFromJumpDistance(i) + context.jumpPenalty;
}
return;
}
if (!MovementHelper.fullyPassable(context, destX, y + 3, destZ)) {
return;
}
}
@@ -130,14 +152,17 @@ public class MovementParkour extends Movement {
if (placeCost >= COST_INF) {
return;
}
IBlockState toReplace = context.get(destX, y - 1, destZ);
BlockState toReplace = context.get(destX, y - 1, destZ);
if (!MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.bsi)) {
return;
}
if (!checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) {
return;
}
for (int i = 0; i < 5; i++) {
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast
continue;
}
@@ -151,6 +176,11 @@ public class MovementParkour extends Movement {
}
}
private static boolean checkOvershootSafety(BlockStateInterface bsi, int x, int y, int z) {
// we're going to walk into these two blocks after the landing of the parkour anyway, so make sure they aren't avoidWalkingInto
return !MovementHelper.avoidWalkingInto(bsi.get0(x, y, z)) && !MovementHelper.avoidWalkingInto(bsi.get0(x, y + 1, z));
}
private static double costFromJumpDistance(int dist) {
switch (dist) {
case 2:
@@ -169,12 +199,23 @@ public class MovementParkour extends Movement {
public double calculateCost(CalculationContext context) {
MutableMoveResult res = new MutableMoveResult();
cost(context, src.x, src.y, src.z, direction, res);
if (res.x != dest.x || res.z != dest.z) {
if (res.x != dest.x || res.y != dest.y || res.z != dest.z) {
return COST_INF;
}
return res.cost;
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
Set<BetterBlockPos> set = new HashSet<>();
for (int i = 0; i <= dist; i++) {
for (int y = 0; y < 2; y++) {
set.add(src.offset(direction, i).up(y));
}
}
return set;
}
@Override
public boolean safeToCancel(MovementState state) {
// once this movement is instantiated, the state is default to PREPPING
@@ -189,16 +230,12 @@ public class MovementParkour extends Movement {
if (state.getStatus() != MovementStatus.RUNNING) {
return state;
}
if (ctx.player().isHandActive()) {
logDebug("Pausing parkour since hand is active");
return state;
}
if (ctx.playerFeet().y < src.y) {
// we have fallen
logDebug("sorry");
return state.setStatus(MovementStatus.UNREACHABLE);
}
if (dist >= 4) {
if (dist >= 4 || ascend) {
state.setInput(Input.SPRINT, true);
}
MovementHelper.moveTowards(ctx, state, dest);
@@ -213,12 +250,13 @@ public class MovementParkour extends Movement {
state.setStatus(MovementStatus.SUCCESS);
}
} else if (!ctx.playerFeet().equals(src)) {
if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - ctx.playerFeet().getY() > 0.0001) {
if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - src.y > 0.0001) {
if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true) == PlaceResult.READY_TO_PLACE) {
// go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory
state.setInput(Input.CLICK_RIGHT, true);
}
if (dist == 3) { // this is a 2 block gap, dest = src + direction * 3
// prevent jumping too late by checking for ascend
if (dist == 3 && !ascend) { // this is a 2 block gap, dest = src + direction * 3
double xDiff = (src.x + 0.5) - ctx.player().posX;
double zDiff = (src.z + 0.5) - ctx.player().posZ;
double distFromStart = Math.max(Math.abs(xDiff), Math.abs(zDiff));

View File

@@ -30,14 +30,13 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
public class MovementPillar extends Movement {
@@ -50,28 +49,33 @@ public class MovementPillar extends Movement {
return cost(context, src.x, src.y, src.z);
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
return ImmutableSet.of(src, dest);
}
public static double cost(CalculationContext context, int x, int y, int z) {
IBlockState fromState = context.get(x, y, z);
BlockState fromState = context.get(x, y, z);
Block from = fromState.getBlock();
boolean ladder = from == Blocks.LADDER || from == Blocks.VINE;
IBlockState fromDown = context.get(x, y - 1, z);
BlockState fromDown = context.get(x, y - 1, z);
if (!ladder) {
if (fromDown.getBlock() == Blocks.LADDER || fromDown.getBlock() == Blocks.VINE) {
return COST_INF; // can't pillar from a ladder or vine onto something that isn't also climbable
}
if (fromDown.getBlock() instanceof BlockSlab && !fromDown.isTopSolid()) {
if (fromDown.getBlock() instanceof SlabBlock && fromDown.get(SlabBlock.TYPE) == SlabType.BOTTOM) {
return COST_INF; // can't pillar up from a bottom slab onto a non ladder
}
}
if (from == Blocks.VINE && !hasAgainst(context, x, y, z)) { // TODO this vine can't be climbed, but we could place a pillar still since vines are replacable, no? perhaps the pillar jump would be impossible because of the slowdown actually.
return COST_INF;
}
IBlockState toBreak = context.get(x, y + 2, z);
BlockState toBreak = context.get(x, y + 2, z);
Block toBreakBlock = toBreak.getBlock();
if (toBreakBlock instanceof BlockFenceGate) { // see issue #172
if (toBreakBlock instanceof FenceGateBlock) { // see issue #172
return COST_INF;
}
IBlockState srcUp = null;
BlockState srcUp = null;
if (MovementHelper.isWater(toBreak) && MovementHelper.isWater(fromState)) { // TODO should this also be allowed if toBreakBlock is air?
srcUp = context.get(x, y + 1, z);
if (MovementHelper.isWater(srcUp)) {
@@ -85,7 +89,7 @@ public class MovementPillar extends Movement {
if (placeCost >= COST_INF) {
return COST_INF;
}
if (fromDown.getBlock() instanceof BlockAir) {
if (fromDown.getBlock() instanceof AirBlock) {
placeCost += 0.1; // slightly (1/200th of a second) penalize pillaring on what's currently air
}
}
@@ -103,20 +107,20 @@ public class MovementPillar extends Movement {
if (toBreakBlock == Blocks.LADDER || toBreakBlock == Blocks.VINE) {
hardness = 0; // we won't actually need to break the ladder / vine because we're going to use it
} else {
IBlockState check = context.get(x, y + 3, z); // the block on top of the one we're going to break, could it fall on us?
if (check.getBlock() instanceof BlockFalling) {
BlockState check = context.get(x, y + 3, z); // the block on top of the one we're going to break, could it fall on us?
if (check.getBlock() instanceof FallingBlock) {
// see MovementAscend's identical check for breaking a falling block above our head
if (srcUp == null) {
srcUp = context.get(x, y + 1, z);
}
if (!(toBreakBlock instanceof BlockFalling) || !(srcUp.getBlock() instanceof BlockFalling)) {
if (!(toBreakBlock instanceof FallingBlock) || !(srcUp.getBlock() instanceof FallingBlock)) {
return COST_INF;
}
}
// this is commented because it may have had a purpose, but it's very unclear what it was. it's from the minebot era.
//if (!MovementHelper.canWalkOn(chkPos, check) || MovementHelper.canWalkThrough(chkPos, check)) {//if the block above where we want to break is not a full block, don't do it
// TODO why does canWalkThrough mean this action is COST_INF?
// BlockFalling makes sense, and !canWalkOn deals with weird cases like if it were lava
// FallingBlock makes sense, and !canWalkOn deals with weird cases like if it were lava
// but I don't understand why canWalkThrough makes it impossible
// return COST_INF;
//}
@@ -130,23 +134,23 @@ public class MovementPillar extends Movement {
}
public static boolean hasAgainst(CalculationContext context, int x, int y, int z) {
return context.get(x + 1, y, z).isBlockNormalCube() ||
context.get(x - 1, y, z).isBlockNormalCube() ||
context.get(x, y, z + 1).isBlockNormalCube() ||
context.get(x, y, z - 1).isBlockNormalCube();
return MovementHelper.isBlockNormalCube(context.get(x + 1, y, z)) ||
MovementHelper.isBlockNormalCube(context.get(x - 1, y, z)) ||
MovementHelper.isBlockNormalCube(context.get(x, y, z + 1)) ||
MovementHelper.isBlockNormalCube(context.get(x, y, z - 1));
}
public static BlockPos getAgainst(CalculationContext context, BetterBlockPos vine) {
if (context.get(vine.north()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.north()))) {
return vine.north();
}
if (context.get(vine.south()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.south()))) {
return vine.south();
}
if (context.get(vine.east()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.east()))) {
return vine.east();
}
if (context.get(vine.west()).isBlockNormalCube()) {
if (MovementHelper.isBlockNormalCube(context.get(vine.west()))) {
return vine.west();
}
return null;
@@ -163,7 +167,7 @@ public class MovementPillar extends Movement {
return state.setStatus(MovementStatus.UNREACHABLE);
}
IBlockState fromDown = BlockStateInterface.get(ctx, src);
BlockState fromDown = BlockStateInterface.get(ctx, src);
if (MovementHelper.isWater(fromDown) && MovementHelper.isWater(ctx, dest)) {
// stay centered while swimming up a water column
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()), false));
@@ -187,7 +191,7 @@ public class MovementPillar extends Movement {
boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
if (ladder) {
BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.get(BlockLadder.FACING).getOpposite());
BlockPos against = vine ? getAgainst(new CalculationContext(baritone), src) : src.offset(fromDown.get(LadderBlock.FACING).getOpposite());
if (against == null) {
logDebug("Unable to climb vines");
return state.setStatus(MovementStatus.UNREACHABLE);
@@ -220,7 +224,7 @@ public class MovementPillar extends Movement {
double diffX = ctx.player().posX - (dest.getX() + 0.5);
double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
double flatMotion = Math.sqrt(ctx.player().motionX * ctx.player().motionX + ctx.player().motionZ * ctx.player().motionZ);
double flatMotion = Math.sqrt(ctx.player().getMotion().x * ctx.player().getMotion().x + ctx.player().getMotion().z * ctx.player().getMotion().z);
if (dist > 0.17) {//why 0.17? because it seemed like a good number, that's why
//[explanation added after baritone port lol] also because it needs to be less than 0.2 because of the 0.3 sneak limit
//and 0.17 is reasonably less than 0.2
@@ -237,18 +241,17 @@ public class MovementPillar extends Movement {
if (!blockIsThere) {
IBlockState frState = BlockStateInterface.get(ctx, src);
BlockState frState = BlockStateInterface.get(ctx, src);
Block fr = frState.getBlock();
// TODO: Evaluate usage of getMaterial().isReplaceable()
if (!(fr instanceof BlockAir || frState.getMaterial().isReplaceable())) {
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance());
if (reachable.isPresent()) {
state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
}
if (!(fr instanceof AirBlock || frState.getMaterial().isReplaceable())) {
RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance())
.map(rot -> new MovementState.MovementTarget(rot, true))
.ifPresent(state::setTarget);
state.setInput(Input.JUMP, false); // breaking is like 5x slower when you're jumping
state.setInput(Input.CLICK_LEFT, true);
blockIsThere = false;
} else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos())) && ctx.player().posY > dest.getY() + 0.1) {
} else if (ctx.player().isSneaking() && (ctx.isLookingAt(src.down()) || ctx.isLookingAt(src)) && ctx.player().posY > dest.getY() + 0.1) {
state.setInput(Input.CLICK_RIGHT, true);
}
}

View File

@@ -30,14 +30,16 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.fluid.WaterFluid;
import net.minecraft.init.Blocks;
import net.minecraft.state.properties.SlabType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import java.util.Optional;
import java.util.Set;
public class MovementTraverse extends Movement {
/**
@@ -60,11 +62,16 @@ public class MovementTraverse extends Movement {
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
}
@Override
protected Set<BetterBlockPos> calculateValidPositions() {
return ImmutableSet.of(src, dest);
}
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
IBlockState pb0 = context.get(destX, y + 1, destZ);
IBlockState pb1 = context.get(destX, y, destZ);
IBlockState destOn = context.get(destX, y - 1, destZ);
IBlockState down = context.get(x, y - 1, z);
BlockState pb0 = context.get(destX, y + 1, destZ);
BlockState pb1 = context.get(destX, y, destZ);
BlockState destOn = context.get(destX, y - 1, destZ);
BlockState down = context.get(x, y - 1, z);
Block srcDown = down.getBlock();
if (MovementHelper.canWalkOn(context.bsi, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge
double WC = WALK_ONE_BLOCK_COST;
@@ -122,9 +129,9 @@ public class MovementTraverse extends Movement {
double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true); // only include falling on the upper block to break
double WC = throughWater ? context.waterWalkSpeed : WALK_ONE_BLOCK_COST;
for (int i = 0; i < 5; i++) {
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
int againstX = destX + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getXOffset();
int againstY = y - 1 + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getYOffset();
int againstZ = destZ + HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP[i].getZOffset();
if (againstX == x && againstZ == z) { // this would be a backplace
continue;
}
@@ -133,7 +140,7 @@ public class MovementTraverse extends Movement {
}
}
// now that we've checked all possible directions to side place, we actually need to backplace
if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && down.get(BlockSlab.TYPE) != SlabType.DOUBLE)) {
if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof SlabBlock && down.get(SlabBlock.TYPE) != SlabType.DOUBLE)) {
return COST_INF; // can't sneak and backplace against soul sand or half slabs (regardless of whether it's top half or bottom half) =/
}
if (down.getFluidState() instanceof WaterFluid) {
@@ -149,8 +156,8 @@ public class MovementTraverse extends Movement {
@Override
public MovementState updateState(MovementState state) {
super.updateState(state);
IBlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
IBlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
BlockState pb0 = BlockStateInterface.get(ctx, positionsToBreak[0]);
BlockState pb1 = BlockStateInterface.get(ctx, positionsToBreak[1]);
if (state.getStatus() != MovementStatus.RUNNING) {
// if the setting is enabled
if (!Baritone.settings().walkWhileBreaking.value) {
@@ -172,18 +179,23 @@ public class MovementTraverse extends Movement {
if (dist < 0.83) {
return state;
}
if (!state.getTarget().getRotation().isPresent()) {
// this can happen rarely when the server lags and doesn't send the falling sand entity until you've already walked through the block and are now mining the next one
return state;
}
// combine the yaw to the center of the destination, and the pitch to the specific block we're trying to break
// it's safe to do this since the two blocks we break (in a traverse) are right on top of each other and so will have the same yaw
float yawToDest = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), dest), ctx.playerRotations()).getYaw();
float pitchToBreak = state.getTarget().getRotation().get().getPitch();
if ((pb0.isFullCube() || pb0.getBlock() instanceof BlockAir && (pb1.isFullCube() || pb1.getBlock() instanceof BlockAir))) {
if ((MovementHelper.isBlockNormalCube(pb0) || pb0.getBlock() instanceof AirBlock && (MovementHelper.isBlockNormalCube(pb1) || pb1.getBlock() instanceof AirBlock))) {
// in the meantime, before we're right up against the block, we can break efficiently at this angle
pitchToBreak = 26;
}
state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true));
return state.setInput(Input.MOVE_FORWARD, true).setInput(Input.SPRINT, true);
return state.setTarget(new MovementState.MovementTarget(new Rotation(yawToDest, pitchToBreak), true))
.setInput(Input.MOVE_FORWARD, true)
.setInput(Input.SPRINT, true);
}
//sneak may have been set to true in the PREPPING state while mining an adjacent block
@@ -192,46 +204,39 @@ public class MovementTraverse extends Movement {
Block fd = BlockStateInterface.get(ctx, src.down()).getBlock();
boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE;
boolean door = pb0.getBlock() instanceof BlockDoor || pb1.getBlock() instanceof BlockDoor;
if (door) {
boolean isDoorActuallyBlockingUs = false;
if (pb0.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, src, dest)) {
isDoorActuallyBlockingUs = true;
} else if (pb1.getBlock() instanceof BlockDoor && !MovementHelper.isDoorPassable(ctx, dest, src)) {
isDoorActuallyBlockingUs = true;
}
if (isDoorActuallyBlockingUs && !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) {
if (pb0.getBlock() instanceof DoorBlock || pb1.getBlock() instanceof DoorBlock) {
boolean notPassable = pb0.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, src, dest) || pb1.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, dest, src);
boolean canOpen = !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()));
if (notPassable && canOpen) {
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), positionsToBreak[0]), ctx.playerRotations()), true))
.setInput(Input.CLICK_RIGHT, true);
}
}
if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
BlockPos blocked = null;
if (!MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up())) {
blocked = positionsToBreak[0];
} else if (!MovementHelper.isGatePassable(ctx, positionsToBreak[1], src)) {
blocked = positionsToBreak[1];
}
if (pb0.getBlock() instanceof FenceGateBlock || pb1.getBlock() instanceof FenceGateBlock) {
BlockPos blocked = !MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up()) ? positionsToBreak[0]
: !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1]
: null;
if (blocked != null) {
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), blocked), ctx.playerRotations()), true))
.setInput(Input.CLICK_RIGHT, true);
Optional<Rotation> rotation = RotationUtils.reachable(ctx, blocked);
if (rotation.isPresent()) {
return state.setTarget(new MovementState.MovementTarget(rotation.get(), true)).setInput(Input.CLICK_RIGHT, true);
}
}
}
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(ctx, positionToPlace) || ladder;
BlockPos whereAmI = ctx.playerFeet();
if (whereAmI.getY() != dest.getY() && !ladder) {
BlockPos feet = ctx.playerFeet();
if (feet.getY() != dest.getY() && !ladder) {
logDebug("Wrong Y coordinate");
if (whereAmI.getY() < dest.getY()) {
state.setInput(Input.JUMP, true);
if (feet.getY() < dest.getY()) {
return state.setInput(Input.JUMP, true);
}
return state;
}
if (isTheBridgeBlockThere) {
BetterBlockPos feet = ctx.playerFeet();
if (feet.equals(dest)) {
return state.setStatus(MovementStatus.SUCCESS);
}
@@ -246,23 +251,23 @@ public class MovementTraverse extends Movement {
return state;
}
BlockPos into = dest.subtract(src).add(dest);
IBlockState intoBelow = BlockStateInterface.get(ctx, into);
IBlockState intoAbove = BlockStateInterface.get(ctx, into.up());
if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, ctx.playerFeet()) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
BlockState intoBelow = BlockStateInterface.get(ctx, into);
BlockState intoAbove = BlockStateInterface.get(ctx, into.up());
if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, feet) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
state.setInput(Input.SPRINT, true);
}
IBlockState destDown = BlockStateInterface.get(ctx, dest.down());
BlockState destDown = BlockStateInterface.get(ctx, dest.down());
BlockPos against = positionsToBreak[0];
if (whereAmI.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) {
against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.get(BlockLadder.FACING).getOpposite());
if (feet.getY() != dest.getY() && ladder && (destDown.getBlock() == Blocks.VINE || destDown.getBlock() == Blocks.LADDER)) {
against = destDown.getBlock() == Blocks.VINE ? MovementPillar.getAgainst(new CalculationContext(baritone), dest.down()) : dest.offset(destDown.get(LadderBlock.FACING).getOpposite());
}
MovementHelper.moveTowards(ctx, state, against);
return state;
} else {
wasTheBridgeBlockAlwaysThere = false;
Block standingOn = BlockStateInterface.get(ctx, ctx.playerFeet().down()).getBlock();
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118
Block standingOn = BlockStateInterface.get(ctx, feet.down()).getBlock();
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof SlabBlock) { // see issue #118
double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().posX), Math.abs(dest.getZ() + 0.5 - ctx.player().posZ));
if (dist < 0.85) { // 0.5 + 0.3 + epsilon
MovementHelper.moveTowards(ctx, state, dest);
@@ -299,7 +304,7 @@ public class MovementTraverse extends Movement {
default:
break;
}
if (whereAmI.equals(dest)) {
if (feet.equals(dest)) {
// If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
// Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D;

View File

@@ -32,7 +32,7 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.movements.*;
import baritone.utils.BlockStateInterface;
import net.minecraft.init.Blocks;
import net.minecraft.block.Blocks;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -43,8 +43,7 @@ import java.util.*;
import static baritone.api.pathing.movement.MovementStatus.*;
/**
* Behavior to execute a precomputed path. Does not (yet) deal with path segmentation or stitching
* or cutting (jumping onto the next path if it starts with a backtrack of this path's ending)
* Behavior to execute a precomputed path
*
* @author leijurv
*/
@@ -99,14 +98,13 @@ public class PathExecutor implements IPathExecutor, Helper {
if (pathPosition >= path.length()) {
return true; // stop bugging me, I'm done
}
BetterBlockPos whereShouldIBe = path.positions().get(pathPosition);
Movement movement = (Movement) path.movements().get(pathPosition);
BetterBlockPos whereAmI = ctx.playerFeet();
if (!whereShouldIBe.equals(whereAmI) && !Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip
for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
if (whereAmI.equals(path.positions().get(i))) {
logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i);
if (!movement.getValidPositions().contains(whereAmI)) {
for (int i = 0; i < pathPosition && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
int previousPos = pathPosition;
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
pathPosition = i;
for (int j = pathPosition; j <= previousPos; j++) {
path.movements().get(j).reset();
}
@@ -115,9 +113,9 @@ public class PathExecutor implements IPathExecutor, Helper {
return false;
}
}
for (int i = pathPosition + 3; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing)
for (int i = pathPosition + 3; i < path.length() - 1; i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing)
// also don't check pathPosition+2 because reasons
if (whereAmI.equals(path.positions().get(i))) {
if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
if (i - pathPosition > 2) {
logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i);
}
@@ -146,38 +144,6 @@ public class PathExecutor implements IPathExecutor, Helper {
cancel();
return false;
}
//this commented block is literally cursed.
/*Out.log(actions.get(pathPosition));
if (pathPosition < actions.size() - 1) {//if there are two ActionBridges in a row and they are at right angles, walk diagonally. This makes it so you walk at 45 degrees along a zigzag path instead of doing inefficient zigging and zagging
if ((actions.get(pathPosition) instanceof ActionBridge) && (actions.get(pathPosition + 1) instanceof ActionBridge)) {
ActionBridge curr = (ActionBridge) actions.get(pathPosition);
ActionBridge next = (ActionBridge) actions.get(pathPosition + 1);
if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two movement are not parallel, so this is a right angle
if (curr.amIGood() && next.amIGood()) {//nothing in the way
BlockPos cornerToCut1 = new BlockPos(next.to.getX() - next.from.getX() + curr.from.getX(), next.to.getY(), next.to.getZ() - next.from.getZ() + curr.from.getZ());
BlockPos cornerToCut2 = cornerToCut1.up();
//Block corner1 = Baritone.get(cornerToCut1).getBlock();
//Block corner2 = Baritone.get(cornerToCut2).getBlock();
//Out.gui("Cutting conner " + cornerToCut1 + " " + corner1, Out.Mode.Debug);
if (!Action.avoidWalkingInto(cornerToCut1) && !Action.avoidWalkingInto(cornerToCut2)) {
double x = (next.from.getX() + next.to.getX() + 1.0D) * 0.5D;
double z = (next.from.getZ() + next.to.getZ() + 1.0D) * 0.5D;
MovementManager.clearMovement();
if (!MovementManager.forward && curr.oneInTen != null && curr.oneInTen) {
MovementManager.clearMovement();
MovementManager.forward = LookManager.lookAtCoords(x, 0, z, false);
} else {
MovementManager.moveTowardsCoords(x, 0, z);
}
if (MovementManager.forward && !MovementManager.backward) {
thePlayer.setSprinting(true);
}
return false;
}
}
}
}
}*/
//long start = System.nanoTime() / 1000000L;
BlockStateInterface bsi = new BlockStateInterface(ctx);
for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
@@ -204,10 +170,10 @@ public class PathExecutor implements IPathExecutor, Helper {
HashSet<BlockPos> newPlace = new HashSet<>();
HashSet<BlockPos> newWalkInto = new HashSet<>();
for (int i = pathPosition; i < path.movements().size(); i++) {
Movement movement = (Movement) path.movements().get(i);
newBreak.addAll(movement.toBreak(bsi));
newPlace.addAll(movement.toPlace(bsi));
newWalkInto.addAll(movement.toWalkInto(bsi));
Movement m = (Movement) path.movements().get(i);
newBreak.addAll(m.toBreak(bsi));
newPlace.addAll(m.toPlace(bsi));
newWalkInto.addAll(m.toWalkInto(bsi));
}
toBreak = newBreak;
toPlace = newPlace;
@@ -218,7 +184,14 @@ public class PathExecutor implements IPathExecutor, Helper {
if (end - start > 0) {
System.out.println("Recalculating break and place took " + (end - start) + "ms");
}*/
IMovement movement = path.movements().get(pathPosition);
if (pathPosition < path.movements().size() - 1) {
IMovement next = path.movements().get(pathPosition + 1);
if (!behavior.baritone.bsi.worldContainsLoadedChunk(next.getDest().x, next.getDest().z)) {
logDebug("Pausing since destination is at edge of loaded chunks");
clearKeys();
return true;
}
}
boolean canCancel = movement.safeToCancel();
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
costEstimateIndex = pathPosition;
@@ -232,7 +205,7 @@ public class PathExecutor implements IPathExecutor, Helper {
}
}
}
double currentCost = ((Movement) movement).recalculateCost(behavior.secretInternalGetCalculationContext());
double currentCost = movement.recalculateCost(behavior.secretInternalGetCalculationContext());
if (currentCost >= ActionCosts.COST_INF && canCancel) {
logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
cancel();
@@ -284,11 +257,13 @@ public class PathExecutor implements IPathExecutor, Helper {
private Tuple<Double, BlockPos> closestPathPos(IPath path) {
double best = -1;
BlockPos bestPos = null;
for (BlockPos pos : path.positions()) {
double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos);
if (dist < best || best == -1) {
best = dist;
bestPos = pos;
for (IMovement movement : path.movements()) {
for (BlockPos pos : ((Movement) movement).getValidPositions()) {
double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos);
if (dist < best || best == -1) {
best = dist;
bestPos = pos;
}
}
}
return new Tuple<>(best, bestPos);
@@ -353,7 +328,7 @@ public class PathExecutor implements IPathExecutor, Helper {
return false;
} else {
// we are either onGround or in liquid
if (ctx.player().motionY < -0.1) {
if (ctx.player().getMotion().y < -0.1) {
// if we are strictly moving downwards (not stationary)
// we could be falling through water, which could be unsafe to splice
return false; // so don't
@@ -451,7 +426,7 @@ public class PathExecutor implements IPathExecutor, Helper {
if (current instanceof MovementFall) {
Tuple<Vec3d, BlockPos> data = overrideFall((MovementFall) current);
if (data != null) {
BlockPos fallDest = data.getB();
BetterBlockPos fallDest = new BetterBlockPos(data.getB());
if (!path.positions().contains(fallDest)) {
throw new IllegalStateException();
}

View File

@@ -26,17 +26,17 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.path.PathExecutor;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk;
import java.util.*;
import java.util.stream.Collectors;
public class BackfillProcess extends BaritoneProcessHelper {
public final class BackfillProcess extends BaritoneProcessHelper {
public HashMap<BlockPos, IBlockState> blocksToReplace = new HashMap<>();
public HashMap<BlockPos, BlockState> blocksToReplace = new HashMap<>();
public BackfillProcess(Baritone baritone) {
super(baritone);
@@ -84,12 +84,14 @@ public class BackfillProcess extends BaritoneProcessHelper {
// patience
baritone.getLookBehavior().updateTarget(fake.getTarget().getRotation().get(), true);
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
default:
throw new IllegalStateException();
}
}
return new PathingCommand(null, PathingCommandType.DEFER); // cede to other process
}
public void amIBreakingABlockHMMMMMMM() {
private void amIBreakingABlockHMMMMMMM() {
if (!ctx.getSelectedBlock().isPresent()) {
return;
}
@@ -103,7 +105,7 @@ public class BackfillProcess extends BaritoneProcessHelper {
.filter(pos -> ctx.world().getBlockState(pos).getBlock() == Blocks.AIR)
.filter(pos -> baritone.getBuilderProcess().placementPlausible(pos, Blocks.DIRT.getDefaultState()))
.filter(pos -> !partOfCurrentMovement(pos))
.sorted(Comparator.<BlockPos>comparingDouble(ctx.player()::getDistanceSq).reversed())
.sorted(Comparator.<BlockPos>comparingDouble(ctx.playerFeet()::distanceSq).reversed())
.collect(Collectors.toList());
}

View File

@@ -35,18 +35,20 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.PathingCommandContext;
import baritone.utils.schematic.AirSchematic;
import baritone.utils.schematic.Schematic;
import baritone.utils.schematic.schematica.SchematicaHelper;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockFlowingFluid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.block.AirBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.*;
import net.minecraft.util.math.shapes.VoxelShape;
@@ -58,7 +60,7 @@ import java.util.*;
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
public class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
public final class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
private HashSet<BetterBlockPos> incorrectPositions;
private LongOpenHashSet observedCompleted; // positions that are completed even if they're out of render distance and we can't make sure right now
@@ -95,7 +97,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
@Override
public boolean build(String name, File schematic, Vec3i origin) {
NBTTagCompound tag;
CompoundNBT tag;
try (FileInputStream fileIn = new FileInputStream(schematic)) {
tag = CompressedStreamTools.readCompressed(fileIn);
} catch (IOException e) {
@@ -109,6 +111,20 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return true;
}
@Override
public void buildOpenSchematic() {
if (SchematicaHelper.isSchematicaPresent()) {
Optional<Tuple<ISchematic, BlockPos>> schematic = SchematicaHelper.getOpenSchematic();
if (schematic.isPresent()) {
this.build(schematic.get().getA().toString(), schematic.get().getA(), schematic.get().getB());
} else {
logDirect("No schematic currently open");
}
} else {
logDirect("Schematica is not present");
}
}
public void clearArea(BlockPos corner1, BlockPos corner2) {
BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ()));
int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1;
@@ -117,7 +133,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
build("clear area", new AirSchematic(widthX, heightY, lengthZ), origin);
}
private static ISchematic parse(NBTTagCompound schematic) {
private static ISchematic parse(CompoundNBT schematic) {
return new Schematic(schematic);
}
@@ -126,15 +142,15 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return schematic != null;
}
public IBlockState placeAt(int x, int y, int z) {
public BlockState placeAt(int x, int y, int z) {
if (!isActive()) {
return null;
}
if (!schematic.inSchematic(x - origin.getX(), y - origin.getY(), z - origin.getZ())) {
return null;
}
IBlockState state = schematic.desiredState(x - origin.getX(), y - origin.getY(), z - origin.getZ());
if (state.getBlock() instanceof BlockAir) {
BlockState state = schematic.desiredState(x - origin.getX(), y - origin.getY(), z - origin.getZ());
if (state.getBlock() instanceof AirBlock) {
return null;
}
return state;
@@ -152,12 +168,12 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
if (dy == -1 && x == pathStart.x && z == pathStart.z) {
continue; // dont mine what we're supported by, but not directly standing on
}
IBlockState desired = bcc.getSchematic(x, y, z);
BlockState desired = bcc.getSchematic(x, y, z);
if (desired == null) {
continue; // irrelevant
}
IBlockState curr = bcc.bsi.get0(x, y, z);
if (!(curr.getBlock() instanceof BlockAir) && !valid(curr, desired)) {
BlockState curr = bcc.bsi.get0(x, y, z);
if (!(curr.getBlock() instanceof AirBlock) && !(curr.getBlock() == Blocks.WATER || curr.getBlock() == Blocks.LAVA) && !valid(curr, desired)) {
BetterBlockPos pos = new BetterBlockPos(x, y, z);
Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
if (rot.isPresent()) {
@@ -173,10 +189,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
public class Placement {
private final int hotbarSelection;
private final BlockPos placeAgainst;
private final EnumFacing side;
private final Direction side;
private final Rotation rot;
public Placement(int hotbarSelection, BlockPos placeAgainst, EnumFacing side, Rotation rot) {
public Placement(int hotbarSelection, BlockPos placeAgainst, Direction side, Rotation rot) {
this.hotbarSelection = hotbarSelection;
this.placeAgainst = placeAgainst;
this.side = side;
@@ -184,7 +200,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
}
private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<BlockState> desirableOnHotbar) {
BetterBlockPos center = ctx.playerFeet();
for (int dx = -5; dx <= 5; dx++) {
for (int dy = -5; dy <= 1; dy++) {
@@ -192,13 +208,13 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
int x = center.x + dx;
int y = center.y + dy;
int z = center.z + dz;
IBlockState desired = bcc.getSchematic(x, y, z);
BlockState desired = bcc.getSchematic(x, y, z);
if (desired == null) {
continue; // irrelevant
}
IBlockState curr = bcc.bsi.get0(x, y, z);
BlockState curr = bcc.bsi.get0(x, y, z);
if (MovementHelper.isReplacable(x, y, z, curr, bcc.bsi) && !valid(curr, desired)) {
if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() instanceof BlockAir) {
if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() instanceof AirBlock) {
continue;
}
desirableOnHotbar.add(desired);
@@ -213,15 +229,15 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return Optional.empty();
}
public boolean placementPlausible(BlockPos pos, IBlockState state) {
public boolean placementPlausible(BlockPos pos, BlockState state) {
VoxelShape voxelshape = state.getCollisionShape(ctx.world(), pos);
return voxelshape.isEmpty() || ctx.world().checkNoEntityCollision(null, voxelshape.withOffset(pos.getX(), pos.getY(), pos.getZ()));
}
private Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
for (EnumFacing against : EnumFacing.values()) {
private Optional<Placement> possibleToPlace(BlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
for (Direction against : Direction.values()) {
BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
BlockState placeAgainstState = bsi.get0(placeAgainstPos);
if (MovementHelper.isReplacable(placeAgainstPos.x, placeAgainstPos.y, placeAgainstPos.z, placeAgainstState, bsi)) {
continue;
}
@@ -238,7 +254,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
Rotation rot = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(placeX, placeY, placeZ), ctx.playerRotations());
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance());
if (result != null && result.type == RayTraceResult.Type.BLOCK && result.getBlockPos().equals(placeAgainstPos) && result.sideHit == against.getOpposite()) {
if (result != null && result.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) result).getPos().equals(placeAgainstPos) && ((BlockRayTraceResult) result).getFace() == against.getOpposite()) {
OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
if (hotbar.isPresent()) {
return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
@@ -249,10 +265,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return Optional.empty();
}
private OptionalInt hasAnyItemThatWouldPlace(IBlockState desired, RayTraceResult result, Rotation rot) {
private OptionalInt hasAnyItemThatWouldPlace(BlockState desired, RayTraceResult result, Rotation rot) {
for (int i = 0; i < 9; i++) {
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) {
continue;
}
float originalYaw = ctx.player().rotationYaw;
@@ -261,15 +277,13 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
ctx.player().rotationYaw = rot.getYaw();
ctx.player().rotationPitch = rot.getPitch();
BlockItemUseContext meme = new BlockItemUseContext(new ItemUseContext(
ctx.world(),
ctx.player(),
Hand.MAIN_HAND,
stack,
result.getBlockPos().offset(result.sideHit),
result.sideHit,
(float) result.hitVec.x - result.getBlockPos().getX(),
(float) result.hitVec.y - result.getBlockPos().getY(),
(float) result.hitVec.z - result.getBlockPos().getZ()
));
IBlockState wouldBePlaced = ((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(meme);
(BlockRayTraceResult) result
) {}); // that {} gives us access to a protected constructor lmfao
BlockState wouldBePlaced = ((BlockItem) stack.getItem()).getBlock().getStateForPlacement(meme);
ctx.player().rotationYaw = originalYaw;
ctx.player().rotationPitch = originalPitch;
if (wouldBePlaced == null) {
@@ -285,7 +299,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return OptionalInt.empty();
}
private static Vec3d[] aabbSideMultipliers(EnumFacing side) {
private static Vec3d[] aabbSideMultipliers(Direction side) {
switch (side) {
case UP:
return new Vec3d[]{new Vec3d(0.5, 1, 0.5), new Vec3d(0.1, 1, 0.5), new Vec3d(0.9, 1, 0.5), new Vec3d(0.5, 1, 0.1), new Vec3d(0.5, 1, 0.9)};
@@ -332,7 +346,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
schematic = new ISchematic() {
@Override
public IBlockState desiredState(int x, int y, int z) {
public BlockState desiredState(int x, int y, int z) {
return realSchematic.desiredState(x, y, z);
}
@@ -376,7 +390,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
return onTick(calcFailed, isSafeToCancel);
}
trim(bcc);
trim();
Optional<Tuple<BetterBlockPos, Rotation>> toBreak = toBreakNearPlayer(bcc);
if (toBreak.isPresent() && isSafeToCancel && ctx.player().onGround) {
@@ -397,25 +411,25 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<IBlockState> desirableOnHotbar = new ArrayList<>();
List<BlockState> desirableOnHotbar = new ArrayList<>();
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ((BlockRayTraceResult) ctx.objectMouseOver()).getFace().equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
}
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<IBlockState> approxPlacable = placable(36);
List<BlockState> approxPlacable = placable(36);
if (Baritone.settings().allowInventory.value) {
ArrayList<Integer> usefulSlots = new ArrayList<>();
List<IBlockState> noValidHotbarOption = new ArrayList<>();
List<BlockState> noValidHotbarOption = new ArrayList<>();
outer:
for (IBlockState desired : desirableOnHotbar) {
for (BlockState desired : desirableOnHotbar) {
for (int i = 0; i < 9; i++) {
if (valid(approxPlacable.get(i), desired)) {
usefulSlots.add(i);
@@ -427,7 +441,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
outer:
for (int i = 9; i < 36; i++) {
for (IBlockState desired : noValidHotbarOption) {
for (BlockState desired : noValidHotbarOption) {
if (valid(approxPlacable.get(i), desired)) {
baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
break outer;
@@ -436,7 +450,6 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
}
Goal goal = assemble(bcc, approxPlacable.subList(0, 9));
if (goal == null) {
goal = assemble(bcc, approxPlacable); // we're far away, so assume that we have our whole inventory to recalculate placable properly
@@ -464,9 +477,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return !incorrectPositions.isEmpty();
}
private void trim(BuilderCalculationContext bcc) {
private void trim() {
HashSet<BetterBlockPos> copy = new HashSet<>(incorrectPositions);
copy.removeIf(pos -> pos.distanceSq(ctx.player().posX, ctx.player().posY, ctx.player().posZ) > 200);
copy.removeIf(pos -> pos.distanceSq(new BlockPos(ctx.player())) > 200);
if (!copy.isEmpty()) {
incorrectPositions = copy;
}
@@ -480,7 +493,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
int x = center.x + dx;
int y = center.y + dy;
int z = center.z + dz;
IBlockState desired = bcc.getSchematic(x, y, z);
BlockState desired = bcc.getSchematic(x, y, z);
if (desired != null) {
// we care about this position
BetterBlockPos pos = new BetterBlockPos(x, y, z);
@@ -529,18 +542,18 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
}
private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlacable) {
private Goal assemble(BuilderCalculationContext bcc, List<BlockState> approxPlacable) {
List<BetterBlockPos> placable = new ArrayList<>();
List<BetterBlockPos> breakable = new ArrayList<>();
List<BetterBlockPos> sourceLiquids = new ArrayList<>();
incorrectPositions.forEach(pos -> {
IBlockState state = bcc.bsi.get0(pos);
if (state.getBlock() instanceof BlockAir) {
BlockState state = bcc.bsi.get0(pos);
if (state.getBlock() instanceof AirBlock) {
if (approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))) {
placable.add(pos);
}
} else {
if (state.getBlock() instanceof BlockFlowingFluid) {
if (state.getBlock() instanceof FlowingFluidBlock) {
// if the block itself is JUST a liquid (i.e. not just a waterlogged block), we CANNOT break it
// TODO for 1.13 make sure that this only matches pure water, not waterlogged blocks
if (!MovementHelper.possiblyFlowing(state)) {
@@ -615,11 +628,11 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) {
if (!(ctx.world().getBlockState(pos).getBlock() instanceof BlockAir)) { // TODO can this even happen?
if (!(ctx.world().getBlockState(pos).getBlock() instanceof AirBlock)) { // TODO can this even happen?
return new GoalPlace(pos);
}
boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir);
for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP) {
boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof AirBlock);
for (Direction facing : Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP) {
if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && placementPlausible(pos, bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()))) {
return new GoalAdjacent(pos, allowSameLevel);
}
@@ -628,7 +641,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
private Goal breakGoal(BlockPos pos, BuilderCalculationContext bcc) {
if (Baritone.settings().goalBreakFromAbove.value && bcc.bsi.get0(pos.up()).getBlock() instanceof BlockAir && bcc.bsi.get0(pos.up(2)).getBlock() instanceof BlockAir) { // TODO maybe possible without the up(2) check?
if (Baritone.settings().goalBreakFromAbove.value && bcc.bsi.get0(pos.up()).getBlock() instanceof AirBlock && bcc.bsi.get0(pos.up(2)).getBlock() instanceof AirBlock) { // TODO maybe possible without the up(2) check?
return new JankyGoalComposite(new GoalBreak(pos), new GoalGetToBlock(pos.up()) {
@Override
public boolean isInGoal(int x, int y, int z) {
@@ -696,26 +709,26 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
return paused ? "Builder Paused" : "Building " + name;
}
private List<IBlockState> placable(int size) {
List<IBlockState> result = new ArrayList<>();
private List<BlockState> placable(int size) {
List<BlockState> result = new ArrayList<>();
for (int i = 0; i < size; i++) {
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem)) {
result.add(Blocks.AIR.getDefaultState());
continue;
}
// <toxic cloud>
result.add(((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))));
result.add(((BlockItem) stack.getItem()).getBlock().getStateForPlacement(new BlockItemUseContext(new ItemUseContext(ctx.world(), ctx.player(), Hand.MAIN_HAND, stack, new BlockRayTraceResult(new Vec3d(ctx.player().posX, ctx.player().posY, ctx.player().posZ), Direction.UP, ctx.playerFeet(), false)) {})));
// </toxic cloud>
}
return result;
}
private boolean valid(IBlockState current, IBlockState desired) {
private boolean valid(BlockState current, BlockState desired) {
if (desired == null) {
return true;
}
if (current.getBlock() instanceof BlockAir && desired.getBlock() instanceof BlockAir) {
if (current.getBlock() instanceof AirBlock && desired.getBlock() instanceof AirBlock) {
return true;
}
// TODO more complicated comparison logic I guess
@@ -723,7 +736,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
}
public class BuilderCalculationContext extends CalculationContext {
private final List<IBlockState> placable;
private final List<BlockState> placable;
private final ISchematic schematic;
private final int originX;
private final int originY;
@@ -741,7 +754,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
this.backtrackCostFavoringCoefficient = 1;
}
private IBlockState getSchematic(int x, int y, int z) {
private BlockState getSchematic(int x, int y, int z) {
if (schematic.inSchematic(x - originX, y - originY, z - originZ)) {
return schematic.desiredState(x - originX, y - originY, z - originZ);
} else {
@@ -754,10 +767,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
if (isPossiblyProtected(x, y, z) || !worldBorder.canPlaceAt(x, z)) { // make calculation fail properly if we can't build
return COST_INF;
}
IBlockState sch = getSchematic(x, y, z);
BlockState sch = getSchematic(x, y, z);
if (sch != null) {
// TODO this can return true even when allowPlace is off.... is that an issue?
if (sch.getBlock() instanceof BlockAir) {
if (sch.getBlock() instanceof AirBlock) {
// we want this to be air, but they're asking if they can place here
// this won't be a schematic block, this will be a throwaway
return placeBlockCost * 2; // we're going to have to break it eventually
@@ -788,9 +801,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
if (!allowBreak || isPossiblyProtected(x, y, z)) {
return COST_INF;
}
IBlockState sch = getSchematic(x, y, z);
BlockState sch = getSchematic(x, y, z);
if (sch != null) {
if (sch.getBlock() instanceof BlockAir) {
if (sch.getBlock() instanceof AirBlock) {
// it should be air
// regardless of current contents, we can break it
return 1;

View File

@@ -29,7 +29,7 @@ import baritone.utils.BaritoneProcessHelper;
*
* @author leijurv
*/
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
public final class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
/**
* The current goal

View File

@@ -41,7 +41,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class ExploreProcess extends BaritoneProcessHelper implements IExploreProcess {
public final class ExploreProcess extends BaritoneProcessHelper implements IExploreProcess {
private BlockPos explorationOrigin;
@@ -122,6 +122,7 @@ public class ExploreProcess extends BaritoneProcessHelper implements IExplorePro
break; // note: this breaks the switch not the for
case EXPLORED:
continue; // note: this continues the for
default:
}
int centerX = ((chunkX + dx) << 4) + 8;
int centerZ = ((chunkZ + dz) << 4) + 8;
@@ -139,6 +140,9 @@ public class ExploreProcess extends BaritoneProcessHelper implements IExplorePro
centers.add(new BlockPos(centerX, 0, centerZ));
}
}
if (dist % 10 == 0) {
count = Math.min(filter.countRemain(), Baritone.settings().exploreChunkSetMinimumSize.value);
}
if (centers.size() >= count) {
return centers.stream().map(pos -> createGoal(pos.getX(), pos.getZ())).toArray(Goal[]::new);
}

View File

@@ -24,6 +24,7 @@ import baritone.api.pathing.goals.GoalComposite;
import baritone.api.process.IFarmProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.api.utils.RayTraceUtils;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
@@ -31,14 +32,15 @@ import baritone.cache.WorldScanner;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@@ -48,10 +50,13 @@ import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
public final class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
private boolean active;
private List<BlockPos> locations;
private int tickCount;
private static final List<Item> FARMLAND_PLANTABLE = Arrays.asList(
Items.BEETROOT_SEEDS,
Items.MELON_SEEDS,
@@ -63,17 +68,16 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
private static final List<Item> PICKUP_DROPPED = Arrays.asList(
Items.BEETROOT_SEEDS,
Items.WHEAT,
Items.BEETROOT,
Items.MELON_SEEDS,
Items.MELON_SLICE,
Blocks.MELON.asItem(),
Items.WHEAT_SEEDS,
Items.WHEAT,
Items.PUMPKIN_SEEDS,
Blocks.PUMPKIN.asItem(),
Items.POTATO,
Items.CARROT,
Items.BEETROOT,
Blocks.PUMPKIN.asItem(),
Blocks.MELON.asItem(),
Items.NETHER_WART,
Blocks.SUGAR_CANE.asItem(),
Blocks.CACTUS.asItem()
@@ -91,47 +95,48 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
@Override
public void farm() {
active = true;
locations = null;
}
private enum Harvest {
WHEAT((BlockCrops) Blocks.WHEAT),
CARROTS((BlockCrops) Blocks.CARROTS),
POTATOES((BlockCrops) Blocks.POTATOES),
BEETROOT((BlockCrops) Blocks.BEETROOTS),
WHEAT((CropsBlock) Blocks.WHEAT),
CARROTS((CropsBlock) Blocks.CARROTS),
POTATOES((CropsBlock) Blocks.POTATOES),
BEETROOT((CropsBlock) Blocks.BEETROOTS),
PUMPKIN(Blocks.PUMPKIN, state -> true),
MELON(Blocks.MELON, state -> true),
NETHERWART(Blocks.NETHER_WART, state -> state.get(BlockNetherWart.AGE) >= 3),
NETHERWART(Blocks.NETHER_WART, state -> state.get(NetherWartBlock.AGE) >= 3),
SUGARCANE(Blocks.SUGAR_CANE, null) {
@Override
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
return world.getBlockState(pos.down()).getBlock() instanceof BlockReed;
public boolean readyToHarvest(World world, BlockPos pos, BlockState state) {
return world.getBlockState(pos.down()).getBlock() instanceof SugarCaneBlock;
}
},
CACTUS(Blocks.CACTUS, null) {
@Override
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
return world.getBlockState(pos.down()).getBlock() instanceof BlockCactus;
public boolean readyToHarvest(World world, BlockPos pos, BlockState state) {
return world.getBlockState(pos.down()).getBlock() instanceof CactusBlock;
}
};
public final Block block;
public final Predicate<IBlockState> readyToHarvest;
public final Predicate<BlockState> readyToHarvest;
Harvest(BlockCrops blockCrops) {
Harvest(CropsBlock blockCrops) {
this(blockCrops, blockCrops::isMaxAge);
// max age is 7 for wheat, carrots, and potatoes, but 3 for beetroot
}
Harvest(Block block, Predicate<IBlockState> readyToHarvest) {
Harvest(Block block, Predicate<BlockState> readyToHarvest) {
this.block = block;
this.readyToHarvest = readyToHarvest;
}
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
public boolean readyToHarvest(World world, BlockPos pos, BlockState state) {
return readyToHarvest.test(state);
}
}
private boolean readyForHarvest(World world, BlockPos pos, IBlockState state) {
private boolean readyForHarvest(World world, BlockPos pos, BlockState state) {
for (Harvest harvest : Harvest.values()) {
if (harvest.block == state.getBlock()) {
return harvest.readyToHarvest(world, pos, state);
@@ -162,16 +167,19 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
if (Baritone.settings().replantNetherWart.value) {
scan.add(Blocks.SOUL_SAND);
}
List<BlockPos> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 4);
if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) {
Baritone.getExecutor().execute(() -> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 10));
}
if (locations == null) {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
List<BlockPos> toBreak = new ArrayList<>();
List<BlockPos> openFarmland = new ArrayList<>();
List<BlockPos> bonemealable = new ArrayList<>();
List<BlockPos> openSoulsand = new ArrayList<>();
for (BlockPos pos : locations) {
IBlockState state = ctx.world().getBlockState(pos);
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
BlockState state = ctx.world().getBlockState(pos);
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof AirBlock;
if (state.getBlock() == Blocks.FARMLAND) {
if (airAbove) {
openFarmland.add(pos);
@@ -214,11 +222,14 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
boolean soulsand = openSoulsand.contains(pos);
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance());
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
if (ctx.isLookingAt(pos)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
if (result instanceof BlockRayTraceResult && ((BlockRayTraceResult) result).getFace() == Direction.UP) {
baritone.getLookBehavior().updateTarget(rot.get(), true);
if (ctx.isLookingAt(pos)) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
}
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
}
for (BlockPos pos : bonemealable) {
@@ -257,9 +268,9 @@ public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
goalz.add(new GoalBlock(pos));
}
}
for (Entity entity : ctx.world().loadedEntityList) {
if (entity instanceof EntityItem && entity.onGround) {
EntityItem ei = (EntityItem) entity;
for (Entity entity : ctx.entities()) {
if (entity instanceof ItemEntity && entity.onGround) {
ItemEntity ei = (ItemEntity) entity;
if (PICKUP_DROPPED.contains(ei.getItem().getItem())) {
// +0.1 because of farmland's 0.9375 dummy height lol
goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ)));

View File

@@ -33,7 +33,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Follow an entity
@@ -78,11 +77,15 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
if (entity.equals(ctx.player())) {
return false;
}
return ctx.world().loadedEntityList.contains(entity);
return ctx.entitiesStream().anyMatch(entity::equals);
}
private void scanWorld() {
cache = Stream.of(ctx.world().loadedEntityList, ctx.world().playerEntities).flatMap(List::stream).filter(this::followable).filter(this.filter).distinct().collect(Collectors.toCollection(ArrayList::new));
cache = ctx.entitiesStream()
.filter(this::followable)
.filter(this.filter)
.distinct()
.collect(Collectors.toCollection(ArrayList::new));
}
@Override

View File

@@ -26,15 +26,16 @@ import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.block.Blocks;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.math.BlockPos;
import java.util.*;
public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {
public final class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBlockProcess {
private Block gettingTo;
private List<BlockPos> knownLocations;
@@ -121,7 +122,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
// blacklist the closest block and its adjacent blocks
public synchronized boolean blacklistClosest() {
List<BlockPos> newBlacklist = new ArrayList<>();
knownLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(newBlacklist::add);
knownLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(newBlacklist::add);
outer:
while (true) {
for (BlockPos known : knownLocations) {
@@ -180,7 +181,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
if (walkIntoInsteadOfAdjacent(gettingTo)) {
return new GoalTwoBlocks(pos);
}
if (blockOnTopMustBeRemoved(gettingTo) && baritone.bsi.get0(pos.up()).isBlockNormalCube()) {
if (blockOnTopMustBeRemoved(gettingTo) && MovementHelper.isBlockNormalCube(baritone.bsi.get0(pos.up()))) { // TODO this should be the check for chest openability
return new GoalBlock(pos.up());
}
return new GoalGetToBlock(pos);
@@ -194,7 +195,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); // TODO find some way to right click even if we're in an ESC menu
System.out.println(ctx.player().openContainer);
if (!(ctx.player().openContainer instanceof ContainerPlayer)) {
if (!(ctx.player().openContainer instanceof PlayerContainer)) {
return true;
}
}

View File

@@ -33,19 +33,21 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.resources.*;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Unit;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.*;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
@@ -67,6 +69,9 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private int desiredQuantity;
private int tickCount;
private static LootTableManager manager;
private static Map<Block, List<Item>> drops = new HashMap<>();
public MineProcess(Baritone baritone) {
super(baritone);
}
@@ -79,11 +84,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (desiredQuantity > 0) {
Item item = mining.get(0).getItemDropped(mining.get(0).getDefaultState(), ctx.world(), null, 0).asItem();
int curr = ctx.player().inventory.mainInventory.stream().filter(stack -> item.equals(stack.getItem())).mapToInt(ItemStack::getCount).sum();
List<Item> item = drops(mining.get(0));
int curr = ctx.player().inventory.mainInventory.stream().filter(stack -> item.contains(stack.getItem())).mapToInt(ItemStack::getCount).sum();
System.out.println("Currently have " + curr + " " + item);
if (curr >= desiredQuantity) {
logDirect("Have " + curr + " " + item.getDisplayName(new ItemStack(item, 1)));
logDirect("Have " + curr);
cancel();
return null;
}
@@ -91,7 +96,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (calcFailed) {
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance...");
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add);
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add);
knownOreLocations.removeIf(blacklist::contains);
} else {
logDirect("Unable to find any path to " + mining + ", canceling Mine");
@@ -99,6 +104,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null;
}
}
if (!Baritone.settings().allowBreak.value) {
logDirect("Unable to mine when allowBreak is false!");
cancel();
return null;
}
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
@@ -111,12 +121,12 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
Optional<BlockPos> shaft = curr.stream()
.filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())
.filter(pos -> pos.getY() >= ctx.playerFeet().getY())
.filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
.min(Comparator.comparingDouble(ctx.player()::getDistanceSq));
.filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof AirBlock)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
.min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq));
baritone.getInputOverrideHandler().clearAllKeys();
if (shaft.isPresent()) {
if (shaft.isPresent() && ctx.player().onGround) {
BlockPos pos = shaft.get();
IBlockState state = baritone.bsi.get0(pos);
BlockState state = baritone.bsi.get0(pos);
if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) {
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
if (rot.isPresent() && isSafeToCancel) {
@@ -139,6 +149,35 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return command;
}
public static LootTableManager getManager() {
if (manager == null) {
ResourcePackList rpl = new ResourcePackList<>(ResourcePackInfo::new);
rpl.addPackFinder(new ServerPackFinder());
rpl.reloadPacksFromFinders();
IResourcePack thePack = ((ResourcePackInfo) rpl.getAllPacks().iterator().next()).getResourcePack();
IReloadableResourceManager resourceManager = new SimpleReloadableResourceManager(ResourcePackType.SERVER_DATA, null);
manager = new LootTableManager();
resourceManager.addReloadListener(manager);
try {
resourceManager.reloadResourcesAndThen(Baritone.getExecutor(), Baritone.getExecutor(), Collections.singletonList(thePack), CompletableFuture.completedFuture(Unit.INSTANCE)).get();
} catch (Exception exception) {
throw new RuntimeException(exception);
}
}
return manager;
}
private static List<Item> drops(Block b) {
return drops.computeIfAbsent(b, block -> {
ResourceLocation lootTableLocation = block.getLootTable();
if (lootTableLocation == LootTables.EMPTY) {
return Collections.emptyList();
} else {
return getManager().getLootTableFromLocation(lootTableLocation).generate(new LootContext.Builder(null).withRandom(new Random()).withParameter(LootParameters.POSITION, BlockPos.ZERO).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, null).withParameter(LootParameters.BLOCK_STATE, block.getDefaultState()).build(LootParameterSets.BLOCK)).stream().map(ItemStack::getItem).collect(Collectors.toList());
}
});
}
@Override
public void onLostControl() {
mine(0, (Block[]) null);
@@ -211,14 +250,14 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return true;
}
Block block = BlockStateInterface.getBlock(ctx, pos);
if (Baritone.settings().internalMiningAirException.value && block instanceof BlockAir) {
if (Baritone.settings().internalMiningAirException.value && block instanceof AirBlock) {
return true;
}
return mining.contains(block);
}
private Goal coalesce(BlockPos loc, List<BlockPos> locs) {
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof BlockFalling);
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock);
if (!Baritone.settings().forceInternalMining.value) {
if (assumeVerticalShaftMine) {
// we can get directly below the block
@@ -279,21 +318,20 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
}
public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {
if (!Baritone.settings().mineScanDroppedItems.value) {
return new ArrayList<>();
return Collections.emptyList();
}
Set<Item> searchingFor = new HashSet<>();
for (Block block : mining) {
Item drop = block.getItemDropped(block.getDefaultState(), world, null, 0).asItem();
Item ore = block.asItem();
searchingFor.add(drop);
searchingFor.add(ore);
searchingFor.addAll(drops(block));
searchingFor.add(block.asItem());
}
List<BlockPos> ret = new ArrayList<>();
for (Entity entity : world.loadedEntityList) {
if (entity instanceof EntityItem) {
EntityItem ei = (EntityItem) entity;
for (Entity entity : ((ClientWorld) world).getAllEntities()) {
if (entity instanceof ItemEntity) {
ItemEntity ei = (ItemEntity) entity;
if (searchingFor.contains(ei.getItem().getItem())) {
ret.add(new BlockPos(entity));
}
@@ -369,7 +407,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
.filter(pos -> !blacklist.contains(pos))
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player()::getDistanceSq))
.sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq))
.collect(Collectors.toList());
if (locs.size() > max) {
@@ -395,6 +433,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override
public void mine(int quantity, Block... blocks) {
this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks);
if (mining != null && !Baritone.settings().allowBreak.value) {
logDirect("Unable to mine when allowBreak is false!");
mining = null;
}
this.desiredQuantity = quantity;
this.knownOreLocations = new ArrayList<>();
this.blacklist = new ArrayList<>();

View File

@@ -26,10 +26,13 @@ import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.client.GameSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.screen.MainMenuScreen;
import net.minecraft.client.settings.AmbientOcclusionStatus;
import net.minecraft.client.settings.CloudOption;
import net.minecraft.client.settings.ParticleStatus;
import net.minecraft.client.tutorial.TutorialSteps;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.HttpUtil;
import net.minecraft.util.HTTPUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameType;
import net.minecraft.world.WorldSettings;
@@ -69,27 +72,27 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
System.out.println("Optimizing Game Settings");
GameSettings s = mc.gameSettings;
s.limitFramerate = 20;
s.framerateLimit = 20;
s.mipmapLevels = 0;
s.particleSetting = 2;
s.particles = ParticleStatus.MINIMAL;
s.overrideWidth = 128;
s.overrideHeight = 128;
s.heldItemTooltips = false;
s.entityShadows = false;
s.chatScale = 0.0F;
s.ambientOcclusion = 0;
s.clouds = 0;
s.ambientOcclusionStatus = AmbientOcclusionStatus.OFF;
s.cloudOption = CloudOption.OFF;
s.fancyGraphics = false;
s.tutorialStep = TutorialSteps.NONE;
s.hideGUI = true;
s.fovSetting = 30.0F;
s.fov = 30.0F;
}
@Override
public void onTick(TickEvent event) {
IPlayerContext ctx = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext();
// If we're on the main menu then create the test world and launch the integrated server
if (mc.currentScreen instanceof GuiMainMenu) {
if (mc.currentScreen instanceof MainMenuScreen) {
System.out.println("Beginning Baritone automatic test routine");
mc.displayGuiScreen(null);
WorldSettings worldsettings = new WorldSettings(TEST_SEED, GameType.getByName("survival"), true, false, WorldType.DEFAULT);
@@ -102,7 +105,11 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
// to our defined starting position
if (server != null && server.getWorld(DimensionType.OVERWORLD) != null) {
server.getWorld(DimensionType.OVERWORLD).setSpawnPoint(STARTING_POSITION);
server.getWorld(DimensionType.OVERWORLD).getGameRules().setOrCreateGameRule("spawnRadius", "0", server);
server.getCommandManager().handleCommand(server.getCommandSource(), "/difficulty peaceful");
int result = server.getCommandManager().handleCommand(server.getCommandSource(), "/gamerule spawnRadius 0");
if (result != 0) {
throw new IllegalStateException(result + "");
}
}
if (event.getType() == TickEvent.Type.IN) { // If we're in-game
@@ -110,7 +117,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
// Force the integrated server to share the world to LAN so that
// the ingame pause menu gui doesn't actually pause our game
if (mc.isSingleplayer() && !mc.getIntegratedServer().getPublic()) {
mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false, HttpUtil.getSuitableLanPort());
mc.getIntegratedServer().shareToLAN(GameType.getByName("survival"), false, HTTPUtil.getSuitableLanPort());
}
// For the first 200 ticks, wait for the world to generate

View File

@@ -19,9 +19,10 @@ package baritone.utils;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
/**
@@ -38,9 +39,9 @@ public final class BlockBreakHelper implements Helper {
this.playerContext = playerContext;
}
public void tryBreakBlock(BlockPos pos, EnumFacing side) {
private void tryBreakBlock(BlockPos pos, Direction side) {
if (playerContext.playerController().onPlayerDamageBlock(pos, side)) {
playerContext.player().swingArm(EnumHand.MAIN_HAND);
playerContext.player().swingArm(Hand.MAIN_HAND);
}
}
@@ -54,10 +55,10 @@ public final class BlockBreakHelper implements Helper {
public void tick(boolean isLeftClick) {
RayTraceResult trace = playerContext.objectMouseOver();
boolean isBlockTrace = trace != null && trace.type == RayTraceResult.Type.BLOCK;
boolean isBlockTrace = trace != null && trace.getType() == RayTraceResult.Type.BLOCK;
if (isLeftClick && isBlockTrace) {
tryBreakBlock(trace.getBlockPos(), trace.sideHit);
tryBreakBlock(((BlockRayTraceResult) trace).getPos(), ((BlockRayTraceResult) trace).getFace());
didBreakLastTick = true;
} else if (didBreakLastTick) {
stopBreakingBlock();

View File

@@ -20,8 +20,9 @@ package baritone.utils;
import baritone.Baritone;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
public class BlockPlaceHelper implements Helper {
@@ -38,16 +39,16 @@ public class BlockPlaceHelper implements Helper {
return;
}
RayTraceResult mouseOver = ctx.objectMouseOver();
if (!rightClickRequested || ctx.player().isRowingBoat() || mouseOver == null || mouseOver.getBlockPos() == null || mouseOver.type != RayTraceResult.Type.BLOCK) {
if (!rightClickRequested || ctx.player().isRowingBoat() || mouseOver == null || mouseOver.getType() != RayTraceResult.Type.BLOCK) {
return;
}
rightClickTimer = Baritone.settings().rightClickSpeed.value;
for (EnumHand hand : EnumHand.values()) {
if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), mouseOver.getBlockPos(), mouseOver.sideHit, mouseOver.hitVec, hand) == EnumActionResult.SUCCESS) {
for (Hand hand : Hand.values()) {
if (ctx.playerController().processRightClickBlock(ctx.player(), ctx.world(), hand, (BlockRayTraceResult) mouseOver) == ActionResultType.SUCCESS) {
ctx.player().swingArm(hand);
return;
}
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == EnumActionResult.SUCCESS) {
if (!ctx.player().getHeldItem(hand).isEmpty() && ctx.playerController().processRightClick(ctx.player(), ctx.world(), hand) == ActionResultType.SUCCESS) {
return;
}
}

View File

@@ -21,17 +21,17 @@ import baritone.Baritone;
import baritone.api.utils.IPlayerContext;
import baritone.cache.CachedRegion;
import baritone.cache.WorldData;
import baritone.utils.accessor.IChunkProviderClient;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import baritone.utils.accessor.IClientChunkProvider;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.client.multiplayer.ClientChunkProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.ChunkStatus;
/**
* Wraps get for chuck caching capability
@@ -40,7 +40,7 @@ import net.minecraft.world.chunk.Chunk;
*/
public class BlockStateInterface {
private final Long2ObjectMap<Chunk> loadedChunks;
private final ClientChunkProvider provider;
private final WorldData worldData;
private Chunk prev = null;
@@ -48,7 +48,7 @@ public class BlockStateInterface {
private final boolean useTheRealWorld;
private static final IBlockState AIR = Blocks.AIR.getDefaultState();
private static final BlockState AIR = Blocks.AIR.getDefaultState();
public BlockStateInterface(IPlayerContext ctx) {
this(ctx, false);
@@ -60,37 +60,36 @@ public class BlockStateInterface {
public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) {
this.worldData = worldData;
Long2ObjectMap<Chunk> worldLoaded = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks();
if (copyLoadedChunks) {
this.loadedChunks = new Long2ObjectOpenHashMap<>(worldLoaded); // make a copy that we can safely access from another thread
this.provider = ((IClientChunkProvider) world.getChunkProvider()).createThreadSafeCopy();
} else {
this.loadedChunks = worldLoaded; // this will only be used on the main thread
this.provider = (ClientChunkProvider) world.getChunkProvider();
}
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value;
if (!Minecraft.getInstance().isCallingFromMinecraftThread()) {
if (!Minecraft.getInstance().isOnExecutionThread()) {
throw new IllegalStateException();
}
}
public boolean worldContainsLoadedChunk(int blockX, int blockZ) {
return loadedChunks.containsKey(ChunkPos.asLong(blockX >> 4, blockZ >> 4));
return provider.chunkExists(blockX >> 4, blockZ >> 4);
}
public static Block getBlock(IPlayerContext ctx, BlockPos pos) { // won't be called from the pathing thread because the pathing thread doesn't make a single blockpos pog
return get(ctx, pos).getBlock();
}
public static IBlockState get(IPlayerContext ctx, BlockPos pos) {
public static BlockState get(IPlayerContext ctx, BlockPos pos) {
return new BlockStateInterface(ctx).get0(pos.getX(), pos.getY(), pos.getZ()); // immense iq
// can't just do world().get because that doesn't work for out of bounds
// and toBreak and stuff fails when the movement is instantiated out of load range but it's not able to BlockStateInterface.get what it's going to walk on
}
public IBlockState get0(BlockPos pos) {
public BlockState get0(BlockPos pos) {
return get0(pos.getX(), pos.getY(), pos.getZ());
}
public IBlockState get0(int x, int y, int z) { // Mickey resigned
public BlockState get0(int x, int y, int z) { // Mickey resigned
// Invalid vertical position
if (y < 0 || y >= 256) {
@@ -105,14 +104,13 @@ public class BlockStateInterface {
// we can just skip the mc.world.getChunk lookup
// which is a Long2ObjectOpenHashMap.get
// see issue #113
if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) {
return cached.getBlockState(x, y, z);
if (cached != null && cached.getPos().x == x >> 4 && cached.getPos().z == z >> 4) {
return getFromChunk(cached, x, y, z);
}
Chunk chunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
if (chunk != null && chunk.isLoaded()) {
Chunk chunk = provider.getChunk(x >> 4, z >> 4, ChunkStatus.FULL, false);
if (chunk != null && !chunk.isEmpty()) {
prev = chunk;
return chunk.getBlockState(x, y, z);
return getFromChunk(chunk, x, y, z);
}
}
// same idea here, skip the Long2ObjectOpenHashMap.get if at all possible
@@ -129,7 +127,7 @@ public class BlockStateInterface {
prevCached = region;
cached = region;
}
IBlockState type = cached.getBlock(x & 511, y, z & 511);
BlockState type = cached.getBlock(x & 511, y, z & 511);
if (type == null) {
return AIR;
}
@@ -138,11 +136,11 @@ public class BlockStateInterface {
public boolean isLoaded(int x, int z) {
Chunk prevChunk = prev;
if (prevChunk != null && prevChunk.x == x >> 4 && prevChunk.z == z >> 4) {
if (prevChunk != null && prevChunk.getPos().x == x >> 4 && prevChunk.getPos().z == z >> 4) {
return true;
}
prevChunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4));
if (prevChunk != null && prevChunk.isLoaded()) {
prevChunk = provider.getChunk(x >> 4, z >> 4, ChunkStatus.FULL, false);
if (prevChunk != null && !prevChunk.isEmpty()) {
prev = prevChunk;
return true;
}
@@ -160,4 +158,13 @@ public class BlockStateInterface {
prevCached = prevRegion;
return prevRegion.isCached(x & 511, z & 511);
}
// get the block at x,y,z from this chunk WITHOUT creating a single blockpos object
public static BlockState getFromChunk(Chunk chunk, int x, int y, int z) {
ChunkSection section = chunk.getSections()[y >> 4];
if (ChunkSection.isEmpty(section)) {
return AIR;
}
return section.getBlockState(x & 15, y & 15, z & 15);
}
}

View File

@@ -22,10 +22,13 @@ import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalTwoBlocks;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import baritone.api.utils.Helper;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.*;
import net.minecraft.util.text.StringTextComponent;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
@@ -36,7 +39,7 @@ import java.util.Collections;
import static org.lwjgl.opengl.GL11.*;
public class GuiClick extends GuiScreen {
public class GuiClick extends Screen implements Helper {
// My name is Brady and I grant leijurv permission to use this pasted code
private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16);
@@ -47,8 +50,12 @@ public class GuiClick extends GuiScreen {
private BlockPos clickStart;
private BlockPos currentMouseOver;
public GuiClick() {
super(new StringTextComponent("CLICK"));
}
@Override
public boolean doesGuiPauseGame() {
public boolean isPauseScreen() {
return false;
}
@@ -62,13 +69,14 @@ public class GuiClick extends GuiScreen {
Vec3d near = toWorld(mx, my, 0);
Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv
if (near != null && far != null) {
Vec3d viewerPos = new Vec3d(mc.getRenderManager().viewerPosX, mc.getRenderManager().viewerPosY, mc.getRenderManager().viewerPosZ);
RayTraceResult result = mc.world.rayTraceBlocks(near.add(viewerPos), far.add(viewerPos), RayTraceFluidMode.NEVER, false, true);
if (result != null && result.type == RayTraceResult.Type.BLOCK) {
currentMouseOver = result.getBlockPos();
///
Vec3d viewerPos = new Vec3d(PathRenderer.posX(), PathRenderer.posY(), PathRenderer.posZ());
ClientPlayerEntity player = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().player();
RayTraceResult result = player.world.rayTraceBlocks(new RayTraceContext(near.add(viewerPos), far.add(viewerPos), RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, player));
if (result != null && result.getType() == RayTraceResult.Type.BLOCK) {
currentMouseOver = ((BlockRayTraceResult) result).getPos();
}
}
}
@Override
@@ -94,8 +102,8 @@ public class GuiClick extends GuiScreen {
}
public void onRender() {
GlStateManager.getFloatv(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear());
GlStateManager.getFloatv(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear());
GlStateManager.getMatrix(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear());
GlStateManager.getMatrix(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear());
GL11.glGetIntegerv(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear());
if (currentMouseOver != null) {
@@ -107,7 +115,7 @@ public class GuiClick extends GuiScreen {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F);
GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
GlStateManager.disableDepthTest();
BetterBlockPos a = new BetterBlockPos(currentMouseOver);
@@ -116,13 +124,13 @@ public class GuiClick extends GuiScreen {
GlStateManager.enableDepthTest();
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}
}
}
public Vec3d toWorld(double x, double y, double z) {
private Vec3d toWorld(double x, double y, double z) {
boolean result = gluUnProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_WORLD_BUFFER.clear());
if (result) {
return new Vec3d(TO_WORLD_BUFFER.get(0), TO_WORLD_BUFFER.get(1), TO_WORLD_BUFFER.get(2));

View File

@@ -115,4 +115,4 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri
public BlockBreakHelper getBlockBreakHelper() {
return blockBreakHelper;
}
}
}

View File

@@ -27,11 +27,12 @@ import baritone.api.utils.Helper;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
import net.minecraft.block.state.IBlockState;
import baritone.utils.accessor.IEntityRenderManager;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntityBeaconRenderer;
import net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
@@ -60,6 +61,18 @@ public final class PathRenderer implements Helper {
private PathRenderer() {}
public static double posX() {
return ((IEntityRenderManager) mc.getRenderManager()).renderPosX();
}
public static double posY() {
return ((IEntityRenderManager) mc.getRenderManager()).renderPosY();
}
public static double posZ() {
return ((IEntityRenderManager) mc.getRenderManager()).renderPosZ();
}
public static void render(RenderEvent event, PathingBehavior behavior) {
float partialTicks = event.getPartialTicks();
Goal goal = behavior.getGoal();
@@ -100,8 +113,6 @@ public final class PathRenderer implements Helper {
}
//drawManySelectionBoxes(player, Collections.singletonList(behavior.pathStart()), partialTicks, Color.WHITE);
//long start = System.nanoTime();
// Render the current path, if there is one
if (current != null && current.getPath() != null) {
@@ -112,8 +123,6 @@ public final class PathRenderer implements Helper {
drawPath(next.getPath(), 0, renderView, partialTicks, Baritone.settings().colorNextPath.value, Baritone.settings().fadePath.value, 10, 20);
}
//long split = System.nanoTime();
// If there is a path calculation currently running, render the path calculation process
behavior.getInProgress().ifPresent(currentlyRunning -> {
currentlyRunning.bestPathSoFar().ifPresent(p -> {
@@ -125,11 +134,6 @@ public final class PathRenderer implements Helper {
drawManySelectionBoxes(renderView, Collections.singletonList(mr.getDest()), Baritone.settings().colorMostRecentConsidered.value);
});
});
//long end = System.nanoTime();
//System.out.println((end - split) + " " + (split - start));
// if (end - start > 0) {
// System.out.println("Frame took " + (split - start) + " " + (end - split));
//}
}
public static void drawPath(IPath path, int startIndex, Entity player, float partialTicks, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) {
@@ -137,7 +141,8 @@ public final class PathRenderer implements Helper {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.disableLighting();
GlStateManager.depthMask(false);
if (Baritone.settings().renderPathIgnoreDepth.value) {
GlStateManager.disableDepthTest();
@@ -187,14 +192,15 @@ public final class PathRenderer implements Helper {
}
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.enableLighting();
GlStateManager.disableBlend();
}
public static void drawLine(double bp1x, double bp1y, double bp1z, double bp2x, double bp2y, double bp2z) {
double d0 = mc.getRenderManager().viewerPosX;
double d1 = mc.getRenderManager().viewerPosY;
double d2 = mc.getRenderManager().viewerPosZ;
double d0 = posX();
double d1 = posY();
double d2 = posZ();
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
BUFFER.pos(bp1x + 0.5D - d0, bp1y + 0.5D - d1, bp1z + 0.5D - d2).endVertex();
BUFFER.pos(bp2x + 0.5D - d0, bp2y + 0.5D - d1, bp2z + 0.5D - d2).endVertex();
@@ -208,7 +214,7 @@ public final class PathRenderer implements Helper {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.4F);
GlStateManager.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
if (Baritone.settings().renderSelectionBoxesIgnoreDepth.value) {
@@ -219,7 +225,7 @@ public final class PathRenderer implements Helper {
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
BlockStateInterface bsi = new BlockStateInterface(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()); // TODO this assumes same dimension between primary baritone and render view? is this safe?
positions.forEach(pos -> {
IBlockState state = bsi.get0(pos);
BlockState state = bsi.get0(pos);
VoxelShape shape = state.getShape(player.world, pos);
AxisAlignedBB toDraw = shape.isEmpty() ? VoxelShapes.fullCube().getBoundingBox() : shape.getBoundingBox();
toDraw = toDraw.offset(pos);
@@ -231,13 +237,13 @@ public final class PathRenderer implements Helper {
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}
public static void drawAABB(AxisAlignedBB aabb) {
float expand = 0.002F;
AxisAlignedBB toDraw = aabb.expand(expand, expand, expand).offset(-mc.getRenderManager().viewerPosX, -mc.getRenderManager().viewerPosY, -mc.getRenderManager().viewerPosZ);
AxisAlignedBB toDraw = aabb.expand(expand, expand, expand).offset(-posX(), -posY(), -posZ());
BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION);
BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
@@ -265,9 +271,9 @@ public final class PathRenderer implements Helper {
}
public static void drawDankLitGoalBox(Entity player, Goal goal, float partialTicks, Color color) {
double renderPosX = mc.getRenderManager().viewerPosX;
double renderPosY = mc.getRenderManager().viewerPosY;
double renderPosZ = mc.getRenderManager().viewerPosZ;
double renderPosX = posX();
double renderPosY = posY();
double renderPosZ = posZ();
double minX;
double maxX;
double minZ;
@@ -307,7 +313,7 @@ public final class PathRenderer implements Helper {
GlStateManager.disableDepthTest();
}
TileEntityBeaconRenderer.renderBeamSegment(
BeaconTileEntityRenderer.renderBeamSegment(
goalPos.getX() - renderPosX,
-renderPosY,
goalPos.getZ() - renderPosZ,
@@ -363,7 +369,7 @@ public final class PathRenderer implements Helper {
GlStateManager.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
GlStateManager.color4f(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.6F);
GlStateManager.lineWidth(Baritone.settings().goalRenderLineWidthPixels.value);
GlStateManager.disableTexture2D();
GlStateManager.disableTexture();
GlStateManager.depthMask(false);
if (Baritone.settings().renderGoalIgnoreDepth.value) {
GlStateManager.disableDepthTest();
@@ -387,7 +393,7 @@ public final class PathRenderer implements Helper {
GlStateManager.enableDepthTest();
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableTexture();
GlStateManager.disableBlend();
}

View File

@@ -92,7 +92,7 @@ public class PathingControlManager implements IPathingControlManager {
p.secretInternalSetGoal(null);
return;
}
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) {
if (!Objects.equals(inControlThisTick, inControlLastTick) && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) {
// if control has changed from a real process to another real process, and the new process wants to do something
p.cancelSegmentIfSafe();
// get rid of the in progress stuff from the last process
@@ -126,7 +126,7 @@ public class PathingControlManager implements IPathingControlManager {
}
}
public void postTick() {
private void postTick() {
// if we did this in pretick, it would suck
// we use the time between ticks as calculation time
// therefore, we only cancel and recalculate after the tick for the current path has executed

View File

@@ -23,15 +23,16 @@ import net.minecraft.util.MovementInput;
public class PlayerMovementInput extends MovementInput {
private final InputOverrideHandler handler;
public PlayerMovementInput(InputOverrideHandler handler) {
PlayerMovementInput(InputOverrideHandler handler) {
this.handler = handler;
}
public void updatePlayerMoveState() {
@Override
public void tick(boolean p_217607_1_, boolean p_217607_2_) {
this.moveStrafe = 0.0F;
this.moveForward = 0.0F;
jump = handler.isInputForcedDown(Input.JUMP); // oppa gangnam
jump = handler.isInputForcedDown(Input.JUMP); // oppa gangnam style
if (this.forwardKeyDown = handler.isInputForcedDown(Input.MOVE_FORWARD)) {
this.moveForward++;

View File

@@ -19,13 +19,13 @@ package baritone.utils;
import baritone.Baritone;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.block.BlockState;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Enchantments;
import net.minecraft.init.MobEffects;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.item.ToolItem;
import net.minecraft.potion.Effects;
import java.util.HashMap;
import java.util.Map;
@@ -48,9 +48,9 @@ public class ToolSet {
*/
private final Function<Block, Double> backendCalculation;
private final EntityPlayerSP player;
private final ClientPlayerEntity player;
public ToolSet(EntityPlayerSP player) {
public ToolSet(ClientPlayerEntity player) {
breakStrengthCache = new HashMap<>();
this.player = player;
@@ -69,7 +69,7 @@ public class ToolSet {
* @param state the blockstate to be mined
* @return the speed of how fast we'll mine it. 1/(time in ticks)
*/
public double getStrVsBlock(IBlockState state) {
public double getStrVsBlock(BlockState state) {
return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation);
}
@@ -80,7 +80,7 @@ public class ToolSet {
* @return Either 1 or -1
*/
private int getMaterialCost(ItemStack itemStack) {
return itemStack.getItem() instanceof ItemTool ? 1 : -1;
return itemStack.getItem() instanceof ToolItem ? 1 : -1;
}
/**
@@ -93,7 +93,7 @@ public class ToolSet {
byte best = 0;
double value = Double.NEGATIVE_INFINITY;
int materialCost = Integer.MIN_VALUE;
IBlockState blockState = b.getDefaultState();
BlockState blockState = b.getDefaultState();
for (byte i = 0; i < 9; i++) {
ItemStack itemStack = player.inventory.getStackInSlot(i);
double v = calculateSpeedVsBlock(itemStack, blockState);
@@ -136,7 +136,7 @@ public class ToolSet {
* @param state the blockstate to be mined
* @return how long it would take in ticks
*/
public static double calculateSpeedVsBlock(ItemStack item, IBlockState state) {
public static double calculateSpeedVsBlock(ItemStack item, BlockState state) {
float hardness = state.getBlockHardness(null, null);
if (hardness < 0) {
return -1;
@@ -165,11 +165,11 @@ public class ToolSet {
*/
private double potionAmplifier() {
double speed = 1;
if (player.isPotionActive(MobEffects.HASTE)) {
speed *= 1 + (player.getActivePotionEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2;
if (player.isPotionActive(Effects.HASTE)) {
speed *= 1 + (player.getActivePotionEffect(Effects.HASTE).getAmplifier() + 1) * 0.2;
}
if (player.isPotionActive(MobEffects.MINING_FATIGUE)) {
switch (player.getActivePotionEffect(MobEffects.MINING_FATIGUE).getAmplifier()) {
if (player.isPotionActive(Effects.MINING_FATIGUE)) {
switch (player.getActivePotionEffect(Effects.MINING_FATIGUE).getAmplifier()) {
case 0:
speed *= 0.3;
break;

View File

@@ -15,25 +15,20 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.launch.mixins;
package baritone.utils.accessor;
import baritone.utils.accessor.IChunkProviderClient;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(ChunkProviderClient.class)
public class MixinChunkProviderClient implements IChunkProviderClient {
import java.util.concurrent.atomic.AtomicReferenceArray;
@Shadow
@Final
private Long2ObjectMap<Chunk> loadedChunks;
public interface IChunkArray {
void copyFrom(IChunkArray other);
@Override
public Long2ObjectMap<Chunk> loadedChunks() {
return this.loadedChunks;
}
AtomicReferenceArray<Chunk> getChunks();
int centerX();
int centerZ();
int viewDistance();
}

View File

@@ -17,13 +17,10 @@
package baritone.utils.accessor;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.client.multiplayer.ClientChunkProvider;
/**
* @author Brady
* @since 8/4/2018
*/
public interface IChunkProviderServer {
public interface IClientChunkProvider {
ClientChunkProvider createThreadSafeCopy();
IChunkLoader getChunkLoader();
IChunkArray extractReferenceArray();
}

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