This commit is contained in:
Leijurv
2018-08-31 11:45:45 -07:00
16 changed files with 73 additions and 76 deletions
+2 -2
View File
@@ -65,11 +65,11 @@ public class Settings {
/**
* Blocks that Baritone is allowed to place (as throwaway, for sneak bridging, pillaring, etc.)
*/
public Setting<List<Item>> acceptableThrowawayItems = new Setting<>(Arrays.asList(
public Setting<List<Item>> acceptableThrowawayItems = new Setting<>(new ArrayList<>(Arrays.asList(
Item.getItemFromBlock(Blocks.DIRT),
Item.getItemFromBlock(Blocks.COBBLESTONE),
Item.getItemFromBlock(Blocks.NETHERRACK)
));
)));
/**
* Enables some more advanced vine features. They're honestly just gimmicks and won't ever be needed in real
@@ -59,7 +59,7 @@ public class MemoryBehavior extends Behavior {
TileEntityLockable lockable = (TileEntityLockable) tileEntity;
int size = lockable.getSizeInventory();
this.futureInventories.add(new FutureInventory(System.currentTimeMillis(), size, lockable.getGuiID(), tileEntity.getPos()));
this.futureInventories.add(new FutureInventory(System.nanoTime() / 1000000L, size, lockable.getGuiID(), tileEntity.getPos()));
}
}
@@ -81,7 +81,7 @@ public class MemoryBehavior extends Behavior {
SPacketOpenWindow packet = event.cast();
// Remove any entries that were created over a second ago, this should make up for INSANE latency
this.futureInventories.removeIf(i -> System.currentTimeMillis() - i.time > 1000);
this.futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000);
this.futureInventories.stream()
.filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount())
@@ -183,7 +183,7 @@ public final class CachedRegion implements IBlockTypeAccess {
return;
System.out.println("Loading region " + x + "," + z + " from disk " + path);
long start = System.currentTimeMillis();
long start = System.nanoTime() / 1000000L;
try (
FileInputStream fileIn = new FileInputStream(regionFile.toFile());
@@ -266,7 +266,7 @@ public final class CachedRegion implements IBlockTypeAccess {
}
}
hasUnsavedChanges = false;
long end = System.currentTimeMillis();
long end = System.nanoTime() / 1000000L;
System.out.println("Loaded region successfully in " + (end - start) + "ms");
} catch (IOException ex) {
ex.printStackTrace();
+16 -18
View File
@@ -67,22 +67,20 @@ public final class CachedWorld implements IBlockTypeAccess {
// Insert an invalid region element
cachedRegions.put(0, null);
new PackerThread().start();
new Thread() {
public void run() {
try {
Thread.sleep(30000);
while (true) {
// since a region only saves if it's been modified since its last save
// saving every 10 minutes means that once it's time to exit
// we'll only have a couple regions to save
save();
Thread.sleep(600000);
}
} catch (InterruptedException e) {
e.printStackTrace();
new Thread(() -> {
try {
Thread.sleep(30000);
while (true) {
// since a region only saves if it's been modified since its last save
// saving every 10 minutes means that once it's time to exit
// we'll only have a couple regions to save
save();
Thread.sleep(600000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}.start();
}).start();
}
public final void queueForPacking(Chunk chunk) {
@@ -153,22 +151,22 @@ public final class CachedWorld implements IBlockTypeAccess {
System.out.println("Not saving to disk; chunk caching is disabled.");
return;
}
long start = System.currentTimeMillis();
long start = System.nanoTime() / 1000000L;
this.cachedRegions.values().parallelStream().forEach(region -> {
if (region != null)
region.save(this.directory);
});
long now = System.currentTimeMillis();
long now = System.nanoTime() / 1000000L;
System.out.println("World save took " + (now - start) + "ms");
}
public final void reloadAllFromDisk() {
long start = System.currentTimeMillis();
long start = System.nanoTime() / 1000000L;
this.cachedRegions.values().forEach(region -> {
if (region != null)
region.load(this.directory);
});
long now = System.currentTimeMillis();
long now = System.nanoTime() / 1000000L;
System.out.println("World load took " + (now - start) + "ms");
}
@@ -39,7 +39,7 @@ public final class ChunkPacker implements Helper {
private ChunkPacker() {}
public static CachedChunk pack(Chunk chunk) {
long start = System.currentTimeMillis();
long start = System.nanoTime() / 1000000L;
Map<String, List<BlockPos>> specialBlocks = new HashMap<>();
BitSet bitSet = new BitSet(CachedChunk.SIZE);
@@ -63,7 +63,7 @@ public final class ChunkPacker implements Helper {
e.printStackTrace();
}
//System.out.println("Packed special blocks: " + specialBlocks);
long end = System.currentTimeMillis();
long end = System.nanoTime() / 1000000L;
//System.out.println("Chunk packing took " + (end - start) + "ms for " + chunk.x + "," + chunk.z);
String[] blockNames = new String[256];
for (int z = 0; z < 16; z++) {
@@ -21,7 +21,6 @@ import baritone.Baritone;
import baritone.chunk.CachedWorld;
import baritone.chunk.WorldProvider;
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
import baritone.pathing.calc.openset.IOpenSet;
import baritone.pathing.goals.Goal;
import baritone.pathing.movement.ActionCosts;
import baritone.pathing.movement.CalculationContext;
@@ -57,7 +56,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
startNode = getNodeAtPosition(start);
startNode.cost = 0;
startNode.combinedCost = startNode.estimatedCostToGoal;
IOpenSet openSet = new BinaryHeapOpenSet();
BinaryHeapOpenSet openSet = new BinaryHeapOpenSet();
openSet.insert(startNode);
startNode.isOpen = true;
bestSoFar = new PathNode[COEFFICIENTS.length];//keep track of the best node by the metric of (estimatedCostToGoal + cost / COEFFICIENTS[i])
@@ -70,7 +69,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
currentlyRunning = this;
CachedWorld cachedWorld = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
long startTime = System.currentTimeMillis();
long startTime = System.nanoTime() / 1000000L;
boolean slowPath = Baritone.settings().slowPath.get();
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).<Long>get();
//long lastPrintout = 0;
@@ -101,7 +100,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
long getNode = 0;
int getNodeCount = 0;
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime && !cancelRequested) {
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.nanoTime() / 1000000L - timeoutTime < 0 && !cancelRequested) {
if (slowPath) {
try {
Thread.sleep(Baritone.settings().slowPathTimeDelayMS.<Long>get());
@@ -117,13 +116,13 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
mostRecentConsidered = currentNode;
BetterBlockPos currentNodePos = currentNode.pos;
numNodes++;
/*if (System.currentTimeMillis() > lastPrintout + 1000) {//print once a second
/*if ((lastPrintout + 1000) - System.nanoTime() / 1000000L < 0) {//print once a second
System.out.println("searching... at " + currentNodePos + ", considered " + numNodes + " nodes so far");
lastPrintout = System.currentTimeMillis();
lastPrintout = System.nanoTime() / 1000000L;
}*/
if (goal.isInGoal(currentNodePos)) {
currentlyRunning = null;
displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered");
return Optional.of(new Path(startNode, currentNode, numNodes));
}
long constructStart = System.nanoTime();
@@ -236,8 +235,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
return Optional.empty();
}
System.out.println(numMovementsConsidered + " movements considered");
System.out.println("Open set size: " + ((BinaryHeapOpenSet) openSet).size());
System.out.println((int) (numNodes * 1.0 / ((System.currentTimeMillis() - startTime) / 1000F)) + " nodes per second");
System.out.println("Open set size: " + openSet.size());
System.out.println((int) (numNodes * 1.0 / ((System.nanoTime() / 1000000L - startTime) / 1000F)) + " nodes per second");
double bestDist = 0;
for (int i = 0; i < bestSoFar.length; i++) {
if (bestSoFar[i] == null) {
@@ -248,7 +247,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
bestDist = dist;
}
if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared
displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered");
if (COEFFICIENTS[i] >= 3) {
System.out.println("Warning: cost coefficient is greater than three! Probably means that");
System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");
@@ -26,7 +26,7 @@ import java.util.Arrays;
*
* @author leijurv
*/
public class BinaryHeapOpenSet implements IOpenSet {
public final class BinaryHeapOpenSet implements IOpenSet {
/**
* The initial capacity of the heap (2^10)
@@ -108,14 +108,13 @@ public class BinaryHeapOpenSet implements IOpenSet {
int smallerChild = 2;
double cost = val.combinedCost;
do {
int right = smallerChild + 1;
PathNode smallerChildNode = array[smallerChild];
double smallerChildCost = smallerChildNode.combinedCost;
if (right <= size) {
PathNode rightChildNode = array[right];
if (smallerChild < size) {
PathNode rightChildNode = array[smallerChild + 1];
double rightChildCost = rightChildNode.combinedCost;
if (smallerChildCost > rightChildCost) {
smallerChild = right;
smallerChild++;
smallerChildCost = rightChildCost;
smallerChildNode = rightChildNode;
}
@@ -128,8 +127,7 @@ public class BinaryHeapOpenSet implements IOpenSet {
val.heapPosition = smallerChild;
smallerChildNode.heapPosition = index;
index = smallerChild;
smallerChild = index << 1;
} while (smallerChild <= size);
} while ((smallerChild <<= 1) <= size);
return result;
}
}
@@ -22,10 +22,11 @@ import baritone.pathing.calc.PathNode;
/**
* A linked list implementation of an open set. This is the original implementation from MineBot.
* It has incredibly fast insert performance, at the cost of O(n) removeLowest.
* It sucks. BinaryHeapOpenSet results in more than 10x more nodes considered in 4 seconds.
*
* @author leijurv
*/
public class LinkedListOpenSet implements IOpenSet {
class LinkedListOpenSet implements IOpenSet {
private Node first = null;
@Override
@@ -20,6 +20,7 @@ package baritone.pathing.goals;
import baritone.Baritone;
import baritone.utils.Utils;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
/**
@@ -88,9 +89,9 @@ public class GoalXZ implements Goal {
}
public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {
double theta = Utils.degToRad(yaw);
double x = origin.x - Math.sin(theta) * distance;
double z = origin.z + Math.cos(theta) * distance;
float theta = (float) Utils.degToRad(yaw);
double x = origin.x - MathHelper.sin(theta) * distance;
double z = origin.z + MathHelper.cos(theta) * distance;
return new GoalXZ((int) x, (int) z);
}
@@ -24,7 +24,8 @@ public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieI
*/
double WALK_ONE_BLOCK_COST = 20 / 4.317; // 4.633
double WALK_ONE_IN_WATER_COST = 20 / 2.2;
double WALK_ONE_OVER_SOUL_SAND_COST = WALK_ONE_IN_WATER_COST; // TODO issue #7
double WALK_ONE_OVER_SOUL_SAND_COST = WALK_ONE_BLOCK_COST * 0.5; // 0.4 in BlockSoulSand but effectively about half
double SPRINT_ONE_OVER_SOUL_SAND_COST = WALK_ONE_OVER_SOUL_SAND_COST / 0.75;
double LADDER_UP_ONE_COST = 20 / 2.35;
double LADDER_DOWN_ONE_COST = 20 / 3.0;
double SNEAK_ONE_BLOCK_COST = 20 / 1.3;
@@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockMagma;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@@ -90,10 +91,12 @@ public class MovementDiagonal extends Movement {
if (BlockStateInterface.get(src.down()).getBlock().equals(Blocks.SOUL_SAND)) {
multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2;
}
if (BlockStateInterface.get(positionsToBreak[2].down()).getBlock() instanceof BlockMagma) {
Block cuttingOver1 = BlockStateInterface.get(positionsToBreak[2].down()).getBlock();
if (cuttingOver1 instanceof BlockMagma || BlockStateInterface.isLava(cuttingOver1)) {
return COST_INF;
}
if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) {
Block cuttingOver2 = BlockStateInterface.get(positionsToBreak[4].down()).getBlock();
if (cuttingOver2 instanceof BlockMagma || BlockStateInterface.isLava(cuttingOver2)) {
return COST_INF;
}
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
@@ -106,18 +109,12 @@ public class MovementDiagonal extends Movement {
return COST_INF;
}
if (optionA == 0) {
if (MovementHelper.avoidWalkingInto(pb2.getBlock())) {
return COST_INF;
}
if (MovementHelper.avoidWalkingInto(pb3.getBlock())) {
if (MovementHelper.avoidWalkingInto(pb2.getBlock()) || MovementHelper.avoidWalkingInto(pb3.getBlock())) {
return COST_INF;
}
}
if (optionB == 0) {
if (MovementHelper.avoidWalkingInto(pb0.getBlock())) {
return COST_INF;
}
if (MovementHelper.avoidWalkingInto(pb1.getBlock())) {
if (MovementHelper.avoidWalkingInto(pb0.getBlock()) || MovementHelper.avoidWalkingInto(pb1.getBlock())) {
return COST_INF;
}
}
@@ -21,6 +21,7 @@ import baritone.Baritone;
import baritone.api.event.events.TickEvent;
import baritone.pathing.movement.ActionCosts;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.movements.MovementDescend;
import baritone.pathing.movement.movements.MovementDiagonal;
@@ -163,7 +164,7 @@ public class PathExecutor implements Helper {
}
}
}*/
long start = System.currentTimeMillis();
long start = System.nanoTime() / 1000000L;
for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
if (i >= 0 && i < path.movements().size()) {
Movement m = path.movements().get(i);
@@ -198,7 +199,7 @@ public class PathExecutor implements Helper {
toWalkInto = newWalkInto;
recalcBP = false;
}
long end = System.currentTimeMillis();
long end = System.nanoTime() / 1000000L;
if (end - start > 0) {
//displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms");
}
@@ -285,7 +286,7 @@ public class PathExecutor implements Helper {
}
}
if (next instanceof MovementTraverse) {
if (next.getDirection().down().equals(movement.getDirection())) {
if (next.getDirection().down().equals(movement.getDirection()) && MovementHelper.canWalkOn(next.getDest().down())) {
if (playerFeet().equals(movement.getDest())) {
pathPosition++;
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
@@ -34,6 +34,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import java.awt.*;
import java.util.Collection;
@@ -188,7 +189,7 @@ public final class PathRenderer implements Helper {
maxX = goalPos.getX() + 1 - 0.002 - renderPosX;
minZ = goalPos.getZ() + 0.002 - renderPosZ;
maxZ = goalPos.getZ() + 1 - 0.002 - renderPosZ;
double y = Math.sin((System.currentTimeMillis() % 2000L) / 2000F * Math.PI * 2);
double y = MathHelper.sin((float) (((float) (System.nanoTime() / 1000000L) % 2000L) / 2000F * Math.PI * 2));
y1 = 1 + y + goalPos.getY() - renderPosY;
y2 = 1 - y + goalPos.getY() - renderPosY;
minY = goalPos.getY() - renderPosY;
+2 -2
View File
@@ -54,9 +54,9 @@ public final class Utils {
*/
public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) {
double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z};
double yaw = Math.atan2(delta[0], -delta[2]);
double yaw = MathHelper.atan2(delta[0], -delta[2]);
double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]);
double pitch = Math.atan2(delta[1], dist);
double pitch = MathHelper.atan2(delta[1], dist);
return new Rotation(
(float) radToDeg(yaw),
(float) radToDeg(pitch)
@@ -42,7 +42,7 @@ public class OpenSetsTest {
public void removeAndTest(int amount, IOpenSet[] test, Optional<Collection<PathNode>> mustContain) {
double[][] results = new double[test.length][amount];
for (int i = 0; i < test.length; i++) {
long before = System.currentTimeMillis();
long before = System.nanoTime() / 1000000L;
for (int j = 0; j < amount; j++) {
PathNode pn = test[i].removeLowest();
if (mustContain.isPresent() && !mustContain.get().contains(pn)) {
@@ -50,7 +50,7 @@ public class OpenSetsTest {
}
results[i][j] = pn.combinedCost;
}
System.out.println(test[i].getClass() + " " + (System.currentTimeMillis() - before));
System.out.println(test[i].getClass() + " " + (System.nanoTime() / 1000000L - before));
}
for (int j = 0; j < amount; j++) {
for (int i = 1; i < test.length; i++) {
@@ -104,10 +104,10 @@ public class OpenSetsTest {
System.out.println("Insertion");
for (IOpenSet set : test) {
long before = System.currentTimeMillis();
long before = System.nanoTime() / 1000000L;
for (int i = 0; i < size; i++)
set.insert(toInsert[i]);
System.out.println(set.getClass() + " " + (System.currentTimeMillis() - before));
System.out.println(set.getClass() + " " + (System.nanoTime() / 1000000L - before));
//all three take either 0 or 1ms to insert up to 10,000 nodes
//linkedlist takes 0ms most often (because there's no array resizing or allocation there, just pointer shuffling)
}
@@ -44,21 +44,21 @@ public class BetterBlockPosTest {
} catch (InterruptedException e) {
e.printStackTrace();
}
long before1 = System.currentTimeMillis();
long before1 = System.nanoTime() / 1000000L;
for (int i = 0; i < 1000000; i++) {
pos.up();
}
long after1 = System.currentTimeMillis();
long after1 = System.nanoTime() / 1000000L;
try {
Thread.sleep(1000); // give GC some time
} catch (InterruptedException e) {
e.printStackTrace();
}
long before2 = System.currentTimeMillis();
long before2 = System.nanoTime() / 1000000L;
for (int i = 0; i < 1000000; i++) {
pos2.up();
}
long after2 = System.currentTimeMillis();
long after2 = System.nanoTime() / 1000000L;
System.out.println((after1 - before1) + " " + (after2 - before2));
}
@@ -70,7 +70,7 @@ public class BetterBlockPosTest {
} catch (InterruptedException e) {
e.printStackTrace();
}
long before1 = System.currentTimeMillis();
long before1 = System.nanoTime() / 1000000L;
for (int i = 0; i < 1000000; i++) {
pos.up(0);
pos.up(1);
@@ -78,13 +78,13 @@ public class BetterBlockPosTest {
pos.up(3);
pos.up(4);
}
long after1 = System.currentTimeMillis();
long after1 = System.nanoTime() / 1000000L;
try {
Thread.sleep(1000); // give GC some time
} catch (InterruptedException e) {
e.printStackTrace();
}
long before2 = System.currentTimeMillis();
long before2 = System.nanoTime() / 1000000L;
for (int i = 0; i < 1000000; i++) {
pos2.up(0);
pos2.up(1);
@@ -92,7 +92,7 @@ public class BetterBlockPosTest {
pos2.up(3);
pos2.up(4);
}
long after2 = System.currentTimeMillis();
long after2 = System.nanoTime() / 1000000L;
System.out.println((after1 - before1) + " " + (after2 - before2));
}
}