helpers and optimizations

This commit is contained in:
Leijurv 2018-08-03 22:14:50 -04:00
parent 8250338210
commit 9dc1f2abab
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 80 additions and 19 deletions

View File

@ -3,11 +3,11 @@ package baritone.bot.pathing.calc;
//import baritone.Baritone;
import baritone.bot.pathing.openset.BinaryHeapOpenSet;
import baritone.bot.pathing.openset.IOpenSet;
import baritone.bot.pathing.goals.Goal;
import baritone.bot.pathing.movement.ActionCosts;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.openset.BinaryHeapOpenSet;
import baritone.bot.pathing.openset.IOpenSet;
import baritone.bot.utils.ToolSet;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
@ -72,6 +72,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
//long constructEnd = System.nanoTime();
//System.out.println(constructEnd - constructStart);
for (Movement movementToGetToNeighbor : possibleMovements) {
if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) {
numEmptyChunk++;
continue;
}
//long costStart = System.nanoTime();
// TODO cache cost
double actionCost = movementToGetToNeighbor.calculateCost(ts);
@ -80,10 +84,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
if (actionCost >= ActionCosts.COST_INF) {
continue;
}
if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) {
numEmptyChunk++;
continue;
}
PathNode neighbor = getNodeAtPosition(movementToGetToNeighbor.getDest());
double tentativeCost = currentNode.cost + actionCost;
if (tentativeCost < neighbor.cost) {

View File

@ -1,24 +1,27 @@
package baritone.bot.pathing.movement;
import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.Helper;
import baritone.bot.utils.ToolSet;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
/**
* Static helpers for cost calculation
*
* @author leijurv
*/
public interface MovementHelper extends ActionCosts {
public interface MovementHelper extends ActionCosts, Helper {
Block waterFlowing = Blocks.FLOWING_WATER;
Block waterStill = Blocks.WATER;
Block lavaFlowing = Blocks.FLOWING_LAVA;
Block lavaStill = Blocks.LAVA;
Block waterStill = Blocks.WATER;
Block lavaFlowing = Blocks.FLOWING_LAVA;
Block lavaStill = Blocks.LAVA;
/**
* Returns whether or not the specified block is
@ -84,8 +87,7 @@ public interface MovementHelper extends ActionCosts {
* @param pos
* @return
*/
static boolean canWalkThrough(BlockPos pos) {
IBlockState state = BlockStateInterface.get(pos);
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
Block block = state.getBlock();
if (block instanceof BlockLilyPad || block instanceof BlockFire) {//you can't actually walk through a lilypad from the side, and you shouldn't walk through fire
return false;
@ -129,8 +131,8 @@ public interface MovementHelper extends ActionCosts {
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
}
static double getHardness(ToolSet ts, IBlockState block, BlockPos position) {
if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) {
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
if (avoidBreaking(position)) {
return COST_INF;
}
@ -142,4 +144,65 @@ public interface MovementHelper extends ActionCosts {
}
return 0;
}
/**
* The currently highlighted block.
* Updated once a tick by Minecraft.
*
* @return the position of the highlighted block, or null if no block is highlighted
*/
static BlockPos whatAmILookingAt() {
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK) {
return mc.objectMouseOver.getBlockPos();
}
return null;
}
/**
* The entity the player is currently looking at
*
* @return the entity object, or null if the player isn't looking at an entity
*/
static Entity whatEntityAmILookingAt() {
Minecraft mc = Minecraft.getMinecraft();
if (mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.ENTITY) {
return mc.objectMouseOver.entityHit;
}
return null;
}
/**
* AutoTool
*/
static void switchToBestTool() {
BlockPos pos = whatAmILookingAt();
if (pos == null) {
return;
}
IBlockState state = BlockStateInterface.get(pos);
if (state.getBlock().equals(Blocks.AIR)) {
return;
}
switchToBestToolFor(state);
}
/**
* AutoTool for a specific block
*
* @param b the blockstate to mine
*/
static void switchToBestToolFor(IBlockState b) {
switchToBestToolFor(b, new ToolSet());
}
/**
* AutoTool for a specific block with precomputed ToolSet data
*
* @param b the blockstate to mine
* @param ts previously calculated ToolSet
*/
static void switchToBestToolFor(IBlockState b, ToolSet ts) {
Minecraft.getMinecraft().player.inventory.currentItem = ts.getBestSlot(b);
}
}

View File

@ -9,7 +9,6 @@ import net.minecraft.block.BlockVine;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class ActionDescend extends ActionPlaceOrBreak {
@ -33,6 +32,6 @@ public class ActionDescend extends ActionPlaceOrBreak {
@Override
protected boolean tick0() {//basically just hold down W until we are where we want to be
MovementManager.moveTowardsBlock(to);
return Baritone.playerFeet.equals(to);
return Baritone.playerFeet.equals(to); // TODO wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
}
}

View File

@ -28,6 +28,6 @@ public class ActionDescendThree extends ActionPlaceOrBreak {
@Override
protected boolean tick0() {//basically just hold down W until we are where we want to be
MovementManager.moveTowardsBlock(to);
return Baritone.playerFeet.equals(to);
return Baritone.playerFeet.equals(to); // TODO wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
}
}

View File

@ -6,7 +6,6 @@ import baritone.util.ToolSet;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class ActionDescendTwo extends ActionPlaceOrBreak {
@ -29,6 +28,6 @@ public class ActionDescendTwo extends ActionPlaceOrBreak {
@Override
protected boolean tick0() {//basically just hold down W until we are where we want to be
MovementManager.moveTowardsBlock(to);
return Baritone.playerFeet.equals(to);
return Baritone.playerFeet.equals(to); // TODO wait until we're actually on the ground before saying we're done because sometimes we continue to fall if the next action starts immediately
}
}