pathfinding.goals and actions are cleared of errors

This commit is contained in:
Leijurv 2018-08-01 12:13:53 -04:00
parent 4cb05a7979
commit 5d4ea57503
No known key found for this signature in database
GPG Key ID: 0936202430AE187C
12 changed files with 101 additions and 41 deletions

View File

@ -85,6 +85,11 @@ public class Baritone {
return get(pos).getBlock();
}
public static boolean isBlockNormalCube(BlockPos pos) {
IBlockState state = get(pos);
return state.getBlock().isBlockNormalCube(state);
}
/**
* Called by minecraft.java
*/

View File

@ -5,6 +5,7 @@
*/
package baritone.movement;
import baritone.Baritone;
import baritone.ui.LookManager;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
@ -18,6 +19,7 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class MovementManager {
public static boolean forward = false;
public static int leftPressTime = 0;
public static boolean isRightClick = false;
@ -28,6 +30,7 @@ public class MovementManager {
public static boolean sneak = false;
public static boolean isLeftClick = false;
public static boolean backward = false;
/**
* calls moveTowardsCoords on the center of this block
*
@ -37,6 +40,7 @@ public class MovementManager {
public static boolean moveTowardsBlock(BlockPos p) {
return moveTowardsBlock(p, true);
}
public static boolean moveTowardsBlock(BlockPos p, boolean rotate) {
Block b = Baritone.get(p).getBlock();
double xDiff = (b.getBlockBoundsMinX() + b.getBlockBoundsMaxX()) / 2;
@ -52,6 +56,7 @@ public class MovementManager {
double z = p.getZ() + zDiff;
return moveTowardsCoords(x, y, z, rotate);
}
/**
* Clears movement, but nothing else. Includes jumping and sneaking, but not
* left clicking.
@ -68,6 +73,7 @@ public class MovementManager {
isLeftClick = false;
//leftPressTime = 0;
}
/**
* Do not question the logic. Called by Minecraft.java
*
@ -81,6 +87,7 @@ public class MovementManager {
return true;
}
}
/**
* Called by our code
*/
@ -88,6 +95,7 @@ public class MovementManager {
leftPressTime = 0;
isLeftClick = false;
}
/**
* Do not question the logic. Called by Minecraft.java
*
@ -96,6 +104,7 @@ public class MovementManager {
public static boolean getLeftIsPressed() {
return isLeftClick && leftPressTime >= -2;
}
/**
* Do not question the logic. Called by Minecraft.java
*
@ -109,6 +118,7 @@ public class MovementManager {
return true;
}
}
/**
* Do not question the logic. Called by Minecraft.java
*
@ -117,9 +127,11 @@ public class MovementManager {
public static boolean getRightIsPressed() {
return isRightClick && rightPressTime >= -2;
}
public static boolean moveTowardsCoords(double x, double y, double z) {
return moveTowardsCoords(x, y, z, true);
}
/**
* Move towards coordinates, not necesarily forwards. e.g. if coordinates
* are closest to being directly behind us, go backwards. This minimizes
@ -199,4 +211,10 @@ public class MovementManager {
}
return false;
}
public static void rightClickMouse() {
Minecraft.getMinecraft().rightClickMouse();
throw new UnsupportedOperationException("Not public");
}
}

View File

@ -5,19 +5,19 @@
*/
package baritone.pathfinding;
import baritone.pathfinding.goals.Goal;
import baritone.pathfinding.actions.ActionBridge;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.pathfinding.actions.Action;
import baritone.pathfinding.actions.ActionBridge;
import baritone.pathfinding.actions.ActionPlaceOrBreak;
import baritone.pathfinding.goals.Goal;
import baritone.ui.LookManager;
import baritone.util.Out;
import baritone.util.ToolSet;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import baritone.ui.LookManager;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.pathfinding.actions.ActionPlaceOrBreak;
import baritone.util.Out;
import baritone.util.ToolSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@ -30,6 +30,7 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class Path {
public final BlockPos start;
public final BlockPos end;
public final Goal goal;
@ -45,6 +46,7 @@ public class Path {
*
*/
public final int numNodes;
Path(Node start, Node end, Goal goal, int numNodes) {
this.numNodes = numNodes;
this.start = start.pos;
@ -74,6 +76,7 @@ public class Path {
Out.log(actions.get(i) + ": " + xDiff + "," + yDiff + "," + zDiff);//print it all out
}*/
}
/**
* We don't really use this any more
*/
@ -101,6 +104,7 @@ public class Path {
* Where are we in the path? This is an index in the actions list
*/
int pathPosition = 0;
public double howFarAmIFromThePath(double x, double y, double z) {
double best = -1;
for (BlockPos pos : path) {
@ -111,6 +115,7 @@ public class Path {
}
return best;
}
public void calculatePathPosition() {
BlockPos playerFeet = Baritone.playerFeet;
for (int i = 0; i < path.size(); i++) {
@ -119,6 +124,7 @@ public class Path {
}
}
}
public static double distance(double x, double y, double z, BlockPos pos) {
double xdiff = x - (pos.getX() + 0.5D);
double ydiff = y - (pos.getY() + 0.5D);
@ -148,6 +154,7 @@ public class Path {
* action take too long
*/
public boolean failed = false;
public boolean tick() {
if (pathPosition >= path.size()) {
Baritone.clearPath();//stop bugging me, I'm done
@ -155,7 +162,7 @@ public class Path {
}
BlockPos whereShouldIBe = path.get(pathPosition);
EntityPlayerSP thePlayer = Minecraft.getMinecraft().player;
BlockPos whereAmI = thePlayer.getPosition0();
BlockPos whereAmI = Baritone.playerFeet;
if (pathPosition == path.size() - 1) {
Out.log("On last path position");
Baritone.clearPath();
@ -163,7 +170,7 @@ public class Path {
}
if (!whereShouldIBe.equals(whereAmI)) {
Out.log("Should be at " + whereShouldIBe + " actually am at " + whereAmI);
if (!Blocks.air.equals(Baritone.get(thePlayer.getPosition0().down()))) {//do not skip if standing on air, because our position isn't stable to skip
if (!Blocks.AIR.equals(Baritone.get(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip
for (int i = 0; i < pathPosition - 2 && i < path.size(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
if (whereAmI.equals(path.get(i))) {
Out.gui("Skipping back " + (pathPosition - i) + " steps, to " + i, Out.Mode.Debug);
@ -248,6 +255,7 @@ public class Path {
}
return false;
}
public HashSet<BlockPos> toMine() {
HashSet<BlockPos> tm = new HashSet<>();
for (int i = pathPosition; i < actions.size(); i++) {
@ -257,6 +265,7 @@ public class Path {
}
return tm;
}
public HashSet<BlockPos> toPlace() {
HashSet<BlockPos> tp = new HashSet<>();
for (int i = pathPosition; i < actions.size(); i++) {

View File

@ -5,6 +5,7 @@
*/
package baritone.pathfinding.actions;
import baritone.Baritone;
import baritone.util.Out;
import baritone.util.ToolSet;
import net.minecraft.block.Block;

View File

@ -5,27 +5,29 @@
*/
package baritone.pathfinding.actions;
import java.util.Objects;
import java.util.Random;
import baritone.ui.LookManager;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.ui.LookManager;
import baritone.util.Out;
import baritone.util.ToolSet;
import java.util.Objects;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class ActionBridge extends ActionPlaceOrBreak {
BlockPos[] against = new BlockPos[3];
public ActionBridge(BlockPos from, BlockPos to) {
super(from, to, new BlockPos[]{to.up(), to}, new BlockPos[]{to.down()});
int i = 0;
@ -47,6 +49,7 @@ public class ActionBridge extends ActionPlaceOrBreak {
}
//note: do NOT add ability to place against .down().down()
}
@Override
protected double calculateCost(ToolSet ts) {
double WC = isWater(blocksToBreak[0]) || isWater(blocksToBreak[1]) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST;
@ -66,7 +69,7 @@ public class ActionBridge extends ActionPlaceOrBreak {
}
if (blocksToPlace[0].equals(Block.getBlockById(0)) || (!isWater(blocksToPlace[0]) && blocksToPlace[0].isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) {
for (BlockPos against1 : against) {
if (Baritone.get(against1).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(against1)) {
return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
}
}
@ -79,15 +82,19 @@ public class ActionBridge extends ActionPlaceOrBreak {
}
boolean wasTheBridgeBlockAlwaysThere = true;//did we have to place a bridge block or was it always there
public Boolean oneInTen = null;//a one in ten chance
public boolean amIGood() {
return canWalkThrough(positionsToBreak[0]) && canWalkThrough(positionsToBreak[1]) && canWalkOn(positionsToPlace[0]);
}
public int dx() {
return to.getX() - from.getX();
}
public int dz() {
return to.getZ() - from.getZ();
}
@Override
protected boolean tick0() {
if (oneInTen == null) {
@ -128,7 +135,7 @@ public class ActionBridge extends ActionPlaceOrBreak {
} else {
wasTheBridgeBlockAlwaysThere = false;
for (BlockPos against1 : against) {
if (Baritone.get(against1).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(against1)) {
if (!switchtothrowaway(true)) {//get ready to place a throwaway block
return false;
}
@ -140,7 +147,7 @@ public class ActionBridge extends ActionPlaceOrBreak {
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
if (Objects.equals(Baritone.whatAreYouLookingAt(), against1) && Minecraft.getMinecraft().player.isSneaking()) {
if (Baritone.whatAreYouLookingAt().offset(side).equals(positionsToPlace[0])) {
Minecraft.getMinecraft().rightClickMouse();
MovementManager.rightClickMouse();
} else {
Out.gui("Wrong. " + side + " " + Baritone.whatAreYouLookingAt().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);
}
@ -163,7 +170,7 @@ public class ActionBridge extends ActionPlaceOrBreak {
BlockPos goalLook = from.down();//this is the block we were just standing on, and the one we want to place against
MovementManager.backward = LookManager.lookAtCoords(faceX, faceY, faceZ, true);//if we are in the block, then we are off the edge of the previous looking backward, so we should be moving backward
if (Objects.equals(Baritone.whatAreYouLookingAt(), goalLook)) {
Minecraft.getMinecraft().rightClickMouse();//wait to right click until we are able to place
MovementManager.rightClickMouse();//wait to right click until we are able to place
return false;
}
Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());

View File

@ -5,24 +5,26 @@
*/
package baritone.pathfinding.actions;
import java.util.Objects;
import baritone.ui.LookManager;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.ui.LookManager;
import baritone.util.Out;
import baritone.util.ToolSet;
import java.util.Objects;
import net.minecraft.block.BlockFalling;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class ActionClimb extends ActionPlaceOrBreak {
BlockPos[] against = new BlockPos[3];
public ActionClimb(BlockPos start, BlockPos end) {
super(start, end, new BlockPos[]{end, start.up(2), end.up()}, new BlockPos[]{end.down()});
BlockPos placementLocation = positionsToPlace[0];//end.down()
@ -46,6 +48,7 @@ public class ActionClimb extends ActionPlaceOrBreak {
//TODO: add ability to place against .down() as well as the cardinal directions
//useful for when you are starting a staircase without anything to place against
}
@Override
protected double calculateCost(ToolSet ts) {
if (!canWalkOn(positionsToPlace[0])) {
@ -53,7 +56,7 @@ public class ActionClimb extends ActionPlaceOrBreak {
return COST_INF;
}
for (BlockPos against1 : against) {
if (Baritone.get(against1).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(against1)) {
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
}
}
@ -65,12 +68,13 @@ public class ActionClimb extends ActionPlaceOrBreak {
return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel)
}
int ticksWithoutPlacement = 0;
@Override
protected boolean tick0() {//basically just hold down W and space until we are where we want to be
EntityPlayerSP thePlayer = Minecraft.getMinecraft().player;
if (!canWalkOn(positionsToPlace[0])) {
for (int i = 0; i < against.length; i++) {
if (Baritone.get(against[i]).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(against[i])) {
if (!switchtothrowaway(true)) {//get ready to place a throwaway block
return false;
}
@ -83,7 +87,7 @@ public class ActionClimb extends ActionPlaceOrBreak {
ticksWithoutPlacement++;
MovementManager.sneak = true;
if (Minecraft.getMinecraft().player.isSneaking()) {
Minecraft.getMinecraft().rightClickMouse();
MovementManager.rightClickMouse();
}
if (ticksWithoutPlacement > 20) {
MovementManager.backward = true;//we might be standing in the way, move back

View File

@ -5,12 +5,12 @@
*/
package baritone.pathfinding.actions;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.util.ToolSet;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
/**
@ -18,9 +18,11 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class ActionDescend extends ActionPlaceOrBreak {
public ActionDescend(BlockPos start, BlockPos end) {
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, new BlockPos[]{end.down()});
}
@Override
protected double calculateCost(ToolSet ts) {
if (!canWalkOn(positionsToPlace[0])) {
@ -32,6 +34,7 @@ public class ActionDescend extends ActionPlaceOrBreak {
}
return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST * 0.2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel)
}
@Override
protected boolean tick0() {//basically just hold down W until we are where we want to be
MovementManager.moveTowardsBlock(to);

View File

@ -5,9 +5,9 @@
*/
package baritone.pathfinding.actions;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.util.ToolSet;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
/**
@ -15,9 +15,11 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class ActionDescendThree extends ActionPlaceOrBreak {
public ActionDescendThree(BlockPos start, BlockPos end) {
super(start, end, new BlockPos[]{end.up(4), end.up(3), end.up(2), end.up(), end}, new BlockPos[]{end.down()});
}
@Override
protected double calculateCost(ToolSet ts) {
if (!canWalkOn(positionsToPlace[0])) {
@ -28,6 +30,7 @@ public class ActionDescendThree extends ActionPlaceOrBreak {
}
return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_THREE_BLOCK_COST, WALK_ONE_BLOCK_COST * 0.2);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel)
}
@Override
protected boolean tick0() {//basically just hold down W until we are where we want to be
MovementManager.moveTowardsBlock(to);

View File

@ -5,9 +5,9 @@
*/
package baritone.pathfinding.actions;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.util.ToolSet;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
/**
@ -15,9 +15,11 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class ActionDescendTwo extends ActionPlaceOrBreak {
public ActionDescendTwo(BlockPos start, BlockPos end) {
super(start, end, new BlockPos[]{end.up(3), end.up(2), end.up(), end}, new BlockPos[]{end.down()});
}
@Override
protected double calculateCost(ToolSet ts) {
if (!canWalkOn(positionsToPlace[0])) {
@ -28,6 +30,7 @@ public class ActionDescendTwo extends ActionPlaceOrBreak {
}
return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_TWO_BLOCK_COST, WALK_ONE_BLOCK_COST * 0.2);//we walk half the block plus 0.3 to get to the edge, then we walk the other 0.2 while simultaneously falling (math.max because of how it's in parallel)
}
@Override
protected boolean tick0() {//basically just hold down W until we are where we want to be
MovementManager.moveTowardsBlock(to);

View File

@ -5,9 +5,9 @@
*/
package baritone.pathfinding.actions;
import baritone.ui.LookManager;
import baritone.Baritone;
import baritone.movement.MovementManager;
import baritone.ui.LookManager;
import baritone.util.Out;
import baritone.util.ToolSet;
import net.minecraft.block.Block;
@ -24,9 +24,11 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class ActionPillar extends ActionPlaceOrBreak {
public ActionPillar(BlockPos start) {
super(start, start.up(), new BlockPos[]{start.up(2)}, new BlockPos[]{start});
}
@Override
protected double calculateCost(ToolSet ts) {
Block fromDown = Baritone.get(from).getBlock();
@ -64,21 +66,23 @@ public class ActionPillar extends ActionPlaceOrBreak {
}
}
int numTicks = 0;
public BlockPos getAgainst(BlockPos vine) {
if (Baritone.get(vine.north()).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(vine.north())) {
return vine.north();
}
if (Baritone.get(vine.south()).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(vine.south())) {
return vine.south();
}
if (Baritone.get(vine.east()).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(vine.east())) {
return vine.east();
}
if (Baritone.get(vine.west()).getBlock().isBlockNormalCube()) {
if (Baritone.isBlockNormalCube(vine.west())) {
return vine.west();
}
return null;
}
@Override
protected boolean tick0() {
IBlockState fromDown = Baritone.get(from);
@ -95,7 +99,7 @@ public class ActionPillar extends ActionPlaceOrBreak {
Out.gui("Unable to climb vines", Out.Mode.Standard);
return false;
}
if (thePlayer.getPosition0().equals(against.up()) || thePlayer.getPosition0().equals(to)) {
if (Baritone.playerFeet.equals(against.up()) || Baritone.playerFeet.equals(to)) {
return true;
}
/*if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) {
@ -126,7 +130,7 @@ public class ActionPillar extends ActionPlaceOrBreak {
MovementManager.isLeftClick = true;
blockIsThere = false;
} else if (Minecraft.getMinecraft().player.isSneaking()) {
Minecraft.getMinecraft().rightClickMouse();//constantly right click
MovementManager.rightClickMouse();//constantly right click
}
}
}

View File

@ -6,7 +6,6 @@
package baritone.pathfinding.actions;
import baritone.Baritone;
import baritone.inventory.SmeltingTask;
import baritone.movement.MovementManager;
import baritone.ui.LookManager;
import baritone.util.Out;
@ -97,9 +96,6 @@ public abstract class ActionPlaceOrBreak extends Action {
if (!Baritone.allowBreakOrPlace) {
return COST_INF;
}
if (SmeltingTask.avoidBreaking(position)) {
return COST_INF;
}
double m = Block.getBlockFromName("minecraft:crafting_table").equals(block) ? 10 : 1;
return m / ts.getStrVsBlock(block, position) + BREAK_ONE_BLOCK_ADD;
}

View File

@ -5,11 +5,10 @@
*/
package baritone.util;
import java.util.HashSet;
import baritone.Baritone;
import baritone.pathfinding.goals.GoalComposite;
import java.util.HashSet;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
@ -18,18 +17,23 @@ import net.minecraft.util.math.BlockPos;
* @author leijurv
*/
public class MCEdit extends Manager {
static BlockPos pos1 = null;
static BlockPos pos2 = null;
public static String pos1(String s) {
return "Pos 1: " + (pos1 = Baritone.playerFeet);
}
public static String pos2(String s) {
return "Pos 2: " + (pos2 = Baritone.playerFeet);
}
public static String delete(String s) {
Manager.getManager(MCEdit.class).toggle();
return "k";
}
private static HashSet<BlockPos> toBreak() {
HashSet<BlockPos> toBreak = new HashSet<>();
for (int x = Math.min(pos1.getX(), pos2.getX()); x <= Math.max(pos1.getX(), pos2.getX()); x++) {
@ -37,7 +41,7 @@ public class MCEdit extends Manager {
for (int z = Math.min(pos1.getZ(), pos2.getZ()); z <= Math.max(pos1.getZ(), pos2.getZ()); z++) {
BlockPos po = new BlockPos(x, y, z);
Block b = Baritone.get(po).getBlock();
if (!Blocks.air.equals(b)) {
if (!Blocks.AIR.equals(b)) {
toBreak.add(po);
if (toBreak.size() > 20) {
return toBreak;
@ -48,6 +52,7 @@ public class MCEdit extends Manager {
}
return toBreak;
}
@Override
protected void onTick() {
HashSet<BlockPos> toBreak = toBreak();
@ -58,10 +63,12 @@ public class MCEdit extends Manager {
}
}
}
@Override
protected void onCancel() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
protected void onStart() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.