Compare commits

...

14 Commits

Author SHA1 Message Date
Leijurv e661330fb6 v1.0.0-hotfix-4 2018-12-04 14:19:20 -08:00
Leijurv 9b13380b29 fixed switched block states in traverse 2018-12-04 14:18:32 -08:00
Leijurv b48444da8c don't splice if not on ground 2018-12-01 10:48:43 -08:00
Leijurv 11a4225eaf fix inability to break fire 2018-11-29 20:10:04 -08:00
Leijurv 0611e3088e cherry pick flowing cache fix 2018-11-28 16:04:13 -08:00
Leijurv 73628f09c1 don't crash when Auto mine does weird things 2018-11-27 10:23:26 -08:00
Leijurv a907746f53 only walk through supported snow, fixes #276 2018-11-26 15:33:33 -08:00
Leijurv 8189e90569 unable to start a parkour jump from stairs 2018-11-26 15:19:03 -08:00
Leijurv 9f83677df9 favored lookup performance 2018-11-26 15:11:36 -08:00
Leijurv 5265c46f60 over 10k less objects per second 2018-11-26 15:08:37 -08:00
Leijurv 6d37e14b0e thousands here too, on long paths 2018-11-26 15:07:38 -08:00
Leijurv fbecff52af believe it or not, this saves thousands of object allocations per second 2018-11-26 15:07:29 -08:00
Leijurv 4af14cf0a6 unneeded, and was allocating thousands of sets a second 2018-11-26 15:07:12 -08:00
Leijurv 16a201255e fix behavior around cocoa pods and vines, fixes #277 2018-11-26 15:03:59 -08:00
12 changed files with 49 additions and 33 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
*/ */
group 'baritone' group 'baritone'
version '1.0.0-hotfix-3' version '1.0.0-hotfix-4'
buildscript { buildscript {
repositories { repositories {
@@ -105,8 +105,9 @@ public interface IPath {
default double ticksRemainingFrom(int pathPosition) { default double ticksRemainingFrom(int pathPosition) {
double sum = 0; double sum = 0;
//this is fast because we aren't requesting recalculation, it's just cached //this is fast because we aren't requesting recalculation, it's just cached
for (int i = pathPosition; i < movements().size(); i++) { List<IMovement> movements = movements();
sum += movements().get(i).getCost(); for (int i = pathPosition; i < movements.size(); i++) {
sum += movements.get(i).getCost();
} }
return sum; return sum;
} }
@@ -85,10 +85,9 @@ public final class VecUtils {
* @see #getBlockPosCenter(BlockPos) * @see #getBlockPosCenter(BlockPos)
*/ */
public static double distanceToCenter(BlockPos pos, double x, double y, double z) { public static double distanceToCenter(BlockPos pos, double x, double y, double z) {
Vec3d center = getBlockPosCenter(pos); double xdiff = pos.getX() + 0.5 - x;
double xdiff = x - center.x; double ydiff = pos.getY() + 0.5 - y;
double ydiff = y - center.y; double zdiff = pos.getZ() + 0.5 - z;
double zdiff = z - center.z;
return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff); return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
} }
@@ -89,7 +89,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
} }
private void updateGoal() { private void updateGoal() {
if (mining == null) { if (mining == null || world() == null || player() == null) {
return; return;
} }
List<BlockPos> locs = knownOreLocations; List<BlockPos> locs = knownOreLocations;
@@ -124,7 +124,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
} }
private void rescan() { private void rescan() {
if (mining == null) { if (mining == null || world() == null || player() == null) {
return; return;
} }
if (Baritone.settings().legitMine.get()) { if (Baritone.settings().legitMine.get()) {
@@ -38,12 +38,14 @@ import baritone.pathing.path.PathExecutor;
import baritone.utils.BlockBreakHelper; import baritone.utils.BlockBreakHelper;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.PathRenderer; import baritone.utils.PathRenderer;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.EmptyChunk; import net.minecraft.world.chunk.EmptyChunk;
import java.util.*; import java.util.ArrayList;
import java.util.Comparator;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper { public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
@@ -134,7 +136,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
return; return;
} }
// at this point, we know current is in progress // at this point, we know current is in progress
if (safe && next != null && next.snipsnapifpossible()) { if (safe && next != null && player().onGround && next.snipsnapifpossible()) {
// a movement just ended; jump directly onto the next path // a movement just ended; jump directly onto the next path
logDebug("Splicing into planned next path early..."); logDebug("Splicing into planned next path early...");
queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
@@ -419,11 +421,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
} else { } else {
timeout = Baritone.settings().planAheadTimeoutMS.<Long>get(); timeout = Baritone.settings().planAheadTimeoutMS.<Long>get();
} }
Optional<HashSet<Long>> favoredPositions; Optional<LongOpenHashSet> favoredPositions = Optional.empty();
if (Baritone.settings().backtrackCostFavoringCoefficient.get() == 1D) { if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous.isPresent()) {
favoredPositions = Optional.empty(); LongOpenHashSet tmp = new LongOpenHashSet();
} else { previous.get().positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos)));
favoredPositions = previous.map(IPath::positions).map(Collection::stream).map(x -> x.map(BetterBlockPos::longHash)).map(x -> x.collect(Collectors.toList())).map(HashSet::new); // <-- okay this is EPIC favoredPositions = Optional.of(tmp);
} }
try { try {
IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions, context); IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions, context);
+6 -3
View File
@@ -40,6 +40,8 @@ import java.util.*;
*/ */
public final class ChunkPacker implements Helper { public final class ChunkPacker implements Helper {
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) {
@@ -93,7 +95,8 @@ public final class ChunkPacker implements Helper {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
// @formatter:off // @formatter:off
https://www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html https:
//www.ibm.com/developerworks/library/j-perry-writing-good-java-code/index.html
// @formatter:on // @formatter:on
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--) {
@@ -120,12 +123,12 @@ public final class ChunkPacker implements Helper {
} }
public static Block stringToBlock(String name) { public static Block stringToBlock(String name) {
return Block.getBlockFromName(name.contains(":") ? name : "minecraft:" + name); return resourceCache.computeIfAbsent(name, n -> Block.getBlockFromName(n.contains(":") ? n : "minecraft:" + n));
} }
private static PathingBlockType getPathingBlockType(IBlockState state) { private static PathingBlockType getPathingBlockType(IBlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block.equals(Blocks.WATER)) { if (block == Blocks.WATER && !MovementHelper.isFlowing(state)) {
// only water source blocks are plausibly usable, flowing water should be avoid // only water source blocks are plausibly usable, flowing water should be avoid
return PathingBlockType.WATER; return PathingBlockType.WATER;
} }
@@ -29,8 +29,8 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.pathing.BetterWorldBorder; import baritone.utils.pathing.BetterWorldBorder;
import baritone.utils.pathing.MutableMoveResult; import baritone.utils.pathing.MutableMoveResult;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
/** /**
@@ -40,10 +40,10 @@ import java.util.Optional;
*/ */
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper { public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
private final Optional<HashSet<Long>> favoredPositions; private final Optional<LongOpenHashSet> favoredPositions;
private final CalculationContext calcContext; private final CalculationContext calcContext;
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<HashSet<Long>> favoredPositions, CalculationContext context) { public AStarPathFinder(int startX, int startY, int startZ, Goal goal, Optional<LongOpenHashSet> favoredPositions, CalculationContext context) {
super(startX, startY, startZ, goal); super(startX, startY, startZ, goal);
this.favoredPositions = favoredPositions; this.favoredPositions = favoredPositions;
this.calcContext = context; this.calcContext = context;
@@ -64,9 +64,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
bestSoFar[i] = startNode; bestSoFar[i] = startNode;
} }
MutableMoveResult res = new MutableMoveResult(); MutableMoveResult res = new MutableMoveResult();
HashSet<Long> favored = favoredPositions.orElse(null);
BetterWorldBorder worldBorder = new BetterWorldBorder(world().getWorldBorder()); BetterWorldBorder worldBorder = new BetterWorldBorder(world().getWorldBorder());
BlockStateInterface.clearCachedChunk(); BlockStateInterface.clearCachedChunk();
LongOpenHashSet favored = favoredPositions.orElse(null);
long startTime = System.nanoTime() / 1000000L; long startTime = System.nanoTime() / 1000000L;
boolean slowPath = Baritone.settings().slowPath.get(); boolean slowPath = Baritone.settings().slowPath.get();
if (slowPath) { if (slowPath) {
@@ -26,6 +26,7 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.Helper; import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import net.minecraft.block.BlockLiquid; import net.minecraft.block.BlockLiquid;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
@@ -176,7 +177,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
if (reachable.isPresent()) { if (reachable.isPresent()) {
MovementHelper.switchToBestToolFor(BlockStateInterface.get(blockPos)); MovementHelper.switchToBestToolFor(BlockStateInterface.get(blockPos));
state.setTarget(new MovementState.MovementTarget(reachable.get(), true)); state.setTarget(new MovementState.MovementTarget(reachable.get(), true));
if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), blockPos)) { if (Objects.equals(RayTraceUtils.getSelectedBlock().orElse(null), blockPos) || BlockStateInterface.getBlock(blockPos) == Blocks.FIRE) {
state.setInput(Input.CLICK_LEFT, true); state.setInput(Input.CLICK_LEFT, true);
} }
return false; return false;
@@ -76,7 +76,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.AIR) { // early return for most common case if (block == Blocks.AIR) { // early return for most common case
return true; return true;
} }
if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL) { if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.WEB || block == Blocks.END_PORTAL || block == Blocks.COCOA) {
return false; return false;
} }
if (block instanceof BlockDoor || block instanceof BlockFenceGate) { if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@@ -98,7 +98,11 @@ public interface MovementHelper extends ActionCosts, Helper {
if (snow) { if (snow) {
// the check in BlockSnow.isPassable is layers < 5 // the check in BlockSnow.isPassable is layers < 5
// while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling // while actually, we want < 3 because 3 or greater makes it impassable in a 2 high ceiling
return state.getValue(BlockSnow.LAYERS) < 3; if (state.getValue(BlockSnow.LAYERS) >= 3) {
return false;
}
// ok, it's low enough we could walk through it, but is it supported?
return canWalkOn(x, y - 1, z);
} }
if (trapdoor) { if (trapdoor) {
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
@@ -145,6 +149,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|| block == Blocks.WEB || block == Blocks.WEB
|| block == Blocks.VINE || block == Blocks.VINE
|| block == Blocks.LADDER || block == Blocks.LADDER
|| block == Blocks.COCOA
|| block instanceof BlockDoor || block instanceof BlockDoor
|| block instanceof BlockFenceGate || block instanceof BlockFenceGate
|| block instanceof BlockSnow || block instanceof BlockSnow
@@ -280,7 +285,7 @@ public interface MovementHelper extends ActionCosts, Helper {
// if assumeWalkOnWater is off, we can only walk on water if there is water above it // if assumeWalkOnWater is off, we can only walk on water if there is water above it
return isWater(up) ^ Baritone.settings().assumeWalkOnWater.get(); return isWater(up) ^ Baritone.settings().assumeWalkOnWater.get();
} }
if (block instanceof BlockGlass || block instanceof BlockStainedGlass) { if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) {
return true; return true;
} }
if (block instanceof BlockSlab) { if (block instanceof BlockSlab) {
@@ -481,7 +486,6 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean isFlowing(IBlockState state) { static boolean isFlowing(IBlockState state) {
// Will be IFluidState in 1.13 // Will be IFluidState in 1.13
return state.getBlock() instanceof BlockLiquid return state.getBlock() instanceof BlockLiquid
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
&& state.getValue(BlockLiquid.LEVEL) != 0; && state.getValue(BlockLiquid.LEVEL) != 0;
} }
} }
@@ -115,7 +115,8 @@ public class MovementDiagonal extends Movement {
return COST_INF; return COST_INF;
} }
boolean water = false; boolean water = false;
if (MovementHelper.isWater(BlockStateInterface.getBlock(x, y, z)) || MovementHelper.isWater(destInto.getBlock())) { Block startIn = BlockStateInterface.getBlock(x, y, z);
if (MovementHelper.isWater(startIn) || MovementHelper.isWater(destInto.getBlock())) {
// Ignore previous multiplier // Ignore previous multiplier
// Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water // Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water
// Not even touching the blocks below // Not even touching the blocks below
@@ -124,6 +125,10 @@ public class MovementDiagonal extends Movement {
} }
if (optionA != 0 || optionB != 0) { if (optionA != 0 || optionB != 0) {
multiplier *= SQRT_2 - 0.001; // TODO tune multiplier *= SQRT_2 - 0.001; // TODO tune
if (startIn == Blocks.LADDER || startIn == Blocks.VINE) {
// edging around doesn't work if doing so would climb a ladder or vine instead of moving sideways
return COST_INF;
}
} }
if (context.canSprint() && !water) { if (context.canSprint() && !water) {
// If we aren't edging around anything, and we aren't in water // If we aren't edging around anything, and we aren't in water
@@ -32,6 +32,7 @@ import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.pathing.MutableMoveResult; import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@@ -68,7 +69,7 @@ public class MovementParkour extends Movement {
return; return;
} }
IBlockState standingOn = BlockStateInterface.get(x, y - 1, z); IBlockState standingOn = BlockStateInterface.get(x, y - 1, z);
if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) { if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || standingOn.getBlock() instanceof BlockStairs || MovementHelper.isBottomSlab(standingOn)) {
return; return;
} }
int xDiff = dir.getXOffset(); int xDiff = dir.getXOffset();
@@ -108,11 +108,11 @@ public class MovementTraverse extends Movement {
if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) { if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) {
return COST_INF; return COST_INF;
} }
double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb0, false); double hardness1 = MovementHelper.getMiningDurationTicks(context, destX, y, destZ, pb1, false);
if (hardness1 >= COST_INF) { if (hardness1 >= COST_INF) {
return COST_INF; return COST_INF;
} }
double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb1, true); double hardness2 = MovementHelper.getMiningDurationTicks(context, destX, y + 1, destZ, pb0, true);
double WC = throughWater ? context.waterWalkSpeed() : WALK_ONE_BLOCK_COST; double WC = throughWater ? context.waterWalkSpeed() : WALK_ONE_BLOCK_COST;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {