address cost calculation of blockfalling stacks

This commit is contained in:
Leijurv 2018-08-26 13:48:08 -07:00
parent 74916dd24e
commit 5abadc6fe5
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 62 additions and 37 deletions

View File

@ -33,6 +33,7 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -214,39 +215,53 @@ public abstract class Movement implements Helper, MovementHelper {
} }
public double getTotalHardnessOfBlocksToBreak(CalculationContext ctx) { public double getTotalHardnessOfBlocksToBreak(CalculationContext ctx) {
/* if (positionsToBreak.length == 0) {
return 0;
}
if (positionsToBreak.length == 1) {
return MovementHelper.getMiningDurationTicks(ctx, positionsToBreak[0], true);
}
int firstColumnX = positionsToBreak[0].getX();
int firstColumnZ = positionsToBreak[0].getZ();
int firstColumnMaxY = positionsToBreak[0].getY();
int firstColumnMaximalIndex = 0;
boolean hasSecondColumn = false;
int secondColumnX = -1;
int secondColumnZ = -1;
int secondColumnMaxY = -1;
int secondColumnMaximalIndex = -1;
for (int i = 0; i < positionsToBreak.length; i++) {
BlockPos pos = positionsToBreak[i];
if (pos.getX() == firstColumnX && pos.getZ() == firstColumnZ) {
if (pos.getY() > firstColumnMaxY) {
firstColumnMaxY = pos.getY();
firstColumnMaximalIndex = i;
}
} else {
if (!hasSecondColumn || (pos.getX() == secondColumnX && pos.getZ() == secondColumnZ)) {
if (hasSecondColumn) {
if (pos.getY() > secondColumnMaxY) {
secondColumnMaxY = pos.getY();
secondColumnMaximalIndex = i;
}
} else {
hasSecondColumn = true;
secondColumnX = pos.getX();
secondColumnZ = pos.getZ();
secondColumnMaxY = pos.getY();
secondColumnMaximalIndex = i;
}
} else {
throw new IllegalStateException("I literally have no idea " + Arrays.asList(positionsToBreak));
}
}
}
double sum = 0; double sum = 0;
HashSet<BlockPos> toBreak = new HashSet(); for (int i = 0; i < positionsToBreak.length; i++) {
for (BlockPos positionsToBreak1 : positionsToBreak) { sum += MovementHelper.getMiningDurationTicks(ctx, positionsToBreak[i], firstColumnMaximalIndex == i || secondColumnMaximalIndex == i);
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) { if (sum >= COST_INF) {
return COST_INF; break;
}
}
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(ctx, pos);
if (sum >= COST_INF) {
return COST_INF;
} }
} }
return sum; return sum;

View File

@ -208,12 +208,12 @@ public interface MovementHelper extends ActionCosts, Helper {
return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling; return BlockStateInterface.get(pos).getBlock() instanceof BlockFalling;
} }
static double getMiningDurationTicks(CalculationContext context, BlockPos position) { static double getMiningDurationTicks(CalculationContext context, BlockPos position, boolean includeFalling) {
IBlockState state = BlockStateInterface.get(position); IBlockState state = BlockStateInterface.get(position);
return getMiningDurationTicks(context, position, state); return getMiningDurationTicks(context, position, state, includeFalling);
} }
static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state) { static double getMiningDurationTicks(CalculationContext context, BlockPos position, IBlockState state, boolean includeFalling) {
Block block = state.getBlock(); Block block = state.getBlock();
if (!block.equals(Blocks.AIR) && !canWalkThrough(position, state)) { // TODO is the air check really necessary? Isn't air canWalkThrough? if (!block.equals(Blocks.AIR) && !canWalkThrough(position, state)) { // TODO is the air check really necessary? Isn't air canWalkThrough?
if (!context.allowBreak()) { if (!context.allowBreak()) {
@ -223,9 +223,17 @@ public interface MovementHelper extends ActionCosts, Helper {
return COST_INF; return COST_INF;
} }
double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table double m = Blocks.CRAFTING_TABLE.equals(block) ? 10 : 1; // TODO see if this is still necessary. it's from MineBot when we wanted to penalize breaking its crafting table
return m / context.getToolSet().getStrVsBlock(state, position); double result = m / context.getToolSet().getStrVsBlock(state, position);
if (includeFalling) {
BlockPos up = position.up();
IBlockState above = BlockStateInterface.get(up);
if (above.getBlock() instanceof BlockFalling) {
result += getMiningDurationTicks(context, up, above, true);
} }
return 0; }
return result;
}
return 0; // we won't actually mine it, so don't check fallings above
} }
/** /**

View File

@ -97,8 +97,8 @@ public class MovementDiagonal extends Movement {
if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) { if (BlockStateInterface.get(positionsToBreak[4].down()).getBlock() instanceof BlockMagma) {
return COST_INF; return COST_INF;
} }
double optionA = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0]) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1]); double optionA = MovementHelper.getMiningDurationTicks(context, positionsToBreak[0], false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[1], true);
double optionB = MovementHelper.getMiningDurationTicks(context, positionsToBreak[2]) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[3]); double optionB = MovementHelper.getMiningDurationTicks(context, positionsToBreak[2], false) + MovementHelper.getMiningDurationTicks(context, positionsToBreak[3], true);
if (optionA != 0 && optionB != 0) { if (optionA != 0 && optionB != 0) {
return COST_INF; return COST_INF;
} }

View File

@ -53,7 +53,8 @@ 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.getMiningDurationTicks(context, dest, d); // we're standing on it, while it might be block falling, it'll be air by the time we get here in the movement
return FALL_N_BLOCKS_COST[1] + MovementHelper.getMiningDurationTicks(context, dest, d, false);
} }
} }

View File

@ -58,7 +58,8 @@ public class MovementFall extends Movement {
} }
double frontThree = 0; double frontThree = 0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
frontThree += MovementHelper.getMiningDurationTicks(context, positionsToBreak[i]); frontThree += MovementHelper.getMiningDurationTicks(context, positionsToBreak[i], false);
// don't include falling because we will check falling right after this, and if it's there it's COST_INF
if (frontThree >= COST_INF) { if (frontThree >= COST_INF) {
return COST_INF; return COST_INF;
} }
@ -72,7 +73,7 @@ public class MovementFall extends Movement {
// Lilypads (i think?) are 0 ticks to mine, but they definitely cause fall damage // Lilypads (i think?) are 0 ticks to mine, but they definitely cause fall damage
// Same thing for falling through water... we can't actually do that // Same thing for falling through water... we can't actually do that
// And falling through signs is possible, but they do have a mining duration, right? // And falling through signs is possible, but they do have a mining duration, right?
if (MovementHelper.getMiningDurationTicks(context, positionsToBreak[i]) > 0) { if (MovementHelper.getMiningDurationTicks(context, positionsToBreak[i], false) > 0) {
//can't break while falling //can't break while falling
return COST_INF; return COST_INF;
} }