Merge branch 'master' into bot-system

This commit is contained in:
Brady
2018-11-11 13:36:22 -06:00
33 changed files with 354 additions and 229 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ Building Baritone:
$ gradlew build
```
For example, to replace out Impact 4.4's Baritone build with a customized one, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.0.0/baritone-api-1.0.0.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.4/1.12.2-Impact_4.4.json`, find the line `"name": "cabaletta:baritone-api:1.0.0"`, remove the comma from the end, and entirely remove the line that's immediately after (starts with `"url"`).
For example, to replace out Impact 4.4's Baritone build with a customized one, switch to the `impact4.4-compat` branch, build Baritone as above then copy `dist/baritone-api-$VERSION$.jar` into `minecraft/libraries/cabaletta/baritone-api/1.0.0/baritone-api-1.0.0.jar`, replacing the jar that was previously there. You also need to edit `minecraft/versions/1.12.2-Impact_4.4/1.12.2-Impact_4.4.json`, find the line `"name": "cabaletta:baritone-api:1.0.0"`, remove the comma from the end, and entirely remove the line that's immediately after (starts with `"url"`).
## IntelliJ's Gradle UI
- Open the project in IntelliJ as a Gradle project
+3 -3
View File
@@ -312,17 +312,17 @@ public class Settings {
/**
* Ignore depth when rendering the goal
*/
public Setting<Boolean> renderGoalIgnoreDepth = new Setting<>(false);
public Setting<Boolean> renderGoalIgnoreDepth = new Setting<>(true);
/**
* Ignore depth when rendering the selection boxes (to break, to place, to walk into)
*/
public Setting<Boolean> renderSelectionBoxesIgnoreDepth = new Setting<>(false);
public Setting<Boolean> renderSelectionBoxesIgnoreDepth = new Setting<>(true);
/**
* Ignore depth when rendering the path
*/
public Setting<Boolean> renderPathIgnoreDepth = new Setting<>(false);
public Setting<Boolean> renderPathIgnoreDepth = new Setting<>(true);
/**
* Line width of the path when rendered, in pixels
@@ -22,6 +22,7 @@ import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.movement.IMovement;
import baritone.api.utils.BetterBlockPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.List;
@@ -120,7 +121,7 @@ public interface IPath {
*
* @return The result of this cut-off operation
*/
default IPath cutoffAtLoadedChunks() {
default IPath cutoffAtLoadedChunks(World world) {
throw new UnsupportedOperationException();
}
@@ -19,6 +19,9 @@ package baritone.api.process;
import net.minecraft.entity.Entity;
import java.util.List;
import java.util.function.Predicate;
/**
* @author Brady
* @since 9/23/2018
@@ -26,16 +29,18 @@ import net.minecraft.entity.Entity;
public interface IFollowProcess extends IBaritoneProcess {
/**
* Set the follow target to the specified entity;
* Set the follow target to any entities matching this predicate
*
* @param entity The entity to follow
* @param filter the predicate
*/
void follow(Entity entity);
void follow(Predicate<Entity> filter);
/**
* @return The entity that is currently being followed
* @return The entities that are currently being followed. null if not currently following, empty if nothing matches the predicate
*/
Entity following();
List<Entity> following();
Predicate<Entity> currentFilter();
/**
* Cancels the follow behavior, this will clear the current follow target.
@@ -30,43 +30,11 @@ import java.util.Optional;
* @since 8/25/2018
*/
public final class RayTraceUtils {
/**
* The {@link Minecraft} instance
*/
private static final Minecraft mc = Minecraft.getMinecraft();
private RayTraceUtils() {}
/**
* Simulates a "vanilla" raytrace. A RayTraceResult returned by this method
* will be that of the next render pass given that the local player's yaw and
* pitch match the specified yaw and pitch values. This is particularly useful
* when you would like to simulate a "legit" raytrace with certainty that the only
* thing to achieve the desired outcome (whether it is hitting and entity or placing
* a block) can be done just by modifying user input.
*
* @param yaw The yaw to raytrace with
* @param pitch The pitch to raytrace with
* @return The calculated raytrace result
*/
public static RayTraceResult simulateRayTrace(float yaw, float pitch) {
RayTraceResult oldTrace = mc.objectMouseOver;
float oldYaw = mc.player.rotationYaw;
float oldPitch = mc.player.rotationPitch;
mc.player.rotationYaw = yaw;
mc.player.rotationPitch = pitch;
mc.entityRenderer.getMouseOver(1.0F);
RayTraceResult result = mc.objectMouseOver;
mc.objectMouseOver = oldTrace;
mc.player.rotationYaw = oldYaw;
mc.player.rotationPitch = oldPitch;
return result;
}
/**
* Performs a block raytrace with the specified rotations. This should only be used when
* any entity collisions can be ignored, because this method will not recognize if an
@@ -75,9 +43,8 @@ public final class RayTraceUtils {
* @param rotation The rotation to raytrace towards
* @return The calculated raytrace result
*/
public static RayTraceResult rayTraceTowards(Rotation rotation) {
double blockReachDistance = mc.playerController.getBlockReachDistance();
Vec3d start = mc.player.getPositionEyes(1.0F);
public static RayTraceResult rayTraceTowards(Entity entity, Rotation rotation, double blockReachDistance) {
Vec3d start = entity.getPositionEyes(1.0F);
Vec3d direction = RotationUtils.calcVec3dFromRotation(rotation);
Vec3d end = start.add(
direction.x * blockReachDistance,
+31 -4
View File
@@ -86,7 +86,7 @@ public class Rotation {
public Rotation clamp() {
return new Rotation(
this.yaw,
RotationUtils.clampPitch(this.pitch)
clampPitch(this.pitch)
);
}
@@ -95,7 +95,7 @@ public class Rotation {
*/
public Rotation normalize() {
return new Rotation(
RotationUtils.normalizeYaw(this.yaw),
normalizeYaw(this.yaw),
this.pitch
);
}
@@ -105,8 +105,35 @@ public class Rotation {
*/
public Rotation normalizeAndClamp() {
return new Rotation(
RotationUtils.normalizeYaw(this.yaw),
RotationUtils.clampPitch(this.pitch)
normalizeYaw(this.yaw),
clampPitch(this.pitch)
);
}
/**
* Clamps the specified pitch value between -90 and 90.
*
* @param pitch The input pitch
* @return The clamped pitch
*/
public static float clampPitch(float pitch) {
return Math.max(-90, Math.min(90, pitch));
}
/**
* Normalizes the specified yaw value between -180 and 180.
*
* @param yaw The input yaw
* @return The normalized yaw
*/
public static float normalizeYaw(float yaw) {
float newYaw = yaw % 360F;
if (newYaw < -180F) {
newYaw += 360F;
}
if (newYaw >= 180F) {
newYaw -= 360F;
}
return newYaw;
}
}
@@ -19,7 +19,6 @@ package baritone.api.utils;
import net.minecraft.block.BlockFire;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.*;
@@ -31,11 +30,6 @@ import java.util.Optional;
*/
public final class RotationUtils {
/**
* The {@link Minecraft} instance
*/
private static final Minecraft mc = Minecraft.getMinecraft();
/**
* Constant that a degree value is multiplied by to get the equivalent radian value
*/
@@ -60,33 +54,6 @@ public final class RotationUtils {
private RotationUtils() {}
/**
* Clamps the specified pitch value between -90 and 90.
*
* @param pitch The input pitch
* @return The clamped pitch
*/
public static float clampPitch(float pitch) {
return Math.max(-90, Math.min(90, pitch));
}
/**
* Normalizes the specified yaw value between -180 and 180.
*
* @param yaw The input yaw
* @return The normalized yaw
*/
public static float normalizeYaw(float yaw) {
float newYaw = yaw % 360F;
if (newYaw < -180F) {
newYaw += 360F;
}
if (newYaw >= 180F) {
newYaw -= 360F;
}
return newYaw;
}
/**
* Calculates the rotation from BlockPos<sub>dest</sub> to BlockPos<sub>orig</sub>
*
@@ -168,7 +135,7 @@ public final class RotationUtils {
* @param pos The target block position
* @return The optional rotation
*/
public static Optional<Rotation> reachable(Entity entity, BlockPos pos) {
public static Optional<Rotation> reachable(Entity entity, BlockPos pos, double blockReachDistance) {
if (pos.equals(RayTraceUtils.getSelectedBlock().orElse(null))) {
/*
* why add 0.0001?
@@ -182,19 +149,19 @@ public final class RotationUtils {
*/
return Optional.of(new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F));
}
Optional<Rotation> possibleRotation = reachableCenter(entity, pos);
Optional<Rotation> possibleRotation = reachableCenter(entity, pos, blockReachDistance);
//System.out.println("center: " + possibleRotation);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
IBlockState state = mc.world.getBlockState(pos);
IBlockState state = entity.world.getBlockState(pos);
AxisAlignedBB aabb = state.getBoundingBox(entity.world, pos);
for (Vec3d sideOffset : BLOCK_SIDE_MULTIPLIERS) {
double xDiff = aabb.minX * sideOffset.x + aabb.maxX * (1 - sideOffset.x);
double yDiff = aabb.minY * sideOffset.y + aabb.maxY * (1 - sideOffset.y);
double zDiff = aabb.minZ * sideOffset.z + aabb.maxZ * (1 - sideOffset.z);
possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff));
possibleRotation = reachableOffset(entity, pos, new Vec3d(pos).add(xDiff, yDiff, zDiff), blockReachDistance);
if (possibleRotation.isPresent()) {
return possibleRotation;
}
@@ -212,9 +179,9 @@ public final class RotationUtils {
* @param offsetPos The position of the block with the offset applied.
* @return The optional rotation
*/
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos) {
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance) {
Rotation rotation = calcRotationFromVec3d(entity.getPositionEyes(1.0F), offsetPos);
RayTraceResult result = RayTraceUtils.rayTraceTowards(rotation);
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance);
//System.out.println(result);
if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
if (result.getBlockPos().equals(pos)) {
@@ -235,7 +202,7 @@ public final class RotationUtils {
* @param pos The target block position
* @return The optional rotation
*/
public static Optional<Rotation> reachableCenter(Entity entity, BlockPos pos) {
return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(pos));
public static Optional<Rotation> reachableCenter(Entity entity, BlockPos pos, double blockReachDistance) {
return reachableOffset(entity, pos, VecUtils.calculateBlockCenter(pos), blockReachDistance);
}
}
@@ -35,6 +35,12 @@ public class MixinBlockPos extends Vec3i {
super(xIn, yIn, zIn);
}
/**
* The purpose of this was to ensure a friendly name for when we print raw
* block positions to chat in the context of an obfuscated environment.
*
* @return a string representation of the object.
*/
@Override
@Nonnull
public String toString() {
@@ -55,6 +55,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
private boolean safeToCancel;
private boolean pauseRequestedLastTick;
private boolean cancelRequested;
private boolean calcFailedLastTick;
private volatile boolean isPathCalcInProgress;
@@ -91,18 +92,22 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
baritone.getPathingControlManager().cancelEverything();
return;
}
baritone.getPathingControlManager().preTick();
tickPath();
dispatchEvents();
}
private void tickPath() {
baritone.getPathingControlManager().doTheThingWithTheStuff();
if (pauseRequestedLastTick && safeToCancel) {
pauseRequestedLastTick = false;
baritone.getInputOverrideHandler().clearAllKeys();
BlockBreakHelper.stopBreakingBlock();
return;
}
if (cancelRequested) {
cancelRequested = false;
baritone.getInputOverrideHandler().clearAllKeys();
}
if (current == null) {
return;
}
@@ -273,6 +278,17 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
return calcFailedLastTick;
}
public void softCancelIfSafe() {
if (!isSafeToCancel()) {
return;
}
current = null;
next = null;
cancelRequested = true;
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel);
// do everything BUT clear keys
}
// just cancel the current path
public void secretInternalSegmentCancel() {
queuePathEvent(PathEvent.CANCELED);
@@ -384,7 +400,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
Optional<IPath> path = calcResult.path;
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
path = path.map(p -> {
IPath result = p.cutoffAtLoadedChunks();
IPath result = p.cutoffAtLoadedChunks(context.world());
if (result instanceof CutoffPath) {
logDebug("Cutting off path at edge of loaded chunks");
+4 -6
View File
@@ -17,7 +17,6 @@
package baritone.cache;
import baritone.api.cache.IBlockTypeAccess;
import baritone.utils.Helper;
import baritone.utils.pathing.PathingBlockType;
import net.minecraft.block.Block;
@@ -31,7 +30,7 @@ import java.util.*;
* @author Brady
* @since 8/3/2018 1:04 AM
*/
public final class CachedChunk implements IBlockTypeAccess, Helper {
public final class CachedChunk implements Helper {
public static final Set<Block> BLOCKS_TO_KEEP_TRACK_OF;
@@ -143,8 +142,7 @@ public final class CachedChunk implements IBlockTypeAccess, Helper {
calculateHeightMap();
}
@Override
public final IBlockState getBlock(int x, int y, int z) {
public final IBlockState getBlock(int x, int y, int z, int dimension) {
int internalPos = z << 4 | x;
if (heightMap[internalPos] == y) {
// we have this exact block, it's a surface block
@@ -155,10 +153,10 @@ public final class CachedChunk implements IBlockTypeAccess, Helper {
return overview[internalPos];
}
PathingBlockType type = getType(x, y, z);
if (type == PathingBlockType.SOLID && y == 127 && mc.player.dimension == -1) {
if (type == PathingBlockType.SOLID && y == 127 && dimension == -1) {
return Blocks.BEDROCK.getDefaultState();
}
return ChunkPacker.pathingTypeToBlock(type);
return ChunkPacker.pathingTypeToBlock(type, dimension);
}
private PathingBlockType getType(int x, int y, int z) {
+5 -2
View File
@@ -59,22 +59,25 @@ public final class CachedRegion implements ICachedRegion {
*/
private final int z;
private final int dimension;
/**
* Has this region been modified since its most recent load or save
*/
private boolean hasUnsavedChanges;
CachedRegion(int x, int z) {
CachedRegion(int x, int z, int dimension) {
this.x = x;
this.z = z;
this.hasUnsavedChanges = false;
this.dimension = dimension;
}
@Override
public final IBlockState getBlock(int x, int y, int z) {
CachedChunk chunk = chunks[x >> 4][z >> 4];
if (chunk != null) {
return chunk.getBlock(x & 15, y, z & 15);
return chunk.getBlock(x & 15, y, z & 15, dimension);
}
return null;
}
+5 -2
View File
@@ -56,7 +56,9 @@ public final class CachedWorld implements ICachedWorld, Helper {
private final LinkedBlockingQueue<Chunk> toPack = new LinkedBlockingQueue<>();
CachedWorld(Path directory) {
private final int dimension;
CachedWorld(Path directory, int dimension) {
if (!Files.exists(directory)) {
try {
Files.createDirectories(directory);
@@ -64,6 +66,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
}
}
this.directory = directory.toString();
this.dimension = dimension;
System.out.println("Cached world directory: " + directory);
// Insert an invalid region element
cachedRegions.put(0, null);
@@ -241,7 +244,7 @@ public final class CachedWorld implements ICachedWorld, Helper {
*/
private synchronized CachedRegion getOrCreateRegion(int regionX, int regionZ) {
return cachedRegions.computeIfAbsent(getRegionID(regionX, regionZ), id -> {
CachedRegion newRegion = new CachedRegion(regionX, regionZ);
CachedRegion newRegion = new CachedRegion(regionX, regionZ, dimension);
newRegion.load(this.directory);
return newRegion;
});
+2 -2
View File
@@ -144,7 +144,7 @@ public final class ChunkPacker implements Helper {
return PathingBlockType.SOLID;
}
public static IBlockState pathingTypeToBlock(PathingBlockType type) {
public static IBlockState pathingTypeToBlock(PathingBlockType type, int dimension) {
switch (type) {
case AIR:
return Blocks.AIR.getDefaultState();
@@ -154,7 +154,7 @@ public final class ChunkPacker implements Helper {
return Blocks.LAVA.getDefaultState();
case SOLID:
// Dimension solid types
switch (mc.player.dimension) {
switch (dimension) {
case -1:
return Blocks.NETHERRACK.getDefaultState();
case 0:
+4 -2
View File
@@ -35,11 +35,13 @@ public class WorldData implements IWorldData {
private final Waypoints waypoints;
//public final MapData map;
public final Path directory;
public final int dimension;
WorldData(Path directory) {
WorldData(Path directory, int dimension) {
this.directory = directory;
this.cache = new CachedWorld(directory.resolve("cache"));
this.cache = new CachedWorld(directory.resolve("cache"), dimension);
this.waypoints = new Waypoints(directory.resolve("waypoints"));
this.dimension = dimension;
}
public void onClose() {
+1 -1
View File
@@ -91,7 +91,7 @@ public enum WorldProvider implements IWorldProvider, Helper {
} catch (IOException ignored) {}
}
System.out.println("Baritone world data dir: " + dir);
this.currentWorld = this.worldCache.computeIfAbsent(dir, WorldData::new);
this.currentWorld = this.worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimensionID));
}
public final void closeWorld() {
@@ -44,7 +44,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
private final CalculationContext calcContext;
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<HashSet<Long>> favoredPositions, CalculationContext context) {
super(startX, startY, startZ, goal);
super(startX, startY, startZ, goal, context);
this.favoredPositions = favoredPositions;
this.calcContext = context;
}
@@ -95,7 +95,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
numNodes++;
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
return Optional.of(new Path(startNode, currentNode, numNodes, goal));
return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext));
}
for (Moves moves : Moves.values()) {
int newX = currentNode.x + moves.xOffset;
@@ -198,7 +198,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
System.out.println("But I'm going to do it anyway, because yolo");
}
System.out.println("Path goes for " + Math.sqrt(dist) + " blocks");
return Optional.of(new Path(startNode, bestSoFar[i], numNodes, goal));
return Optional.of(new Path(startNode, bestSoFar[i], numNodes, goal, calcContext));
}
}
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks");
@@ -22,6 +22,7 @@ import baritone.api.pathing.calc.IPath;
import baritone.api.pathing.calc.IPathFinder;
import baritone.api.pathing.goals.Goal;
import baritone.api.utils.PathCalculationResult;
import baritone.pathing.movement.CalculationContext;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.Optional;
@@ -44,6 +45,8 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
protected final Goal goal;
private final CalculationContext context;
/**
* @see <a href="https://github.com/cabaletta/baritone/issues/107">Issue #107</a>
*/
@@ -71,11 +74,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
*/
protected final static double MIN_DIST_PATH = 5;
AbstractNodeCostSearch(int startX, int startY, int startZ, Goal goal) {
AbstractNodeCostSearch(int startX, int startY, int startZ, Goal goal, CalculationContext context) {
this.startX = startX;
this.startY = startY;
this.startZ = startZ;
this.goal = goal;
this.context = context;
this.map = new Long2ObjectOpenHashMap<>(Baritone.settings().pathingMapDefaultSize.value, Baritone.settings().pathingMapLoadFactor.get());
}
@@ -171,7 +175,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
@Override
public Optional<IPath> pathToMostRecentNodeConsidered() {
try {
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal));
return Optional.ofNullable(mostRecentConsidered).map(node -> new Path(startNode, node, 0, goal, context));
} catch (IllegalStateException ex) {
System.out.println("Unable to construct path to render");
return Optional.empty();
@@ -193,7 +197,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
}
if (getDistFromStartSq(bestSoFar[i]) > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
try {
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal));
return Optional.of(new Path(startNode, bestSoFar[i], 0, goal, context));
} catch (IllegalStateException ex) {
System.out.println("Unable to construct path to render");
return Optional.empty();
@@ -21,6 +21,7 @@ import baritone.api.pathing.calc.IPath;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.movement.IMovement;
import baritone.api.utils.BetterBlockPos;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.Moves;
import baritone.pathing.path.CutoffPath;
@@ -63,9 +64,11 @@ class Path extends PathBase {
private final int numNodes;
private final CalculationContext context;
private volatile boolean verified;
Path(PathNode start, PathNode end, int numNodes, Goal goal) {
Path(PathNode start, PathNode end, int numNodes, Goal goal, CalculationContext context) {
this.start = new BetterBlockPos(start.x, start.y, start.z);
this.end = new BetterBlockPos(end.x, end.y, end.z);
this.numNodes = numNodes;
@@ -73,6 +76,7 @@ class Path extends PathBase {
this.movements = new ArrayList<>();
this.nodes = new ArrayList<>();
this.goal = goal;
this.context = context;
assemblePath(end);
}
@@ -123,9 +127,9 @@ class Path extends PathBase {
return false;
}
private static Movement runBackwards(BetterBlockPos src, BetterBlockPos dest, double cost) {
private Movement runBackwards(BetterBlockPos src, BetterBlockPos dest, double cost) {
for (Moves moves : Moves.values()) {
Movement move = moves.apply0(src);
Movement move = moves.apply0(context, src);
if (move.getDest().equals(dest)) {
// have to calculate the cost at calculation time so we can accurately judge whether a cost increase happened between cached calculation and real execution
move.override(cost);
@@ -22,19 +22,23 @@ import baritone.api.pathing.movement.ActionCosts;
import baritone.utils.Helper;
import baritone.utils.ToolSet;
import baritone.utils.pathing.BetterWorldBorder;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* @author Brady
* @since 8/7/2018 4:30 PM
*/
public class CalculationContext implements Helper {
public class CalculationContext {
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
private final EntityPlayerSP player;
private final World world;
private final ToolSet toolSet;
private final boolean hasWaterBucket;
private final boolean hasThrowaway;
@@ -48,15 +52,17 @@ public class CalculationContext implements Helper {
private final BetterWorldBorder worldBorder;
public CalculationContext() {
this.toolSet = new ToolSet();
this.player = Helper.HELPER.player();
this.world = Helper.HELPER.world();
this.toolSet = new ToolSet(player);
this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(false);
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether();
this.canSprint = Baritone.settings().allowSprint.get() && player().getFoodStats().getFoodLevel() > 6;
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether();
this.canSprint = Baritone.settings().allowSprint.get() && player.getFoodStats().getFoodLevel() > 6;
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get();
this.allowBreak = Baritone.settings().allowBreak.get();
this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get();
this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get();
int depth = EnchantmentHelper.getDepthStriderModifier(player());
int depth = EnchantmentHelper.getDepthStriderModifier(player);
if (depth > 3) {
depth = 3;
}
@@ -66,7 +72,7 @@ public class CalculationContext implements Helper {
// why cache these things here, why not let the movements just get directly from settings?
// because if some movements are calculated one way and others are calculated another way,
// then you get a wildly inconsistent path that isn't optimal for either scenario.
this.worldBorder = new BetterWorldBorder(world().getWorldBorder());
this.worldBorder = new BetterWorldBorder(world.getWorldBorder());
}
public boolean canPlaceThrowawayAt(int x, int y, int z) {
@@ -91,6 +97,15 @@ public class CalculationContext implements Helper {
return false;
}
public World world() {
return world;
}
public EntityPlayerSP player() {
return player;
}
public ToolSet getToolSet() {
return toolSet;
}
@@ -20,13 +20,8 @@ package baritone.pathing.movement;
import baritone.Baritone;
import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.VecUtils;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler;
import baritone.api.utils.*;
import baritone.utils.*;
import net.minecraft.block.BlockLiquid;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
@@ -34,6 +29,7 @@ import net.minecraft.world.chunk.EmptyChunk;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static baritone.utils.InputOverrideHandler.Input;
@@ -151,10 +147,13 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
for (BetterBlockPos blockPos : positionsToBreak) {
if (!MovementHelper.canWalkThrough(blockPos) && !(BlockStateInterface.getBlock(blockPos) instanceof BlockLiquid)) { // can't break liquid, so don't try
somethingInTheWay = true;
Optional<Rotation> reachable = RotationUtils.reachable(player(), blockPos);
Optional<Rotation> reachable = RotationUtils.reachable(player(), blockPos, playerController().getBlockReachDistance());
if (reachable.isPresent()) {
MovementHelper.switchToBestToolFor(BlockStateInterface.get(blockPos));
state.setTarget(new MovementState.MovementTarget(reachable.get(), true)).setInput(Input.CLICK_LEFT, true);
state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), blockPos)) {
state.setInput(Input.CLICK_LEFT, true);
}
return false;
}
//get rekt minecraft
@@ -163,7 +162,9 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
//you dont own me!!!!
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(player().getPositionEyes(1.0F),
VecUtils.getBlockPosCenter(blockPos)), true)
).setInput(InputOverrideHandler.Input.CLICK_LEFT, true);
);
// don't check selectedblock on this one, this is a fallback when we can't see any face directly, it's intended to be breaking the "incorrect" block
state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true);
return false;
}
}
@@ -21,14 +21,10 @@ import baritone.Baritone;
import baritone.api.pathing.movement.ActionCosts;
import baritone.api.utils.*;
import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler;
import baritone.utils.ToolSet;
import baritone.utils.*;
import net.minecraft.block.*;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemPickaxe;
@@ -384,7 +380,7 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param b the blockstate to mine
*/
static void switchToBestToolFor(IBlockState b) {
switchToBestToolFor(b, new ToolSet());
switchToBestToolFor(b, new ToolSet(Helper.HELPER.player()));
}
/**
@@ -394,11 +390,11 @@ public interface MovementHelper extends ActionCosts, Helper {
* @param ts previously calculated ToolSet
*/
static void switchToBestToolFor(IBlockState b, ToolSet ts) {
mc.player.inventory.currentItem = ts.getBestSlot(b.getBlock());
Helper.HELPER.player().inventory.currentItem = ts.getBestSlot(b.getBlock());
}
static boolean throwaway(boolean select) {
EntityPlayerSP p = Minecraft.getMinecraft().player;
EntityPlayerSP p = Helper.HELPER.player();
NonNullList<ItemStack> inv = p.inventory.mainInventory;
for (byte i = 0; i < 9; i++) {
ItemStack item = inv.get(i);
@@ -434,10 +430,11 @@ public interface MovementHelper extends ActionCosts, Helper {
}
static void moveTowards(MovementState state, BlockPos pos) {
EntityPlayerSP player = Helper.HELPER.player();
state.setTarget(new MovementTarget(
new Rotation(RotationUtils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
new Rotation(RotationUtils.calcRotationFromVec3d(player.getPositionEyes(1.0F),
VecUtils.getBlockPosCenter(pos),
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getYaw(), mc.player.rotationPitch),
new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch),
false
)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
}
@@ -30,7 +30,7 @@ import net.minecraft.util.EnumFacing;
public enum Moves {
DOWNWARD(0, -1, 0) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDownward(src, src.down());
}
@@ -42,7 +42,7 @@ public enum Moves {
PILLAR(0, +1, 0) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementPillar(src, src.up());
}
@@ -54,7 +54,7 @@ public enum Moves {
TRAVERSE_NORTH(0, 0, -1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementTraverse(src, src.north());
}
@@ -66,7 +66,7 @@ public enum Moves {
TRAVERSE_SOUTH(0, 0, +1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementTraverse(src, src.south());
}
@@ -78,7 +78,7 @@ public enum Moves {
TRAVERSE_EAST(+1, 0, 0) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementTraverse(src, src.east());
}
@@ -90,7 +90,7 @@ public enum Moves {
TRAVERSE_WEST(-1, 0, 0) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementTraverse(src, src.west());
}
@@ -102,7 +102,7 @@ public enum Moves {
ASCEND_NORTH(0, +1, -1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementAscend(src, new BetterBlockPos(src.x, src.y + 1, src.z - 1));
}
@@ -114,7 +114,7 @@ public enum Moves {
ASCEND_SOUTH(0, +1, +1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementAscend(src, new BetterBlockPos(src.x, src.y + 1, src.z + 1));
}
@@ -126,7 +126,7 @@ public enum Moves {
ASCEND_EAST(+1, +1, 0) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementAscend(src, new BetterBlockPos(src.x + 1, src.y + 1, src.z));
}
@@ -138,7 +138,7 @@ public enum Moves {
ASCEND_WEST(-1, +1, 0) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementAscend(src, new BetterBlockPos(src.x - 1, src.y + 1, src.z));
}
@@ -150,9 +150,9 @@ public enum Moves {
DESCEND_EAST(+1, -1, 0, false, true) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(new CalculationContext(), src.x, src.y, src.z, res);
apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
return new MovementDescend(src, new BetterBlockPos(res.x, res.y, res.z));
} else {
@@ -168,9 +168,9 @@ public enum Moves {
DESCEND_WEST(-1, -1, 0, false, true) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(new CalculationContext(), src.x, src.y, src.z, res);
apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
return new MovementDescend(src, new BetterBlockPos(res.x, res.y, res.z));
} else {
@@ -186,9 +186,9 @@ public enum Moves {
DESCEND_NORTH(0, -1, -1, false, true) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(new CalculationContext(), src.x, src.y, src.z, res);
apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
return new MovementDescend(src, new BetterBlockPos(res.x, res.y, res.z));
} else {
@@ -204,9 +204,9 @@ public enum Moves {
DESCEND_SOUTH(0, -1, +1, false, true) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
MutableMoveResult res = new MutableMoveResult();
apply(new CalculationContext(), src.x, src.y, src.z, res);
apply(context, src.x, src.y, src.z, res);
if (res.y == src.y - 1) {
return new MovementDescend(src, new BetterBlockPos(res.x, res.y, res.z));
} else {
@@ -222,7 +222,7 @@ public enum Moves {
DIAGONAL_NORTHEAST(+1, 0, -1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(src, EnumFacing.NORTH, EnumFacing.EAST);
}
@@ -234,7 +234,7 @@ public enum Moves {
DIAGONAL_NORTHWEST(-1, 0, -1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(src, EnumFacing.NORTH, EnumFacing.WEST);
}
@@ -246,7 +246,7 @@ public enum Moves {
DIAGONAL_SOUTHEAST(+1, 0, +1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(src, EnumFacing.SOUTH, EnumFacing.EAST);
}
@@ -258,7 +258,7 @@ public enum Moves {
DIAGONAL_SOUTHWEST(-1, 0, +1) {
@Override
public Movement apply0(BetterBlockPos src) {
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return new MovementDiagonal(src, EnumFacing.SOUTH, EnumFacing.WEST);
}
@@ -270,8 +270,8 @@ public enum Moves {
PARKOUR_NORTH(0, 0, -4, true, false) {
@Override
public Movement apply0(BetterBlockPos src) {
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.NORTH);
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.NORTH);
}
@Override
@@ -282,8 +282,8 @@ public enum Moves {
PARKOUR_SOUTH(0, 0, +4, true, false) {
@Override
public Movement apply0(BetterBlockPos src) {
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.SOUTH);
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.SOUTH);
}
@Override
@@ -294,8 +294,8 @@ public enum Moves {
PARKOUR_EAST(+4, 0, 0, true, false) {
@Override
public Movement apply0(BetterBlockPos src) {
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.EAST);
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.EAST);
}
@Override
@@ -306,8 +306,8 @@ public enum Moves {
PARKOUR_WEST(-4, 0, 0, true, false) {
@Override
public Movement apply0(BetterBlockPos src) {
return MovementParkour.cost(new CalculationContext(), src, EnumFacing.WEST);
public Movement apply0(CalculationContext context, BetterBlockPos src) {
return MovementParkour.cost(context, src, EnumFacing.WEST);
}
@Override
@@ -335,7 +335,7 @@ public enum Moves {
this(x, y, z, false, false);
}
public abstract Movement apply0(BetterBlockPos src);
public abstract Movement apply0(CalculationContext context, BetterBlockPos src);
public void apply(CalculationContext context, int x, int y, int z, MutableMoveResult result) {
if (dynamicXZ || dynamicY) {
@@ -19,7 +19,10 @@ package baritone.pathing.movement.movements;
import baritone.Baritone;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.*;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.VecUtils;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
@@ -67,13 +70,13 @@ public class MovementFall extends Movement {
return state.setStatus(MovementStatus.UNREACHABLE);
}
if (player().posY - dest.getY() < mc.playerController.getBlockReachDistance()) {
if (player().posY - dest.getY() < playerController().getBlockReachDistance()) {
player().inventory.currentItem = player().inventory.getSlotFor(STACK_BUCKET_WATER);
targetRotation = new Rotation(player().rotationYaw, 90.0F);
RayTraceResult trace = RayTraceUtils.simulateRayTrace(player().rotationYaw, 90.0F);
if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK) {
RayTraceResult trace = mc.objectMouseOver;
if (trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK && player().rotationPitch > 89.0F) {
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
}
}
@@ -27,9 +27,7 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler;
import baritone.utils.*;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -227,7 +225,7 @@ public class MovementParkour extends Movement {
double faceY = (dest.getY() + against1.getY()) * 0.5D;
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
Rotation place = RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations());
RayTraceResult res = RayTraceUtils.rayTraceTowards(place);
RayTraceResult res = RayTraceUtils.rayTraceTowards(player(), place, playerController().getBlockReachDistance());
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(dest.down())) {
state.setTarget(new MovementState.MovementTarget(place, true));
}
@@ -20,7 +20,6 @@ package baritone.pathing.movement.movements;
import baritone.api.pathing.movement.MovementStatus;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.VecUtils;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
@@ -28,9 +27,9 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
import baritone.api.utils.RotationUtils;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
@@ -158,11 +157,11 @@ public class MovementPillar extends Movement {
}
boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine;
boolean vine = fromDown.getBlock() instanceof BlockVine;
Rotation rotation = RotationUtils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
Rotation rotation = RotationUtils.calcRotationFromVec3d(player().getPositionEyes(1.0F),
VecUtils.getBlockPosCenter(positionToPlace),
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch));
new Rotation(player().rotationYaw, player().rotationPitch));
if (!ladder) {
state.setTarget(new MovementState.MovementTarget(new Rotation(mc.player.rotationYaw, rotation.getPitch()), true));
state.setTarget(new MovementState.MovementTarget(new Rotation(player().rotationYaw, rotation.getPitch()), true));
}
boolean blockIsThere = MovementHelper.canWalkOn(src) || ladder;
@@ -215,10 +214,10 @@ public class MovementPillar extends Movement {
if (!blockIsThere) {
Block fr = BlockStateInterface.get(src).getBlock();
if (!(fr instanceof BlockAir || fr.isReplaceable(Minecraft.getMinecraft().world, src))) {
if (!(fr instanceof BlockAir || fr.isReplaceable(world(), src))) {
state.setInput(InputOverrideHandler.Input.CLICK_LEFT, true);
blockIsThere = false;
} else if (Minecraft.getMinecraft().player.isSneaking()) { // 1 tick after we're able to place
} else if (player().isSneaking()) { // 1 tick after we're able to place
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
}
}
@@ -26,6 +26,8 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
import baritone.api.utils.RayTraceUtils;
import baritone.api.utils.RotationUtils;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@@ -265,7 +267,7 @@ public class MovementTraverse extends Movement {
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations()), true));
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (Minecraft.getMinecraft().player.isSneaking() || Baritone.settings().assumeSafeWalk.get()) && RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), against1) && (player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) && RayTraceUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
}
//System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock());
@@ -18,6 +18,8 @@
package baritone.process;
import baritone.Baritone;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalComposite;
import baritone.api.pathing.goals.GoalNear;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.process.IFollowProcess;
@@ -27,6 +29,12 @@ import baritone.utils.BaritoneProcessHelper;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Follow an entity
*
@@ -34,7 +42,8 @@ import net.minecraft.util.math.BlockPos;
*/
public final class FollowProcess extends BaritoneProcessHelper implements IFollowProcess {
private Entity following;
private Predicate<Entity> filter;
private List<Entity> cache;
public FollowProcess(Baritone baritone) {
super(baritone, 1);
@@ -42,39 +51,76 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
scanWorld();
Goal goal = new GoalComposite(cache.stream().map(this::towards).toArray(Goal[]::new));
return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH);
}
private Goal towards(Entity following) {
// lol this is trashy but it works
BlockPos pos;
if (Baritone.settings().followOffsetDistance.get() == 0) {
pos = following.getPosition();
pos = new BlockPos(following);
} else {
GoalXZ g = GoalXZ.fromDirection(following.getPositionVector(), Baritone.settings().followOffsetDirection.get(), Baritone.settings().followOffsetDistance.get());
pos = new BlockPos(g.getX(), following.posY, g.getZ());
}
return new PathingCommand(new GoalNear(pos, Baritone.settings().followRadius.get()), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH);
return new GoalNear(pos, Baritone.settings().followRadius.get());
}
private boolean followable(Entity entity) {
if (entity == null) {
return false;
}
if (entity.isDead) {
return false;
}
if (entity.equals(player())) {
return false;
}
if (!world().loadedEntityList.contains(entity) && !world().playerEntities.contains(entity)) {
return false;
}
return true;
}
private void scanWorld() {
cache = Stream.of(world().loadedEntityList, world().playerEntities).flatMap(List::stream).filter(this::followable).filter(this.filter).distinct().collect(Collectors.toCollection(ArrayList::new));
}
@Override
public boolean isActive() {
return following != null;
if (filter == null) {
return false;
}
scanWorld();
return !cache.isEmpty();
}
@Override
public void onLostControl() {
following = null;
filter = null;
cache = null;
}
@Override
public String displayName() {
return "Follow " + following;
return "Follow " + cache;
}
@Override
public void follow(Entity entity) {
this.following = entity;
public void follow(Predicate<Entity> filter) {
this.filter = filter;
}
@Override
public Entity following() {
return this.following;
public List<Entity> following() {
return cache;
}
@Override
public Predicate<Entity> currentFilter() {
return filter;
}
}
@@ -22,7 +22,6 @@ import baritone.api.pathing.goals.*;
import baritone.api.process.IMineProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
import baritone.api.utils.RotationUtils;
import baritone.cache.CachedChunk;
import baritone.cache.ChunkPacker;
import baritone.cache.WorldProvider;
@@ -31,6 +30,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.api.utils.RotationUtils;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
@@ -241,13 +241,14 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
}
public void addNearby() {
knownOreLocations.addAll(droppedItemsScan(mining, world()));
BlockPos playerFeet = playerFeet();
int searchDist = 4;//why four? idk
for (int x = playerFeet.getX() - searchDist; x <= playerFeet.getX() + searchDist; x++) {
for (int y = playerFeet.getY() - searchDist; y <= playerFeet.getY() + searchDist; y++) {
for (int z = playerFeet.getZ() - searchDist; z <= playerFeet.getZ() + searchDist; z++) {
BlockPos pos = new BlockPos(x, y, z);
if (mining.contains(BlockStateInterface.getBlock(pos)) && RotationUtils.reachable(player(), pos).isPresent()) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught
if (mining.contains(BlockStateInterface.getBlock(pos)) && RotationUtils.reachable(player(), pos, playerController().getBlockReachDistance()).isPresent()) {//crucial to only add blocks we can see because otherwise this is an x-ray and it'll get caught
knownOreLocations.add(pos);
}
}
@@ -260,6 +261,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
List<BlockPos> dropped = droppedItemsScan(mining, world);
List<BlockPos> locs = locs2
.stream()
.distinct()
// remove any that are within loaded chunks that aren't actually what we want
.filter(pos -> world.getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock()) || dropped.contains(pos))
@@ -32,6 +32,7 @@ import baritone.cache.ChunkPacker;
import baritone.cache.Waypoint;
import baritone.cache.WorldProvider;
import baritone.pathing.calc.AbstractNodeCostSearch;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.Moves;
import baritone.process.CustomGoalProcess;
@@ -264,6 +265,11 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
});
return true;
}
if (msg.startsWith("followplayers")) {
baritone.getFollowProcess().follow(EntityPlayer.class::isInstance); // O P P A
logDirect("Following any players");
return true;
}
if (msg.startsWith("follow")) {
String name = msg.substring(6).trim();
Optional<Entity> toFollow = Optional.empty();
@@ -281,7 +287,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("Not found");
return true;
}
baritone.getFollowProcess().follow(toFollow.get());
Entity effectivelyFinal = toFollow.get();
baritone.getFollowProcess().follow(x -> effectivelyFinal.equals(x));
logDirect("Following " + toFollow.get());
return true;
}
@@ -446,7 +453,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true;
}
if (msg.equals("costs")) {
List<Movement> moves = Stream.of(Moves.values()).map(x -> x.apply0(playerFeet())).collect(Collectors.toCollection(ArrayList::new));
List<Movement> moves = Stream.of(Moves.values()).map(x -> x.apply0(new CalculationContext(), playerFeet())).collect(Collectors.toCollection(ArrayList::new));
while (moves.contains(null)) {
moves.remove(null);
}
+11
View File
@@ -23,6 +23,7 @@ import baritone.api.utils.Rotation;
import net.minecraft.block.BlockSlab;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
@@ -51,9 +52,19 @@ public interface Helper {
Minecraft mc = Minecraft.getMinecraft();
default EntityPlayerSP player() {
if (!mc.isCallingFromMinecraftThread()) {
throw new IllegalStateException("h00000000");
}
return mc.player;
}
default PlayerControllerMP playerController() { // idk
if (!mc.isCallingFromMinecraftThread()) {
throw new IllegalStateException("h00000000");
}
return mc.playerController;
}
default WorldClient world() {
return mc.world;
}
@@ -18,10 +18,13 @@
package baritone.utils;
import baritone.Baritone;
import baritone.api.event.events.TickEvent;
import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.pathing.goals.Goal;
import baritone.api.process.IBaritoneProcess;
import baritone.api.process.PathingCommand;
import baritone.behavior.PathingBehavior;
import baritone.pathing.calc.AbstractNodeCostSearch;
import baritone.pathing.path.PathExecutor;
import net.minecraft.util.math.BlockPos;
@@ -36,10 +39,20 @@ public class PathingControlManager {
private final HashSet<IBaritoneProcess> processes; // unGh
private IBaritoneProcess inControlLastTick;
private IBaritoneProcess inControlThisTick;
private PathingCommand command;
public PathingControlManager(Baritone baritone) {
this.baritone = baritone;
this.processes = new HashSet<>();
baritone.registerEventListener(new AbstractGameEventListener() { // needs to be after all behavior ticks
@Override
public void onTick(TickEvent event) {
if (event.getType() == TickEvent.Type.OUT) {
return;
}
postTick();
}
});
}
public void registerProcess(IBaritoneProcess process) {
@@ -61,38 +74,35 @@ public class PathingControlManager {
return inControlThisTick;
}
public void doTheThingWithTheStuff() {
public void preTick() {
inControlLastTick = inControlThisTick;
PathingCommand cmd = doTheStuff();
if (cmd == null) {
command = doTheStuff();
if (command == null) {
return;
}
PathingBehavior p = baritone.getPathingBehavior();
switch (cmd.commandType) {
switch (command.commandType) {
case REQUEST_PAUSE:
p.requestPause();
break;
case CANCEL_AND_SET_GOAL:
p.secretInternalSetGoal(cmd.goal);
p.secretInternalSetGoal(command.goal);
p.cancelSegmentIfSafe();
break;
case FORCE_REVALIDATE_GOAL_AND_PATH:
p.secretInternalSetGoalAndPath(cmd.goal);
if (cmd.goal == null || forceRevalidate(cmd.goal) || revalidateGoal(cmd.goal)) {
// pwnage
p.cancelSegmentIfSafe();
if (!p.isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) {
p.secretInternalSetGoalAndPath(command.goal);
}
break;
case REVALIDATE_GOAL_AND_PATH:
p.secretInternalSetGoalAndPath(cmd.goal);
if (Baritone.settings().cancelOnGoalInvalidation.get() && (cmd.goal == null || revalidateGoal(cmd.goal))) {
p.cancelSegmentIfSafe();
if (!p.isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) {
p.secretInternalSetGoalAndPath(command.goal);
}
break;
case SET_GOAL_AND_PATH:
// now this i can do
if (cmd.goal != null) {
baritone.getPathingBehavior().secretInternalSetGoalAndPath(cmd.goal);
if (command.goal != null) {
baritone.getPathingBehavior().secretInternalSetGoalAndPath(command.goal);
}
break;
default:
@@ -100,6 +110,33 @@ public class PathingControlManager {
}
}
public void postTick() {
// if we did this in pretick, it would suck
// we use the time between ticks as calculation time
// therefore, we only cancel and recalculate after the tick for the current path has executed
// "it would suck" means it would actually execute a path every other tick
if (command == null) {
return;
}
PathingBehavior p = baritone.getPathingBehavior();
switch (command.commandType) {
case FORCE_REVALIDATE_GOAL_AND_PATH:
if (command.goal == null || forceRevalidate(command.goal) || revalidateGoal(command.goal)) {
// pwnage
p.softCancelIfSafe();
}
p.secretInternalSetGoalAndPath(command.goal);
break;
case REVALIDATE_GOAL_AND_PATH:
if (Baritone.settings().cancelOnGoalInvalidation.get() && (command.goal == null || revalidateGoal(command.goal))) {
p.softCancelIfSafe();
}
p.secretInternalSetGoalAndPath(command.goal);
break;
default:
}
}
public boolean forceRevalidate(Goal newGoal) {
PathExecutor current = baritone.getPathingBehavior().getCurrent();
if (current != null) {
+12 -8
View File
@@ -20,6 +20,7 @@ package baritone.utils;
import baritone.Baritone;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Enchantments;
import net.minecraft.init.MobEffects;
@@ -36,7 +37,7 @@ import java.util.function.Function;
*
* @author Avery, Brady, leijurv
*/
public class ToolSet implements Helper {
public class ToolSet {
/**
* A cache mapping a {@link Block} to how long it will take to break
* with this toolset, given the optimum tool is used.
@@ -48,8 +49,11 @@ public class ToolSet implements Helper {
*/
private final Function<Block, Double> backendCalculation;
public ToolSet() {
private final EntityPlayerSP player;
public ToolSet(EntityPlayerSP player) {
breakStrengthCache = new HashMap<>();
this.player = player;
if (Baritone.settings().considerPotionEffects.get()) {
double amplifier = potionAmplifier();
@@ -98,7 +102,7 @@ public class ToolSet implements Helper {
int materialCost = Integer.MIN_VALUE;
IBlockState blockState = b.getDefaultState();
for (byte i = 0; i < 9; i++) {
ItemStack itemStack = player().inventory.getStackInSlot(i);
ItemStack itemStack = player.inventory.getStackInSlot(i);
double v = calculateStrVsBlock(itemStack, blockState);
if (v > value) {
value = v;
@@ -123,7 +127,7 @@ public class ToolSet implements Helper {
* @return A double containing the destruction ticks with the best tool
*/
private double getBestDestructionTime(Block b) {
ItemStack stack = player().inventory.getStackInSlot(getBestSlot(b));
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b));
return calculateStrVsBlock(stack, b.getDefaultState());
}
@@ -164,11 +168,11 @@ public class ToolSet implements Helper {
*/
private double potionAmplifier() {
double speed = 1;
if (player().isPotionActive(MobEffects.HASTE)) {
speed *= 1 + (player().getActivePotionEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2;
if (player.isPotionActive(MobEffects.HASTE)) {
speed *= 1 + (player.getActivePotionEffect(MobEffects.HASTE).getAmplifier() + 1) * 0.2;
}
if (player().isPotionActive(MobEffects.MINING_FATIGUE)) {
switch (player().getActivePotionEffect(MobEffects.MINING_FATIGUE).getAmplifier()) {
if (player.isPotionActive(MobEffects.MINING_FATIGUE)) {
switch (player.getActivePotionEffect(MobEffects.MINING_FATIGUE).getAmplifier()) {
case 0:
speed *= 0.3;
break;
@@ -21,16 +21,16 @@ import baritone.api.BaritoneAPI;
import baritone.api.pathing.calc.IPath;
import baritone.api.pathing.goals.Goal;
import baritone.pathing.path.CutoffPath;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.EmptyChunk;
public abstract class PathBase implements IPath {
@Override
public IPath cutoffAtLoadedChunks() {
public IPath cutoffAtLoadedChunks(World world) {
for (int i = 0; i < positions().size(); i++) {
BlockPos pos = positions().get(i);
if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) {
if (world.getChunk(pos) instanceof EmptyChunk) {
return new CutoffPath(this, i);
}
}