helpers and optimizations
This commit is contained in:
@@ -3,11 +3,11 @@ package baritone.bot.pathing.calc;
|
|||||||
|
|
||||||
//import baritone.Baritone;
|
//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.goals.Goal;
|
||||||
import baritone.bot.pathing.movement.ActionCosts;
|
import baritone.bot.pathing.movement.ActionCosts;
|
||||||
import baritone.bot.pathing.movement.Movement;
|
import baritone.bot.pathing.movement.Movement;
|
||||||
|
import baritone.bot.pathing.openset.BinaryHeapOpenSet;
|
||||||
|
import baritone.bot.pathing.openset.IOpenSet;
|
||||||
import baritone.bot.utils.ToolSet;
|
import baritone.bot.utils.ToolSet;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -72,6 +72,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
|
|||||||
//long constructEnd = System.nanoTime();
|
//long constructEnd = System.nanoTime();
|
||||||
//System.out.println(constructEnd - constructStart);
|
//System.out.println(constructEnd - constructStart);
|
||||||
for (Movement movementToGetToNeighbor : possibleMovements) {
|
for (Movement movementToGetToNeighbor : possibleMovements) {
|
||||||
|
if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) {
|
||||||
|
numEmptyChunk++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//long costStart = System.nanoTime();
|
//long costStart = System.nanoTime();
|
||||||
// TODO cache cost
|
// TODO cache cost
|
||||||
double actionCost = movementToGetToNeighbor.calculateCost(ts);
|
double actionCost = movementToGetToNeighbor.calculateCost(ts);
|
||||||
@@ -80,10 +84,6 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
|
|||||||
if (actionCost >= ActionCosts.COST_INF) {
|
if (actionCost >= ActionCosts.COST_INF) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Minecraft.getMinecraft().world.getChunk(movementToGetToNeighbor.getDest()) instanceof EmptyChunk) {
|
|
||||||
numEmptyChunk++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
PathNode neighbor = getNodeAtPosition(movementToGetToNeighbor.getDest());
|
PathNode neighbor = getNodeAtPosition(movementToGetToNeighbor.getDest());
|
||||||
double tentativeCost = currentNode.cost + actionCost;
|
double tentativeCost = currentNode.cost + actionCost;
|
||||||
if (tentativeCost < neighbor.cost) {
|
if (tentativeCost < neighbor.cost) {
|
||||||
|
@@ -1,24 +1,27 @@
|
|||||||
package baritone.bot.pathing.movement;
|
package baritone.bot.pathing.movement;
|
||||||
|
|
||||||
import baritone.bot.utils.BlockStateInterface;
|
import baritone.bot.utils.BlockStateInterface;
|
||||||
|
import baritone.bot.utils.Helper;
|
||||||
import baritone.bot.utils.ToolSet;
|
import baritone.bot.utils.ToolSet;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
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.entity.Entity;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static helpers for cost calculation
|
* Static helpers for cost calculation
|
||||||
*
|
*
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public interface MovementHelper extends ActionCosts {
|
public interface MovementHelper extends ActionCosts, Helper {
|
||||||
|
|
||||||
Block waterFlowing = Blocks.FLOWING_WATER;
|
Block waterFlowing = Blocks.FLOWING_WATER;
|
||||||
Block waterStill = Blocks.WATER;
|
Block waterStill = Blocks.WATER;
|
||||||
Block lavaFlowing = Blocks.FLOWING_LAVA;
|
Block lavaFlowing = Blocks.FLOWING_LAVA;
|
||||||
Block lavaStill = Blocks.LAVA;
|
Block lavaStill = Blocks.LAVA;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the specified block is
|
* Returns whether or not the specified block is
|
||||||
@@ -84,8 +87,7 @@ public interface MovementHelper extends ActionCosts {
|
|||||||
* @param pos
|
* @param pos
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static boolean canWalkThrough(BlockPos pos) {
|
static boolean canWalkThrough(BlockPos pos, IBlockState state) {
|
||||||
IBlockState state = BlockStateInterface.get(pos);
|
|
||||||
Block block = state.getBlock();
|
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
|
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;
|
return false;
|
||||||
@@ -129,8 +131,8 @@ public interface MovementHelper extends ActionCosts {
|
|||||||
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double getHardness(ToolSet ts, IBlockState block, BlockPos position) {
|
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
|
||||||
if (!block.equals(Blocks.AIR) && !canWalkThrough(position)) {
|
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
|
||||||
if (avoidBreaking(position)) {
|
if (avoidBreaking(position)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
@@ -142,4 +144,65 @@ public interface MovementHelper extends ActionCosts {
|
|||||||
}
|
}
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,6 @@ import net.minecraft.block.BlockVine;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class ActionDescend extends ActionPlaceOrBreak {
|
public class ActionDescend extends ActionPlaceOrBreak {
|
||||||
@@ -33,6 +32,6 @@ public class ActionDescend extends ActionPlaceOrBreak {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean tick0() {//basically just hold down W until we are where we want to be
|
protected boolean tick0() {//basically just hold down W until we are where we want to be
|
||||||
MovementManager.moveTowardsBlock(to);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,6 @@ public class ActionDescendThree extends ActionPlaceOrBreak {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean tick0() {//basically just hold down W until we are where we want to be
|
protected boolean tick0() {//basically just hold down W until we are where we want to be
|
||||||
MovementManager.moveTowardsBlock(to);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ import baritone.util.ToolSet;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class ActionDescendTwo extends ActionPlaceOrBreak {
|
public class ActionDescendTwo extends ActionPlaceOrBreak {
|
||||||
@@ -29,6 +28,6 @@ public class ActionDescendTwo extends ActionPlaceOrBreak {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean tick0() {//basically just hold down W until we are where we want to be
|
protected boolean tick0() {//basically just hold down W until we are where we want to be
|
||||||
MovementManager.moveTowardsBlock(to);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user