First commit
This commit is contained in:
211
pathfinding/actions/Action.java
Normal file
211
pathfinding/actions/Action.java
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import baritone.util.Out;
|
||||
import baritone.util.ToolSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCactus;
|
||||
import net.minecraft.block.BlockFire;
|
||||
import net.minecraft.block.BlockLadder;
|
||||
import net.minecraft.block.BlockLilyPad;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public abstract class Action {
|
||||
|
||||
//These costs are measured roughly in ticks btw
|
||||
public static final double WALK_ONE_BLOCK_COST = 20 / 4.317;
|
||||
public static final double WALK_ONE_IN_WATER_COST = 20 / 2.2;
|
||||
public static final double JUMP_ONE_BLOCK_COST = 5.72854;//see below calculation for fall. 1.25 blocks
|
||||
public static final double LADDER_UP_ONE_COST = 20 / 2.35;
|
||||
public static final double LADDER_DOWN_ONE_COST = 20 / 3;
|
||||
public static final double SNEAK_ONE_BLOCK_COST = 20 / 1.3;
|
||||
public static final double SPRINT_ONE_BLOCK_COST = 20 / 5.612;
|
||||
/**
|
||||
* Doesn't include walking forwards, just the falling
|
||||
*
|
||||
* Based on a sketchy formula from minecraftwiki
|
||||
*
|
||||
* d(t) = 3.92 × (99 - 49.50×(0.98^t+1) - t)
|
||||
*
|
||||
* Solved in mathematica
|
||||
*/
|
||||
public static final double FALL_ONE_BLOCK_COST = 5.11354;
|
||||
public static final double FALL_TWO_BLOCK_COST = 7.28283;
|
||||
public static final double FALL_THREE_BLOCK_COST = 8.96862;
|
||||
/**
|
||||
* It doesn't actually take ten ticks to place a block, this cost is so high
|
||||
* because we want to generally conserve blocks which might be limited
|
||||
*/
|
||||
public static final double PLACE_ONE_BLOCK_COST = 20;
|
||||
/**
|
||||
* Add this to the cost of breaking any block. The cost of breaking any
|
||||
* block is calculated as the number of ticks that block takes to break with
|
||||
* the tools you have. You add this because there's always a little overhead
|
||||
* (e.g. looking at the block)
|
||||
*/
|
||||
public static final double BREAK_ONE_BLOCK_ADD = 4;
|
||||
public static final double COST_INF = 1000000;
|
||||
public final BlockPos from;
|
||||
public final BlockPos to;
|
||||
private Double cost;
|
||||
public boolean finished = false;
|
||||
|
||||
protected Action(BlockPos from, BlockPos to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.cost = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cost. It's cached
|
||||
*
|
||||
* @param ts
|
||||
* @return
|
||||
*/
|
||||
public double cost(ToolSet ts) {
|
||||
if (cost == null) {
|
||||
cost = calculateCost0(ts == null ? new ToolSet() : ts);
|
||||
}
|
||||
if (cost < 1) {
|
||||
Out.log("Bad cost " + this + " " + cost);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
public double calculateCost0(ToolSet ts) {
|
||||
if (!(this instanceof ActionPillar) && !(this instanceof ActionBridge) && !(this instanceof ActionFall)) {
|
||||
Block fromDown = Minecraft.getMinecraft().world.getBlockState(from.down()).getBlock();
|
||||
if (fromDown instanceof BlockLadder || fromDown instanceof BlockVine) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
return calculateCost(ts);
|
||||
}
|
||||
|
||||
protected abstract double calculateCost(ToolSet ts);
|
||||
static Block waterFlowing = Block.getBlockById(8);
|
||||
static Block waterStill = Block.getBlockById(9);
|
||||
static Block lavaFlowing = Block.getBlockById(10);
|
||||
static Block lavaStill = Block.getBlockById(11);
|
||||
|
||||
/**
|
||||
* Is this block water? Includes both still and flowing
|
||||
*
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public static boolean isWater(Block b) {
|
||||
return waterFlowing.equals(b) || waterStill.equals(b);
|
||||
}
|
||||
|
||||
public static boolean isWater(BlockPos bp) {
|
||||
return isWater(Minecraft.getMinecraft().world.getBlockState(bp).getBlock());
|
||||
}
|
||||
|
||||
public static boolean isLiquid(Block b) {
|
||||
return b instanceof BlockLiquid;
|
||||
//return b != null && (waterFlowing.equals(b) || waterStill.equals(b) || lavaFlowing.equals(b) || lavaStill.equals(b));
|
||||
}
|
||||
|
||||
public static boolean isFlowing(BlockPos pos, IBlockState state) {
|
||||
Block b = state.getBlock();
|
||||
Material m = b.getMaterial(state);
|
||||
if (b instanceof BlockLiquid) {
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
//return BlockLiquid.getFlow(Minecraft.getMinecraft().world, pos, state) != -1000.0D;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isLava(Block b) {
|
||||
return lavaFlowing.equals(b) || lavaStill.equals(b);
|
||||
}
|
||||
|
||||
public static boolean isLiquid(BlockPos p) {
|
||||
return isLiquid(Minecraft.getMinecraft().world.getBlockState(p).getBlock());
|
||||
}
|
||||
|
||||
public static boolean avoidBreaking(BlockPos pos) {
|
||||
Block b = Minecraft.getMinecraft().world.getBlockState(pos).getBlock();
|
||||
Block below = Minecraft.getMinecraft().world.getBlockState(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())).getBlock();
|
||||
return Block.getBlockFromName("minecraft:ice").equals(b)//ice becomes water, and water can mess up the path
|
||||
|| isLiquid(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ()))//don't break anything touching liquid on any side
|
||||
|| isLiquid(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ()))
|
||||
|| isLiquid(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))
|
||||
|| isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1))
|
||||
|| isLiquid(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1))
|
||||
|| (!(b instanceof BlockLilyPad && isWater(below)) && isLiquid(below));//if it's a lilypad above water, it's ok to break, otherwise don't break if its liquid
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I walk through this block? e.g. air, saplings, torches, etc
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*/
|
||||
public static boolean canWalkThrough(BlockPos pos) {
|
||||
IBlockState state = Minecraft.getMinecraft().world.getBlockState(pos);
|
||||
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;
|
||||
}
|
||||
if (isFlowing(pos, state)) {
|
||||
return false;//don't walk through flowing liquids
|
||||
}
|
||||
if (isLiquid(pos.up())) {
|
||||
return false;//you could drown
|
||||
}
|
||||
return block.isPassable(Minecraft.getMinecraft().world, pos);
|
||||
}
|
||||
|
||||
public static boolean avoidWalkingInto(BlockPos pos) {
|
||||
Block block = Minecraft.getMinecraft().world.getBlockState(pos).getBlock();
|
||||
if (isLava(block)) {
|
||||
return true;
|
||||
}
|
||||
if (block instanceof BlockCactus) {
|
||||
return true;
|
||||
}
|
||||
return block instanceof BlockFire;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can I walk on this block without anything weird happening like me falling
|
||||
* through? Includes water because we know that we automatically jump on
|
||||
* lava
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
*/
|
||||
public static boolean canWalkOn(BlockPos pos) {
|
||||
IBlockState state = Minecraft.getMinecraft().world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof BlockLadder || block instanceof BlockVine) {
|
||||
return true;
|
||||
}
|
||||
if (isWater(block)) {
|
||||
return isWater(pos.up());//you can only walk on water if there is water above it
|
||||
}
|
||||
return block.isBlockNormalCube(state) && !isLava(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick this action
|
||||
*
|
||||
* @return is it done
|
||||
*/
|
||||
public abstract boolean tick();
|
||||
}
|
178
pathfinding/actions/ActionBridge.java
Normal file
178
pathfinding/actions/ActionBridge.java
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
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.util.Out;
|
||||
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.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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;
|
||||
if (!to.north().equals(from)) {
|
||||
against[i] = to.north().down();
|
||||
i++;
|
||||
}
|
||||
if (!to.south().equals(from)) {
|
||||
against[i] = to.south().down();
|
||||
i++;
|
||||
}
|
||||
if (!to.east().equals(from)) {
|
||||
against[i] = to.east().down();
|
||||
i++;
|
||||
}
|
||||
if (!to.west().equals(from)) {
|
||||
against[i] = to.west().down();
|
||||
i++;
|
||||
}
|
||||
//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;
|
||||
if (canWalkOn(positionsToPlace[0])) {//this is a walk, not a bridge
|
||||
if (canWalkThrough(positionsToBreak[0]) && canWalkThrough(positionsToBreak[1])) {
|
||||
return WC;
|
||||
}
|
||||
//double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]);
|
||||
//double hardness2 = blocksToBreak[1].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[1]);
|
||||
//Out.log("Can't walk through " + blocksToBreak[0] + " (hardness" + hardness1 + ") or " + blocksToBreak[1] + " (hardness " + hardness2 + ")");
|
||||
return WC + getTotalHardnessOfBlocksToBreak(ts);
|
||||
} else {//this is a bridge, so we need to place a block
|
||||
//return 1000000;
|
||||
Block f = Minecraft.getMinecraft().world.getBlockState(from.down()).getBlock();
|
||||
if (f instanceof BlockLadder || f instanceof BlockVine) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (blocksToPlace[0].equals(Block.getBlockById(0)) || (!isWater(blocksToPlace[0]) && blocksToPlace[0].isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) {
|
||||
for (BlockPos against1 : against) {
|
||||
if (Minecraft.getMinecraft().world.getBlockState(against1).getBlock().isBlockNormalCube()) {
|
||||
return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
}
|
||||
WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking
|
||||
return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
return COST_INF;
|
||||
//Out.log("Can't walk on " + Minecraft.getMinecraft().world.getBlockState(positionsToPlace[0]).getBlock());
|
||||
}
|
||||
}
|
||||
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) {
|
||||
oneInTen = new Random().nextInt(10) == 0;
|
||||
}
|
||||
Block fd = Minecraft.getMinecraft().world.getBlockState(from.down()).getBlock();
|
||||
boolean ladder = fd instanceof BlockLadder || fd instanceof BlockVine;
|
||||
boolean isTheBridgeBlockThere = canWalkOn(positionsToPlace[0]) || ladder;
|
||||
//Out.log("is block there: " + isTheBridgeBlockThere + " block " + Minecraft.getMinecraft().world.getBlockState(positionsToPlace[0]).getBlock());
|
||||
EntityPlayerSP thePlayer = Minecraft.getMinecraft().player;
|
||||
BlockPos whereAmI = new BlockPos(thePlayer.posX, thePlayer.posY, thePlayer.posZ);
|
||||
if (whereAmI.getY() != to.getY() && !ladder) {
|
||||
Out.log("Wrong Y coordinate");
|
||||
if (whereAmI.getY() < to.getY()) {
|
||||
MovementManager.jumping = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (isTheBridgeBlockThere) {//either the bridge block was there the whole time or we just placed it
|
||||
if (oneInTen && wasTheBridgeBlockAlwaysThere) {
|
||||
//basically one in every ten blocks we walk forwards normally without sneaking and placing, rotate to look forwards.
|
||||
//this way we tend towards looking forwards
|
||||
MovementManager.forward = LookManager.lookAtBlock(to, false);
|
||||
} else {
|
||||
MovementManager.moveTowardsBlock(to);
|
||||
}
|
||||
if (wasTheBridgeBlockAlwaysThere) {
|
||||
if (MovementManager.forward && !MovementManager.backward) {
|
||||
thePlayer.setSprinting(true);
|
||||
}
|
||||
}
|
||||
if (whereAmI.equals(to)) {//if we are there
|
||||
Out.log("Done walking to " + to);
|
||||
return true;//and we are done
|
||||
}
|
||||
Out.log("Trying to get to " + to + " currently at " + whereAmI);
|
||||
return false;//not there yet
|
||||
} else {
|
||||
wasTheBridgeBlockAlwaysThere = false;
|
||||
for (BlockPos against1 : against) {
|
||||
if (Minecraft.getMinecraft().world.getBlockState(against1).getBlock().isBlockNormalCube()) {
|
||||
if (!switchtothrowaway(true)) {//get ready to place a throwaway block
|
||||
return false;
|
||||
}
|
||||
MovementManager.sneak = true;
|
||||
double faceX = (to.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (to.getY() + against1.getY()) * 0.5D;
|
||||
double faceZ = (to.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
LookManager.lookAtCoords(faceX, faceY, faceZ, true);
|
||||
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();
|
||||
} else {
|
||||
Out.gui("Wrong. " + side + " " + Baritone.whatAreYouLookingAt().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);
|
||||
}
|
||||
}
|
||||
Out.log("Trying to look at " + against1 + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MovementManager.sneak = true;
|
||||
if (whereAmI.equals(to)) {
|
||||
//if we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
|
||||
//Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
|
||||
if (!switchtothrowaway(true)) {//get ready to place a throwaway block
|
||||
return false;
|
||||
}
|
||||
double faceX = (to.getX() + from.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (to.getY() + from.getY() - 1.0D) * 0.5D;
|
||||
double faceZ = (to.getZ() + from.getZ() + 1.0D) * 0.5D;
|
||||
//faceX,faceY,faceZ is the middle of the face between from and to
|
||||
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
|
||||
return false;
|
||||
}
|
||||
Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
return false;
|
||||
} else {
|
||||
Out.log("Not there yet m9");
|
||||
MovementManager.moveTowardsBlock(to);//move towards not look at because if we are bridging for a couple blocks in a row, it is faster if we dont spin around and walk forwards then spin around and place backwards for every block
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
107
pathfinding/actions/ActionClimb.java
Normal file
107
pathfinding/actions/ActionClimb.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import java.util.Objects;
|
||||
import baritone.ui.LookManager;
|
||||
import baritone.Baritone;
|
||||
import baritone.movement.MovementManager;
|
||||
import baritone.util.Out;
|
||||
import baritone.util.ToolSet;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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()
|
||||
int i = 0;
|
||||
if (!placementLocation.north().equals(from)) {
|
||||
against[i] = placementLocation.north();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.south().equals(from)) {
|
||||
against[i] = placementLocation.south();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.east().equals(from)) {
|
||||
against[i] = placementLocation.east();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.west().equals(from)) {
|
||||
against[i] = placementLocation.west();
|
||||
i++;
|
||||
}
|
||||
//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])) {
|
||||
if (!Baritone.isAir(positionsToPlace[0]) && !isWater(positionsToPlace[0])) {
|
||||
return COST_INF;
|
||||
}
|
||||
for (BlockPos against1 : against) {
|
||||
if (Minecraft.getMinecraft().world.getBlockState(against1).getBlock().isBlockNormalCube()) {
|
||||
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
}
|
||||
return COST_INF;
|
||||
}
|
||||
if (Minecraft.getMinecraft().world.getBlockState(from.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us
|
||||
return COST_INF;
|
||||
}
|
||||
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 (Minecraft.getMinecraft().world.getBlockState(against[i]).getBlock().isBlockNormalCube()) {
|
||||
if (!switchtothrowaway(true)) {//get ready to place a throwaway block
|
||||
return false;
|
||||
}
|
||||
double faceX = (to.getX() + against[i].getX() + 1.0D) * 0.5D;
|
||||
double faceY = (to.getY() + against[i].getY()) * 0.5D;
|
||||
double faceZ = (to.getZ() + against[i].getZ() + 1.0D) * 0.5D;
|
||||
LookManager.lookAtCoords(faceX, faceY, faceZ, true);
|
||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||
if (Objects.equals(Baritone.whatAreYouLookingAt(), against[i]) && Baritone.whatAreYouLookingAt().offset(side).equals(positionsToPlace[0])) {
|
||||
ticksWithoutPlacement++;
|
||||
MovementManager.sneak = true;
|
||||
if (Minecraft.getMinecraft().player.isSneaking()) {
|
||||
Minecraft.getMinecraft().rightClickMouse();
|
||||
}
|
||||
if (ticksWithoutPlacement > 20) {
|
||||
MovementManager.backward = true;//we might be standing in the way, move back
|
||||
}
|
||||
}
|
||||
Out.log("Trying to look at " + against[i] + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Out.gui("This is impossible", Out.Mode.Standard);
|
||||
return false;
|
||||
}
|
||||
double flatDistToNext = Math.abs(to.getX() - from.getX()) * Math.abs((to.getX() + 0.5D) - thePlayer.posX) + Math.abs(to.getZ() - from.getZ()) * Math.abs((to.getZ() + 0.5D) - thePlayer.posZ);
|
||||
boolean pointingInCorrectDirection = MovementManager.moveTowardsBlock(to);
|
||||
MovementManager.jumping = flatDistToNext < 1.2 && pointingInCorrectDirection;
|
||||
//once we are pointing the right way and moving, start jumping
|
||||
//this is slightly more efficient because otherwise we might start jumping before moving, and fall down without moving onto the block we want to jump onto
|
||||
//also wait until we are close enough, because we might jump and hit our head on an adjacent block
|
||||
return Minecraft.getMinecraft().player.getPosition0().equals(to);
|
||||
}
|
||||
}
|
40
pathfinding/actions/ActionDescend.java
Normal file
40
pathfinding/actions/ActionDescend.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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])) {
|
||||
return COST_INF;
|
||||
}
|
||||
Block tmp1 = Minecraft.getMinecraft().world.getBlockState(to).getBlock();
|
||||
if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) {
|
||||
return COST_INF;
|
||||
}
|
||||
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);
|
||||
return Minecraft.getMinecraft().player.getPosition0().equals(to);
|
||||
}
|
||||
}
|
36
pathfinding/actions/ActionDescendThree.java
Normal file
36
pathfinding/actions/ActionDescendThree.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import baritone.movement.MovementManager;
|
||||
import baritone.util.ToolSet;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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])) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (getTotalHardnessOfBlocksToBreak(ts) != 0) {
|
||||
return COST_INF;
|
||||
}
|
||||
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);
|
||||
return Minecraft.getMinecraft().player.getPosition0().equals(to);
|
||||
}
|
||||
}
|
36
pathfinding/actions/ActionDescendTwo.java
Normal file
36
pathfinding/actions/ActionDescendTwo.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import baritone.movement.MovementManager;
|
||||
import baritone.util.ToolSet;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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])) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (getTotalHardnessOfBlocksToBreak(ts) != 0) {
|
||||
return COST_INF;
|
||||
}
|
||||
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);
|
||||
return Minecraft.getMinecraft().player.getPosition0().equals(to);
|
||||
}
|
||||
}
|
47
pathfinding/actions/ActionFall.java
Normal file
47
pathfinding/actions/ActionFall.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class ActionFall extends ActionPlaceOrBreak {
|
||||
public ActionFall(BlockPos start) {
|
||||
super(start, start.down(), new BlockPos[]{start.down()}, new BlockPos[0]);
|
||||
}
|
||||
int numTicks = 0;
|
||||
@Override
|
||||
protected boolean tick0() {
|
||||
numTicks++;
|
||||
if (numTicks > 10) {
|
||||
MovementManager.moveTowardsBlock(to);
|
||||
}
|
||||
return Minecraft.getMinecraft().player.getPosition0().equals(to);
|
||||
}
|
||||
@Override
|
||||
protected double calculateCost(ToolSet ts) {
|
||||
if (!Baritone.allowVerticalMotion || !canWalkOn(to.down())) {
|
||||
return COST_INF;
|
||||
}
|
||||
Block td = Minecraft.getMinecraft().world.getBlockState(to).getBlock();
|
||||
boolean ladder = td instanceof BlockLadder || td instanceof BlockVine;
|
||||
if (ladder) {
|
||||
return LADDER_DOWN_ONE_COST;
|
||||
} else {
|
||||
return FALL_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
}
|
||||
}
|
141
pathfinding/actions/ActionPillar.java
Normal file
141
pathfinding/actions/ActionPillar.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import baritone.ui.LookManager;
|
||||
import baritone.Baritone;
|
||||
import baritone.movement.MovementManager;
|
||||
import baritone.util.Out;
|
||||
import baritone.util.ToolSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.BlockLadder;
|
||||
import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
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 = Minecraft.getMinecraft().world.getBlockState(from).getBlock();
|
||||
boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine;
|
||||
if (!ladder) {
|
||||
Block d = Minecraft.getMinecraft().world.getBlockState(from.down()).getBlock();
|
||||
if (d instanceof BlockLadder || d instanceof BlockVine) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
if ((!Baritone.hasThrowaway && !ladder) || !Baritone.allowVerticalMotion) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (fromDown instanceof BlockVine) {
|
||||
if (getAgainst(from) == null) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
double hardness = getTotalHardnessOfBlocksToBreak(ts);
|
||||
if (hardness != 0) {
|
||||
Block tmp = Minecraft.getMinecraft().world.getBlockState(from.up(2)).getBlock();
|
||||
if (tmp instanceof BlockLadder || tmp instanceof BlockVine) {
|
||||
hardness = 0;
|
||||
} else if (!canWalkOn(from.up(3)) || canWalkThrough(from.up(3)) || Minecraft.getMinecraft().world.getBlockState(from.up(3)).getBlock() instanceof BlockFalling) {//if the block above where we want to break is not a full block, don't do it
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
if (isLiquid(from) || isLiquid(from.down())) {//can't pillar on water or in water
|
||||
return COST_INF;
|
||||
}
|
||||
if (ladder) {
|
||||
return LADDER_UP_ONE_COST + hardness;
|
||||
} else {
|
||||
return JUMP_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + hardness;
|
||||
}
|
||||
}
|
||||
int numTicks = 0;
|
||||
public BlockPos getAgainst(BlockPos vine) {
|
||||
if (Minecraft.getMinecraft().world.getBlockState(vine.north()).getBlock().isBlockNormalCube()) {
|
||||
return vine.north();
|
||||
}
|
||||
if (Minecraft.getMinecraft().world.getBlockState(vine.south()).getBlock().isBlockNormalCube()) {
|
||||
return vine.south();
|
||||
}
|
||||
if (Minecraft.getMinecraft().world.getBlockState(vine.east()).getBlock().isBlockNormalCube()) {
|
||||
return vine.east();
|
||||
}
|
||||
if (Minecraft.getMinecraft().world.getBlockState(vine.west()).getBlock().isBlockNormalCube()) {
|
||||
return vine.west();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected boolean tick0() {
|
||||
IBlockState fromDown = Minecraft.getMinecraft().world.getBlockState(from);
|
||||
boolean ladder = fromDown.getBlock() instanceof BlockLadder || fromDown.getBlock() instanceof BlockVine;
|
||||
boolean vine = fromDown.getBlock() instanceof BlockVine;
|
||||
if (!ladder && !LookManager.lookAtBlock(positionsToPlace[0], true)) {
|
||||
return false;
|
||||
}
|
||||
EntityPlayerSP thePlayer = Minecraft.getMinecraft().player;
|
||||
boolean blockIsThere = canWalkOn(from) || ladder;
|
||||
if (ladder) {
|
||||
BlockPos against = vine ? getAgainst(from) : from.offset(fromDown.getValue(BlockLadder.FACING).getOpposite());
|
||||
if (against == null) {
|
||||
Out.gui("Unable to climb vines", Out.Mode.Standard);
|
||||
return false;
|
||||
}
|
||||
if (thePlayer.getPosition0().equals(against.up()) || thePlayer.getPosition0().equals(to)) {
|
||||
return true;
|
||||
}
|
||||
/*if (thePlayer.getPosition0().getX() != from.getX() || thePlayer.getPosition0().getZ() != from.getZ()) {
|
||||
Baritone.moveTowardsBlock(from);
|
||||
}*/
|
||||
MovementManager.moveTowardsBlock(against);
|
||||
return false;
|
||||
} else {
|
||||
if (!switchtothrowaway(true)) {//get ready to place a throwaway block
|
||||
return false;
|
||||
}
|
||||
numTicks++;
|
||||
MovementManager.jumping = thePlayer.posY < to.getY(); //if our Y coordinate is above our goal, stop jumping
|
||||
MovementManager.sneak = true;
|
||||
//otherwise jump
|
||||
if (numTicks > 40) {
|
||||
double diffX = thePlayer.posX - (to.getX() + 0.5);
|
||||
double diffZ = thePlayer.posZ - (to.getZ() + 0.5);
|
||||
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
if (dist > 0.17) {//why 0.17? because it seemed like a good number, that's why
|
||||
MovementManager.forward = true;//if it's been more than forty ticks of trying to jump and we aren't done yet, go forward, maybe we are stuck
|
||||
}
|
||||
}
|
||||
if (!blockIsThere) {
|
||||
Out.log("Block not there yet");
|
||||
Block fr = Minecraft.getMinecraft().world.getBlockState(from).getBlock();
|
||||
if (!(Baritone.isAir(from) || fr.isReplaceable(Minecraft.getMinecraft().world, from))) {
|
||||
MovementManager.isLeftClick = true;
|
||||
blockIsThere = false;
|
||||
} else if (Minecraft.getMinecraft().player.isSneaking()) {
|
||||
Minecraft.getMinecraft().rightClickMouse();//constantly right click
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockPos whereAmI = new BlockPos(thePlayer.posX, thePlayer.posY, thePlayer.posZ);
|
||||
if (whereAmI.equals(to) && blockIsThere) {//if we are at our goal and the block below us is placed
|
||||
Out.log("Done pillaring to " + to);
|
||||
MovementManager.jumping = false;//stop jumping
|
||||
return true;//we are done
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
221
pathfinding/actions/ActionPlaceOrBreak.java
Normal file
221
pathfinding/actions/ActionPlaceOrBreak.java
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import baritone.util.ToolSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import baritone.ui.LookManager;
|
||||
import baritone.Baritone;
|
||||
import baritone.movement.MovementManager;
|
||||
import baritone.util.Out;
|
||||
import baritone.inventory.SmeltingTask;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public abstract class ActionPlaceOrBreak extends Action {
|
||||
public final BlockPos[] positionsToBreak;//the positions that need to be broken before this action can ensue
|
||||
public final BlockPos[] positionsToPlace;//the positions where we need to place a block before this aciton can ensue
|
||||
public final Block[] blocksToBreak;//the blocks at those positions
|
||||
public final Block[] blocksToPlace;
|
||||
public ActionPlaceOrBreak(BlockPos start, BlockPos end, BlockPos[] toBreak, BlockPos[] toPlace) {
|
||||
super(start, end);
|
||||
this.positionsToBreak = toBreak;
|
||||
this.positionsToPlace = toPlace;
|
||||
blocksToBreak = new Block[positionsToBreak.length];
|
||||
blocksToPlace = new Block[positionsToPlace.length];
|
||||
for (int i = 0; i < blocksToBreak.length; i++) {
|
||||
blocksToBreak[i] = Minecraft.getMinecraft().world.getBlockState(positionsToBreak[i]).getBlock();
|
||||
}
|
||||
for (int i = 0; i < blocksToPlace.length; i++) {
|
||||
blocksToPlace[i] = Minecraft.getMinecraft().world.getBlockState(positionsToPlace[i]).getBlock();
|
||||
}
|
||||
}
|
||||
public double getTotalHardnessOfBlocksToBreak() {//of all the blocks we need to break before starting this action, what's the sum of how hard they are (phrasing)
|
||||
ToolSet ts = new ToolSet();
|
||||
return this.getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
public double getTotalHardnessOfBlocksToBreak(ToolSet ts) {
|
||||
double sum = 0;
|
||||
HashSet<BlockPos> toBreak = new HashSet();
|
||||
for (BlockPos positionsToBreak1 : positionsToBreak) {
|
||||
toBreak.add(positionsToBreak1);
|
||||
if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us
|
||||
continue;
|
||||
}
|
||||
BlockPos tmp = positionsToBreak1.up();
|
||||
while (canFall(tmp)) {
|
||||
toBreak.add(tmp);
|
||||
tmp = tmp.up();
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : toBreak) {
|
||||
sum += getHardness(ts, Minecraft.getMinecraft().world.getBlockState(pos).getBlock(), pos);
|
||||
if (sum >= COST_INF) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) {
|
||||
for (int i = 0; i < blocksToPlace.length; i++) {
|
||||
if (!canWalkOn(positionsToPlace[i])) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
public static boolean canFall(BlockPos pos) {
|
||||
return Minecraft.getMinecraft().world.getBlockState(pos).getBlock() instanceof BlockFalling;
|
||||
}
|
||||
public static double getHardness(ToolSet ts, Block block, BlockPos position) {
|
||||
if (!block.equals(Block.getBlockById(0)) && !canWalkThrough(position)) {
|
||||
if (avoidBreaking(position)) {
|
||||
return COST_INF;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass() + " place " + Arrays.asList(blocksToPlace) + " break " + Arrays.asList(blocksToBreak) + " cost " + cost(null) + " break cost " + getTotalHardnessOfBlocksToBreak();
|
||||
}
|
||||
@Override
|
||||
public boolean tick() {
|
||||
//breaking first
|
||||
for (int i = 0; i < positionsToBreak.length; i++) {
|
||||
if (!canWalkThrough(positionsToBreak[i])) {
|
||||
if (!Baritone.allowBreakOrPlace) {
|
||||
Out.gui("BB I can't break this =(((", Out.Mode.Standard);
|
||||
return false;
|
||||
}
|
||||
//Out.log("Breaking " + blocksToBreak[i] + " at " + positionsToBreak[i]);
|
||||
boolean lookingInCorrectDirection = LookManager.lookAtBlock(positionsToBreak[i], true);
|
||||
//TODO decide if when actuallyLookingAtTheBlock==true then should it still keep moving the look direction to the exact center of the block
|
||||
boolean actuallyLookingAtTheBlock = positionsToBreak[i].equals(Baritone.whatAreYouLookingAt());
|
||||
if (!(lookingInCorrectDirection || actuallyLookingAtTheBlock)) {
|
||||
return false;
|
||||
}
|
||||
/*if (!positionsToBreak[i].equals(Baritone.whatAreYouLookingAt())) {//hmmm, our crosshairs are looking at the wrong block
|
||||
//TODO add a timer here, and if we are stuck looking at the wrong block for more than 1 second, do something
|
||||
//(it cant take longer than twenty ticks, because the Baritone.MAX_YAW_CHANGE_PER_TICK=18, and 18*20 = 360°
|
||||
Out.log("Wrong");
|
||||
return false;
|
||||
}*/
|
||||
if (Baritone.whatAreYouLookingAt() != null) {
|
||||
Baritone.switchtotool(Minecraft.getMinecraft().world.getBlockState(Baritone.whatAreYouLookingAt()).getBlock());
|
||||
}
|
||||
MovementManager.isLeftClick = true;//hold down left click
|
||||
if (canWalkThrough(positionsToBreak[i])) {
|
||||
MovementManager.letGoOfLeftClick();
|
||||
Out.log("Done breaking " + blocksToBreak[i] + " at " + positionsToBreak[i]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MovementManager.letGoOfLeftClick();//sometimes it keeps on left clicking so we need this here (yes it scares me too)
|
||||
for (BlockPos positionsToPlace1 : positionsToPlace) {
|
||||
if (!canWalkOn(positionsToPlace1)) {
|
||||
if (!Baritone.allowBreakOrPlace) {
|
||||
Out.gui("BB I can't place this =(((", Out.Mode.Standard);
|
||||
return false;
|
||||
}
|
||||
//Baritone.lookAtBlock(positionsToPlace[i], true);
|
||||
//Out.log("CANT DO IT. CANT WALK ON " + blocksToPlace[i] + " AT " + positionsToPlace[i]);
|
||||
//one of the blocks that needs to be there isn't there
|
||||
//so basically someone mined out our path from under us
|
||||
//
|
||||
//this doesn't really do anything, because all the cases for positionToPlace are handled in their respective action tick0s (e.g. pillar and bridge)
|
||||
}
|
||||
}
|
||||
return tick0();
|
||||
}
|
||||
//I dont want to make this static, because then it might be executed before Item gets initialized
|
||||
private static List<Item> ACCEPTABLE_THROWAWAY_ITEMS = null;
|
||||
private static void set() {
|
||||
if (ACCEPTABLE_THROWAWAY_ITEMS != null) {
|
||||
return;
|
||||
}
|
||||
ACCEPTABLE_THROWAWAY_ITEMS = Arrays.asList(new Item[]{Item.getByNameOrId("minecraft:dirt"), Item.getByNameOrId("minecraft:cobblestone")});
|
||||
}
|
||||
public static boolean switchtothrowaway(boolean message) {
|
||||
set();
|
||||
EntityPlayerSP p = Minecraft.getMinecraft().player;
|
||||
ItemStack[] inv = p.inventory.mainInventory;
|
||||
for (byte i = 0; i < 9; i++) {
|
||||
ItemStack item = inv[i];
|
||||
if (inv[i] == null) {
|
||||
item = new ItemStack(Item.getByNameOrId("minecraft:apple"));
|
||||
}
|
||||
if (ACCEPTABLE_THROWAWAY_ITEMS.contains(item.getItem())) {
|
||||
p.inventory.currentItem = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (message) {
|
||||
Out.gui("bb pls get me some blocks. dirt or cobble", Out.Mode.Minimal);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean hasthrowaway() {
|
||||
set();
|
||||
EntityPlayerSP p = Minecraft.getMinecraft().player;
|
||||
ItemStack[] inv = p.inventory.mainInventory;
|
||||
for (byte i = 0; i < 9; i++) {
|
||||
ItemStack item = inv[i];
|
||||
if (inv[i] == null) {
|
||||
item = new ItemStack(Item.getByNameOrId("minecraft:apple"));
|
||||
}
|
||||
if (ACCEPTABLE_THROWAWAY_ITEMS.contains(item.getItem())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Do the actual tick. This function can assume that all blocks in
|
||||
* positionsToBreak are now walk-through-able.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean tick0();
|
||||
public ArrayList<BlockPos> toMine() {
|
||||
ArrayList<BlockPos> result = new ArrayList<>();
|
||||
for (BlockPos positionsToBreak1 : positionsToBreak) {
|
||||
if (!canWalkThrough(positionsToBreak1)) {
|
||||
result.add(positionsToBreak1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ArrayList<BlockPos> toPlace() {
|
||||
ArrayList<BlockPos> result = new ArrayList<>();
|
||||
for (BlockPos positionsToPlace1 : positionsToPlace) {
|
||||
if (!canWalkOn(positionsToPlace1)) {
|
||||
result.add(positionsToPlace1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
61
pathfinding/actions/ActionWalkDiagonal.java
Normal file
61
pathfinding/actions/ActionWalkDiagonal.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package baritone.pathfinding.actions;
|
||||
|
||||
import java.util.Random;
|
||||
import baritone.Baritone;
|
||||
import baritone.movement.MovementManager;
|
||||
import baritone.ui.LookManager;
|
||||
import baritone.util.ToolSet;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author leijurv
|
||||
*/
|
||||
public class ActionWalkDiagonal extends ActionPlaceOrBreak {
|
||||
public ActionWalkDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
||||
this(start, start.offset(dir1), start.offset(dir2), dir2);
|
||||
//super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
||||
}
|
||||
public ActionWalkDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) {
|
||||
this(start, dir1.offset(drr2), dir1, dir2);
|
||||
}
|
||||
public ActionWalkDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
||||
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()});
|
||||
}
|
||||
private Boolean oneInTen = null;
|
||||
@Override
|
||||
protected boolean tick0() {
|
||||
if (oneInTen == null) {
|
||||
oneInTen = new Random().nextInt(10) == 0;
|
||||
}
|
||||
if (oneInTen) {
|
||||
MovementManager.forward = LookManager.lookAtBlock(to, false);
|
||||
} else {
|
||||
MovementManager.moveTowardsBlock(to);
|
||||
}
|
||||
if (MovementManager.forward && !MovementManager.backward) {
|
||||
Minecraft.getMinecraft().player.setSprinting(true);
|
||||
}
|
||||
return to.equals(Minecraft.getMinecraft().player.getPosition0());
|
||||
}
|
||||
@Override
|
||||
protected double calculateCost(ToolSet ts) {
|
||||
if (!Baritone.allowDiagonal) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (getTotalHardnessOfBlocksToBreak(ts) != 0) {
|
||||
return COST_INF;
|
||||
}
|
||||
if (!canWalkOn(positionsToPlace[0])) {
|
||||
return COST_INF;
|
||||
}
|
||||
return Math.sqrt(2) * (isWater(from) || isWater(to) ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user