Compare commits
101 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 16b74ff53c | |||
| 9297e98ac3 | |||
| 6861bfd4e6 | |||
| 0dd4834e18 | |||
| da58988f01 | |||
| b2f3880722 | |||
| 0293a76702 | |||
| 6a13e94c4f | |||
| 79d448e5f4 | |||
| 264b3db63c | |||
| c8cd4b5f28 | |||
| c9e81897a5 | |||
| c738007538 | |||
| da8bf6b1b3 | |||
| 1501d721e7 | |||
| 482d874af2 | |||
| 7dcd7384f1 | |||
| 2a5ef35794 | |||
| 0f09a46540 | |||
| a6d4708ccf | |||
| 77303b4a62 | |||
| 0ffbb0c151 | |||
| b521d7bee1 | |||
| 4e96c5e5ee | |||
| e05010c9d2 | |||
| d0a1c241a4 | |||
| 4ea8f23fc7 | |||
| ec819220b7 | |||
| 54da0d24a3 | |||
| 58ebd5f9a6 | |||
| d60a0bee9e | |||
| e9e26c981a | |||
| 5f12f04e87 | |||
| 7b7be32ca7 | |||
| a14166b1e2 | |||
| 166eb97c3f | |||
| 920ce745c2 | |||
| c931cde3ae | |||
| f7a577e163 | |||
| 9bf3a041d4 | |||
| 85eb7d8043 | |||
| b338dcc9de | |||
| 7d9b8ee4f3 | |||
| 0927e0e017 | |||
| 783a7cedc3 | |||
| b1ee23ad50 | |||
| 9118e0b368 | |||
| 5a0ccac0a1 | |||
| c8419dc362 | |||
| 9127ba2fce | |||
| 36858ca219 | |||
| 30469e2de2 | |||
| 79c433b14d | |||
| bc419cfd1a | |||
| 09fbf675ec | |||
| 2ee119fc64 | |||
| 83265fcb54 | |||
| e8b4f4d2b6 | |||
| 714c6773c3 | |||
| 2fac594315 | |||
| 4bec49de5b | |||
| 4eaa6e20c3 | |||
| 315cc26525 | |||
| 794a761243 | |||
| 5da14fcb3f | |||
| 1047d4ade9 | |||
| 0b8fa3ffe3 | |||
| 498e4e2d6c | |||
| 850c414e8f | |||
| d5a8ed5cb1 | |||
| dd8406c39a | |||
| 13469053b9 | |||
| c4c85b4f49 | |||
| af0c3bbd5c | |||
| 2fcf9ace64 | |||
| 47e1c67bd8 | |||
| 7e3aa6efdd | |||
| 7a2f26ef62 | |||
| b64154e3b3 | |||
| 26256e7155 | |||
| 6599736e00 | |||
| 343bb20bd8 | |||
| 518fa1c74d | |||
| 0b72a8b4b3 | |||
| c013d1e0d9 | |||
| fe51220e3c | |||
| 44d757347b | |||
| 3d3a5f420e | |||
| c136182e17 | |||
| a1a9b4e6b9 | |||
| f49df63183 | |||
| 96414b37f3 | |||
| 544168ff45 | |||
| e0a618a791 | |||
| 3333797144 | |||
| 9c9c9d4387 | |||
| f7f003c0f9 | |||
| 236d02cb47 | |||
| 6e97fe2210 | |||
| 6741666c24 | |||
| f58b6b41cb |
@@ -0,0 +1 @@
|
|||||||
|
* text=auto
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
[](http://hits.dwyl.com/cabaletta/baritone)
|
[](http://hits.dwyl.com/cabaletta/baritone)
|
||||||
[](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md)
|
[](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md)
|
||||||
[](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle)
|
[](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle)
|
||||||
[](https://github.com/cabaletta/baritone/issues)
|
[](https://github.com/cabaletta/baritone/issues)
|
||||||
[](https://github.com/cabaletta/baritone/issues/)
|
[](https://github.com/cabaletta/baritone/issues/)
|
||||||
[](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed)
|
[](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed)
|
||||||
[](https://github.com/cabaletta/baritone/pulls/)
|
[](https://github.com/cabaletta/baritone/pulls/)
|
||||||
@@ -43,7 +43,7 @@ Here are some links to help to get started:
|
|||||||
|
|
||||||
- [Installation & setup](SETUP.md)
|
- [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)
|
- [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail)
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ Here are some links to help to get started:
|
|||||||
|
|
||||||
# API
|
# 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
|
Please note that usage of anything located outside of the ``baritone.api`` package is not supported by the API release
|
||||||
jar.
|
jar.
|
||||||
|
|
||||||
|
|||||||
@@ -34,15 +34,18 @@ Some common examples:
|
|||||||
- `cancel` or `stop` to stop everything
|
- `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)
|
- `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.)
|
- `mine diamond_ore` to mine diamond ore (turn on the setting `legitMine` to only mine ores that it can actually see. It will explore randomly around y=11 until it finds them.)
|
||||||
- `click` to click your destination on the screen. left click to path into it, right click to path on top of it. left click and drag to clear an area.
|
- `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. `follow` to follow the entity you're looking at (only works if it hitting range). `followplayers` to follow any players in range (combine with Kill Aura for a fun time).
|
||||||
- `save waypointName` to save a waypoint. `goto waypointName` to go to it.
|
- `save waypointName` to save a waypoint. `goto waypointName` to go to it.
|
||||||
|
- `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420).
|
||||||
|
- `tunnel` to dig just straight ahead and make a tunnel
|
||||||
|
- `farm` to automatically harvest, replant, or bone meal crops
|
||||||
- `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120).
|
- `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120).
|
||||||
|
- `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load.
|
||||||
- `invert` to invert the current goal and path. This gets as far away from it as possible, instead of as close as possible. For example, do `goal` then `invert` to run as far as possible from where you're standing at the start.
|
- `invert` to invert the current goal and path. This gets as far away from it as possible, instead of as close as possible. For example, do `goal` then `invert` to run as far as possible from where you're standing at the start.
|
||||||
- `render` to rerender the world in case `renderCachedChunks` is being glitchy
|
|
||||||
- `version` to get the version of Baritone you're running
|
- `version` to get the version of Baritone you're running
|
||||||
- `damn` daniel
|
- `damn` daniel
|
||||||
- `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).
|
|
||||||
|
|
||||||
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/main/java/baritone/utils/ExampleBaritoneControl.java).
|
||||||
|
|
||||||
@@ -54,18 +57,23 @@ There are about a hundred settings, but here are some fun / interesting / import
|
|||||||
- `allowPlace`
|
- `allowPlace`
|
||||||
- `allowParkour`
|
- `allowParkour`
|
||||||
- `allowParkourPlace`
|
- `allowParkourPlace`
|
||||||
|
- `blockPlacementPenalty`
|
||||||
- `renderCachedChunks` (and `cachedChunksOpacity`) <-- very fun but you need a beefy computer
|
- `renderCachedChunks` (and `cachedChunksOpacity`) <-- very fun but you need a beefy computer
|
||||||
- `avoidance`
|
- `avoidance` (avoidance of mobs / mob spawners)
|
||||||
- `legitMine`
|
- `legitMine`
|
||||||
- `followRadius`
|
- `followRadius`
|
||||||
|
- `backfill` (fill in tunnels behind you)
|
||||||
|
- `buildInLayers`
|
||||||
|
- `buildRepeatDistance` and `buildRepeatDirection`
|
||||||
|
- `worldExploringChunkOffset`
|
||||||
|
- `acceptableThrowawayItems`
|
||||||
|
- `blocksToAvoidBreaking`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Troubleshooting / common issues
|
# Troubleshooting / common issues
|
||||||
|
|
||||||
## Baritone highlights a block in green but gets completely stuck? Also I'm using Baritone with Future?
|
|
||||||
Baritone is trying to right click to place a block there, but it can't since there's a conflicting mixin. Baritone can't force click right click when Future is also installed. Left click **does work** on recent Baritone even with Future, however. For now, turn off `allowPlace` and Baritone will only search for paths that don't require placing blocks to complete. `allowBreak` can remain on.
|
|
||||||
|
|
||||||
## Why doesn't Baritone respond to any of my chat commands?
|
## Why doesn't Baritone respond to any of my chat commands?
|
||||||
This could be one of many things.
|
This could be one of many things.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
group 'baritone'
|
group 'baritone'
|
||||||
version '1.3.1'
|
version '1.3.2'
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
Vendored
+2
@@ -23,6 +23,8 @@
|
|||||||
-keep class baritone.BaritoneProvider
|
-keep class baritone.BaritoneProvider
|
||||||
-keep class baritone.api.IBaritoneProvider
|
-keep class baritone.api.IBaritoneProvider
|
||||||
|
|
||||||
|
-keep class baritone.api.utils.MyChunkPos { *; } # even in standalone we need to keep this for gson reflect
|
||||||
|
|
||||||
# setting names are reflected from field names, so keep field names
|
# setting names are reflected from field names, so keep field names
|
||||||
-keepclassmembers class baritone.api.Settings {
|
-keepclassmembers class baritone.api.Settings {
|
||||||
public <fields>;
|
public <fields>;
|
||||||
|
|||||||
@@ -71,6 +71,18 @@ public interface IBaritone {
|
|||||||
*/
|
*/
|
||||||
IBuilderProcess getBuilderProcess();
|
IBuilderProcess getBuilderProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IExploreProcess} instance
|
||||||
|
* @see IExploreProcess
|
||||||
|
*/
|
||||||
|
IExploreProcess getExploreProcess();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The {@link IFarmProcess} instance
|
||||||
|
* @see IFarmProcess
|
||||||
|
*/
|
||||||
|
IFarmProcess getFarmProcess();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The {@link ICustomGoalProcess} instance
|
* @return The {@link ICustomGoalProcess} instance
|
||||||
* @see ICustomGoalProcess
|
* @see ICustomGoalProcess
|
||||||
@@ -115,4 +127,6 @@ public interface IBaritone {
|
|||||||
* @see IEventBus
|
* @see IEventBus
|
||||||
*/
|
*/
|
||||||
IEventBus getGameEventHandler();
|
IEventBus getGameEventHandler();
|
||||||
|
|
||||||
|
void openClick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,18 @@
|
|||||||
package baritone.api;
|
package baritone.api;
|
||||||
|
|
||||||
import baritone.api.utils.SettingsUtil;
|
import baritone.api.utils.SettingsUtil;
|
||||||
|
import baritone.api.utils.TypeUtils;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -80,7 +84,7 @@ public final class Settings {
|
|||||||
/**
|
/**
|
||||||
* Walking on water uses up hunger really quick, so penalize it
|
* Walking on water uses up hunger really quick, so penalize it
|
||||||
*/
|
*/
|
||||||
public final Setting<Double> walkOnWaterOnePenalty = new Setting<>(5D);
|
public final Setting<Double> walkOnWaterOnePenalty = new Setting<>(3D);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow Baritone to fall arbitrary distances and place a water bucket beneath it.
|
* Allow Baritone to fall arbitrary distances and place a water bucket beneath it.
|
||||||
@@ -142,9 +146,34 @@ public final class Settings {
|
|||||||
public final Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList(
|
public final Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList(
|
||||||
Blocks.DIRT.asItem(),
|
Blocks.DIRT.asItem(),
|
||||||
Blocks.COBBLESTONE.asItem(),
|
Blocks.COBBLESTONE.asItem(),
|
||||||
Blocks.NETHERRACK.asItem()
|
Blocks.NETHERRACK.asItem(),
|
||||||
|
Blocks.STONE.asItem()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks that Baritone will attempt to avoid (Used in avoidance)
|
||||||
|
*/
|
||||||
|
public final Setting<List<Block>> blocksToAvoid = new Setting<>(new ArrayList<>(
|
||||||
|
// Leave Empty by Default
|
||||||
|
));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocks that Baritone is not allowed to break
|
||||||
|
*/
|
||||||
|
public final Setting<List<Block>> blocksToAvoidBreaking = new Setting<>(new ArrayList<>(Arrays.asList( // TODO can this be a HashSet or ImmutableSet?
|
||||||
|
Blocks.CRAFTING_TABLE,
|
||||||
|
Blocks.FURNACE,
|
||||||
|
Blocks.CHEST,
|
||||||
|
Blocks.TRAPPED_CHEST
|
||||||
|
)));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this setting is true, Baritone will never break a block that is adjacent to an unsupported falling block.
|
||||||
|
* <p>
|
||||||
|
* I.E. it will never trigger cascading sand / gravel falls
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> avoidUpdatingFallingBlocks = new Setting<>(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real
|
* 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.
|
* pathing scenarios. And they can cause Baritone to get trapped indefinitely in a strange scenario.
|
||||||
@@ -185,6 +214,18 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Boolean> sprintAscends = new Setting<>(true);
|
public final Setting<Boolean> sprintAscends = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we overshoot a traverse and end up one block beyond the destination, mark it as successful anyway.
|
||||||
|
* <p>
|
||||||
|
* This helps with speed at >=20m/s
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> overshootTraverse = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When breaking blocks for a movement, wait until all falling blocks have settled before continuing
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> pauseMiningForFallingBlocks = new Setting<>(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many ticks between right clicks are allowed. Default in game is 4
|
* How many ticks between right clicks are allowed. Default in game is 4
|
||||||
*/
|
*/
|
||||||
@@ -401,10 +442,12 @@ public final class Settings {
|
|||||||
* On save, delete from RAM any cached regions that are more than 1024 blocks away from the player
|
* On save, delete from RAM any cached regions that are more than 1024 blocks away from the player
|
||||||
* <p>
|
* <p>
|
||||||
* Temporarily disabled
|
* Temporarily disabled
|
||||||
|
* <p>
|
||||||
|
* Temporarily reenabled
|
||||||
*
|
*
|
||||||
* @see <a href="https://github.com/cabaletta/baritone/issues/248">Issue #248</a>
|
* @see <a href="https://github.com/cabaletta/baritone/issues/248">Issue #248</a>
|
||||||
*/
|
*/
|
||||||
public final Setting<Boolean> pruneRegionsFromRAM = new Setting<>(false);
|
public final Setting<Boolean> pruneRegionsFromRAM = new Setting<>(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remember the contents of containers (chests, echests, furnaces)
|
* Remember the contents of containers (chests, echests, furnaces)
|
||||||
@@ -413,6 +456,11 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Boolean> containerMemory = new Setting<>(false);
|
public final Setting<Boolean> containerMemory = new Setting<>(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill in blocks behind you
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> backfill = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print all the debug messages to chat
|
* Print all the debug messages to chat
|
||||||
*/
|
*/
|
||||||
@@ -496,6 +544,8 @@ public final class Settings {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Exclusively use cached chunks for pathing
|
* Exclusively use cached chunks for pathing
|
||||||
|
* <p>
|
||||||
|
* Never turn this on
|
||||||
*/
|
*/
|
||||||
public final Setting<Boolean> pathThroughCachedOnly = new Setting<>(false);
|
public final Setting<Boolean> pathThroughCachedOnly = new Setting<>(false);
|
||||||
|
|
||||||
@@ -526,7 +576,7 @@ public final class Settings {
|
|||||||
public final Setting<Boolean> renderCachedChunks = new Setting<>(false);
|
public final Setting<Boolean> renderCachedChunks = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 0.0f = not visible, fully transparent
|
* 0.0f = not visible, fully transparent (instead of setting this to 0, turn off renderCachedChunks)
|
||||||
* 1.0f = fully opaque
|
* 1.0f = fully opaque
|
||||||
*/
|
*/
|
||||||
public final Setting<Float> cachedChunksOpacity = new Setting<>(0.5f);
|
public final Setting<Float> cachedChunksOpacity = new Setting<>(0.5f);
|
||||||
@@ -541,6 +591,16 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Boolean> walkWhileBreaking = new Setting<>(true);
|
public final Setting<Boolean> walkWhileBreaking = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a new segment is calculated that doesn't overlap with the current one, but simply begins where the current segment ends,
|
||||||
|
* splice it on and make a longer combined path. If this setting is off, any planned segment will not be spliced and will instead
|
||||||
|
* be the "next path" in PathingBehavior, and will only start after this one ends. Turning this off hurts planning ahead,
|
||||||
|
* because the next segment will exist even if it's very short.
|
||||||
|
*
|
||||||
|
* @see #planningTickLookahead
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> splicePath = new Setting<>(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we are more than 300 movements into the current path, discard the oldest segments, as they are no longer useful
|
* If we are more than 300 movements into the current path, discard the oldest segments, as they are no longer useful
|
||||||
*/
|
*/
|
||||||
@@ -567,20 +627,67 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Boolean> exploreForBlocks = new Setting<>(true);
|
public final Setting<Boolean> exploreForBlocks = new Setting<>(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While exploring the world, offset the closest unloaded chunk by this much in both axes.
|
||||||
|
* <p>
|
||||||
|
* This can result in more efficient loading, if you set this to the render distance.
|
||||||
|
*/
|
||||||
|
public final Setting<Integer> worldExploringChunkOffset = new Setting<>(0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the 10 closest chunks, even if they aren't strictly tied for distance metric from origin.
|
||||||
|
*/
|
||||||
|
public final Setting<Integer> exploreChunkSetMinimumSize = new Setting<>(10);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to maintain Y coordinate while exploring
|
||||||
|
* <p>
|
||||||
|
* -1 to disable
|
||||||
|
*/
|
||||||
|
public final Setting<Integer> exploreMaintainY = new Setting<>(64);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replant nether wart while farming
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> replantNetherWart = new Setting<>(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the cache scan gives less blocks than the maximum threshold (but still above zero), scan the main world too.
|
||||||
|
* <p>
|
||||||
|
* Only if you have a beefy CPU and automatically mine blocks that are in cache
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> extendCacheOnThreshold = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't consider the next layer in builder until the current one is done
|
* Don't consider the next layer in builder until the current one is done
|
||||||
*/
|
*/
|
||||||
public final Setting<Boolean> buildInLayers = new Setting<>(false);
|
public final Setting<Boolean> buildInLayers = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How far to move before repeating the build. -1 for the size of the build in that axis. 0 to disable
|
* false = build from bottom to top
|
||||||
|
* <p>
|
||||||
|
* true = build from top to bottom
|
||||||
*/
|
*/
|
||||||
public final Setting<Integer> buildRepeatDistance=new Setting<>(0);
|
public final Setting<Boolean> layerOrder = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What direction te repeat the build in
|
* How far to move before repeating the build. 0 to disable repeating on a certain axis, 0,0,0 to disable entirely
|
||||||
*/
|
*/
|
||||||
public final Setting<EnumFacing> buildRepeatDirection = new Setting<>(EnumFacing.NORTH);
|
public final Setting<Vec3i> buildRepeat = new Setting<>(new Vec3i(0, 0, 0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow standing above a block while mining it, in BuilderProcess
|
||||||
|
* <p>
|
||||||
|
* Experimental
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> breakFromAbove = new Setting<>(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As well as breaking from above, set a goal to up and to the side of all blocks to break.
|
||||||
|
* <p>
|
||||||
|
* Never turn this on without also turning on breakFromAbove.
|
||||||
|
*/
|
||||||
|
public final Setting<Boolean> goalBreakFromAbove = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)?
|
* While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)?
|
||||||
@@ -668,11 +775,10 @@ public final class Settings {
|
|||||||
public final Setting<Integer> followRadius = new Setting<>(3);
|
public final Setting<Integer> followRadius = new Setting<>(3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true = exploration uses pythagorean distance to choose closest uncached chunk
|
* Turn this on if your exploration filter is enormous, you don't want it to check if it's done,
|
||||||
* <p>
|
* and you are just fine with it just hanging on completion
|
||||||
* false = exploration uses manhattan / taxicab distance to choose
|
|
||||||
*/
|
*/
|
||||||
public final Setting<Boolean> exploreUsePythagorean = new Setting<>(false);
|
public final Setting<Boolean> disableCompletionCheck = new Setting<>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached chunks (regardless of if they're in RAM or saved to disk) expire and are deleted after this number of seconds
|
* Cached chunks (regardless of if they're in RAM or saved to disk) expire and are deleted after this number of seconds
|
||||||
@@ -703,6 +809,11 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage);
|
public final Setting<Consumer<ITextComponent>> logger = new Setting<>(Minecraft.getInstance().ingameGUI.getChatGUI()::printChatMessage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size of the box that is rendered when the current goal is a GoalYLevel
|
||||||
|
*/
|
||||||
|
public final Setting<Double> yLevelBoxSize = new Setting<>(15D);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The color of the current path
|
* The color of the current path
|
||||||
*/
|
*/
|
||||||
@@ -754,11 +865,12 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final List<Setting<?>> allSettings;
|
public final List<Setting<?>> allSettings;
|
||||||
|
|
||||||
|
public final Map<Setting<?>, Type> settingTypes;
|
||||||
|
|
||||||
public final class Setting<T> {
|
public final class Setting<T> {
|
||||||
public T value;
|
public T value;
|
||||||
public final T defaultValue;
|
public final T defaultValue;
|
||||||
private String name;
|
private String name;
|
||||||
private final Class<T> klass;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Setting(T value) {
|
private Setting(T value) {
|
||||||
@@ -767,7 +879,6 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.defaultValue = value;
|
this.defaultValue = value;
|
||||||
this.klass = (Class<T>) value.getClass();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -785,7 +896,8 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Class<T> getValueClass() {
|
public Class<T> getValueClass() {
|
||||||
return klass;
|
// noinspection unchecked
|
||||||
|
return (Class<T>) TypeUtils.resolveBaseClass(getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -799,14 +911,21 @@ public final class Settings {
|
|||||||
public void reset() {
|
public void reset() {
|
||||||
value = defaultValue;
|
value = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Type getType() {
|
||||||
|
return settingTypes.get(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// here be dragons
|
// here be dragons
|
||||||
|
|
||||||
Settings() {
|
Settings() {
|
||||||
Field[] temp = getClass().getFields();
|
Field[] temp = getClass().getFields();
|
||||||
HashMap<String, Setting<?>> tmpByName = new HashMap<>();
|
|
||||||
|
Map<String, Setting<?>> tmpByName = new HashMap<>();
|
||||||
List<Setting<?>> tmpAll = new ArrayList<>();
|
List<Setting<?>> tmpAll = new ArrayList<>();
|
||||||
|
Map<Setting<?>, Type> tmpSettingTypes = new HashMap<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (Field field : temp) {
|
for (Field field : temp) {
|
||||||
if (field.getType().equals(Setting.class)) {
|
if (field.getType().equals(Setting.class)) {
|
||||||
@@ -819,6 +938,7 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
tmpByName.put(name, setting);
|
tmpByName.put(name, setting);
|
||||||
tmpAll.add(setting);
|
tmpAll.add(setting);
|
||||||
|
tmpSettingTypes.put(setting, ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
@@ -826,6 +946,7 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
byLowerName = Collections.unmodifiableMap(tmpByName);
|
byLowerName = Collections.unmodifiableMap(tmpByName);
|
||||||
allSettings = Collections.unmodifiableList(tmpAll);
|
allSettings = Collections.unmodifiableList(tmpAll);
|
||||||
|
settingTypes = Collections.unmodifiableMap(tmpSettingTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -23,9 +23,8 @@ import baritone.api.event.listener.IGameEventListener;
|
|||||||
/**
|
/**
|
||||||
* A behavior is simply a type that is able to listen to events.
|
* A behavior is simply a type that is able to listen to events.
|
||||||
*
|
*
|
||||||
* @see IGameEventListener
|
|
||||||
*
|
|
||||||
* @author Brady
|
* @author Brady
|
||||||
|
* @see IGameEventListener
|
||||||
* @since 9/23/2018
|
* @since 9/23/2018
|
||||||
*/
|
*/
|
||||||
public interface IBehavior extends AbstractGameEventListener {}
|
public interface IBehavior extends AbstractGameEventListener {}
|
||||||
|
|||||||
@@ -80,6 +80,13 @@ public interface IPathingBehavior extends IBehavior {
|
|||||||
*/
|
*/
|
||||||
boolean cancelEverything();
|
boolean cancelEverything();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PLEASE never call this
|
||||||
|
* <p>
|
||||||
|
* If cancelEverything was like "kill" this is "sudo kill -9". Or shutting off your computer.
|
||||||
|
*/
|
||||||
|
void forceCancel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current path, from the current path executor, if there is one.
|
* Returns the current path, from the current path executor, if there is one.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -81,4 +81,6 @@ public interface ICachedWorld {
|
|||||||
* in a new thread by default.
|
* in a new thread by default.
|
||||||
*/
|
*/
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -15,9 +15,8 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.cache;
|
package baritone.api.cache;
|
||||||
|
|
||||||
import baritone.api.cache.IWaypoint;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -47,7 +46,7 @@ public class Waypoint implements IWaypoint {
|
|||||||
* @param location The waypoint location
|
* @param location The waypoint location
|
||||||
* @param creationTimestamp When the waypoint was created
|
* @param creationTimestamp When the waypoint was created
|
||||||
*/
|
*/
|
||||||
Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) {
|
public Waypoint(String name, Tag tag, BlockPos location, long creationTimestamp) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package baritone.api.pathing.goals;
|
package baritone.api.pathing.goals;
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
|||||||
@@ -31,17 +31,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos {
|
|||||||
/**
|
/**
|
||||||
* The X block position of this goal
|
* The X block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int x;
|
protected final int x;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Y block position of this goal
|
* The Y block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int y;
|
protected final int y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Z block position of this goal
|
* The Z block position of this goal
|
||||||
*/
|
*/
|
||||||
private final int z;
|
protected final int z;
|
||||||
|
|
||||||
public GoalTwoBlocks(BlockPos pos) {
|
public GoalTwoBlocks(BlockPos pos) {
|
||||||
this(pos.getX(), pos.getY(), pos.getZ());
|
this(pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class GoalYLevel implements Goal, ActionCosts {
|
|||||||
/**
|
/**
|
||||||
* The target Y level
|
* The target Y level
|
||||||
*/
|
*/
|
||||||
private final int level;
|
public final int level;
|
||||||
|
|
||||||
public GoalYLevel(int level) {
|
public GoalYLevel(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
package baritone.api.process;
|
package baritone.api.process;
|
||||||
|
|
||||||
import baritone.api.utils.ISchematic;
|
import baritone.api.utils.ISchematic;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -46,4 +48,15 @@ public interface IBuilderProcess extends IBaritoneProcess {
|
|||||||
* @return Whether or not the schematic was able to load from file
|
* @return Whether or not the schematic was able to load from file
|
||||||
*/
|
*/
|
||||||
boolean build(String name, File schematic, Vec3i origin);
|
boolean build(String name, File schematic, Vec3i origin);
|
||||||
|
|
||||||
|
default boolean build(String schematicFile, BlockPos origin) {
|
||||||
|
File file = new File(new File(Minecraft.getInstance().gameDir, "schematics"), schematicFile);
|
||||||
|
return build(schematicFile, file, origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pause();
|
||||||
|
|
||||||
|
void resume();
|
||||||
|
|
||||||
|
void clearArea(BlockPos corner1, BlockPos corner2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.process;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public interface IExploreProcess extends IBaritoneProcess {
|
||||||
|
void explore(int centerX, int centerZ);
|
||||||
|
|
||||||
|
void applyJsonFilter(Path path, boolean invert) throws Exception;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.process;
|
||||||
|
|
||||||
|
public interface IFarmProcess extends IBaritoneProcess {
|
||||||
|
void farm();
|
||||||
|
}
|
||||||
@@ -25,4 +25,6 @@ import net.minecraft.block.Block;
|
|||||||
public interface IGetToBlockProcess extends IBaritoneProcess {
|
public interface IGetToBlockProcess extends IBaritoneProcess {
|
||||||
|
|
||||||
void getToBlock(Block block);
|
void getToBlock(Block block);
|
||||||
|
|
||||||
|
boolean blacklistClosest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,5 +51,10 @@ public enum PathingCommandType {
|
|||||||
* <p>
|
* <p>
|
||||||
* Cancel the current path if the goals are not equal
|
* Cancel the current path if the goals are not equal
|
||||||
*/
|
*/
|
||||||
FORCE_REVALIDATE_GOAL_AND_PATH
|
FORCE_REVALIDATE_GOAL_AND_PATH,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go and ask the next process what to do
|
||||||
|
*/
|
||||||
|
DEFER
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ public final class BetterBlockPos extends BlockPos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static long longHash(int x, int y, int z) {
|
public static long longHash(int x, int y, int z) {
|
||||||
|
// TODO use the same thing as BlockPos.fromLong();
|
||||||
|
// invertibility would be incredibly useful
|
||||||
/*
|
/*
|
||||||
* This is the hashcode implementation of Vec3i (the superclass of the class which I shall not name)
|
* This is the hashcode implementation of Vec3i (the superclass of the class which I shall not name)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.utils;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.registry.IRegistry;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class BlockUtils {
|
||||||
|
private static transient Map<String, Block> resourceCache = new HashMap<>();
|
||||||
|
|
||||||
|
public static String blockToString(Block block) {
|
||||||
|
ResourceLocation loc = IRegistry.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?
|
||||||
|
name = loc.toString(); // include the namespace with the colon
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Block stringToBlockNullable(String name) {
|
||||||
|
// do NOT just replace this with a computeWithAbsent, it isn't thread safe
|
||||||
|
Block block = resourceCache.get(name); // map is never mutated in place so this is safe
|
||||||
|
if (block != null) {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
if (resourceCache.containsKey(name)) {
|
||||||
|
return null; // cached as null
|
||||||
|
}
|
||||||
|
block = IRegistry.BLOCK.get(ResourceLocation.tryCreate(name.contains(":") ? name : "minecraft:" + name));
|
||||||
|
Map<String, Block> copy = new HashMap<>(resourceCache); // read only copy is safe, wont throw concurrentmodification
|
||||||
|
copy.put(name, block);
|
||||||
|
resourceCache = copy;
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockUtils() {}
|
||||||
|
}
|
||||||
+111
-78
@@ -15,27 +15,21 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
|
import baritone.api.behavior.IPathingBehavior;
|
||||||
import baritone.api.cache.IRememberedInventory;
|
import baritone.api.cache.IRememberedInventory;
|
||||||
import baritone.api.cache.IWaypoint;
|
import baritone.api.cache.IWaypoint;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
import baritone.api.event.events.ChatEvent;
|
import baritone.api.event.events.ChatEvent;
|
||||||
|
import baritone.api.event.listener.AbstractGameEventListener;
|
||||||
import baritone.api.pathing.goals.*;
|
import baritone.api.pathing.goals.*;
|
||||||
import baritone.api.pathing.movement.ActionCosts;
|
|
||||||
import baritone.api.process.IBaritoneProcess;
|
import baritone.api.process.IBaritoneProcess;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.process.ICustomGoalProcess;
|
||||||
import baritone.api.utils.SettingsUtil;
|
import baritone.api.process.IGetToBlockProcess;
|
||||||
import baritone.behavior.Behavior;
|
|
||||||
import baritone.behavior.PathingBehavior;
|
|
||||||
import baritone.cache.ChunkPacker;
|
|
||||||
import baritone.cache.Waypoint;
|
|
||||||
import baritone.pathing.movement.CalculationContext;
|
|
||||||
import baritone.pathing.movement.Movement;
|
|
||||||
import baritone.pathing.movement.Moves;
|
|
||||||
import baritone.process.CustomGoalProcess;
|
|
||||||
import baritone.utils.pathing.SegmentedCalculator;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||||
@@ -45,11 +39,10 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class ExampleBaritoneControl extends Behavior implements Helper {
|
public class ExampleBaritoneControl implements Helper, AbstractGameEventListener {
|
||||||
|
|
||||||
private static final String HELP_MSG =
|
private static final String HELP_MSG =
|
||||||
"baritone - Output settings into chat\n" +
|
"baritone - Output settings into chat\n" +
|
||||||
@@ -83,21 +76,26 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
|
|
||||||
private static final String COMMAND_PREFIX = "#";
|
private static final String COMMAND_PREFIX = "#";
|
||||||
|
|
||||||
public ExampleBaritoneControl(Baritone baritone) {
|
public final IBaritone baritone;
|
||||||
super(baritone);
|
public final IPlayerContext ctx;
|
||||||
|
|
||||||
|
public ExampleBaritoneControl(IBaritone baritone) {
|
||||||
|
this.baritone = baritone;
|
||||||
|
this.ctx = baritone.getPlayerContext();
|
||||||
|
baritone.getGameEventHandler().registerEventListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendChatMessage(ChatEvent event) {
|
public void onSendChatMessage(ChatEvent event) {
|
||||||
String msg = event.getMessage();
|
String msg = event.getMessage();
|
||||||
if (Baritone.settings().prefixControl.value && msg.startsWith(COMMAND_PREFIX)) {
|
if (BaritoneAPI.getSettings().prefixControl.value && msg.startsWith(COMMAND_PREFIX)) {
|
||||||
if (!runCommand(msg.substring(COMMAND_PREFIX.length()))) {
|
if (!runCommand(msg.substring(COMMAND_PREFIX.length()))) {
|
||||||
logDirect("Invalid command");
|
logDirect("Invalid command");
|
||||||
}
|
}
|
||||||
event.cancel(); // always cancel if using prefixControl
|
event.cancel(); // always cancel if using prefixControl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!Baritone.settings().chatControl.value && !Baritone.settings().removePrefix.value) {
|
if (!BaritoneAPI.getSettings().chatControl.value && !BaritoneAPI.getSettings().removePrefix.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (runCommand(msg)) {
|
if (runCommand(msg)) {
|
||||||
@@ -107,20 +105,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
|
|
||||||
public boolean runCommand(String msg0) { // you may think this can be private, but impcat calls it from .b =)
|
public boolean runCommand(String msg0) { // you may think this can be private, but impcat calls it from .b =)
|
||||||
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
||||||
PathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||||
CustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||||
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
List<Settings.Setting<Boolean>> toggleable = BaritoneAPI.getSettings().getAllValuesByType(Boolean.class);
|
||||||
for (Settings.Setting<Boolean> setting : toggleable) {
|
for (Settings.Setting<Boolean> setting : toggleable) {
|
||||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||||
setting.value ^= true;
|
setting.value ^= true;
|
||||||
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
logDirect("Toggled " + setting.getName() + " to " + setting.value);
|
||||||
SettingsUtil.save(Baritone.settings());
|
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) {
|
if (msg.equals("baritone") || msg.equals("modifiedsettings") || msg.startsWith("settings m") || msg.equals("modified")) {
|
||||||
logDirect("All settings that have been modified from their default values:");
|
logDirect("All settings that have been modified from their default values:");
|
||||||
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(Baritone.settings())) {
|
for (Settings.Setting<?> setting : SettingsUtil.modifiedSettings(BaritoneAPI.getSettings())) {
|
||||||
logDirect(setting.toString());
|
logDirect(setting.toString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -130,15 +128,15 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
try {
|
try {
|
||||||
int page = Integer.parseInt(rest.trim());
|
int page = Integer.parseInt(rest.trim());
|
||||||
int min = page * 10;
|
int min = page * 10;
|
||||||
int max = Math.min(Baritone.settings().allSettings.size(), (page + 1) * 10);
|
int max = Math.min(BaritoneAPI.getSettings().allSettings.size(), (page + 1) * 10);
|
||||||
logDirect("Settings " + min + " to " + (max - 1) + ":");
|
logDirect("Settings " + min + " to " + (max - 1) + ":");
|
||||||
for (int i = min; i < max; i++) {
|
for (int i = min; i < max; i++) {
|
||||||
logDirect(Baritone.settings().allSettings.get(i).toString());
|
logDirect(BaritoneAPI.getSettings().allSettings.get(i).toString());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) { // NumberFormatException | ArrayIndexOutOfBoundsException and probably some others I'm forgetting lol
|
} catch (Exception ex) { // NumberFormatException | ArrayIndexOutOfBoundsException and probably some others I'm forgetting lol
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
logDirect("All settings:");
|
logDirect("All settings:");
|
||||||
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
|
for (Settings.Setting<?> setting : BaritoneAPI.getSettings().allSettings) {
|
||||||
logDirect(setting.toString());
|
logDirect(setting.toString());
|
||||||
}
|
}
|
||||||
logDirect("To get one page of ten settings at a time, do settings <num>");
|
logDirect("To get one page of ten settings at a time, do settings <num>");
|
||||||
@@ -154,26 +152,26 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
if (msg.contains(" ")) {
|
if (msg.contains(" ")) {
|
||||||
String settingName = msg.substring(0, msg.indexOf(' '));
|
String settingName = msg.substring(0, msg.indexOf(' '));
|
||||||
String settingValue = msg.substring(msg.indexOf(' ') + 1);
|
String settingValue = msg.substring(msg.indexOf(' ') + 1);
|
||||||
Settings.Setting setting = Baritone.settings().byLowerName.get(settingName);
|
Settings.Setting setting = BaritoneAPI.getSettings().byLowerName.get(settingName);
|
||||||
if (setting != null) {
|
if (setting != null) {
|
||||||
if (settingValue.equals("reset")) {
|
if (settingValue.equals("reset")) {
|
||||||
logDirect("Resetting setting " + settingName + " to default value.");
|
logDirect("Resetting setting " + settingName + " to default value.");
|
||||||
setting.reset();
|
setting.reset();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
SettingsUtil.parseAndApply(Baritone.settings(), settingName, settingValue);
|
SettingsUtil.parseAndApply(BaritoneAPI.getSettings(), settingName, settingValue);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logDirect("Unable to parse setting");
|
logDirect("Unable to parse setting");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SettingsUtil.save(Baritone.settings());
|
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||||
logDirect(setting.toString());
|
logDirect(setting.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Baritone.settings().byLowerName.containsKey(msg)) {
|
if (BaritoneAPI.getSettings().byLowerName.containsKey(msg)) {
|
||||||
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg);
|
Settings.Setting<?> setting = BaritoneAPI.getSettings().byLowerName.get(msg);
|
||||||
logDirect(setting.toString());
|
logDirect(setting.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -209,7 +207,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("fullpath")) {
|
/*if (msg.equals("fullpath")) {
|
||||||
if (pathingBehavior.getGoal() == null) {
|
if (pathingBehavior.getGoal() == null) {
|
||||||
logDirect("No goal.");
|
logDirect("No goal.");
|
||||||
} else {
|
} else {
|
||||||
@@ -225,7 +223,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
if (msg.equals("proc")) {
|
if (msg.equals("proc")) {
|
||||||
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
|
Optional<IBaritoneProcess> proc = baritone.getPathingControlManager().mostRecentInControl();
|
||||||
if (!proc.isPresent()) {
|
if (!proc.isPresent()) {
|
||||||
@@ -283,7 +281,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("come")) {
|
if (msg.equals("come")) {
|
||||||
customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(mc.getRenderViewEntity())));
|
customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity())));
|
||||||
logDirect("Coming");
|
logDirect("Coming");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -358,11 +356,16 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("resumed");
|
logDirect("resumed");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.equals("pause")) {
|
||||||
|
baritone.getBuilderProcess().pause();
|
||||||
|
logDirect("paused");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (msg.equals("reset")) {
|
if (msg.equals("reset")) {
|
||||||
for (Settings.Setting setting : Baritone.settings().allSettings) {
|
for (Settings.Setting setting : BaritoneAPI.getSettings().allSettings) {
|
||||||
setting.reset();
|
setting.reset();
|
||||||
}
|
}
|
||||||
SettingsUtil.save(Baritone.settings());
|
SettingsUtil.save(BaritoneAPI.getSettings());
|
||||||
logDirect("Baritone settings reset");
|
logDirect("Baritone settings reset");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -377,7 +380,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("okay");
|
logDirect("okay");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("echest")) {
|
if (msg.equals("farm")) {
|
||||||
|
baritone.getFarmProcess().farm();
|
||||||
|
logDirect("farming");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// this literally doesn't work, memory is disabled lol
|
||||||
|
/*if (msg.equals("echest")) {
|
||||||
Optional<List<ItemStack>> contents = baritone.getMemoryBehavior().echest();
|
Optional<List<ItemStack>> contents = baritone.getMemoryBehavior().echest();
|
||||||
if (contents.isPresent()) {
|
if (contents.isPresent()) {
|
||||||
logDirect("echest contents:");
|
logDirect("echest contents:");
|
||||||
@@ -386,18 +395,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("echest contents unknown");
|
logDirect("echest contents unknown");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
if (msg.equals("chests")) {
|
if (msg.equals("chests")) {
|
||||||
System.out.println(baritone.getWorldProvider());
|
|
||||||
System.out.println(baritone.getWorldProvider().getCurrentWorld());
|
|
||||||
|
|
||||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory());
|
|
||||||
|
|
||||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories());
|
|
||||||
|
|
||||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet());
|
|
||||||
|
|
||||||
System.out.println(baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet());
|
|
||||||
for (Map.Entry<BlockPos, IRememberedInventory> entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) {
|
for (Map.Entry<BlockPos, IRememberedInventory> entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) {
|
||||||
logDirect(entry.getKey() + "");
|
logDirect(entry.getKey() + "");
|
||||||
log(entry.getValue().getContents());
|
log(entry.getValue().getContents());
|
||||||
@@ -431,6 +430,29 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Following " + toFollow.get());
|
logDirect("Following " + toFollow.get());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.startsWith("explorefilter")) {
|
||||||
|
// explorefilter blah.json
|
||||||
|
// means that entries in blah.json are already explored
|
||||||
|
// explorefilter blah.json invert
|
||||||
|
// means that entries in blah.json are NOT already explored
|
||||||
|
String path = msg.substring("explorefilter".length()).trim();
|
||||||
|
String[] parts = path.split(" ");
|
||||||
|
Path path1 = Minecraft.getInstance().gameDir.toPath().resolve(parts[0]);
|
||||||
|
boolean invert = parts.length > 1;
|
||||||
|
try {
|
||||||
|
baritone.getExploreProcess().applyJsonFilter(path1, invert);
|
||||||
|
logDirect("Loaded filter. Inverted: " + invert);
|
||||||
|
if (invert) {
|
||||||
|
logDirect("Chunks on this list will be treated as possibly unexplored, all others will be treated as certainly explored");
|
||||||
|
} else {
|
||||||
|
logDirect("Chunks on this list will be treated as certainly explored, all others will be treated as possibly unexplored");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logDirect("Unable to load " + path1);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (msg.equals("reloadall")) {
|
if (msg.equals("reloadall")) {
|
||||||
baritone.getWorldProvider().getCurrentWorld().getCachedWorld().reloadAllFromDisk();
|
baritone.getWorldProvider().getCurrentWorld().getCachedWorld().reloadAllFromDisk();
|
||||||
logDirect("ok");
|
logDirect("ok");
|
||||||
@@ -456,14 +478,27 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Exploring from " + centerX + "," + centerZ);
|
logDirect("Exploring from " + centerX + "," + centerZ);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (msg.equals("blacklist")) {
|
||||||
|
IGetToBlockProcess proc = baritone.getGetToBlockProcess();
|
||||||
|
if (!proc.isActive()) {
|
||||||
|
logDirect("GetToBlockProcess is not currently active");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (proc.blacklistClosest()) {
|
||||||
|
logDirect("Blacklisted closest instances");
|
||||||
|
} else {
|
||||||
|
logDirect("No known locations, unable to blacklist");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (msg.startsWith("find")) {
|
if (msg.startsWith("find")) {
|
||||||
String blockType = msg.substring(4).trim();
|
String blockType = msg.substring(4).trim();
|
||||||
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
ArrayList<BlockPos> locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, ctx.playerFeet().getX(), ctx.playerFeet().getZ(), 4);
|
||||||
logDirect("Have " + locs.size() + " locations");
|
logDirect("Have " + locs.size() + " locations");
|
||||||
for (BlockPos pos : locs) {
|
for (BlockPos pos : locs) {
|
||||||
Block actually = BlockStateInterface.get(ctx, pos).getBlock();
|
Block actually = ctx.world().getBlockState(pos).getBlock();
|
||||||
if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) {
|
if (!BlockUtils.blockToString(actually).equalsIgnoreCase(blockType)) {
|
||||||
System.out.println("Was looking for " + blockType + " but actually found " + actually + " " + ChunkPacker.blockToString(actually));
|
logDebug("Was looking for " + blockType + " but actually found " + actually + " " + BlockUtils.blockToString(actually));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -472,13 +507,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
String[] blockTypes = msg.substring(4).trim().split(" ");
|
String[] blockTypes = msg.substring(4).trim().split(" ");
|
||||||
try {
|
try {
|
||||||
int quantity = Integer.parseInt(blockTypes[1]);
|
int quantity = Integer.parseInt(blockTypes[1]);
|
||||||
Block block = ChunkPacker.stringToBlockRequired(blockTypes[0]);
|
Block block = BlockUtils.stringToBlockRequired(blockTypes[0]);
|
||||||
baritone.getMineProcess().mine(quantity, block);
|
baritone.getMineProcess().mine(quantity, block);
|
||||||
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
||||||
for (String s : blockTypes) {
|
for (String s : blockTypes) {
|
||||||
if (ChunkPacker.stringToBlockNullable(s) == null) {
|
if (BlockUtils.stringToBlockNullable(s) == null) {
|
||||||
logDirect(s + " isn't a valid block name");
|
logDirect(s + " isn't a valid block name");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -489,12 +524,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("click")) {
|
if (msg.equals("click")) {
|
||||||
new Thread(() -> {
|
baritone.openClick();
|
||||||
try {
|
|
||||||
Thread.sleep(100);
|
|
||||||
mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiClick()));
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}).start();
|
|
||||||
logDirect("aight dude");
|
logDirect("aight dude");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -514,9 +544,9 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
// for example, "show deaths"
|
// for example, "show deaths"
|
||||||
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||||
}
|
}
|
||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
logDirect("Not a valid tag. Tags are: " + Arrays.asList(IWaypoint.Tag.values()).toString().toLowerCase());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Set<IWaypoint> waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag);
|
Set<IWaypoint> waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag);
|
||||||
@@ -547,21 +577,21 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
name = parts[0];
|
name = parts[0];
|
||||||
}
|
}
|
||||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, pos));
|
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, IWaypoint.Tag.USER, pos));
|
||||||
logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints.");
|
logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.startsWith("goto")) {
|
if (msg.startsWith("goto")) {
|
||||||
String waypointType = msg.substring(4).trim();
|
String waypointType = msg.substring(4).trim();
|
||||||
if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
|
if (waypointType.endsWith("s") && IWaypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
|
||||||
// for example, "show deaths"
|
// for example, "show deaths"
|
||||||
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
waypointType = waypointType.substring(0, waypointType.length() - 1);
|
||||||
}
|
}
|
||||||
Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
|
IWaypoint.Tag tag = IWaypoint.Tag.fromString(waypointType);
|
||||||
IWaypoint waypoint;
|
IWaypoint waypoint;
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
String mining = waypointType;
|
String mining = waypointType;
|
||||||
Block block = ChunkPacker.stringToBlockNullable(mining);
|
Block block = BlockUtils.stringToBlockNullable(mining);
|
||||||
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
//logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null);
|
||||||
@@ -584,12 +614,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Goal goal = waypoint.getTag() == Waypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation());
|
Goal goal = waypoint.getTag() == IWaypoint.Tag.BED ? new GoalGetToBlock(waypoint.getLocation()) : new GoalBlock(waypoint.getLocation());
|
||||||
customGoalProcess.setGoalAndPath(goal);
|
customGoalProcess.setGoalAndPath(goal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("spawn") || msg.equals("bed")) {
|
if (msg.equals("spawn") || msg.equals("bed")) {
|
||||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED);
|
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(IWaypoint.Tag.BED);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
BlockPos spawnPoint = ctx.player().getBedLocation();
|
BlockPos spawnPoint = ctx.player().getBedLocation();
|
||||||
// for some reason the default spawnpoint is underground sometimes
|
// for some reason the default spawnpoint is underground sometimes
|
||||||
@@ -604,12 +634,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("sethome")) {
|
if (msg.equals("sethome")) {
|
||||||
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, ctx.playerFeet()));
|
baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", IWaypoint.Tag.HOME, ctx.playerFeet()));
|
||||||
logDirect("Saved. Say home to set goal.");
|
logDirect("Saved. Say home to set goal.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("home")) {
|
if (msg.equals("home")) {
|
||||||
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME);
|
IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(IWaypoint.Tag.HOME);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
logDirect("home not saved");
|
logDirect("home not saved");
|
||||||
} else {
|
} else {
|
||||||
@@ -619,7 +649,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("costs")) {
|
// 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));
|
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)) {
|
while (moves.contains(null)) {
|
||||||
moves.remove(null);
|
moves.remove(null);
|
||||||
@@ -635,7 +666,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
|
logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
if (msg.equals("damn")) {
|
if (msg.equals("damn")) {
|
||||||
logDirect("daniel");
|
logDirect("daniel");
|
||||||
}
|
}
|
||||||
@@ -657,18 +688,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
private Goal parseGoal(String[] params) {
|
private Goal parseGoal(String[] params) {
|
||||||
Goal goal;
|
Goal goal;
|
||||||
try {
|
try {
|
||||||
|
BetterBlockPos playerFeet = ctx.playerFeet();
|
||||||
switch (params.length) {
|
switch (params.length) {
|
||||||
case 0:
|
case 0:
|
||||||
goal = new GoalBlock(ctx.playerFeet());
|
goal = new GoalBlock(playerFeet);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
goal = new GoalYLevel(Integer.parseInt(params[0]));
|
|
||||||
|
goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
goal = new GoalXZ(Integer.parseInt(params[0]), Integer.parseInt(params[1]));
|
goal = new GoalXZ(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.z));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2])));
|
goal = new GoalBlock(new BlockPos(parseOrDefault(params[0], playerFeet.x), parseOrDefault(params[1], playerFeet.y), parseOrDefault(params[2], playerFeet.z)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logDirect("unable to understand lol");
|
logDirect("unable to understand lol");
|
||||||
+4
-4
@@ -15,9 +15,9 @@
|
|||||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package baritone.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.api.BaritoneAPI;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentString;
|
import net.minecraft.util.text.TextComponentString;
|
||||||
@@ -50,7 +50,7 @@ public interface Helper {
|
|||||||
* @param message The message to display in chat
|
* @param message The message to display in chat
|
||||||
*/
|
*/
|
||||||
default void logDebug(String message) {
|
default void logDebug(String message) {
|
||||||
if (!Baritone.settings().chatDebug.value) {
|
if (!BaritoneAPI.getSettings().chatDebug.value) {
|
||||||
//System.out.println("Suppressed debug message:");
|
//System.out.println("Suppressed debug message:");
|
||||||
//System.out.println(message);
|
//System.out.println(message);
|
||||||
return;
|
return;
|
||||||
@@ -67,6 +67,6 @@ public interface Helper {
|
|||||||
ITextComponent component = MESSAGE_PREFIX.shallowCopy();
|
ITextComponent component = MESSAGE_PREFIX.shallowCopy();
|
||||||
component.getStyle().setColor(TextFormatting.GRAY);
|
component.getStyle().setColor(TextFormatting.GRAY);
|
||||||
component.appendSibling(new TextComponentString(" " + message));
|
component.appendSibling(new TextComponentString(" " + message));
|
||||||
Minecraft.getInstance().addScheduledTask(() -> Baritone.settings().logger.value.accept(component));
|
Minecraft.getInstance().addScheduledTask(() -> BaritoneAPI.getSettings().logger.value.accept(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,20 +71,26 @@ public interface IPlayerContext {
|
|||||||
* @return The position of the highlighted block
|
* @return The position of the highlighted block
|
||||||
*/
|
*/
|
||||||
default Optional<BlockPos> getSelectedBlock() {
|
default Optional<BlockPos> getSelectedBlock() {
|
||||||
if (objectMouseOver() != null && objectMouseOver().type == RayTraceResult.Type.BLOCK) {
|
RayTraceResult result = objectMouseOver();
|
||||||
return Optional.of(objectMouseOver().getBlockPos());
|
if (result != null && result.type == RayTraceResult.Type.BLOCK) {
|
||||||
|
return Optional.of(result.getBlockPos());
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean isLookingAt(BlockPos pos) {
|
||||||
|
return getSelectedBlock().equals(Optional.of(pos));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the entity that the crosshair is currently placed over. Updated once per tick.
|
* Returns the entity that the crosshair is currently placed over. Updated once per tick.
|
||||||
*
|
*
|
||||||
* @return The entity
|
* @return The entity
|
||||||
*/
|
*/
|
||||||
default Optional<Entity> getSelectedEntity() {
|
default Optional<Entity> getSelectedEntity() {
|
||||||
if (objectMouseOver() != null && objectMouseOver().type == RayTraceResult.Type.ENTITY) {
|
RayTraceResult result = objectMouseOver();
|
||||||
return Optional.of(objectMouseOver().entity);
|
if (result != null && result.type == RayTraceResult.Type.ENTITY) {
|
||||||
|
return Optional.of(result.entity);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Need a non obfed chunkpos that we can load using GSON
|
||||||
|
*/
|
||||||
|
public class MyChunkPos {
|
||||||
|
public int x;
|
||||||
|
public int z;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return x + ", " + z;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -160,7 +160,7 @@ public final class RotationUtils {
|
|||||||
*/
|
*/
|
||||||
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
|
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance) {
|
||||||
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
|
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
|
||||||
if (pos.equals(baritone.getPlayerContext().getSelectedBlock().orElse(null))) {
|
if (baritone.getPlayerContext().isLookingAt(pos)) {
|
||||||
/*
|
/*
|
||||||
* why add 0.0001?
|
* why add 0.0001?
|
||||||
* to indicate that we actually have a desired pitch
|
* to indicate that we actually have a desired pitch
|
||||||
|
|||||||
@@ -18,33 +18,38 @@
|
|||||||
package baritone.api.utils;
|
package baritone.api.utils;
|
||||||
|
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.registry.IRegistry;
|
import net.minecraft.util.registry.IRegistry;
|
||||||
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class SettingsUtil {
|
public class SettingsUtil {
|
||||||
|
|
||||||
private static final Path SETTINGS_PATH = Minecraft.getInstance().gameDir.toPath().resolve("baritone").resolve("settings.txt");
|
private static final Path SETTINGS_PATH = Minecraft.getInstance().gameDir.toPath().resolve("baritone").resolve("settings.txt");
|
||||||
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>[^ ]+)"); // 2 words separated by spaces
|
private static final Pattern SETTING_PATTERN = Pattern.compile("^(?<setting>[^ ]+) +(?<value>.+)"); // key and value split by the first space
|
||||||
|
|
||||||
private static final Map<Class<?>, SettingsIO> map;
|
|
||||||
|
|
||||||
private static boolean isComment(String line) {
|
private static boolean isComment(String line) {
|
||||||
return line.startsWith("#") || line.startsWith("//");
|
return line.startsWith("#") || line.startsWith("//");
|
||||||
@@ -80,6 +85,8 @@ public class SettingsUtil {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (NoSuchFileException ignored) {
|
||||||
|
System.out.println("Baritone settings file not found, resetting.");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!");
|
System.out.println("Exception while reading Baritone settings, some settings may be reset to default values!");
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@@ -119,11 +126,11 @@ public class SettingsUtil {
|
|||||||
if (setting.getName().equals("logger")) {
|
if (setting.getName().equals("logger")) {
|
||||||
return "logger";
|
return "logger";
|
||||||
}
|
}
|
||||||
SettingsIO io = map.get(setting.getValueClass());
|
Parser io = Parser.getParser(setting.getType());
|
||||||
if (io == null) {
|
if (io == null) {
|
||||||
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName());
|
throw new IllegalStateException("Missing " + setting.getValueClass() + " " + setting.getName());
|
||||||
}
|
}
|
||||||
return setting.getName() + " " + io.toString.apply(setting.value);
|
return setting.getName() + " " + io.toString(new ParserContext(setting), setting.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
public static void parseAndApply(Settings settings, String settingName, String settingValue) throws IllegalStateException, NumberFormatException {
|
||||||
@@ -132,46 +139,131 @@ public class SettingsUtil {
|
|||||||
throw new IllegalStateException("No setting by that name");
|
throw new IllegalStateException("No setting by that name");
|
||||||
}
|
}
|
||||||
Class intendedType = setting.getValueClass();
|
Class intendedType = setting.getValueClass();
|
||||||
SettingsIO ioMethod = map.get(intendedType);
|
ISettingParser ioMethod = Parser.getParser(setting.getType());
|
||||||
Object parsed = ioMethod.parser.apply(settingValue);
|
Object parsed = ioMethod.parse(new ParserContext(setting), settingValue);
|
||||||
if (!intendedType.isInstance(parsed)) {
|
if (!intendedType.isInstance(parsed)) {
|
||||||
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
|
throw new IllegalStateException(ioMethod + " parser returned incorrect type, expected " + intendedType + " got " + parsed + " which is " + parsed.getClass());
|
||||||
}
|
}
|
||||||
setting.value = parsed;
|
setting.value = parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum SettingsIO {
|
private interface ISettingParser<T> {
|
||||||
|
|
||||||
|
T parse(ParserContext context, String raw);
|
||||||
|
|
||||||
|
String toString(ParserContext context, T value);
|
||||||
|
|
||||||
|
boolean accepts(Type type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ParserContext {
|
||||||
|
|
||||||
|
private final Settings.Setting<?> setting;
|
||||||
|
|
||||||
|
public ParserContext(Settings.Setting<?> setting) {
|
||||||
|
this.setting = setting;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Settings.Setting<?> getSetting() {
|
||||||
|
return this.setting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Parser implements ISettingParser {
|
||||||
|
|
||||||
DOUBLE(Double.class, Double::parseDouble),
|
DOUBLE(Double.class, Double::parseDouble),
|
||||||
BOOLEAN(Boolean.class, Boolean::parseBoolean),
|
BOOLEAN(Boolean.class, Boolean::parseBoolean),
|
||||||
INTEGER(Integer.class, Integer::parseInt),
|
INTEGER(Integer.class, Integer::parseInt),
|
||||||
FLOAT(Float.class, Float::parseFloat),
|
FLOAT(Float.class, Float::parseFloat),
|
||||||
LONG(Long.class, Long::parseLong),
|
LONG(Long.class, Long::parseLong),
|
||||||
|
ENUMFACING(EnumFacing.class, EnumFacing::byName),
|
||||||
|
COLOR(
|
||||||
|
Color.class,
|
||||||
|
str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])),
|
||||||
|
color -> color.getRed() + "," + color.getGreen() + "," + color.getBlue()
|
||||||
|
),
|
||||||
|
VEC3I(
|
||||||
|
Vec3i.class,
|
||||||
|
str -> new Vec3i(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])),
|
||||||
|
vec -> vec.getX() + "," + vec.getY() + "," + vec.getZ()
|
||||||
|
),
|
||||||
|
BLOCK(
|
||||||
|
Block.class,
|
||||||
|
str -> BlockUtils.stringToBlockRequired(str.trim()),
|
||||||
|
BlockUtils::blockToString
|
||||||
|
),
|
||||||
|
ITEM(
|
||||||
|
Item.class,
|
||||||
|
str -> IRegistry.ITEM.get(new ResourceLocation(str.trim())),
|
||||||
|
item -> IRegistry.ITEM.getKey(item).toString()
|
||||||
|
),
|
||||||
|
LIST() {
|
||||||
|
@Override
|
||||||
|
public Object parse(ParserContext context, String raw) {
|
||||||
|
Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0];
|
||||||
|
Parser parser = Parser.getParser(type);
|
||||||
|
return Arrays.stream(raw.split(","))
|
||||||
|
.map(s -> parser.parse(context, s))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
ITEM_LIST(ArrayList.class, str -> Stream.of(str.split(",")).map(ResourceLocation::new).map(IRegistry.ITEM::get).collect(Collectors.toCollection(ArrayList::new)), list -> ((ArrayList<Item>) list).stream().map(IRegistry.ITEM::getKey).map(ResourceLocation::toString).collect(Collectors.joining(","))),
|
@Override
|
||||||
COLOR(Color.class, str -> new Color(Integer.parseInt(str.split(",")[0]), Integer.parseInt(str.split(",")[1]), Integer.parseInt(str.split(",")[2])), color -> color.getRed() + "," + color.getGreen() + "," + color.getBlue()),
|
public String toString(ParserContext context, Object value) {
|
||||||
ENUMFACING(EnumFacing.class, EnumFacing::byName);
|
Type type = ((ParameterizedType) context.getSetting().getType()).getActualTypeArguments()[0];
|
||||||
|
Parser parser = Parser.getParser(type);
|
||||||
|
|
||||||
|
return ((List<?>) value).stream()
|
||||||
|
.map(o -> parser.toString(context, o))
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
}
|
||||||
|
|
||||||
Class<?> klass;
|
@Override
|
||||||
Function<String, Object> parser;
|
public boolean accepts(Type type) {
|
||||||
Function<Object, String> toString;
|
return List.class.isAssignableFrom(TypeUtils.resolveBaseClass(type));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
<T> SettingsIO(Class<T> klass, Function<String, T> parser) {
|
private final Class<?> klass;
|
||||||
|
private final Function<String, Object> parser;
|
||||||
|
private final Function<Object, String> toString;
|
||||||
|
|
||||||
|
Parser() {
|
||||||
|
this.klass = null;
|
||||||
|
this.parser = null;
|
||||||
|
this.toString = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<T> Parser(Class<T> klass, Function<String, T> parser) {
|
||||||
this(klass, parser, Object::toString);
|
this(klass, parser, Object::toString);
|
||||||
}
|
}
|
||||||
|
|
||||||
<T> SettingsIO(Class<T> klass, Function<String, T> parser, Function<T, String> toString) {
|
<T> Parser(Class<T> klass, Function<String, T> parser, Function<T, String> toString) {
|
||||||
this.klass = klass;
|
this.klass = klass;
|
||||||
this.parser = parser::apply;
|
this.parser = parser::apply;
|
||||||
this.toString = x -> toString.apply((T) x);
|
this.toString = x -> toString.apply((T) x);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
@Override
|
||||||
HashMap<Class<?>, SettingsIO> tempMap = new HashMap<>();
|
public Object parse(ParserContext context, String raw) {
|
||||||
for (SettingsIO type : SettingsIO.values()) {
|
Object parsed = this.parser.apply(raw);
|
||||||
tempMap.put(type.klass, type);
|
Objects.requireNonNull(parsed);
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(ParserContext context, Object value) {
|
||||||
|
return this.toString.apply(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accepts(Type type) {
|
||||||
|
return type instanceof Class && this.klass.isAssignableFrom((Class) type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Parser getParser(Type type) {
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.filter(parser -> parser.accepts(type))
|
||||||
|
.findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
map = Collections.unmodifiableMap(tempMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.api.utils;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Brady
|
||||||
|
* @since 4/20/2019
|
||||||
|
*/
|
||||||
|
public final class TypeUtils {
|
||||||
|
|
||||||
|
private TypeUtils() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the "base type" for the specified type. For example, if the specified
|
||||||
|
* type is {@code List<String>}, then {@code List.class} will be returned. If the
|
||||||
|
* specified type is already a class, then it is directly returned.
|
||||||
|
*
|
||||||
|
* @param type The type to resolve
|
||||||
|
* @return The base class
|
||||||
|
*/
|
||||||
|
public static Class<?> resolveBaseClass(Type type) {
|
||||||
|
return type instanceof Class ? (Class<?>) type
|
||||||
|
: type instanceof ParameterizedType ? (Class<?>) ((ParameterizedType) type).getRawType()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,8 +28,10 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.GL_ONE;
|
||||||
import static org.lwjgl.opengl.GL14.*;
|
import static org.lwjgl.opengl.GL11.GL_ZERO;
|
||||||
|
import static org.lwjgl.opengl.GL14.GL_CONSTANT_ALPHA;
|
||||||
|
import static org.lwjgl.opengl.GL14.GL_ONE_MINUS_CONSTANT_ALPHA;
|
||||||
|
|
||||||
@Mixin(ChunkRenderContainer.class)
|
@Mixin(ChunkRenderContainer.class)
|
||||||
public class MixinChunkRenderContainer {
|
public class MixinChunkRenderContainer {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import baritone.api.BaritoneAPI;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
import baritone.api.event.listener.IEventBus;
|
import baritone.api.event.listener.IEventBus;
|
||||||
|
import baritone.api.utils.ExampleBaritoneControl;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import baritone.behavior.*;
|
import baritone.behavior.*;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
@@ -33,8 +35,6 @@ import net.minecraft.client.Minecraft;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.SynchronousQueue;
|
import java.util.concurrent.SynchronousQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@@ -67,7 +67,6 @@ public class Baritone implements IBaritone {
|
|||||||
|
|
||||||
private GameEventHandler gameEventHandler;
|
private GameEventHandler gameEventHandler;
|
||||||
|
|
||||||
private List<Behavior> behaviors;
|
|
||||||
private PathingBehavior pathingBehavior;
|
private PathingBehavior pathingBehavior;
|
||||||
private LookBehavior lookBehavior;
|
private LookBehavior lookBehavior;
|
||||||
private MemoryBehavior memoryBehavior;
|
private MemoryBehavior memoryBehavior;
|
||||||
@@ -80,6 +79,8 @@ public class Baritone implements IBaritone {
|
|||||||
private CustomGoalProcess customGoalProcess;
|
private CustomGoalProcess customGoalProcess;
|
||||||
private BuilderProcess builderProcess;
|
private BuilderProcess builderProcess;
|
||||||
private ExploreProcess exploreProcess;
|
private ExploreProcess exploreProcess;
|
||||||
|
private BackfillProcess backfillProcess;
|
||||||
|
private FarmProcess farmProcess;
|
||||||
|
|
||||||
private PathingControlManager pathingControlManager;
|
private PathingControlManager pathingControlManager;
|
||||||
|
|
||||||
@@ -101,7 +102,6 @@ public class Baritone implements IBaritone {
|
|||||||
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
||||||
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
||||||
|
|
||||||
this.behaviors = new ArrayList<>();
|
|
||||||
{
|
{
|
||||||
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||||
pathingBehavior = new PathingBehavior(this);
|
pathingBehavior = new PathingBehavior(this);
|
||||||
@@ -120,6 +120,8 @@ public class Baritone implements IBaritone {
|
|||||||
getToBlockProcess = new GetToBlockProcess(this);
|
getToBlockProcess = new GetToBlockProcess(this);
|
||||||
builderProcess = new BuilderProcess(this);
|
builderProcess = new BuilderProcess(this);
|
||||||
exploreProcess = new ExploreProcess(this);
|
exploreProcess = new ExploreProcess(this);
|
||||||
|
backfillProcess = new BackfillProcess(this);
|
||||||
|
farmProcess = new FarmProcess(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.worldProvider = new WorldProvider();
|
this.worldProvider = new WorldProvider();
|
||||||
@@ -136,12 +138,7 @@ public class Baritone implements IBaritone {
|
|||||||
return this.pathingControlManager;
|
return this.pathingControlManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Behavior> getBehaviors() {
|
|
||||||
return this.behaviors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerBehavior(Behavior behavior) {
|
public void registerBehavior(Behavior behavior) {
|
||||||
this.behaviors.add(behavior);
|
|
||||||
this.gameEventHandler.registerEventListener(behavior);
|
this.gameEventHandler.registerEventListener(behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +194,10 @@ public class Baritone implements IBaritone {
|
|||||||
return this.mineProcess;
|
return this.mineProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FarmProcess getFarmProcess() {
|
||||||
|
return this.farmProcess;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PathingBehavior getPathingBehavior() {
|
public PathingBehavior getPathingBehavior() {
|
||||||
return this.pathingBehavior;
|
return this.pathingBehavior;
|
||||||
@@ -212,6 +213,16 @@ public class Baritone implements IBaritone {
|
|||||||
return this.gameEventHandler;
|
return this.gameEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openClick() {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
Helper.mc.addScheduledTask(() -> Helper.mc.displayGuiScreen(new GuiClick()));
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
public static Settings settings() {
|
public static Settings settings() {
|
||||||
return BaritoneAPI.getSettings();
|
return BaritoneAPI.getSettings();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,27 +123,27 @@ public class InventoryBehavior extends Behavior {
|
|||||||
|
|
||||||
public boolean hasGenericThrowaway() {
|
public boolean hasGenericThrowaway() {
|
||||||
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
||||||
if (throwaway(false, item::equals)) {
|
if (throwaway(false, stack -> item.equals(stack.getItem()))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean selectThrowawayForLocation(int x, int y, int z) {
|
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
|
||||||
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z);
|
||||||
if (maybe != null && throwaway(true, item -> item instanceof ItemBlock && ((ItemBlock) item).getBlock().equals(maybe.getBlock()))) {
|
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(maybe.getBlock()))) {
|
||||||
return true; // gotem
|
return true; // gotem
|
||||||
}
|
}
|
||||||
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
for (Item item : Baritone.settings().acceptableThrowawayItems.value) {
|
||||||
if (throwaway(true, item::equals)) {
|
if (throwaway(select, stack -> item.equals(stack.getItem()))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean throwaway(boolean select, Predicate<? super Item> desired) {
|
public boolean throwaway(boolean select, Predicate<? super ItemStack> desired) {
|
||||||
EntityPlayerSP p = ctx.player();
|
EntityPlayerSP p = ctx.player();
|
||||||
NonNullList<ItemStack> inv = p.inventory.mainInventory;
|
NonNullList<ItemStack> inv = p.inventory.mainInventory;
|
||||||
for (byte i = 0; i < 9; i++) {
|
for (byte i = 0; i < 9; i++) {
|
||||||
@@ -153,14 +153,14 @@ public class InventoryBehavior extends Behavior {
|
|||||||
// and then it's called during execution
|
// and then it's called during execution
|
||||||
// since this function is never called during cost calculation, we don't need to migrate
|
// since this function is never called during cost calculation, we don't need to migrate
|
||||||
// acceptableThrowawayItems to the CalculationContext
|
// acceptableThrowawayItems to the CalculationContext
|
||||||
if (desired.test(item.getItem())) {
|
if (desired.test(item)) {
|
||||||
if (select) {
|
if (select) {
|
||||||
p.inventory.currentItem = i;
|
p.inventory.currentItem = i;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desired.test(p.inventory.offHandInventory.get(0).getItem())) {
|
if (desired.test(p.inventory.offHandInventory.get(0))) {
|
||||||
// main hand takes precedence over off hand
|
// main hand takes precedence over off hand
|
||||||
// that means that if we have block A selected in main hand and block B in off hand, right clicking places block B
|
// that means that if we have block A selected in main hand and block B in off hand, right clicking places block B
|
||||||
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
|
// we've already checked above ^ and the main hand can't possible have an acceptablethrowawayitem
|
||||||
|
|||||||
@@ -18,13 +18,13 @@
|
|||||||
package baritone.behavior;
|
package baritone.behavior;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
import baritone.api.event.events.BlockInteractEvent;
|
import baritone.api.event.events.BlockInteractEvent;
|
||||||
import baritone.api.event.events.PacketEvent;
|
import baritone.api.event.events.PacketEvent;
|
||||||
import baritone.api.event.events.PlayerUpdateEvent;
|
import baritone.api.event.events.PlayerUpdateEvent;
|
||||||
import baritone.api.event.events.TickEvent;
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.cache.ContainerMemory;
|
import baritone.cache.ContainerMemory;
|
||||||
import baritone.cache.Waypoint;
|
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockBed;
|
import net.minecraft.block.BlockBed;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import baritone.api.pathing.goals.Goal;
|
|||||||
import baritone.api.pathing.goals.GoalXZ;
|
import baritone.api.pathing.goals.GoalXZ;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.PathCalculationResult;
|
import baritone.api.utils.PathCalculationResult;
|
||||||
import baritone.api.utils.interfaces.IGoalRenderPos;
|
import baritone.api.utils.interfaces.IGoalRenderPos;
|
||||||
import baritone.pathing.calc.AStarPathFinder;
|
import baritone.pathing.calc.AStarPathFinder;
|
||||||
@@ -32,7 +33,6 @@ import baritone.pathing.calc.AbstractNodeCostSearch;
|
|||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.PathRenderer;
|
import baritone.utils.PathRenderer;
|
||||||
import baritone.utils.PathingCommandContext;
|
import baritone.utils.PathingCommandContext;
|
||||||
import baritone.utils.pathing.Favoring;
|
import baritone.utils.pathing.Favoring;
|
||||||
@@ -195,7 +195,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
current.onTick();
|
current.onTick();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
current = current.trySplice(next);
|
if (Baritone.settings().splicePath.value) {
|
||||||
|
current = current.trySplice(next);
|
||||||
|
}
|
||||||
if (next != null && current.getPath().getDest().equals(next.getPath().getDest())) {
|
if (next != null && current.getPath().getDest().equals(next.getPath().getDest())) {
|
||||||
next = null;
|
next = null;
|
||||||
}
|
}
|
||||||
@@ -350,7 +352,8 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forceCancel() { // NOT exposed on public api
|
@Override
|
||||||
|
public void forceCancel() { // exposed on public api because :sob:
|
||||||
cancelEverything();
|
cancelEverything();
|
||||||
secretInternalSegmentCancel();
|
secretInternalSegmentCancel();
|
||||||
synchronized (pathCalcLock) {
|
synchronized (pathCalcLock) {
|
||||||
@@ -358,11 +361,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void secretCursedFunctionDoNotCall(IPath path) {
|
/*public void secretCursedFunctionDoNotCall(IPath path) {
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
current = new PathExecutor(this, path);
|
current = new PathExecutor(this, path);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public CalculationContext secretInternalGetCalculationContext() {
|
public CalculationContext secretInternalGetCalculationContext() {
|
||||||
return context;
|
return context;
|
||||||
|
|||||||
+3
-2
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import baritone.utils.pathing.PathingBlockType;
|
import baritone.utils.pathing.PathingBlockType;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -113,7 +114,7 @@ public final class CachedChunk {
|
|||||||
temp.add(Blocks.GREEN_BED);
|
temp.add(Blocks.GREEN_BED);
|
||||||
temp.add(Blocks.RED_BED);
|
temp.add(Blocks.RED_BED);
|
||||||
temp.add(Blocks.BLACK_BED);
|
temp.add(Blocks.BLACK_BED);
|
||||||
|
|
||||||
temp.add(Blocks.DRAGON_EGG);
|
temp.add(Blocks.DRAGON_EGG);
|
||||||
temp.add(Blocks.JUKEBOX);
|
temp.add(Blocks.JUKEBOX);
|
||||||
temp.add(Blocks.END_GATEWAY);
|
temp.add(Blocks.END_GATEWAY);
|
||||||
@@ -212,7 +213,7 @@ public final class CachedChunk {
|
|||||||
if (special != null) {
|
if (special != null) {
|
||||||
String str = special.get(index);
|
String str = special.get(index);
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
return ChunkPacker.stringToBlockRequired(str).getDefaultState();
|
return BlockUtils.stringToBlockRequired(str).getDefaultState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -19,6 +19,7 @@ package baritone.cache;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.cache.ICachedRegion;
|
import baritone.api.cache.ICachedRegion;
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
if (chunks[x][z] != null) {
|
if (chunks[x][z] != null) {
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
out.writeUTF(ChunkPacker.blockToString(chunks[x][z].getOverview()[i].getBlock()));
|
out.writeUTF(BlockUtils.blockToString(chunks[x][z].getOverview()[i].getBlock()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +241,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
if (present[x][z]) {
|
if (present[x][z]) {
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
overview[x][z][i] = ChunkPacker.stringToBlockRequired(in.readUTF()).getDefaultState();
|
overview[x][z][i] = BlockUtils.stringToBlockRequired(in.readUTF()).getDefaultState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +256,7 @@ public final class CachedRegion implements ICachedRegion {
|
|||||||
int numSpecialBlockTypes = in.readShort() & 0xffff;
|
int numSpecialBlockTypes = in.readShort() & 0xffff;
|
||||||
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
for (int i = 0; i < numSpecialBlockTypes; i++) {
|
||||||
String blockName = in.readUTF();
|
String blockName = in.readUTF();
|
||||||
ChunkPacker.stringToBlockRequired(blockName);
|
BlockUtils.stringToBlockRequired(blockName);
|
||||||
List<BlockPos> locs = new ArrayList<>();
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
location[x][z].put(blockName, locs);
|
location[x][z].put(blockName, locs);
|
||||||
int numLocations = in.readShort() & 0xffff;
|
int numLocations = in.readShort() & 0xffff;
|
||||||
|
|||||||
+4
-4
@@ -22,7 +22,7 @@ import baritone.api.BaritoneAPI;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.cache.ICachedWorld;
|
import baritone.api.cache.ICachedWorld;
|
||||||
import baritone.api.cache.IWorldData;
|
import baritone.api.cache.IWorldData;
|
||||||
import baritone.utils.Helper;
|
import baritone.api.utils.Helper;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -180,8 +180,8 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
if (region == null) {
|
if (region == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int distX = (region.getX() << 9 + 256) - pruneCenter.getX();
|
int distX = ((region.getX() << 9) + 256) - pruneCenter.getX();
|
||||||
int distZ = (region.getZ() << 9 + 256) - pruneCenter.getZ();
|
int distZ = ((region.getZ() << 9) + 256) - pruneCenter.getZ();
|
||||||
double dist = Math.sqrt(distX * distX + distZ * distZ);
|
double dist = Math.sqrt(distX * distX + distZ * distZ);
|
||||||
if (dist > 1024) {
|
if (dist > 1024) {
|
||||||
logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram");
|
logDebug("Deleting cached region " + region.getX() + "," + region.getZ() + " from ram");
|
||||||
@@ -216,7 +216,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
if (mostRecentlyModified == null) {
|
if (mostRecentlyModified == null) {
|
||||||
return new BlockPos(0, 0, 0);
|
return new BlockPos(0, 0, 0);
|
||||||
}
|
}
|
||||||
return new BlockPos(mostRecentlyModified.x << 4 + 8, 0, mostRecentlyModified.z << 4 + 8);
|
return new BlockPos((mostRecentlyModified.x << 4) + 8, 0, (mostRecentlyModified.z << 4) + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized List<CachedRegion> allRegions() {
|
private synchronized List<CachedRegion> allRegions() {
|
||||||
|
|||||||
+11
-33
@@ -17,15 +17,14 @@
|
|||||||
|
|
||||||
package baritone.cache;
|
package baritone.cache;
|
||||||
|
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.utils.pathing.PathingBlockType;
|
import baritone.utils.pathing.PathingBlockType;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.registry.IRegistry;
|
|
||||||
import net.minecraft.world.chunk.BlockStateContainer;
|
import net.minecraft.world.chunk.BlockStateContainer;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.ChunkSection;
|
import net.minecraft.world.chunk.ChunkSection;
|
||||||
@@ -38,8 +37,6 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public final class ChunkPacker {
|
public final class ChunkPacker {
|
||||||
|
|
||||||
private static final Map<String, Block> resourceCache = new HashMap<>();
|
|
||||||
|
|
||||||
private ChunkPacker() {}
|
private ChunkPacker() {}
|
||||||
|
|
||||||
public static CachedChunk pack(Chunk chunk) {
|
public static CachedChunk pack(Chunk chunk) {
|
||||||
@@ -77,7 +74,7 @@ public final class ChunkPacker {
|
|||||||
bitSet.set(index + 1, bits[1]);
|
bitSet.set(index + 1, bits[1]);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
|
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
|
||||||
String name = blockToString(block);
|
String name = BlockUtils.blockToString(block);
|
||||||
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z));
|
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,8 +89,7 @@ public final class ChunkPacker {
|
|||||||
IBlockState[] blocks = new IBlockState[256];
|
IBlockState[] blocks = new IBlockState[256];
|
||||||
|
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
https:
|
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
||||||
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
|
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
for (int y = 255; y >= 0; y--) {
|
for (int y = 255; y >= 0; y--) {
|
||||||
int index = CachedChunk.getPositionIndex(x, y, z);
|
int index = CachedChunk.getPositionIndex(x, y, z);
|
||||||
@@ -108,29 +104,6 @@ public final class ChunkPacker {
|
|||||||
return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
|
return new CachedChunk(chunk.x, chunk.z, bitSet, blocks, specialBlocks, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String blockToString(Block block) {
|
|
||||||
ResourceLocation loc = IRegistry.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?
|
|
||||||
name = loc.toString(); // include the namespace with the colon
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Block stringToBlockRequired(String name) {
|
|
||||||
if (name.equals("lit_redstone_ore")) {
|
|
||||||
return stringToBlockRequired("redstone_ore");
|
|
||||||
}
|
|
||||||
Block block = stringToBlockNullable(name);
|
|
||||||
Objects.requireNonNull(block);
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Block stringToBlockNullable(String name) {
|
|
||||||
return resourceCache.computeIfAbsent(name, n -> IRegistry.BLOCK.get(new ResourceLocation(n.contains(":") ? n : "minecraft:" + n)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
|
private static PathingBlockType getPathingBlockType(IBlockState state, Chunk chunk, int x, int y, int z) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (MovementHelper.isWater(state)) {
|
if (MovementHelper.isWater(state)) {
|
||||||
@@ -139,6 +112,14 @@ public final class ChunkPacker {
|
|||||||
if (MovementHelper.possiblyFlowing(state)) {
|
if (MovementHelper.possiblyFlowing(state)) {
|
||||||
return PathingBlockType.AVOID;
|
return PathingBlockType.AVOID;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
(x != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)))
|
||||||
|
|| (x != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)))
|
||||||
|
|| (z != 15 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)))
|
||||||
|
|| (z != 0 && MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1)))
|
||||||
|
) {
|
||||||
|
return PathingBlockType.AVOID;
|
||||||
|
}
|
||||||
if (x == 0 || x == 15 || z == 0 || z == 15) {
|
if (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.x << 4, y, z + chunk.z << 4));
|
||||||
if (flow.x != 0.0 || flow.z != 0.0) {
|
if (flow.x != 0.0 || flow.z != 0.0) {
|
||||||
@@ -146,9 +127,6 @@ public final class ChunkPacker {
|
|||||||
}
|
}
|
||||||
return PathingBlockType.AVOID;
|
return PathingBlockType.AVOID;
|
||||||
}
|
}
|
||||||
if (MovementHelper.possiblyFlowing(chunk.getBlockState(x + 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x - 1, y, z)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z + 1)) || MovementHelper.possiblyFlowing(chunk.getBlockState(x, y, z - 1))) {
|
|
||||||
return PathingBlockType.AVOID;
|
|
||||||
}
|
|
||||||
return PathingBlockType.WATER;
|
return PathingBlockType.WATER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -45,6 +46,8 @@ public class ContainerMemory implements IContainerMemory {
|
|||||||
this.saveTo = saveTo;
|
this.saveTo = saveTo;
|
||||||
try {
|
try {
|
||||||
read(Files.readAllBytes(saveTo));
|
read(Files.readAllBytes(saveTo));
|
||||||
|
} catch (NoSuchFileException ignored) {
|
||||||
|
inventories.clear();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
inventories.clear();
|
inventories.clear();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package baritone.cache;
|
|||||||
|
|
||||||
import baritone.api.cache.IWaypoint;
|
import baritone.api.cache.IWaypoint;
|
||||||
import baritone.api.cache.IWaypointCollection;
|
import baritone.api.cache.IWaypointCollection;
|
||||||
|
import baritone.api.cache.Waypoint;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ package baritone.cache;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.cache.IWorldProvider;
|
import baritone.api.cache.IWorldProvider;
|
||||||
import baritone.utils.Helper;
|
import baritone.api.utils.Helper;
|
||||||
import baritone.utils.accessor.IAnvilChunkLoader;
|
import baritone.utils.accessor.IAnvilChunkLoader;
|
||||||
import baritone.utils.accessor.IChunkProviderServer;
|
import baritone.utils.accessor.IChunkProviderServer;
|
||||||
import net.minecraft.server.integrated.IntegratedServer;
|
import net.minecraft.server.integrated.IntegratedServer;
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import baritone.api.event.events.*;
|
|||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.api.event.listener.IEventBus;
|
import baritone.api.event.listener.IEventBus;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import baritone.api.pathing.calc.IPath;
|
|||||||
import baritone.api.pathing.calc.IPathFinder;
|
import baritone.api.pathing.calc.IPathFinder;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.PathCalculationResult;
|
import baritone.api.utils.PathCalculationResult;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -186,7 +186,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Optional<IPath> bestSoFar(boolean logInfo, int numNodes) {
|
protected Optional<IPath> bestSoFar(boolean logInfo, int numNodes) {
|
||||||
if (startNode == null || bestSoFar == null) {
|
if (startNode == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
double bestDist = 0;
|
double bestDist = 0;
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ import baritone.api.pathing.calc.IPath;
|
|||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.movement.Moves;
|
import baritone.pathing.movement.Moves;
|
||||||
import baritone.pathing.path.CutoffPath;
|
import baritone.pathing.path.CutoffPath;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.pathing.PathBase;
|
import baritone.utils.pathing.PathBase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|||||||
@@ -17,18 +17,20 @@
|
|||||||
|
|
||||||
package baritone.pathing.movement;
|
package baritone.pathing.movement;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.utils.*;
|
import baritone.api.utils.*;
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import net.minecraft.entity.item.EntityFallingBlock;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class Movement implements IMovement, MovementHelper {
|
public abstract class Movement implements IMovement, MovementHelper {
|
||||||
@@ -139,6 +141,9 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
}
|
}
|
||||||
boolean somethingInTheWay = false;
|
boolean somethingInTheWay = false;
|
||||||
for (BetterBlockPos blockPos : positionsToBreak) {
|
for (BetterBlockPos blockPos : positionsToBreak) {
|
||||||
|
if (!ctx.world().getEntitiesWithinAABB(EntityFallingBlock.class, new AxisAlignedBB(0, 0, 0, 1, 1.1, 1).offset(blockPos)).isEmpty() && Baritone.settings().pauseMiningForFallingBlocks.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!MovementHelper.canWalkThrough(ctx, blockPos)) { // can't break air, so don't try
|
if (!MovementHelper.canWalkThrough(ctx, blockPos)) { // can't break air, so don't try
|
||||||
somethingInTheWay = true;
|
somethingInTheWay = true;
|
||||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
|
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
|
||||||
@@ -146,7 +151,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
Rotation rotTowardsBlock = reachable.get();
|
Rotation rotTowardsBlock = reachable.get();
|
||||||
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
||||||
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
|
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
|
||||||
if (Objects.equals(ctx.getSelectedBlock().orElse(null), blockPos) || ctx.playerRotations().isReallyCloseTo(rotTowardsBlock)) {
|
if (ctx.isLookingAt(blockPos) || ctx.playerRotations().isReallyCloseTo(rotTowardsBlock)) {
|
||||||
state.setInput(Input.CLICK_LEFT, true);
|
state.setInput(Input.CLICK_LEFT, true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -269,4 +274,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
}
|
}
|
||||||
return toWalkIntoCached;
|
return toWalkIntoCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockPos[] toBreakAll() {
|
||||||
|
return positionsToBreak;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import baritone.api.utils.*;
|
|||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import baritone.utils.ToolSet;
|
import baritone.utils.ToolSet;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -59,11 +58,27 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|
||||||
|| b instanceof BlockSilverfish // obvious reasons
|
|| b instanceof BlockSilverfish // obvious reasons
|
||||||
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
// call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason
|
||||||
|| !bsi.get0(x, y + 1, z).getFluidState().isEmpty()//don't break anything touching liquid on any side
|
|| avoidAdjacentBreaking(bsi, x, y + 1, z, true)
|
||||||
|| !bsi.get0(x + 1, y, z).getFluidState().isEmpty()
|
|| avoidAdjacentBreaking(bsi, x + 1, y, z, false)
|
||||||
|| !bsi.get0(x - 1, y, z).getFluidState().isEmpty()
|
|| avoidAdjacentBreaking(bsi, x - 1, y, z, false)
|
||||||
|| !bsi.get0(x, y, z + 1).getFluidState().isEmpty()
|
|| avoidAdjacentBreaking(bsi, x, y, z + 1, false)
|
||||||
|| !bsi.get0(x, y, z - 1).getFluidState().isEmpty();
|
|| avoidAdjacentBreaking(bsi, x, y, z - 1, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean avoidAdjacentBreaking(BlockStateInterface bsi, int x, int y, int z, boolean directlyAbove) {
|
||||||
|
// returns true if you should avoid breaking a block that's adjacent to this one (e.g. lava that will start flowing if you give it a path)
|
||||||
|
// this is only called for north, south, east, west, and up. this is NOT called for down.
|
||||||
|
// we assume that it's ALWAYS okay to break the block thats ABOVE liquid
|
||||||
|
IBlockState state = bsi.get0(x, y, z);
|
||||||
|
Block block = state.getBlock();
|
||||||
|
if (!directlyAbove // it is fine to mine a block that has a falling block directly above, this (the cost of breaking the stacked fallings) is included in cost calculations
|
||||||
|
// therefore if directlyAbove is true, we will actually ignore if this is falling
|
||||||
|
&& block instanceof BlockFalling // obviously, this check is only valid for falling blocks
|
||||||
|
&& Baritone.settings().avoidUpdatingFallingBlocks.value // and if the setting is enabled
|
||||||
|
&& BlockFalling.canFallThrough(bsi.get0(x, y - 1, z))) { // and if it would fall (i.e. it's unsupported)
|
||||||
|
return true; // dont break a block that is adjacent to unsupported gravel because it can cause really weird stuff
|
||||||
|
}
|
||||||
|
return !state.getFluidState().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {
|
static boolean canWalkThrough(IPlayerContext ctx, BetterBlockPos pos) {
|
||||||
@@ -82,6 +97,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
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 BlockSkull || block == Blocks.BUBBLE_COLUMN || block instanceof BlockShulkerBox || block instanceof BlockSlab || block instanceof BlockTrapDoor) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (Baritone.settings().blocksToAvoid.value.contains(block)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
|
||||||
// Because there's no nice method in vanilla to check if a door is openable or not, we just have to assume
|
// 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
|
// that anything that isn't an iron door isn't openable, ignoring that some doors introduced in mods can't
|
||||||
@@ -319,6 +337,10 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state);
|
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean canWalkOn(IPlayerContext ctx, BlockPos pos) {
|
||||||
|
return canWalkOn(new BlockStateInterface(ctx), pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) {
|
static boolean canWalkOn(IPlayerContext ctx, BetterBlockPos pos) {
|
||||||
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
return canWalkOn(new BlockStateInterface(ctx), pos.x, pos.y, pos.z);
|
||||||
}
|
}
|
||||||
@@ -353,6 +375,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (!canWalkThrough(context.bsi, x, y, z, state)) {
|
if (!canWalkThrough(context.bsi, x, y, z, state)) {
|
||||||
|
if (!state.getFluidState().isEmpty()) {
|
||||||
|
return COST_INF;
|
||||||
|
}
|
||||||
double mult = context.breakCostMultiplierAt(x, y, z);
|
double mult = context.breakCostMultiplierAt(x, y, z);
|
||||||
if (mult >= COST_INF) {
|
if (mult >= COST_INF) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
@@ -360,16 +385,11 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
if (avoidBreaking(context.bsi, x, y, z, state)) {
|
if (avoidBreaking(context.bsi, x, y, z, state)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (!state.getFluidState().isEmpty()) {
|
|
||||||
return COST_INF;
|
|
||||||
}
|
|
||||||
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
|
|
||||||
double strVsBlock = context.toolSet.getStrVsBlock(state);
|
double strVsBlock = context.toolSet.getStrVsBlock(state);
|
||||||
if (strVsBlock <= 0) {
|
if (strVsBlock <= 0) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
|
double result = 1 / strVsBlock;
|
||||||
double result = m / strVsBlock;
|
|
||||||
result += context.breakBlockAdditionalCost;
|
result += context.breakBlockAdditionalCost;
|
||||||
result *= mult;
|
result *= mult;
|
||||||
if (includeFalling) {
|
if (includeFalling) {
|
||||||
@@ -494,8 +514,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
for (int i = 0; i < 5; i++) {
|
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 (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
||||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
|
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 or cobble");
|
Helper.HELPER.logDebug("bb pls get me some blocks. dirt, netherrack, cobble");
|
||||||
state.setStatus(MovementStatus.UNREACHABLE);
|
state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
return PlaceResult.NO_OPTION;
|
return PlaceResult.NO_OPTION;
|
||||||
}
|
}
|
||||||
@@ -521,10 +541,15 @@ public interface MovementHelper extends ActionCosts, Helper {
|
|||||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||||
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
|
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
|
||||||
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
|
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
|
||||||
|
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||||
return PlaceResult.READY_TO_PLACE;
|
return PlaceResult.READY_TO_PLACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found ? PlaceResult.ATTEMPTING : PlaceResult.NO_OPTION;
|
if (found) {
|
||||||
|
((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, placeAt.getX(), placeAt.getY(), placeAt.getZ());
|
||||||
|
return PlaceResult.ATTEMPTING;
|
||||||
|
}
|
||||||
|
return PlaceResult.NO_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PlaceResult {
|
enum PlaceResult {
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class MovementAscend extends Movement {
|
|||||||
if (headBonkClear()) {
|
if (headBonkClear()) {
|
||||||
return state.setInput(Input.JUMP, true);
|
return state.setInput(Input.JUMP, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flatDistToNext > 1.2 || sideDist > 0.2) {
|
if (flatDistToNext > 1.2 || sideDist > 0.2) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import net.minecraft.init.Items;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
|
||||||
@@ -94,8 +93,7 @@ public class MovementFall extends Movement {
|
|||||||
|
|
||||||
targetRotation = new Rotation(toDest.getYaw(), 90.0F);
|
targetRotation = new Rotation(toDest.getYaw(), 90.0F);
|
||||||
|
|
||||||
RayTraceResult trace = ctx.objectMouseOver();
|
if (ctx.isLookingAt(dest) || ctx.isLookingAt(dest.down())) {
|
||||||
if (trace != null && trace.type == RayTraceResult.Type.BLOCK && (trace.getBlockPos().equals(dest) || trace.getBlockPos().equals(dest.down()))) {
|
|
||||||
state.setInput(Input.CLICK_RIGHT, true);
|
state.setInput(Input.CLICK_RIGHT, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,9 @@ public class MovementParkour extends Movement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i)) {
|
IBlockState landingOn = context.bsi.get0(x + xDiff * i, y - 1, z + zDiff * i);
|
||||||
|
// farmland needs to be canwalkon otherwise farm can never work at all, but we want to specifically disallow ending a jumy on farmland haha
|
||||||
|
if (landingOn.getBlock() != Blocks.FARMLAND && MovementHelper.canWalkOn(context.bsi, x + xDiff * i, y - 1, z + zDiff * i, landingOn)) {
|
||||||
res.x = x + xDiff * i;
|
res.x = x + xDiff * i;
|
||||||
res.y = y;
|
res.y = y;
|
||||||
res.z = z + zDiff * i;
|
res.z = z + zDiff * i;
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ public class MovementPillar extends Movement {
|
|||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
// Get ready to place a throwaway block
|
// Get ready to place a throwaway block
|
||||||
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(src.x, src.y, src.z)) {
|
if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(true, src.x, src.y, src.z)) {
|
||||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ import net.minecraft.state.properties.SlabType;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MovementTraverse extends Movement {
|
public class MovementTraverse extends Movement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,7 +231,11 @@ public class MovementTraverse extends Movement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isTheBridgeBlockThere) {
|
if (isTheBridgeBlockThere) {
|
||||||
if (ctx.playerFeet().equals(dest)) {
|
BetterBlockPos feet = ctx.playerFeet();
|
||||||
|
if (feet.equals(dest)) {
|
||||||
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
|
}
|
||||||
|
if (Baritone.settings().overshootTraverse.value && (feet.equals(dest.add(getDirection())) || feet.equals(dest.add(getDirection()).add(getDirection())))) {
|
||||||
return state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
}
|
}
|
||||||
Block low = BlockStateInterface.get(ctx, src).getBlock();
|
Block low = BlockStateInterface.get(ctx, src).getBlock();
|
||||||
@@ -249,12 +251,13 @@ public class MovementTraverse extends Movement {
|
|||||||
if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, ctx.playerFeet()) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
|
if (wasTheBridgeBlockAlwaysThere && (!MovementHelper.isLiquid(ctx, ctx.playerFeet()) || Baritone.settings().sprintInWater.value) && (!MovementHelper.avoidWalkingInto(intoBelow) || MovementHelper.isWater(intoBelow)) && !MovementHelper.avoidWalkingInto(intoAbove)) {
|
||||||
state.setInput(Input.SPRINT, true);
|
state.setInput(Input.SPRINT, true);
|
||||||
}
|
}
|
||||||
Block destDown = BlockStateInterface.get(ctx, dest.down()).getBlock();
|
|
||||||
if (whereAmI.getY() != dest.getY() && ladder && (destDown == Blocks.VINE || destDown == Blocks.LADDER)) {
|
IBlockState destDown = BlockStateInterface.get(ctx, dest.down());
|
||||||
new MovementPillar(baritone, dest.down(), dest).updateState(state); // i'm sorry
|
BlockPos against = positionsToBreak[0];
|
||||||
return state;
|
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());
|
||||||
}
|
}
|
||||||
MovementHelper.moveTowards(ctx, state, positionsToBreak[0]);
|
MovementHelper.moveTowards(ctx, state, against);
|
||||||
return state;
|
return state;
|
||||||
} else {
|
} else {
|
||||||
wasTheBridgeBlockAlwaysThere = false;
|
wasTheBridgeBlockAlwaysThere = false;
|
||||||
@@ -315,7 +318,7 @@ public class MovementTraverse extends Movement {
|
|||||||
} else {
|
} else {
|
||||||
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
||||||
}
|
}
|
||||||
if (Objects.equals(ctx.getSelectedBlock().orElse(null), goalLook)) {
|
if (ctx.isLookingAt(goalLook)) {
|
||||||
return state.setInput(Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
return state.setInput(Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
||||||
}
|
}
|
||||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ import baritone.api.pathing.movement.ActionCosts;
|
|||||||
import baritone.api.pathing.movement.IMovement;
|
import baritone.api.pathing.movement.IMovement;
|
||||||
import baritone.api.pathing.movement.MovementStatus;
|
import baritone.api.pathing.movement.MovementStatus;
|
||||||
import baritone.api.pathing.path.IPathExecutor;
|
import baritone.api.pathing.path.IPathExecutor;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.*;
|
||||||
import baritone.api.utils.IPlayerContext;
|
|
||||||
import baritone.api.utils.RotationUtils;
|
|
||||||
import baritone.api.utils.VecUtils;
|
|
||||||
import baritone.api.utils.input.Input;
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.behavior.PathingBehavior;
|
import baritone.behavior.PathingBehavior;
|
||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
@@ -35,9 +32,7 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.movements.*;
|
import baritone.pathing.movement.movements.*;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.init.Fluids;
|
|
||||||
import net.minecraft.util.Tuple;
|
import net.minecraft.util.Tuple;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
@@ -441,7 +436,10 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
IMovement prev = path.movements().get(pathPosition - 1);
|
IMovement prev = path.movements().get(pathPosition - 1);
|
||||||
if (prev instanceof MovementDescend && prev.getDirection().up().equals(current.getDirection().down())) {
|
if (prev instanceof MovementDescend && prev.getDirection().up().equals(current.getDirection().down())) {
|
||||||
BlockPos center = current.getSrc().up();
|
BlockPos center = current.getSrc().up();
|
||||||
if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand
|
// playerFeet adds 0.1251 to account for soul sand
|
||||||
|
// farmland is 0.9375
|
||||||
|
// 0.07 is to account for farmland
|
||||||
|
if (ctx.player().posY >= center.getY() - 0.07) {
|
||||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
|
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -566,7 +564,10 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) {
|
if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection()) && MovementHelper.canWalkOn(ctx, next.getDest().down())) {
|
if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.value;
|
return next instanceof MovementDiagonal && Baritone.settings().allowOvershootDiagonalDescend.value;
|
||||||
@@ -608,7 +609,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
ret.costEstimateIndex = costEstimateIndex;
|
ret.costEstimateIndex = costEstimateIndex;
|
||||||
ret.ticksOnCurrent = ticksOnCurrent;
|
ret.ticksOnCurrent = ticksOnCurrent;
|
||||||
return ret;
|
return ret;
|
||||||
}).orElse(cutIfTooLong());
|
}).orElseGet(this::cutIfTooLong); // dont actually call cutIfTooLong every tick if we won't actually use it, use a method reference
|
||||||
}
|
}
|
||||||
|
|
||||||
private PathExecutor cutIfTooLong() {
|
private PathExecutor cutIfTooLong() {
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.process;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.process.PathingCommand;
|
||||||
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.api.utils.input.Input;
|
||||||
|
import baritone.pathing.movement.Movement;
|
||||||
|
import baritone.pathing.movement.MovementHelper;
|
||||||
|
import baritone.pathing.movement.MovementState;
|
||||||
|
import baritone.pathing.path.PathExecutor;
|
||||||
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class BackfillProcess extends BaritoneProcessHelper {
|
||||||
|
|
||||||
|
public HashMap<BlockPos, IBlockState> blocksToReplace = new HashMap<>();
|
||||||
|
|
||||||
|
public BackfillProcess(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
if (ctx.player() == null || ctx.world() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Baritone.settings().backfill.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Baritone.settings().allowParkour.value) {
|
||||||
|
logDirect("Backfill cannot be used with allowParkour true");
|
||||||
|
Baritone.settings().backfill.value = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
amIBreakingABlockHMMMMMMM();
|
||||||
|
for (BlockPos pos : new ArrayList<>(blocksToReplace.keySet())) {
|
||||||
|
if (ctx.world().getChunk(pos) instanceof EmptyChunk) {
|
||||||
|
blocksToReplace.remove(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
|
||||||
|
return !toFillIn().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||||
|
if (!isSafeToCancel) {
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
for (BlockPos toPlace : toFillIn()) {
|
||||||
|
MovementState fake = new MovementState();
|
||||||
|
switch (MovementHelper.attemptToPlaceABlock(fake, baritone, toPlace, false)) {
|
||||||
|
case NO_OPTION:
|
||||||
|
continue;
|
||||||
|
case READY_TO_PLACE:
|
||||||
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
case ATTEMPTING:
|
||||||
|
// patience
|
||||||
|
baritone.getLookBehavior().updateTarget(fake.getTarget().getRotation().get(), true);
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PathingCommand(null, PathingCommandType.DEFER); // cede to other process
|
||||||
|
}
|
||||||
|
|
||||||
|
public void amIBreakingABlockHMMMMMMM() {
|
||||||
|
if (!ctx.getSelectedBlock().isPresent()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
blocksToReplace.put(ctx.getSelectedBlock().get(), ctx.world().getBlockState(ctx.getSelectedBlock().get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlockPos> toFillIn() {
|
||||||
|
return blocksToReplace
|
||||||
|
.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(pos -> ctx.world().getBlockState(pos).getBlock() == Blocks.AIR)
|
||||||
|
.filter(pos -> baritone.getBuilderProcess().placementPlausible(pos, Blocks.DIRT.getDefaultState()))
|
||||||
|
.filter(pos -> !partOfCurrentMovement(pos))
|
||||||
|
.sorted(Comparator.<BlockPos>comparingDouble(ctx.player()::getDistanceSq).reversed())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean partOfCurrentMovement(BlockPos pos) {
|
||||||
|
PathExecutor exec = baritone.getPathingBehavior().getCurrent();
|
||||||
|
if (exec == null || exec.finished() || exec.failed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Movement movement = (Movement) exec.getPath().movements().get(exec.getPosition());
|
||||||
|
return Arrays.asList(movement.toBreakAll()).contains(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLostControl() {
|
||||||
|
if (blocksToReplace != null && !blocksToReplace.isEmpty()) {
|
||||||
|
blocksToReplace.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName0() {
|
||||||
|
return "Backfill";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTemporary() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double priority() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,9 +35,10 @@ import baritone.utils.BlockStateInterface;
|
|||||||
import baritone.utils.PathingCommandContext;
|
import baritone.utils.PathingCommandContext;
|
||||||
import baritone.utils.schematic.AirSchematic;
|
import baritone.utils.schematic.AirSchematic;
|
||||||
import baritone.utils.schematic.Schematic;
|
import baritone.utils.schematic.Schematic;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
import net.minecraft.block.BlockAir;
|
import net.minecraft.block.BlockAir;
|
||||||
|
import net.minecraft.block.BlockFlowingFluid;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.BlockItemUseContext;
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
@@ -54,13 +55,13 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||||
|
|
||||||
public class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
|
public class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess {
|
||||||
|
|
||||||
private HashSet<BetterBlockPos> incorrectPositions;
|
private HashSet<BetterBlockPos> incorrectPositions;
|
||||||
|
private LongOpenHashSet observedCompleted; // positions that are completed even if they're out of render distance and we can't make sure right now
|
||||||
private String name;
|
private String name;
|
||||||
private ISchematic realSchematic;
|
private ISchematic realSchematic;
|
||||||
private ISchematic schematic;
|
private ISchematic schematic;
|
||||||
@@ -73,12 +74,6 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
super(baritone);
|
super(baritone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean build(String schematicFile, BlockPos origin) {
|
|
||||||
File file = new File(new File(Minecraft.getInstance().gameDir, "schematics"), schematicFile);
|
|
||||||
System.out.println(file + " " + file.exists());
|
|
||||||
return build(schematicFile, file, origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(String name, ISchematic schematic, Vec3i origin) {
|
public void build(String name, ISchematic schematic, Vec3i origin) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -87,12 +82,17 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
this.layer = 0;
|
this.layer = 0;
|
||||||
|
this.observedCompleted = new LongOpenHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pause() {
|
||||||
|
paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean build(String name, File schematic, Vec3i origin) {
|
public boolean build(String name, File schematic, Vec3i origin) {
|
||||||
NBTTagCompound tag;
|
NBTTagCompound tag;
|
||||||
@@ -140,15 +140,18 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
|
||||||
public Optional<Tuple<BetterBlockPos, Rotation>> toBreakNearPlayer(BuilderCalculationContext bcc) {
|
|
||||||
BetterBlockPos center = ctx.playerFeet();
|
BetterBlockPos center = ctx.playerFeet();
|
||||||
|
BetterBlockPos pathStart = baritone.getPathingBehavior().pathStart();
|
||||||
for (int dx = -5; dx <= 5; dx++) {
|
for (int dx = -5; dx <= 5; dx++) {
|
||||||
for (int dy = 0; dy <= 5; dy++) {
|
for (int dy = Baritone.settings().breakFromAbove.value ? -1 : 0; dy <= 5; dy++) {
|
||||||
for (int dz = -5; dz <= 5; dz++) {
|
for (int dz = -5; dz <= 5; dz++) {
|
||||||
int x = center.x + dx;
|
int x = center.x + dx;
|
||||||
int y = center.y + dy;
|
int y = center.y + dy;
|
||||||
int z = center.z + dz;
|
int z = center.z + dz;
|
||||||
|
if (dy == -1 && x == pathStart.x && z == pathStart.z) {
|
||||||
|
continue; // dont mine what we're supported by, but not directly standing on
|
||||||
|
}
|
||||||
IBlockState desired = bcc.getSchematic(x, y, z);
|
IBlockState desired = bcc.getSchematic(x, y, z);
|
||||||
if (desired == null) {
|
if (desired == null) {
|
||||||
continue; // irrelevant
|
continue; // irrelevant
|
||||||
@@ -181,7 +184,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
|
private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
|
||||||
BetterBlockPos center = ctx.playerFeet();
|
BetterBlockPos center = ctx.playerFeet();
|
||||||
for (int dx = -5; dx <= 5; dx++) {
|
for (int dx = -5; dx <= 5; dx++) {
|
||||||
for (int dy = -5; dy <= 1; dy++) {
|
for (int dy = -5; dy <= 1; dy++) {
|
||||||
@@ -215,7 +218,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return voxelshape.isEmpty() || ctx.world().checkNoEntityCollision(null, voxelshape.withOffset(pos.getX(), pos.getY(), pos.getZ()));
|
return voxelshape.isEmpty() || ctx.world().checkNoEntityCollision(null, voxelshape.withOffset(pos.getX(), pos.getY(), pos.getZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
|
private Optional<Placement> possibleToPlace(IBlockState toPlace, int x, int y, int z, BlockStateInterface bsi) {
|
||||||
for (EnumFacing against : EnumFacing.values()) {
|
for (EnumFacing against : EnumFacing.values()) {
|
||||||
BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
|
BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
|
||||||
IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
|
IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
|
||||||
@@ -246,8 +249,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OptionalInt hasAnyItemThatWouldPlace(IBlockState desired, RayTraceResult result, Rotation rot) {
|
||||||
public OptionalInt hasAnyItemThatWouldPlace(IBlockState desired, RayTraceResult result, Rotation rot) {
|
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
|
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
|
||||||
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
|
if (stack.isEmpty() || !(stack.getItem() instanceof ItemBlock)) {
|
||||||
@@ -310,18 +312,35 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
}
|
}
|
||||||
baritone.getInputOverrideHandler().clearAllKeys();
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
if (paused) {
|
if (paused) {
|
||||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||||
}
|
}
|
||||||
if (Baritone.settings().buildInLayers.value) {
|
if (Baritone.settings().buildInLayers.value) {
|
||||||
if (realSchematic == null) {
|
if (realSchematic == null) {
|
||||||
realSchematic = schematic;
|
realSchematic = schematic;
|
||||||
}
|
}
|
||||||
|
ISchematic realSchematic = this.realSchematic; // wrap this properly, dont just have the inner class refer to the builderprocess.this
|
||||||
|
int minYInclusive;
|
||||||
|
int maxYInclusive;
|
||||||
|
// layer = 0 should be nothing
|
||||||
|
// layer = realSchematic.heightY() should be everything
|
||||||
|
if (Baritone.settings().layerOrder.value) { // top to bottom
|
||||||
|
maxYInclusive = realSchematic.heightY() - 1;
|
||||||
|
minYInclusive = realSchematic.heightY() - layer;
|
||||||
|
} else {
|
||||||
|
maxYInclusive = layer - 1;
|
||||||
|
minYInclusive = 0;
|
||||||
|
}
|
||||||
schematic = new ISchematic() {
|
schematic = new ISchematic() {
|
||||||
@Override
|
@Override
|
||||||
public IBlockState desiredState(int x, int y, int z) {
|
public IBlockState desiredState(int x, int y, int z) {
|
||||||
return realSchematic.desiredState(x, y, z);
|
return realSchematic.desiredState(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inSchematic(int x, int y, int z) {
|
||||||
|
return ISchematic.super.inSchematic(x, y, z) && y >= minYInclusive && y <= maxYInclusive;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int widthX() {
|
public int widthX() {
|
||||||
return realSchematic.widthX();
|
return realSchematic.widthX();
|
||||||
@@ -329,7 +348,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int heightY() {
|
public int heightY() {
|
||||||
return layer;
|
return realSchematic.heightY();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -345,20 +364,17 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
layer++;
|
layer++;
|
||||||
return onTick(calcFailed, isSafeToCancel);
|
return onTick(calcFailed, isSafeToCancel);
|
||||||
}
|
}
|
||||||
int distance = Baritone.settings().buildRepeatDistance.value;
|
Vec3i repeat = Baritone.settings().buildRepeat.value;
|
||||||
EnumFacing direction = Baritone.settings().buildRepeatDirection.value;
|
if (repeat.equals(new Vec3i(0, 0, 0))) {
|
||||||
if (distance == 0) {
|
|
||||||
logDirect("Done building");
|
logDirect("Done building");
|
||||||
onLostControl();
|
onLostControl();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// build repeat time
|
// build repeat time
|
||||||
if (distance == -1) {
|
|
||||||
distance = schematic.size(direction.getAxis());
|
|
||||||
}
|
|
||||||
layer = 0;
|
layer = 0;
|
||||||
origin = new BlockPos(origin).offset(direction, distance);
|
origin = new BlockPos(origin).add(repeat);
|
||||||
logDirect("Repeating build " + distance + " blocks to the " + direction + ", new origin is " + origin);
|
logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
|
||||||
|
return onTick(calcFailed, isSafeToCancel);
|
||||||
}
|
}
|
||||||
trim(bcc);
|
trim(bcc);
|
||||||
|
|
||||||
@@ -376,10 +392,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
// and is unable since it's unsneaked in the intermediary tick
|
// and is unable since it's unsneaked in the intermediary tick
|
||||||
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
|
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
|
||||||
}
|
}
|
||||||
if (Objects.equals(ctx.objectMouseOver().getBlockPos(), pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
||||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
||||||
}
|
}
|
||||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||||
}
|
}
|
||||||
List<IBlockState> desirableOnHotbar = new ArrayList<>();
|
List<IBlockState> desirableOnHotbar = new ArrayList<>();
|
||||||
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
|
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
|
||||||
@@ -388,10 +404,10 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
baritone.getLookBehavior().updateTarget(rot, true);
|
baritone.getLookBehavior().updateTarget(rot, true);
|
||||||
ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
|
ctx.player().inventory.currentItem = toPlace.get().hotbarSelection;
|
||||||
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
|
baritone.getInputOverrideHandler().setInputForceState(Input.SNEAK, true);
|
||||||
if ((Objects.equals(ctx.objectMouseOver().getBlockPos(), toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
if ((ctx.isLookingAt(toPlace.get().placeAgainst) && ctx.objectMouseOver().sideHit.equals(toPlace.get().side)) || ctx.playerRotations().isReallyCloseTo(rot)) {
|
||||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||||
}
|
}
|
||||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<IBlockState> approxPlacable = placable(36);
|
List<IBlockState> approxPlacable = placable(36);
|
||||||
@@ -433,7 +449,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
|
return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean recalc(BuilderCalculationContext bcc) {
|
private boolean recalc(BuilderCalculationContext bcc) {
|
||||||
if (incorrectPositions == null) {
|
if (incorrectPositions == null) {
|
||||||
incorrectPositions = new HashSet<>();
|
incorrectPositions = new HashSet<>();
|
||||||
fullRecalc(bcc);
|
fullRecalc(bcc);
|
||||||
@@ -448,7 +464,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return !incorrectPositions.isEmpty();
|
return !incorrectPositions.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trim(BuilderCalculationContext bcc) {
|
private void trim(BuilderCalculationContext bcc) {
|
||||||
HashSet<BetterBlockPos> copy = new HashSet<>(incorrectPositions);
|
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(ctx.player().posX, ctx.player().posY, ctx.player().posZ) > 200);
|
||||||
if (!copy.isEmpty()) {
|
if (!copy.isEmpty()) {
|
||||||
@@ -456,7 +472,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recalcNearby(BuilderCalculationContext bcc) {
|
private void recalcNearby(BuilderCalculationContext bcc) {
|
||||||
BetterBlockPos center = ctx.playerFeet();
|
BetterBlockPos center = ctx.playerFeet();
|
||||||
for (int dx = -5; dx <= 5; dx++) {
|
for (int dx = -5; dx <= 5; dx++) {
|
||||||
for (int dy = -5; dy <= 5; dy++) {
|
for (int dy = -5; dy <= 5; dy++) {
|
||||||
@@ -467,10 +483,13 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
IBlockState desired = bcc.getSchematic(x, y, z);
|
IBlockState desired = bcc.getSchematic(x, y, z);
|
||||||
if (desired != null) {
|
if (desired != null) {
|
||||||
// we care about this position
|
// we care about this position
|
||||||
|
BetterBlockPos pos = new BetterBlockPos(x, y, z);
|
||||||
if (valid(bcc.bsi.get0(x, y, z), desired)) {
|
if (valid(bcc.bsi.get0(x, y, z), desired)) {
|
||||||
incorrectPositions.remove(new BetterBlockPos(x, y, z));
|
incorrectPositions.remove(pos);
|
||||||
|
observedCompleted.add(BetterBlockPos.longHash(pos));
|
||||||
} else {
|
} else {
|
||||||
incorrectPositions.add(new BetterBlockPos(x, y, z));
|
incorrectPositions.add(pos);
|
||||||
|
observedCompleted.remove(BetterBlockPos.longHash(pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,13 +497,32 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fullRecalc(BuilderCalculationContext bcc) {
|
private void fullRecalc(BuilderCalculationContext bcc) {
|
||||||
incorrectPositions = new HashSet<>();
|
incorrectPositions = new HashSet<>();
|
||||||
for (int y = 0; y < schematic.heightY(); y++) {
|
for (int y = 0; y < schematic.heightY(); y++) {
|
||||||
for (int z = 0; z < schematic.lengthZ(); z++) {
|
for (int z = 0; z < schematic.lengthZ(); z++) {
|
||||||
for (int x = 0; x < schematic.widthX(); x++) {
|
for (int x = 0; x < schematic.widthX(); x++) {
|
||||||
if (schematic.inSchematic(x, y, z) && !valid(bcc.bsi.get0(x + origin.getX(), y + origin.getY(), z + origin.getZ()), schematic.desiredState(x, y, z))) {
|
if (!schematic.inSchematic(x, y, z)) {
|
||||||
incorrectPositions.add(new BetterBlockPos(x + origin.getX(), y + origin.getY(), z + origin.getZ()));
|
continue;
|
||||||
|
}
|
||||||
|
int blockX = x + origin.getX();
|
||||||
|
int blockY = y + origin.getY();
|
||||||
|
int blockZ = z + origin.getZ();
|
||||||
|
if (bcc.bsi.worldContainsLoadedChunk(blockX, blockZ)) { // check if its in render distance, not if its in cache
|
||||||
|
// we can directly observe this block, it is in render distance
|
||||||
|
if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z))) {
|
||||||
|
observedCompleted.add(BetterBlockPos.longHash(blockX, blockY, blockZ));
|
||||||
|
} else {
|
||||||
|
incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
|
||||||
|
observedCompleted.remove(BetterBlockPos.longHash(blockX, blockY, blockZ));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// this is not in render distance
|
||||||
|
if (!observedCompleted.contains(BetterBlockPos.longHash(blockX, blockY, blockZ))) {
|
||||||
|
// and we've never seen this position be correct
|
||||||
|
// therefore mark as incorrect
|
||||||
|
incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -492,17 +530,45 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlacable) {
|
private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlacable) {
|
||||||
List<BetterBlockPos> placable = incorrectPositions.stream().filter(pos -> bcc.bsi.get0(pos).getBlock() instanceof BlockAir && approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))).collect(Collectors.toList());
|
List<BetterBlockPos> placable = new ArrayList<>();
|
||||||
Goal[] toBreak = incorrectPositions.stream().filter(pos -> !(bcc.bsi.get0(pos).getBlock() instanceof BlockAir)).map(GoalBreak::new).toArray(Goal[]::new);
|
List<BetterBlockPos> breakable = new ArrayList<>();
|
||||||
Goal[] toPlace = placable.stream().filter(pos -> !placable.contains(pos.down()) && !placable.contains(pos.down(2))).map(pos -> placementgoal(pos, bcc)).toArray(Goal[]::new);
|
List<BetterBlockPos> sourceLiquids = new ArrayList<>();
|
||||||
|
incorrectPositions.forEach(pos -> {
|
||||||
|
IBlockState state = bcc.bsi.get0(pos);
|
||||||
|
if (state.getBlock() instanceof BlockAir) {
|
||||||
|
if (approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z))) {
|
||||||
|
placable.add(pos);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (state.getBlock() instanceof BlockFlowingFluid) {
|
||||||
|
// if the block itself is JUST a liquid (i.e. not just a waterlogged block), we CANNOT break it
|
||||||
|
// TODO for 1.13 make sure that this only matches pure water, not waterlogged blocks
|
||||||
|
if (!MovementHelper.possiblyFlowing(state)) {
|
||||||
|
// if it's a source block then we want to replace it with a throwaway
|
||||||
|
sourceLiquids.add(pos);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
breakable.add(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
List<Goal> toBreak = new ArrayList<>();
|
||||||
|
breakable.forEach(pos -> toBreak.add(breakGoal(pos, bcc)));
|
||||||
|
List<Goal> toPlace = new ArrayList<>();
|
||||||
|
placable.forEach(pos -> {
|
||||||
|
if (!placable.contains(pos.down()) && !placable.contains(pos.down(2))) {
|
||||||
|
toPlace.add(placementGoal(pos, bcc));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sourceLiquids.forEach(pos -> toPlace.add(new GoalBlock(pos.up())));
|
||||||
|
|
||||||
if (toPlace.length != 0) {
|
if (!toPlace.isEmpty()) {
|
||||||
return new JankyGoalComposite(new GoalComposite(toPlace), new GoalComposite(toBreak));
|
return new JankyGoalComposite(new GoalComposite(toPlace.toArray(new Goal[0])), new GoalComposite(toBreak.toArray(new Goal[0])));
|
||||||
}
|
}
|
||||||
if (toBreak.length == 0) {
|
if (toBreak.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new GoalComposite(toBreak);
|
return new GoalComposite(toBreak.toArray(new Goal[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class JankyGoalComposite implements Goal {
|
public static class JankyGoalComposite implements Goal {
|
||||||
@@ -548,8 +614,8 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Goal placementgoal(BlockPos pos, BuilderCalculationContext bcc) {
|
private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) {
|
||||||
if (!(ctx.world().getBlockState(pos).getBlock() instanceof BlockAir)) {
|
if (!(ctx.world().getBlockState(pos).getBlock() instanceof BlockAir)) { // TODO can this even happen?
|
||||||
return new GoalPlace(pos);
|
return new GoalPlace(pos);
|
||||||
}
|
}
|
||||||
boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir);
|
boolean allowSameLevel = !(ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir);
|
||||||
@@ -561,6 +627,21 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return new GoalPlace(pos);
|
return new GoalPlace(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Goal breakGoal(BlockPos pos, BuilderCalculationContext bcc) {
|
||||||
|
if (Baritone.settings().goalBreakFromAbove.value && bcc.bsi.get0(pos.up()).getBlock() instanceof BlockAir && bcc.bsi.get0(pos.up(2)).getBlock() instanceof BlockAir) { // TODO maybe possible without the up(2) check?
|
||||||
|
return new JankyGoalComposite(new GoalBreak(pos), new GoalGetToBlock(pos.up()) {
|
||||||
|
@Override
|
||||||
|
public boolean isInGoal(int x, int y, int z) {
|
||||||
|
if (y > this.y || (x == this.x && y == this.y && z == this.z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.isInGoal(x, y, z);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return new GoalBreak(pos);
|
||||||
|
}
|
||||||
|
|
||||||
public static class GoalAdjacent extends GoalGetToBlock {
|
public static class GoalAdjacent extends GoalGetToBlock {
|
||||||
private boolean allowSameLevel;
|
private boolean allowSameLevel;
|
||||||
|
|
||||||
@@ -607,6 +688,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
realSchematic = null;
|
realSchematic = null;
|
||||||
layer = 0;
|
layer = 0;
|
||||||
paused = false;
|
paused = false;
|
||||||
|
observedCompleted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -614,7 +696,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return paused ? "Builder Paused" : "Building " + name;
|
return paused ? "Builder Paused" : "Building " + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IBlockState> placable(int size) {
|
private List<IBlockState> placable(int size) {
|
||||||
List<IBlockState> result = new ArrayList<>();
|
List<IBlockState> result = new ArrayList<>();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
|
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
|
||||||
@@ -629,7 +711,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean valid(IBlockState current, IBlockState desired) {
|
private boolean valid(IBlockState current, IBlockState desired) {
|
||||||
if (desired == null) {
|
if (desired == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,33 @@ import baritone.api.cache.ICachedWorld;
|
|||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.goals.GoalComposite;
|
import baritone.api.pathing.goals.GoalComposite;
|
||||||
import baritone.api.pathing.goals.GoalXZ;
|
import baritone.api.pathing.goals.GoalXZ;
|
||||||
|
import baritone.api.pathing.goals.GoalYLevel;
|
||||||
|
import baritone.api.process.IExploreProcess;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.process.PathingCommandType;
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.api.utils.MyChunkPos;
|
||||||
import baritone.cache.CachedWorld;
|
import baritone.cache.CachedWorld;
|
||||||
import baritone.utils.BaritoneProcessHelper;
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ExploreProcess extends BaritoneProcessHelper {
|
public class ExploreProcess extends BaritoneProcessHelper implements IExploreProcess {
|
||||||
|
|
||||||
private BlockPos explorationOrigin;
|
private BlockPos explorationOrigin;
|
||||||
|
|
||||||
|
private IChunkFilter filter;
|
||||||
|
|
||||||
|
private int distanceCompleted;
|
||||||
|
|
||||||
public ExploreProcess(Baritone baritone) {
|
public ExploreProcess(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone);
|
||||||
}
|
}
|
||||||
@@ -44,8 +58,25 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
|||||||
return explorationOrigin != null;
|
return explorationOrigin != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void explore(int centerX, int centerZ) {
|
public void explore(int centerX, int centerZ) {
|
||||||
explorationOrigin = new BlockPos(centerX, 0, centerZ);
|
explorationOrigin = new BlockPos(centerX, 0, centerZ);
|
||||||
|
distanceCompleted = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyJsonFilter(Path path, boolean invert) throws Exception {
|
||||||
|
filter = new JsonChunkFilter(path, invert);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IChunkFilter calcFilter() {
|
||||||
|
IChunkFilter filter;
|
||||||
|
if (this.filter != null) {
|
||||||
|
filter = new EitherChunk(this.filter, new BaritoneChunkCache());
|
||||||
|
} else {
|
||||||
|
filter = new BaritoneChunkCache();
|
||||||
|
}
|
||||||
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -55,45 +86,192 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
|||||||
onLostControl();
|
onLostControl();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Goal[] closestUncached = closestUncachedChunks(explorationOrigin);
|
IChunkFilter filter = calcFilter();
|
||||||
|
if (!Baritone.settings().disableCompletionCheck.value && filter.countRemain() == 0) {
|
||||||
|
logDirect("Explored all chunks");
|
||||||
|
onLostControl();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Goal[] closestUncached = closestUncachedChunks(explorationOrigin, filter);
|
||||||
if (closestUncached == null) {
|
if (closestUncached == null) {
|
||||||
logDebug("awaiting region load from disk");
|
logDebug("awaiting region load from disk");
|
||||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
}
|
}
|
||||||
System.out.println("Closest uncached: " + closestUncached);
|
|
||||||
return new PathingCommand(new GoalComposite(closestUncached), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
|
return new PathingCommand(new GoalComposite(closestUncached), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Goal[] closestUncachedChunks(BlockPos center) {
|
private Goal[] closestUncachedChunks(BlockPos center, IChunkFilter filter) {
|
||||||
int chunkX = center.getX() >> 4;
|
int chunkX = center.getX() >> 4;
|
||||||
int chunkZ = center.getZ() >> 4;
|
int chunkZ = center.getZ() >> 4;
|
||||||
ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
int count = Math.min(filter.countRemain(), Baritone.settings().exploreChunkSetMinimumSize.value);
|
||||||
for (int dist = 0; ; dist++) {
|
List<BlockPos> centers = new ArrayList<>();
|
||||||
List<BlockPos> centers = new ArrayList<>();
|
int renderDistance = Baritone.settings().worldExploringChunkOffset.value;
|
||||||
|
for (int dist = distanceCompleted; ; dist++) {
|
||||||
for (int dx = -dist; dx <= dist; dx++) {
|
for (int dx = -dist; dx <= dist; dx++) {
|
||||||
for (int dz = -dist; dz <= dist; dz++) {
|
int zval = dist - Math.abs(dx);
|
||||||
int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz * dz : Math.abs(dx) + Math.abs(dz);
|
for (int mult = 0; mult < 2; mult++) {
|
||||||
|
int dz = (mult * 2 - 1) * zval; // dz can be either -zval or zval
|
||||||
|
int trueDist = Math.abs(dx) + Math.abs(dz);
|
||||||
if (trueDist != dist) {
|
if (trueDist != dist) {
|
||||||
continue; // not considering this one just yet in our expanding search
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
int centerX = (chunkX + dx) * 16 + 8;
|
switch (filter.isAlreadyExplored(chunkX + dx, chunkZ + dz)) {
|
||||||
int centerZ = (chunkZ + dz) * 18 + 8;
|
case UNKNOWN:
|
||||||
|
return null; // awaiting load
|
||||||
if (cache.isCached(centerX, centerZ)) {
|
case NOT_EXPLORED:
|
||||||
continue;
|
break; // note: this breaks the switch not the for
|
||||||
|
case EXPLORED:
|
||||||
|
continue; // note: this continues the for
|
||||||
}
|
}
|
||||||
if (!((CachedWorld) cache).regionLoaded(centerX, centerZ)) {
|
int centerX = ((chunkX + dx) << 4) + 8;
|
||||||
Baritone.getExecutor().execute(() -> {
|
int centerZ = ((chunkZ + dz) << 4) + 8;
|
||||||
((CachedWorld) cache).tryLoadFromDisk(centerX >> 9, centerZ >> 9);
|
int offset = renderDistance << 4;
|
||||||
});
|
if (dx < 0) {
|
||||||
return null; // we still need to load regions from disk in order to decide properly
|
centerX -= offset;
|
||||||
|
} else {
|
||||||
|
centerX += offset;
|
||||||
|
}
|
||||||
|
if (dz < 0) {
|
||||||
|
centerZ -= offset;
|
||||||
|
} else {
|
||||||
|
centerZ += offset;
|
||||||
}
|
}
|
||||||
centers.add(new BlockPos(centerX, 0, centerZ));
|
centers.add(new BlockPos(centerX, 0, centerZ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!centers.isEmpty()) {
|
if (centers.size() >= count) {
|
||||||
return centers.stream().map(pos -> new GoalXZ(pos.getX(), pos.getZ())).toArray(Goal[]::new);
|
return centers.stream().map(pos -> createGoal(pos.getX(), pos.getZ())).toArray(Goal[]::new);
|
||||||
}
|
}
|
||||||
|
if (centers.isEmpty()) {
|
||||||
|
// we have explored everything from 0 to dist inclusive
|
||||||
|
// next time we should start our check at dist+1
|
||||||
|
distanceCompleted = dist + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Goal createGoal(int x, int z) {
|
||||||
|
if (Baritone.settings().exploreMaintainY.value == -1) {
|
||||||
|
return new GoalXZ(x, z);
|
||||||
|
}
|
||||||
|
// don't use a goalblock because we still want isInGoal to return true if X and Z are correct
|
||||||
|
// we just want to try and maintain Y on the way there, not necessarily end at that specific Y
|
||||||
|
return new GoalXZ(x, z) {
|
||||||
|
@Override
|
||||||
|
public double heuristic(int x, int y, int z) {
|
||||||
|
return super.heuristic(x, y, z) + GoalYLevel.calculate(Baritone.settings().exploreMaintainY.value, y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Status {
|
||||||
|
EXPLORED, NOT_EXPLORED, UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface IChunkFilter {
|
||||||
|
Status isAlreadyExplored(int chunkX, int chunkZ);
|
||||||
|
|
||||||
|
int countRemain();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class BaritoneChunkCache implements IChunkFilter {
|
||||||
|
|
||||||
|
private final ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status isAlreadyExplored(int chunkX, int chunkZ) {
|
||||||
|
int centerX = chunkX << 4;
|
||||||
|
int centerZ = chunkZ << 4;
|
||||||
|
if (cache.isCached(centerX, centerZ)) {
|
||||||
|
return Status.EXPLORED;
|
||||||
|
}
|
||||||
|
if (!((CachedWorld) cache).regionLoaded(centerX, centerZ)) {
|
||||||
|
Baritone.getExecutor().execute(() -> {
|
||||||
|
((CachedWorld) cache).tryLoadFromDisk(centerX >> 9, centerZ >> 9);
|
||||||
|
});
|
||||||
|
return Status.UNKNOWN; // we still need to load regions from disk in order to decide properly
|
||||||
|
}
|
||||||
|
return Status.NOT_EXPLORED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countRemain() {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class JsonChunkFilter implements IChunkFilter {
|
||||||
|
private final boolean invert; // if true, the list is interpreted as a list of chunks that are NOT explored, if false, the list is interpreted as a list of chunks that ARE explored
|
||||||
|
private final LongOpenHashSet inFilter;
|
||||||
|
private final MyChunkPos[] positions;
|
||||||
|
|
||||||
|
private JsonChunkFilter(Path path, boolean invert) throws Exception { // ioexception, json exception, etc
|
||||||
|
this.invert = invert;
|
||||||
|
Gson gson = new GsonBuilder().create();
|
||||||
|
positions = gson.fromJson(new InputStreamReader(Files.newInputStream(path)), MyChunkPos[].class);
|
||||||
|
logDirect("Loaded " + positions.length + " positions");
|
||||||
|
inFilter = new LongOpenHashSet();
|
||||||
|
for (MyChunkPos mcp : positions) {
|
||||||
|
inFilter.add(ChunkPos.asLong(mcp.x, mcp.z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status isAlreadyExplored(int chunkX, int chunkZ) {
|
||||||
|
if (inFilter.contains(ChunkPos.asLong(chunkX, chunkZ)) ^ invert) {
|
||||||
|
// either it's on the list of explored chunks, or it's not on the list of unexplored chunks
|
||||||
|
// either way, we have it
|
||||||
|
return Status.EXPLORED;
|
||||||
|
} else {
|
||||||
|
// either it's not on the list of explored chunks, or it's on the list of unexplored chunks
|
||||||
|
// either way, it depends on if baritone has cached it so defer to that
|
||||||
|
return Status.UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countRemain() {
|
||||||
|
if (!invert) {
|
||||||
|
// if invert is false, anything not on the list is uncached
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
// but if invert is true, anything not on the list IS assumed cached
|
||||||
|
// so we are done if everything on our list is cached!
|
||||||
|
int countRemain = 0;
|
||||||
|
BaritoneChunkCache bcc = new BaritoneChunkCache();
|
||||||
|
for (MyChunkPos pos : positions) {
|
||||||
|
if (bcc.isAlreadyExplored(pos.x, pos.z) != Status.EXPLORED) {
|
||||||
|
// either waiting for it or dont have it at all
|
||||||
|
countRemain++;
|
||||||
|
if (countRemain >= Baritone.settings().exploreChunkSetMinimumSize.value) {
|
||||||
|
return countRemain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return countRemain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class EitherChunk implements IChunkFilter {
|
||||||
|
private final IChunkFilter a;
|
||||||
|
private final IChunkFilter b;
|
||||||
|
|
||||||
|
private EitherChunk(IChunkFilter a, IChunkFilter b) {
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status isAlreadyExplored(int chunkX, int chunkZ) {
|
||||||
|
if (a.isAlreadyExplored(chunkX, chunkZ) == Status.EXPLORED) {
|
||||||
|
return Status.EXPLORED;
|
||||||
|
}
|
||||||
|
return b.isAlreadyExplored(chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countRemain() {
|
||||||
|
return Math.min(a.countRemain(), b.countRemain());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +282,6 @@ public class ExploreProcess extends BaritoneProcessHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String displayName0() {
|
public String displayName0() {
|
||||||
return "Exploring around " + explorationOrigin + ", currently going to " + new GoalComposite(closestUncachedChunks(explorationOrigin));
|
return "Exploring around " + explorationOrigin + ", distance completed " + distanceCompleted + ", currently going to " + new GoalComposite(closestUncachedChunks(explorationOrigin, calcFilter()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,281 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package baritone.process;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
|
import baritone.api.pathing.goals.Goal;
|
||||||
|
import baritone.api.pathing.goals.GoalBlock;
|
||||||
|
import baritone.api.pathing.goals.GoalComposite;
|
||||||
|
import baritone.api.process.IFarmProcess;
|
||||||
|
import baritone.api.process.PathingCommand;
|
||||||
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.api.utils.Rotation;
|
||||||
|
import baritone.api.utils.RotationUtils;
|
||||||
|
import baritone.api.utils.input.Input;
|
||||||
|
import baritone.cache.WorldScanner;
|
||||||
|
import baritone.pathing.movement.MovementHelper;
|
||||||
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
import net.minecraft.block.*;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
public class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
|
||||||
|
|
||||||
|
private boolean active;
|
||||||
|
|
||||||
|
private static final List<Item> FARMLAND_PLANTABLE = Arrays.asList(
|
||||||
|
Items.BEETROOT_SEEDS,
|
||||||
|
Items.MELON_SEEDS,
|
||||||
|
Items.WHEAT_SEEDS,
|
||||||
|
Items.PUMPKIN_SEEDS,
|
||||||
|
Items.POTATO,
|
||||||
|
Items.CARROT
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final List<Item> PICKUP_DROPPED = Arrays.asList(
|
||||||
|
Items.BEETROOT_SEEDS,
|
||||||
|
Items.WHEAT,
|
||||||
|
Items.MELON_SEEDS,
|
||||||
|
Items.MELON_SLICE,
|
||||||
|
Items.WHEAT_SEEDS,
|
||||||
|
Items.WHEAT,
|
||||||
|
Items.PUMPKIN_SEEDS,
|
||||||
|
Items.POTATO,
|
||||||
|
Items.CARROT,
|
||||||
|
Items.BEETROOT,
|
||||||
|
Blocks.PUMPKIN.asItem(),
|
||||||
|
Blocks.MELON.asItem(),
|
||||||
|
Items.NETHER_WART,
|
||||||
|
Blocks.SUGAR_CANE.asItem(),
|
||||||
|
Blocks.CACTUS.asItem()
|
||||||
|
);
|
||||||
|
|
||||||
|
public FarmProcess(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void farm() {
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum Harvest {
|
||||||
|
WHEAT((BlockCrops) Blocks.WHEAT),
|
||||||
|
CARROTS((BlockCrops) Blocks.CARROTS),
|
||||||
|
POTATOES((BlockCrops) Blocks.POTATOES),
|
||||||
|
BEETROOT((BlockCrops) Blocks.BEETROOTS),
|
||||||
|
PUMPKIN(Blocks.PUMPKIN, state -> true),
|
||||||
|
MELON(Blocks.MELON, state -> true),
|
||||||
|
NETHERWART(Blocks.NETHER_WART, state -> state.get(BlockNetherWart.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;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
CACTUS(Blocks.CACTUS, null) {
|
||||||
|
@Override
|
||||||
|
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
|
||||||
|
return world.getBlockState(pos.down()).getBlock() instanceof BlockCactus;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public final Block block;
|
||||||
|
public final Predicate<IBlockState> readyToHarvest;
|
||||||
|
|
||||||
|
Harvest(BlockCrops blockCrops) {
|
||||||
|
this(blockCrops, blockCrops::isMaxAge);
|
||||||
|
// max age is 7 for wheat, carrots, and potatoes, but 3 for beetroot
|
||||||
|
}
|
||||||
|
|
||||||
|
Harvest(Block block, Predicate<IBlockState> readyToHarvest) {
|
||||||
|
this.block = block;
|
||||||
|
this.readyToHarvest = readyToHarvest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readyToHarvest(World world, BlockPos pos, IBlockState state) {
|
||||||
|
return readyToHarvest.test(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean readyForHarvest(World world, BlockPos pos, IBlockState state) {
|
||||||
|
for (Harvest harvest : Harvest.values()) {
|
||||||
|
if (harvest.block == state.getBlock()) {
|
||||||
|
return harvest.readyToHarvest(world, pos, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPlantable(ItemStack stack) {
|
||||||
|
return FARMLAND_PLANTABLE.contains(stack.getItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBoneMeal(ItemStack stack) {
|
||||||
|
return !stack.isEmpty() && stack.getItem().equals(Items.BONE_MEAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNetherWart(ItemStack stack) {
|
||||||
|
return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||||
|
ArrayList<Block> scan = new ArrayList<>();
|
||||||
|
for (Harvest harvest : Harvest.values()) {
|
||||||
|
scan.add(harvest.block);
|
||||||
|
}
|
||||||
|
scan.add(Blocks.FARMLAND);
|
||||||
|
if (Baritone.settings().replantNetherWart.value) {
|
||||||
|
scan.add(Blocks.SOUL_SAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BlockPos> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 4);
|
||||||
|
|
||||||
|
List<BlockPos> toBreak = new ArrayList<>();
|
||||||
|
List<BlockPos> openFarmland = new ArrayList<>();
|
||||||
|
List<BlockPos> bonemealable = new ArrayList<>();
|
||||||
|
List<BlockPos> openSoulsand = new ArrayList<>();
|
||||||
|
for (BlockPos pos : locations) {
|
||||||
|
IBlockState state = ctx.world().getBlockState(pos);
|
||||||
|
boolean airAbove = ctx.world().getBlockState(pos.up()).getBlock() instanceof BlockAir;
|
||||||
|
if (state.getBlock() == Blocks.FARMLAND) {
|
||||||
|
if (airAbove) {
|
||||||
|
openFarmland.add(pos);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (state.getBlock() == Blocks.SOUL_SAND) {
|
||||||
|
if (airAbove) {
|
||||||
|
openSoulsand.add(pos);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (readyForHarvest(ctx.world(), pos, state)) {
|
||||||
|
toBreak.add(pos);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (state.getBlock() instanceof IGrowable) {
|
||||||
|
IGrowable ig = (IGrowable) state.getBlock();
|
||||||
|
if (ig.canGrow(ctx.world(), pos, state, true) && ig.canUseBonemeal(ctx.world(), ctx.world().rand, pos, state)) {
|
||||||
|
bonemealable.add(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
for (BlockPos pos : toBreak) {
|
||||||
|
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||||
|
if (rot.isPresent() && isSafeToCancel) {
|
||||||
|
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||||
|
MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
|
||||||
|
if (ctx.isLookingAt(pos)) {
|
||||||
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
||||||
|
}
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrayList<BlockPos> both = new ArrayList<>(openFarmland);
|
||||||
|
both.addAll(openSoulsand);
|
||||||
|
for (BlockPos pos : both) {
|
||||||
|
boolean soulsand = openSoulsand.contains(pos);
|
||||||
|
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance());
|
||||||
|
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
|
||||||
|
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||||
|
if (ctx.isLookingAt(pos)) {
|
||||||
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||||
|
}
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (BlockPos pos : bonemealable) {
|
||||||
|
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||||
|
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
|
||||||
|
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||||
|
if (ctx.isLookingAt(pos)) {
|
||||||
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||||
|
}
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (calcFailed) {
|
||||||
|
logDirect("Farm failed");
|
||||||
|
onLostControl();
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Goal> goalz = new ArrayList<>();
|
||||||
|
for (BlockPos pos : toBreak) {
|
||||||
|
goalz.add(new BuilderProcess.GoalBreak(pos));
|
||||||
|
}
|
||||||
|
if (baritone.getInventoryBehavior().throwaway(false, this::isPlantable)) {
|
||||||
|
for (BlockPos pos : openFarmland) {
|
||||||
|
goalz.add(new GoalBlock(pos.up()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (baritone.getInventoryBehavior().throwaway(false, this::isNetherWart)) {
|
||||||
|
for (BlockPos pos : openSoulsand) {
|
||||||
|
goalz.add(new GoalBlock(pos.up()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (baritone.getInventoryBehavior().throwaway(false, this::isBoneMeal)) {
|
||||||
|
for (BlockPos pos : bonemealable) {
|
||||||
|
goalz.add(new GoalBlock(pos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Entity entity : ctx.world().loadedEntityList) {
|
||||||
|
if (entity instanceof EntityItem && entity.onGround) {
|
||||||
|
EntityItem ei = (EntityItem) entity;
|
||||||
|
if (PICKUP_DROPPED.contains(ei.getItem().getItem())) {
|
||||||
|
// +0.1 because of farmland's 0.9375 dummy height lol
|
||||||
|
goalz.add(new GoalBlock(new BlockPos(entity.posX, entity.posY + 0.1, entity.posZ)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PathingCommand(new GoalComposite(goalz.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLostControl() {
|
||||||
|
active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName0() {
|
||||||
|
return "Farming";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
private BlockPos start;
|
private BlockPos start;
|
||||||
|
|
||||||
private int tickCount = 0;
|
private int tickCount = 0;
|
||||||
|
private int arrivalTickCount = 0;
|
||||||
|
|
||||||
public GetToBlockProcess(Baritone baritone) {
|
public GetToBlockProcess(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone);
|
||||||
@@ -53,6 +54,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
gettingTo = block;
|
gettingTo = block;
|
||||||
start = ctx.playerFeet();
|
start = ctx.playerFeet();
|
||||||
blacklist = new ArrayList<>();
|
blacklist = new ArrayList<>();
|
||||||
|
arrivalTickCount = 0;
|
||||||
rescan(new ArrayList<>(), new CalculationContext(baritone));
|
rescan(new ArrayList<>(), new CalculationContext(baritone));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +119,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// blacklist the closest block and its adjacent blocks
|
// blacklist the closest block and its adjacent blocks
|
||||||
public synchronized void blacklistClosest() {
|
public synchronized boolean blacklistClosest() {
|
||||||
List<BlockPos> newBlacklist = new ArrayList<>();
|
List<BlockPos> newBlacklist = new ArrayList<>();
|
||||||
knownLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(newBlacklist::add);
|
knownLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(newBlacklist::add);
|
||||||
outer:
|
outer:
|
||||||
@@ -140,6 +142,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
}
|
}
|
||||||
logDebug("Blacklisting unreachable locations " + newBlacklist);
|
logDebug("Blacklisting unreachable locations " + newBlacklist);
|
||||||
blacklist.addAll(newBlacklist);
|
blacklist.addAll(newBlacklist);
|
||||||
|
return !newBlacklist.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// safer than direct double comparison from distanceSq
|
// safer than direct double comparison from distanceSq
|
||||||
@@ -195,6 +198,10 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (arrivalTickCount++ > 20) {
|
||||||
|
logDirect("Right click timed out");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false; // trying to right click, will do it next tick or so
|
return false; // trying to right click, will do it next tick or so
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ import baritone.api.pathing.goals.*;
|
|||||||
import baritone.api.process.IMineProcess;
|
import baritone.api.process.IMineProcess;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.process.PathingCommandType;
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.api.utils.BlockUtils;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
|
import baritone.api.utils.Rotation;
|
||||||
import baritone.api.utils.RotationUtils;
|
import baritone.api.utils.RotationUtils;
|
||||||
|
import baritone.api.utils.input.Input;
|
||||||
import baritone.cache.CachedChunk;
|
import baritone.cache.CachedChunk;
|
||||||
import baritone.cache.ChunkPacker;
|
|
||||||
import baritone.cache.WorldScanner;
|
import baritone.cache.WorldScanner;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
@@ -33,6 +35,8 @@ import baritone.utils.BaritoneProcessHelper;
|
|||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockAir;
|
import net.minecraft.block.BlockAir;
|
||||||
|
import net.minecraft.block.BlockFalling;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
@@ -44,6 +48,8 @@ import net.minecraft.world.World;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mine blocks of a certain type
|
* Mine blocks of a certain type
|
||||||
*
|
*
|
||||||
@@ -82,27 +88,47 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean shouldCancel = calcFailed;
|
if (calcFailed) {
|
||||||
if (calcFailed && !knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
|
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
|
||||||
logDirect("Unable to find any path to " + mining + ", blacklisting presumably unreachable closest instance...");
|
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.player()::getDistanceSq)).ifPresent(blacklist::add);
|
||||||
knownOreLocations.removeIf(blacklist::contains);
|
knownOreLocations.removeIf(blacklist::contains);
|
||||||
shouldCancel = false; // 😎
|
} else {
|
||||||
}
|
logDirect("Unable to find any path to " + mining + ", canceling Mine");
|
||||||
if (shouldCancel) {
|
cancel();
|
||||||
logDirect("Unable to find any path to " + mining + ", canceling Mine");
|
return null;
|
||||||
cancel();
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
|
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
|
||||||
|
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
|
||||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||||
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
|
|
||||||
CalculationContext context = new CalculationContext(baritone, true);
|
CalculationContext context = new CalculationContext(baritone, true);
|
||||||
Baritone.getExecutor().execute(() -> rescan(curr, context));
|
Baritone.getExecutor().execute(() -> rescan(curr, context));
|
||||||
}
|
}
|
||||||
if (Baritone.settings().legitMine.value) {
|
if (Baritone.settings().legitMine.value) {
|
||||||
addNearby();
|
addNearby();
|
||||||
}
|
}
|
||||||
|
Optional<BlockPos> shaft = curr.stream()
|
||||||
|
.filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())
|
||||||
|
.filter(pos -> pos.getY() >= ctx.playerFeet().getY())
|
||||||
|
.filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
|
||||||
|
.min(Comparator.comparingDouble(ctx.player()::getDistanceSq));
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
if (shaft.isPresent()) {
|
||||||
|
BlockPos pos = shaft.get();
|
||||||
|
IBlockState state = baritone.bsi.get0(pos);
|
||||||
|
if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) {
|
||||||
|
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||||
|
if (rot.isPresent() && isSafeToCancel) {
|
||||||
|
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||||
|
MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
|
||||||
|
if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot.get())) {
|
||||||
|
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
|
||||||
|
}
|
||||||
|
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
PathingCommand command = updateGoal();
|
PathingCommand command = updateGoal();
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
// none in range
|
// none in range
|
||||||
@@ -129,7 +155,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
if (!locs.isEmpty()) {
|
if (!locs.isEmpty()) {
|
||||||
List<BlockPos> locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT, blacklist);
|
List<BlockPos> locs2 = prune(new CalculationContext(baritone), new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT, blacklist);
|
||||||
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
|
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
|
||||||
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(ctx, loc, locs2)).toArray(Goal[]::new));
|
Goal goal = new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new));
|
||||||
knownOreLocations = locs2;
|
knownOreLocations = locs2;
|
||||||
return new PathingCommand(goal, legit ? PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH : PathingCommandType.REVALIDATE_GOAL_AND_PATH);
|
return new PathingCommand(goal, legit ? PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH : PathingCommandType.REVALIDATE_GOAL_AND_PATH);
|
||||||
}
|
}
|
||||||
@@ -179,15 +205,78 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
knownOreLocations = locs;
|
knownOreLocations = locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List<BlockPos> locs) {
|
private boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List<BlockPos> locs) {
|
||||||
|
// Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of)
|
||||||
|
if (locs.contains(pos)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Block block = BlockStateInterface.getBlock(ctx, pos);
|
||||||
|
if (Baritone.settings().internalMiningAirException.value && block instanceof BlockAir) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return mining.contains(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Goal coalesce(BlockPos loc, List<BlockPos> locs) {
|
||||||
|
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof BlockFalling);
|
||||||
if (!Baritone.settings().forceInternalMining.value) {
|
if (!Baritone.settings().forceInternalMining.value) {
|
||||||
return new GoalTwoBlocks(loc);
|
if (assumeVerticalShaftMine) {
|
||||||
|
// we can get directly below the block
|
||||||
|
return new GoalThreeBlocks(loc);
|
||||||
|
} else {
|
||||||
|
// we need to get feet or head into the block
|
||||||
|
return new GoalTwoBlocks(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs);
|
||||||
|
boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs);
|
||||||
|
boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs);
|
||||||
|
if (upwardGoal == downwardGoal) { // symmetric
|
||||||
|
if (doubleDownwardGoal && assumeVerticalShaftMine) {
|
||||||
|
// we have a checkerboard like pattern
|
||||||
|
// this one, and the one two below it
|
||||||
|
// therefore it's fine to path to immediately below this one, since your feet will be in the doubleDownwardGoal
|
||||||
|
// but only if assumeVerticalShaftMine
|
||||||
|
return new GoalThreeBlocks(loc);
|
||||||
|
} else {
|
||||||
|
// this block has nothing interesting two below, but is symmetric vertically so we can get either feet or head into it
|
||||||
|
return new GoalTwoBlocks(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (upwardGoal) {
|
||||||
|
// downwardGoal known to be false
|
||||||
|
// ignore the gap then potential doubleDownward, because we want to path feet into this one and head into upwardGoal
|
||||||
|
return new GoalBlock(loc);
|
||||||
|
}
|
||||||
|
// upwardGoal known to be false, downwardGoal known to be true
|
||||||
|
if (doubleDownwardGoal && assumeVerticalShaftMine) {
|
||||||
|
// this block and two below it are goals
|
||||||
|
// path into the center of the one below, because that includes directly below this one
|
||||||
|
return new GoalTwoBlocks(loc.down());
|
||||||
|
}
|
||||||
|
// upwardGoal false, downwardGoal true, doubleDownwardGoal false
|
||||||
|
// just this block and the one immediately below, no others
|
||||||
|
return new GoalBlock(loc.down());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GoalThreeBlocks extends GoalTwoBlocks {
|
||||||
|
|
||||||
|
public GoalThreeBlocks(BlockPos pos) {
|
||||||
|
super(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of)
|
@Override
|
||||||
boolean upwardGoal = locs.contains(loc.up()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.up()) instanceof BlockAir);
|
public boolean isInGoal(int x, int y, int z) {
|
||||||
boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.down()) instanceof BlockAir);
|
return x == this.x && (y == this.y || y == this.y - 1 || y == this.y - 2) && z == this.z;
|
||||||
return upwardGoal == downwardGoal ? new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : new GoalBlock(loc.down());
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double heuristic(int x, int y, int z) {
|
||||||
|
int xDiff = x - this.x;
|
||||||
|
int yDiff = y - this.y;
|
||||||
|
int zDiff = z - this.z;
|
||||||
|
return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {
|
public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {
|
||||||
@@ -216,24 +305,20 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
public static List<BlockPos> searchWorld(CalculationContext ctx, List<Block> mining, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist) {
|
public static List<BlockPos> searchWorld(CalculationContext ctx, List<Block> mining, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist) {
|
||||||
List<BlockPos> locs = new ArrayList<>();
|
List<BlockPos> locs = new ArrayList<>();
|
||||||
List<Block> uninteresting = new ArrayList<>();
|
List<Block> uninteresting = new ArrayList<>();
|
||||||
//long b = System.currentTimeMillis();
|
|
||||||
for (Block m : mining) {
|
for (Block m : mining) {
|
||||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) {
|
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) {
|
||||||
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
|
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
|
||||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), Baritone.settings().maxCachedWorldScanCount.value, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2));
|
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(BlockUtils.blockToString(m), Baritone.settings().maxCachedWorldScanCount.value, ctx.getBaritone().getPlayerContext().playerFeet().getX(), ctx.getBaritone().getPlayerContext().playerFeet().getZ(), 2));
|
||||||
} else {
|
} else {
|
||||||
uninteresting.add(m);
|
uninteresting.add(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
locs = prune(ctx, locs, mining, max, blacklist);
|
locs = prune(ctx, locs, mining, max, blacklist);
|
||||||
//System.out.println("Scan of cached chunks took " + (System.currentTimeMillis() - b) + "ms");
|
if (locs.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) {
|
||||||
if (locs.isEmpty()) {
|
|
||||||
uninteresting = mining;
|
uninteresting = mining;
|
||||||
}
|
}
|
||||||
if (!uninteresting.isEmpty()) {
|
if (!uninteresting.isEmpty()) {
|
||||||
//long before = System.currentTimeMillis();
|
|
||||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 32)); // maxSearchRadius is NOT sq
|
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(ctx.getBaritone().getPlayerContext(), uninteresting, max, 10, 32)); // maxSearchRadius is NOT sq
|
||||||
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
|
|
||||||
}
|
}
|
||||||
locs.addAll(alreadyKnown);
|
locs.addAll(alreadyKnown);
|
||||||
return prune(ctx, locs, mining, max, blacklist);
|
return prune(ctx, locs, mining, max, blacklist);
|
||||||
@@ -266,7 +351,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
List<BlockPos> dropped = droppedItemsScan(mining, ctx.world);
|
List<BlockPos> dropped = droppedItemsScan(mining, ctx.world);
|
||||||
dropped.removeIf(drop -> {
|
dropped.removeIf(drop -> {
|
||||||
for (BlockPos pos : locs2) {
|
for (BlockPos pos : locs2) {
|
||||||
if (pos.distanceSq(drop) <= 9 && mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx.bsi, pos)) { // TODO maybe drop also has to be supported? no lava below?
|
if (pos.distanceSq(drop) <= 9 && mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) && MineProcess.plausibleToBreak(ctx, pos)) { // TODO maybe drop also has to be supported? no lava below?
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,11 +365,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
.filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
|
.filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || mining.contains(ctx.getBlock(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
|
||||||
|
|
||||||
// remove any that are implausible to mine (encased in bedrock, or touching lava)
|
// remove any that are implausible to mine (encased in bedrock, or touching lava)
|
||||||
.filter(pos -> MineProcess.plausibleToBreak(ctx.bsi, pos))
|
.filter(pos -> MineProcess.plausibleToBreak(ctx, pos))
|
||||||
|
|
||||||
.filter(pos -> !blacklist.contains(pos))
|
.filter(pos -> !blacklist.contains(pos))
|
||||||
|
|
||||||
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().playerFeet()::distanceSq))
|
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player()::getDistanceSq))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (locs.size() > max) {
|
if (locs.size() > max) {
|
||||||
@@ -293,18 +378,18 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
return locs;
|
return locs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean plausibleToBreak(BlockStateInterface bsi, BlockPos pos) {
|
public static boolean plausibleToBreak(CalculationContext ctx, BlockPos pos) {
|
||||||
if (MovementHelper.avoidBreaking(bsi, pos.getX(), pos.getY(), pos.getZ(), bsi.get0(pos))) {
|
if (MovementHelper.getMiningDurationTicks(ctx, pos.getX(), pos.getY(), pos.getZ(), ctx.bsi.get0(pos), true) >= COST_INF) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// bedrock above and below makes it implausible, otherwise we're good
|
// bedrock above and below makes it implausible, otherwise we're good
|
||||||
return !(bsi.get0(pos.up()).getBlock() == Blocks.BEDROCK && bsi.get0(pos.down()).getBlock() == Blocks.BEDROCK);
|
return !(ctx.bsi.get0(pos.up()).getBlock() == Blocks.BEDROCK && ctx.bsi.get0(pos.down()).getBlock() == Blocks.BEDROCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mineByName(int quantity, String... blocks) {
|
public void mineByName(int quantity, String... blocks) {
|
||||||
mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(ChunkPacker::stringToBlockRequired).toArray(Block[]::new));
|
mine(quantity, blocks == null || blocks.length == 0 ? null : Arrays.stream(blocks).map(BlockUtils::stringToBlockRequired).toArray(Block[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import baritone.api.event.events.TickEvent;
|
|||||||
import baritone.api.event.listener.AbstractGameEventListener;
|
import baritone.api.event.listener.AbstractGameEventListener;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.goals.GoalBlock;
|
import baritone.api.pathing.goals.GoalBlock;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import net.minecraft.client.GameSettings;
|
import net.minecraft.client.GameSettings;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package baritone.utils;
|
|||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.process.IBaritoneProcess;
|
import baritone.api.process.IBaritoneProcess;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
|
|
||||||
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.utils;
|
package baritone.utils;
|
||||||
|
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package baritone.utils;
|
package baritone.utils;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import net.minecraft.util.EnumActionResult;
|
import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import baritone.api.event.events.RenderEvent;
|
|||||||
import baritone.api.pathing.calc.IPath;
|
import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.pathing.goals.*;
|
import baritone.api.pathing.goals.*;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.interfaces.IGoalRenderPos;
|
import baritone.api.utils.interfaces.IGoalRenderPos;
|
||||||
import baritone.behavior.PathingBehavior;
|
import baritone.behavior.PathingBehavior;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
@@ -275,13 +276,13 @@ public final class PathRenderer implements Helper {
|
|||||||
double maxY;
|
double maxY;
|
||||||
double y1;
|
double y1;
|
||||||
double y2;
|
double y2;
|
||||||
|
double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2));
|
||||||
if (goal instanceof IGoalRenderPos) {
|
if (goal instanceof IGoalRenderPos) {
|
||||||
BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos();
|
BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos();
|
||||||
minX = goalPos.getX() + 0.002 - renderPosX;
|
minX = goalPos.getX() + 0.002 - renderPosX;
|
||||||
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
|
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
|
||||||
minZ = goalPos.getZ() + 0.002 - renderPosZ;
|
minZ = goalPos.getZ() + 0.002 - renderPosZ;
|
||||||
maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ;
|
maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ;
|
||||||
double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2));
|
|
||||||
if (goal instanceof GoalGetToBlock || goal instanceof GoalTwoBlocks) {
|
if (goal instanceof GoalGetToBlock || goal instanceof GoalTwoBlocks) {
|
||||||
y /= 2;
|
y /= 2;
|
||||||
}
|
}
|
||||||
@@ -344,6 +345,16 @@ public final class PathRenderer implements Helper {
|
|||||||
drawDankLitGoalBox(player, g, partialTicks, color);
|
drawDankLitGoalBox(player, g, partialTicks, color);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
} else if (goal instanceof GoalYLevel) {
|
||||||
|
GoalYLevel goalpos = (GoalYLevel) goal;
|
||||||
|
minX = player.posX - Baritone.settings().yLevelBoxSize.value - renderPosX;
|
||||||
|
minZ = player.posZ - Baritone.settings().yLevelBoxSize.value - renderPosZ;
|
||||||
|
maxX = player.posX + Baritone.settings().yLevelBoxSize.value - renderPosX;
|
||||||
|
maxZ = player.posZ + Baritone.settings().yLevelBoxSize.value - renderPosZ;
|
||||||
|
minY = ((GoalYLevel) goal).level - renderPosY;
|
||||||
|
maxY = minY + 2;
|
||||||
|
y1 = 1 + y + goalpos.level - renderPosY;
|
||||||
|
y2 = 1 - y + goalpos.level - renderPosY;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ public class PathingControlManager implements IPathingControlManager {
|
|||||||
p.secretInternalSetGoal(null);
|
p.secretInternalSetGoal(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE) {
|
if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) {
|
||||||
// if control has changed, and the new process wants to do something
|
// if control has changed from a real process to another real process, and the new process wants to do something
|
||||||
p.cancelSegmentIfSafe();
|
p.cancelSegmentIfSafe();
|
||||||
// get rid of the in progress stuff from the last process
|
// get rid of the in progress stuff from the last process
|
||||||
}
|
}
|
||||||
@@ -200,10 +200,10 @@ public class PathingControlManager implements IPathingControlManager {
|
|||||||
PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
|
PathingCommand exec = proc.onTick(Objects.equals(proc, inControlLastTick) && baritone.getPathingBehavior().calcFailedLastTick(), baritone.getPathingBehavior().isSafeToCancel());
|
||||||
if (exec == null) {
|
if (exec == null) {
|
||||||
if (proc.isActive()) {
|
if (proc.isActive()) {
|
||||||
throw new IllegalStateException(proc.displayName() + " returned null PathingCommand");
|
throw new IllegalStateException(proc.displayName() + " actively returned null PathingCommand");
|
||||||
}
|
}
|
||||||
proc.onLostControl();
|
// no need to call onLostControl; they are reporting inactive.
|
||||||
} else {
|
} else if (exec.commandType != PathingCommandType.DEFER) {
|
||||||
inControlThisTick = proc;
|
inControlThisTick = proc;
|
||||||
if (!proc.isTemporary()) {
|
if (!proc.isTemporary()) {
|
||||||
iterator.forEachRemaining(IBaritoneProcess::onLostControl);
|
iterator.forEachRemaining(IBaritoneProcess::onLostControl);
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ public class ToolSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Using the best tool on the hotbar, how long would it take to mine this block
|
* Using the best tool on the hotbar, how fast we can mine this block
|
||||||
*
|
*
|
||||||
* @param state the blockstate to be mined
|
* @param state the blockstate to be mined
|
||||||
* @return how long it would take in ticks
|
* @return the speed of how fast we'll mine it. 1/(time in ticks)
|
||||||
*/
|
*/
|
||||||
public double getStrVsBlock(IBlockState state) {
|
public double getStrVsBlock(IBlockState state) {
|
||||||
return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation);
|
return breakStrengthCache.computeIfAbsent(state.getBlock(), backendCalculation);
|
||||||
@@ -121,7 +121,11 @@ public class ToolSet {
|
|||||||
*/
|
*/
|
||||||
private double getBestDestructionTime(Block b) {
|
private double getBestDestructionTime(Block b) {
|
||||||
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b));
|
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b));
|
||||||
return calculateSpeedVsBlock(stack, b.getDefaultState());
|
return calculateSpeedVsBlock(stack, b.getDefaultState()) * avoidanceMultiplier(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double avoidanceMultiplier(Block b) {
|
||||||
|
return Baritone.settings().blocksToAvoidBreaking.value.contains(b) ? 0.1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package baritone.utils.pathing;
|
|||||||
|
|
||||||
import baritone.api.pathing.calc.IPath;
|
import baritone.api.pathing.calc.IPath;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
import baritone.pathing.movement.CalculationContext;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
|
||||||
@@ -31,7 +32,7 @@ public final class Favoring {
|
|||||||
for (Avoidance avoid : Avoidance.create(ctx)) {
|
for (Avoidance avoid : Avoidance.create(ctx)) {
|
||||||
avoid.applySpherical(favorings);
|
avoid.applySpherical(favorings);
|
||||||
}
|
}
|
||||||
System.out.println("Favoring size: " + favorings.size());
|
Helper.HELPER.logDebug("Favoring size: " + favorings.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances
|
public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ package baritone.utils.player;
|
|||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
import baritone.api.BaritoneAPI;
|
||||||
import baritone.api.cache.IWorldData;
|
import baritone.api.cache.IWorldData;
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerContext;
|
import baritone.api.utils.IPlayerContext;
|
||||||
import baritone.api.utils.IPlayerController;
|
import baritone.api.utils.IPlayerController;
|
||||||
import baritone.api.utils.RayTraceUtils;
|
import baritone.api.utils.RayTraceUtils;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package baritone.utils.player;
|
package baritone.utils.player;
|
||||||
|
|
||||||
|
import baritone.api.utils.Helper;
|
||||||
import baritone.api.utils.IPlayerController;
|
import baritone.api.utils.IPlayerController;
|
||||||
import baritone.utils.Helper;
|
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.multiplayer.WorldClient;
|
import net.minecraft.client.multiplayer.WorldClient;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|||||||
Reference in New Issue
Block a user