Fix location of method

This commit is contained in:
Howard Stark 2018-08-06 17:34:49 -07:00
parent 5b3eb5a375
commit 24cbb5e149
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
7 changed files with 63 additions and 56 deletions

View File

@ -131,6 +131,47 @@ public abstract class Movement implements Helper, MovementHelper {
currentState.setStatus(MovementStatus.CANCELED); currentState.setStatus(MovementStatus.CANCELED);
} }
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, Baritone.get(pos), 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;
}
}
}*/
//^ the above implementation properly deals with falling blocks, TODO integrate
double sum = 0;
for (BlockPos pos : positionsToBreak) {
sum += MovementHelper.getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
if (sum >= COST_INF) {
return COST_INF;
}
}
return sum;
}
/** /**
* Calculate latest movement state. * Calculate latest movement state.
* Gets called once a tick. * Gets called once a tick.
@ -154,9 +195,9 @@ public abstract class Movement implements Helper, MovementHelper {
return toBreakCached; return toBreakCached;
} }
ArrayList<BlockPos> result = new ArrayList<>(); ArrayList<BlockPos> result = new ArrayList<>();
for (BlockPos positionsToBreak1 : positionsToBreak) { for (BlockPos positionToBreak : positionsToBreak) {
if (!MovementHelper.canWalkThrough(positionsToBreak1, BlockStateInterface.get(positionsToBreak1))) { if (!MovementHelper.canWalkThrough(positionToBreak, BlockStateInterface.get(positionToBreak))) {
result.add(positionsToBreak1); result.add(positionToBreak);
} }
} }
toBreakCached = result; toBreakCached = result;
@ -168,9 +209,9 @@ public abstract class Movement implements Helper, MovementHelper {
return toPlaceCached; return toPlaceCached;
} }
ArrayList<BlockPos> result = new ArrayList<>(); ArrayList<BlockPos> result = new ArrayList<>();
for (BlockPos positionsToPlace1 : positionsToPlace) { for (BlockPos positionToBreak : positionsToPlace) {
if (!MovementHelper.canWalkOn(positionsToPlace1)) { if (!MovementHelper.canWalkOn(positionToBreak)) {
result.add(positionsToPlace1); result.add(positionToBreak);
} }
} }
toPlaceCached = result; toPlaceCached = result;
@ -178,6 +219,7 @@ public abstract class Movement implements Helper, MovementHelper {
} }
protected void moveTowards(BlockPos pos) { protected void moveTowards(BlockPos pos) {
currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch))).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); currentState.setTarget(new MovementState.MovementTarget(new Rotation(Utils.calcRotationFromVec3d(playerHead(), Utils.calcCenterFromCoords(pos, world()), playerRotations()).getFirst(), player().rotationPitch)))
.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
} }
} }

View File

@ -98,46 +98,6 @@ public interface MovementHelper extends ActionCosts, Helper {
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
} }
static double getTotalHardnessOfBlocksToBreak(ToolSet ts, BlockPos[] positionsToBreak) {
/*
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, Baritone.get(pos), 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;
}
}
}*/
//^ the above implementation properly deals with falling blocks, TODO integrate
double sum = 0;
for (BlockPos pos : positionsToBreak) {
sum += getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
if (sum >= COST_INF) {
return COST_INF;
}
}
return sum;
}
static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) { static double getMiningDurationTicks(ToolSet ts, IBlockState block, BlockPos position) {
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) { if (!block.equals(Blocks.AIR) && !canWalkThrough(position, block)) {
if (avoidBreaking(position)) { if (avoidBreaking(position)) {

View File

@ -50,7 +50,7 @@ public class MovementAscend extends Movement {
} }
for (BlockPos against1 : against) { for (BlockPos against1 : against) {
if (BlockStateInterface.get(against1).isBlockNormalCube()) { if (BlockStateInterface.get(against1).isBlockNormalCube()) {
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts );
} }
} }
return COST_INF; return COST_INF;
@ -58,7 +58,7 @@ public class MovementAscend extends Movement {
if (BlockStateInterface.get(src.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us if (BlockStateInterface.get(src.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us
return COST_INF; return COST_INF;
} }
return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);//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) 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)
} }
@Override @Override

View File

@ -25,13 +25,12 @@ public class MovementDescend extends Movement {
if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) { if (tmp1 instanceof BlockLadder || tmp1 instanceof BlockVine) {
return COST_INF; return COST_INF;
} }
return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_N_BLOCKS_COST[1], WALK_ONE_BLOCK_COST * 0.2) + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak);//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) return WALK_ONE_BLOCK_COST * 0.8 + Math.max(FALL_N_BLOCKS_COST[1], 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 @Override
public MovementState updateState(MovementState state) { public MovementState updateState(MovementState state) {
super.updateState(state); super.updateState(state);
System.out.println("Ticking with state " + state.getStatus());
switch (state.getStatus()) { switch (state.getStatus()) {
case PREPPING: case PREPPING:
case UNREACHABLE: case UNREACHABLE:

View File

@ -52,7 +52,7 @@ public class MovementDownward extends Movement {
if (ladder) { if (ladder) {
return LADDER_DOWN_ONE_COST; return LADDER_DOWN_ONE_COST;
} else { } else {
return FALL_N_BLOCKS_COST[1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); return FALL_N_BLOCKS_COST[1] + getTotalHardnessOfBlocksToBreak(ts);
} }
} }
} }

View File

@ -12,6 +12,9 @@ import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.Rotation; import baritone.bot.utils.Rotation;
import baritone.bot.utils.ToolSet; import baritone.bot.utils.ToolSet;
import baritone.bot.utils.Utils; import baritone.bot.utils.Utils;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -43,7 +46,7 @@ public class MovementFall extends Movement {
if(!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3) { if(!BlockStateInterface.isWater(dest) && src.getY() - dest.getY() > 3) {
placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST; placeBucketCost = ActionCosts.PLACE_ONE_BLOCK_COST;
} }
return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak) + placeBucketCost; return WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[positionsToBreak.length - 1] + getTotalHardnessOfBlocksToBreak(ts) + placeBucketCost;
} }
@Override @Override
@ -58,6 +61,9 @@ public class MovementFall extends Movement {
state.setStatus(MovementStatus.RUNNING); state.setStatus(MovementStatus.RUNNING);
case RUNNING: case RUNNING:
BlockPos playerFeet = playerFeet(); BlockPos playerFeet = playerFeet();
if(src.getY() - dest.getY() > 3 && !BlockStateInterface.isWater(dest) && !player().inventory.hasItemStack(new ItemStack(new ItemBucket(Blocks.WATER)))) {
return state.setStatus(MovementStatus.UNREACHABLE);
}
if(playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 || BlockStateInterface.isWater(dest))) if(playerFeet.equals(dest) && (player().posY - playerFeet.getY() < 0.01 || BlockStateInterface.isWater(dest)))
return state.setStatus(MovementStatus.SUCCESS); return state.setStatus(MovementStatus.SUCCESS);
Vec3d destCenter = Utils.calcCenterFromCoords(dest, world()); Vec3d destCenter = Utils.calcCenterFromCoords(dest, world());

View File

@ -58,7 +58,7 @@ public class MovementTraverse extends Movement {
//double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]); //double hardness1 = blocksToBreak[0].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[0]);
//double hardness2 = blocksToBreak[1].getBlockHardness(Minecraft.getMinecraft().world, positionsToBreak[1]); //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 + ")"); //Out.log("Can't walk through " + blocksToBreak[0] + " (hardness" + hardness1 + ") or " + blocksToBreak[1] + " (hardness " + hardness2 + ")");
return WC + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); return WC + getTotalHardnessOfBlocksToBreak(ts);
} else {//this is a bridge, so we need to place a block } else {//this is a bridge, so we need to place a block
//return 1000000; //return 1000000;
Block f = BlockStateInterface.get(src.down()).getBlock(); Block f = BlockStateInterface.get(src.down()).getBlock();
@ -69,11 +69,11 @@ public class MovementTraverse extends Movement {
if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.isWater(pp0.getBlock()) && pp0.getBlock().isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) { if (pp0.getBlock().equals(Blocks.AIR) || (!BlockStateInterface.isWater(pp0.getBlock()) && pp0.getBlock().isReplaceable(Minecraft.getMinecraft().world, positionsToPlace[0]))) {
for (BlockPos against1 : against) { for (BlockPos against1 : against) {
if (BlockStateInterface.get(against1).isBlockNormalCube()) { if (BlockStateInterface.get(against1).isBlockNormalCube()) {
return WC + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); 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 WC = WC * SNEAK_ONE_BLOCK_COST / WALK_ONE_BLOCK_COST;//since we are placing, we are sneaking
return WC + PLACE_ONE_BLOCK_COST + MovementHelper.getTotalHardnessOfBlocksToBreak(ts, positionsToBreak); return WC + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
} }
return COST_INF; return COST_INF;
//Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock()); //Out.log("Can't walk on " + Baritone.get(positionsToPlace[0]).getBlock());