Compare commits

...

18 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
Leijurv
22bb9f0ec8 v1.0.0-hotfix-3 2018-11-12 09:07:48 -08:00
Leijurv
654ac1075a wait a tick until objectMouseOver matches, fixes #254 2018-11-10 09:26:32 -08:00
Leijurv
ffc050668b fix cherry pick merge errors 2018-11-07 10:01:58 -08:00
Leijurv
80f65452e1 make sure to pick up dropped items while mining, fixes #170 2018-11-07 09:56:47 -08:00
14 changed files with 100 additions and 48 deletions

View File

@@ -16,7 +16,7 @@
*/
group 'baritone'
version '1.0.0-hotfix-2'
version '1.0.0-hotfix-4'
buildscript {
repositories {

View File

@@ -24,8 +24,8 @@ import net.minecraft.util.text.ITextComponent;
import java.awt.*;
import java.lang.reflect.Field;
import java.util.List;
import java.util.*;
import java.util.List;
import java.util.function.Consumer;
/**
@@ -376,6 +376,11 @@ public class Settings {
*/
public Setting<Integer> mineGoalUpdateInterval = new Setting<>(5);
/**
* While mining, should it also consider dropped items of the correct type as a pathing destination (as well as ore blocks)?
*/
public Setting<Boolean> mineScanDroppedItems = new Setting<>(true);
/**
* Cancel the current path if the goal has changed, and the path originally ended in the goal but doesn't anymore.
* <p>

View File

@@ -105,8 +105,9 @@ public interface IPath {
default double ticksRemainingFrom(int pathPosition) {
double sum = 0;
//this is fast because we aren't requesting recalculation, it's just cached
for (int i = pathPosition; i < movements().size(); i++) {
sum += movements().get(i).getCost();
List<IMovement> movements = movements();
for (int i = pathPosition; i < movements.size(); i++) {
sum += movements.get(i).getCost();
}
return sum;
}

View File

@@ -85,10 +85,9 @@ public final class VecUtils {
* @see #getBlockPosCenter(BlockPos)
*/
public static double distanceToCenter(BlockPos pos, double x, double y, double z) {
Vec3d center = getBlockPosCenter(pos);
double xdiff = x - center.x;
double ydiff = y - center.y;
double zdiff = z - center.z;
double xdiff = pos.getX() + 0.5 - x;
double ydiff = pos.getY() + 0.5 - y;
double zdiff = pos.getZ() + 0.5 - z;
return Math.sqrt(xdiff * xdiff + ydiff * ydiff + zdiff * zdiff);
}

View File

@@ -30,10 +30,13 @@ import baritone.pathing.movement.MovementHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.EmptyChunk;
import java.util.*;
@@ -45,7 +48,7 @@ import java.util.stream.Collectors;
* @author leijurv
*/
public final class MineBehavior extends Behavior implements IMineBehavior, Helper {
public static final int ORE_LOCATIONS_COUNT = 64;
private List<Block> mining;
private List<BlockPos> knownOreLocations;
private BlockPos branchPoint;
@@ -86,12 +89,12 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
}
private void updateGoal() {
if (mining == null) {
if (mining == null || world() == null || player() == null) {
return;
}
List<BlockPos> locs = knownOreLocations;
if (!locs.isEmpty()) {
List<BlockPos> locs2 = prune(new ArrayList<>(locs), mining, 64);
List<BlockPos> locs2 = prune(new ArrayList<>(locs), mining, ORE_LOCATIONS_COUNT, world());
// 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
baritone.getPathingBehavior().setGoalAndPath(new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)));
knownOreLocations = locs2;
@@ -121,13 +124,14 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
}
private void rescan() {
if (mining == null) {
if (mining == null || world() == null || player() == null) {
return;
}
if (Baritone.settings().legitMine.get()) {
return;
}
List<BlockPos> locs = searchWorld(mining, 64);
List<BlockPos> locs = searchWorld(mining, ORE_LOCATIONS_COUNT, world());
locs.addAll(droppedItemsScan(mining, world()));
if (locs.isEmpty()) {
logDebug("No locations for " + mining + " known, cancelling");
mine(0, (String[]) null);
@@ -158,7 +162,30 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
}
}
public List<BlockPos> searchWorld(List<Block> mining, int max) {
public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {
if (!Baritone.settings().mineScanDroppedItems.get()) {
return new ArrayList<>();
}
Set<Item> searchingFor = new HashSet<>();
for (Block block : mining) {
Item drop = block.getItemDropped(block.getDefaultState(), new Random(), 0);
Item ore = Item.getItemFromBlock(block);
searchingFor.add(drop);
searchingFor.add(ore);
}
List<BlockPos> ret = new ArrayList<>();
for (Entity entity : world.loadedEntityList) {
if (entity instanceof EntityItem) {
EntityItem ei = (EntityItem) entity;
if (searchingFor.contains(ei.getItem().getItem())) {
ret.add(entity.getPosition());
}
}
}
return ret;
}
public static List<BlockPos> searchWorld(List<Block> mining, int max, World world) {
List<BlockPos> locs = new ArrayList<>();
List<Block> uninteresting = new ArrayList<>();
//long b = System.currentTimeMillis();
@@ -178,7 +205,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(uninteresting, max, 10, 26));
//System.out.println("Scan of loaded chunks took " + (System.currentTimeMillis() - before) + "ms");
}
return prune(locs, mining, max);
return prune(locs, mining, max, world);
}
public void addNearby() {
@@ -194,15 +221,16 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
}
}
}
knownOreLocations = prune(knownOreLocations, mining, 64);
knownOreLocations = prune(knownOreLocations, mining, ORE_LOCATIONS_COUNT, world());
}
public List<BlockPos> prune(List<BlockPos> locs2, List<Block> mining, int max) {
public static List<BlockPos> prune(List<BlockPos> locs2, List<Block> mining, int max, World world) {
List<BlockPos> dropped = droppedItemsScan(mining, world);
List<BlockPos> locs = locs2
.stream()
// 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()))
.filter(pos -> world.getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock()) || dropped.contains(pos))
// remove any that are implausible to mine (encased in bedrock, or touching lava)
.filter(MineBehavior::plausibleToBreak)

View File

@@ -38,12 +38,14 @@ import baritone.pathing.path.PathExecutor;
import baritone.utils.BlockBreakHelper;
import baritone.utils.Helper;
import baritone.utils.PathRenderer;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import net.minecraft.util.math.BlockPos;
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.stream.Collectors;
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
@@ -134,7 +136,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
return;
}
// 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
logDebug("Splicing into planned next path early...");
queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
@@ -419,11 +421,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
} else {
timeout = Baritone.settings().planAheadTimeoutMS.<Long>get();
}
Optional<HashSet<Long>> favoredPositions;
if (Baritone.settings().backtrackCostFavoringCoefficient.get() == 1D) {
favoredPositions = Optional.empty();
} else {
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
Optional<LongOpenHashSet> favoredPositions = Optional.empty();
if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous.isPresent()) {
LongOpenHashSet tmp = new LongOpenHashSet();
previous.get().positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos)));
favoredPositions = Optional.of(tmp);
}
try {
IPathFinder pf = new AStarPathFinder(start.getX(), start.getY(), start.getZ(), goal, favoredPositions, context);

View File

@@ -40,6 +40,8 @@ import java.util.*;
*/
public final class ChunkPacker implements Helper {
private static final Map<String, Block> resourceCache = new HashMap<>();
private ChunkPacker() {}
public static CachedChunk pack(Chunk chunk) {
@@ -93,7 +95,8 @@ public final class ChunkPacker implements Helper {
for (int z = 0; z < 16; z++) {
// @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
for (int x = 0; x < 16; x++) {
for (int y = 255; y >= 0; y--) {
@@ -120,12 +123,12 @@ public final class ChunkPacker implements Helper {
}
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) {
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
return PathingBlockType.WATER;
}

View File

@@ -29,8 +29,8 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.utils.pathing.BetterWorldBorder;
import baritone.utils.pathing.MutableMoveResult;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.HashSet;
import java.util.Optional;
/**
@@ -40,10 +40,10 @@ import java.util.Optional;
*/
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
private final Optional<HashSet<Long>> favoredPositions;
private final Optional<LongOpenHashSet> favoredPositions;
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);
this.favoredPositions = favoredPositions;
this.calcContext = context;
@@ -64,9 +64,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
bestSoFar[i] = startNode;
}
MutableMoveResult res = new MutableMoveResult();
HashSet<Long> favored = favoredPositions.orElse(null);
BetterWorldBorder worldBorder = new BetterWorldBorder(world().getWorldBorder());
BlockStateInterface.clearCachedChunk();
LongOpenHashSet favored = favoredPositions.orElse(null);
long startTime = System.nanoTime() / 1000000L;
boolean slowPath = Baritone.settings().slowPath.get();
if (slowPath) {

View File

@@ -20,15 +20,13 @@ 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.api.utils.*;
import baritone.utils.BlockBreakHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler;
import net.minecraft.block.BlockLiquid;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
@@ -36,6 +34,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;
@@ -177,7 +176,10 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
Optional<Rotation> reachable = RotationUtils.reachable(player(), blockPos);
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) || BlockStateInterface.getBlock(blockPos) == Blocks.FIRE) {
state.setInput(Input.CLICK_LEFT, true);
}
return false;
}
//get rekt minecraft
@@ -186,7 +188,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;
}
}

View File

@@ -76,7 +76,7 @@ public interface MovementHelper extends ActionCosts, Helper {
if (block == Blocks.AIR) { // early return for most common case
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;
}
if (block instanceof BlockDoor || block instanceof BlockFenceGate) {
@@ -98,7 +98,11 @@ public interface MovementHelper extends ActionCosts, Helper {
if (snow) {
// 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
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) {
return !state.getValue(BlockTrapDoor.OPEN); // see BlockTrapDoor.isPassable
@@ -145,6 +149,7 @@ public interface MovementHelper extends ActionCosts, Helper {
|| block == Blocks.WEB
|| block == Blocks.VINE
|| block == Blocks.LADDER
|| block == Blocks.COCOA
|| block instanceof BlockDoor
|| block instanceof BlockFenceGate
|| 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
return isWater(up) ^ Baritone.settings().assumeWalkOnWater.get();
}
if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
if (block == Blocks.GLASS || block == Blocks.STAINED_GLASS) {
return true;
}
if (block instanceof BlockSlab) {
@@ -481,7 +486,6 @@ public interface MovementHelper extends ActionCosts, Helper {
static boolean isFlowing(IBlockState state) {
// Will be IFluidState in 1.13
return state.getBlock() instanceof BlockLiquid
&& state.getPropertyKeys().contains(BlockLiquid.LEVEL)
&& state.getValue(BlockLiquid.LEVEL) != 0;
}
}

View File

@@ -115,7 +115,8 @@ public class MovementDiagonal extends Movement {
return COST_INF;
}
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
// Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water
// Not even touching the blocks below
@@ -124,6 +125,10 @@ public class MovementDiagonal extends Movement {
}
if (optionA != 0 || optionB != 0) {
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 we aren't edging around anything, and we aren't in water

View File

@@ -32,6 +32,7 @@ import baritone.utils.Helper;
import baritone.utils.InputOverrideHandler;
import baritone.utils.pathing.MutableMoveResult;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
@@ -68,7 +69,7 @@ public class MovementParkour extends Movement {
return;
}
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;
}
int xDiff = dir.getXOffset();

View File

@@ -108,11 +108,11 @@ public class MovementTraverse extends Movement {
if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) {
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) {
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;
for (int i = 0; i < 4; i++) {

View File

@@ -410,7 +410,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true;
}
} else {
List<BlockPos> locs = baritone.getMineBehavior().searchWorld(Collections.singletonList(block), 64);
List<BlockPos> locs = baritone.getMineBehavior().searchWorld(Collections.singletonList(block), 64, world());
if (locs.isEmpty()) {
logDirect("No locations for " + mining + " known, cancelling");
return true;