MovementPillar

This commit is contained in:
Leijurv 2018-09-22 19:13:59 -07:00
parent 7888dd24e5
commit e33564f1eb
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 33 additions and 20 deletions

View File

@ -47,11 +47,12 @@ import java.util.Optional;
*/
public interface MovementHelper extends ActionCosts, Helper {
static boolean avoidBreaking(BlockPos pos, IBlockState state) {
static boolean avoidBreaking(BetterBlockPos pos, IBlockState state) {
return avoidBreaking(pos.x, pos.y, pos.z, state);
}
static boolean avoidBreaking(int x, int y, int z, IBlockState state) {
Block b = state.getBlock();
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
return b == Blocks.ICE // ice becomes water, and water can mess up the path
|| b instanceof BlockSilverfish // obvious reasons
// call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason
@ -322,16 +323,20 @@ public interface MovementHelper extends ActionCosts, Helper {
static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, boolean includeFalling) {
IBlockState state = BlockStateInterface.get(position);
return getMiningDurationTicks(context, position, state, includeFalling);
return getMiningDurationTicks(context, position.x, position.y, position.z, state, includeFalling);
}
static double getMiningDurationTicks(CalculationContext context, BetterBlockPos position, IBlockState state, boolean includeFalling) {
return getMiningDurationTicks(context, position.x, position.y, position.z, state, includeFalling);
}
static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) {
Block block = state.getBlock();
if (!canWalkThrough(position, state)) {
if (!canWalkThrough(x, y, z, state)) {
if (!context.allowBreak()) {
return COST_INF;
}
if (avoidBreaking(position, state)) {
if (avoidBreaking(x, y, z, state)) {
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
@ -342,10 +347,9 @@ public interface MovementHelper extends ActionCosts, Helper {
double result = m / strVsBlock;
if (includeFalling) {
BetterBlockPos up = position.up();
IBlockState above = BlockStateInterface.get(up);
IBlockState above = BlockStateInterface.get(x, y + 1, z);
if (above.getBlock() instanceof BlockFalling) {
result += getMiningDurationTicks(context, up, above, true);
result += getMiningDurationTicks(context, x, y + 1, z, above, true);
}
}
return result;

View File

@ -48,9 +48,13 @@ public class MovementPillar extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
Block fromDown = BlockStateInterface.get(src).getBlock();
return cost(context, src.x, src.y, src.z);
}
public static double cost(CalculationContext context, int x, int y, int z) {
Block fromDown = BlockStateInterface.get(x, y, z).getBlock();
boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine;
IBlockState fromDownDown = BlockStateInterface.get(src.down());
IBlockState fromDownDown = BlockStateInterface.get(x, y - 1, z);
if (!ladder) {
if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) {
return COST_INF;
@ -65,24 +69,23 @@ public class MovementPillar extends Movement {
return COST_INF;
}
if (fromDown instanceof BlockVine) {
if (getAgainst(src) == null) {
if (!hasAgainst(x, y, z)) {
return COST_INF;
}
}
BetterBlockPos toBreakPos = src.up(2);
IBlockState toBreak = BlockStateInterface.get(toBreakPos);
IBlockState toBreak = BlockStateInterface.get(x, y + 2, z);
Block toBreakBlock = toBreak.getBlock();
if (toBreakBlock instanceof BlockFenceGate) {
return COST_INF;
}
Block srcUp = null;
if (BlockStateInterface.isWater(toBreakBlock) && BlockStateInterface.isWater(fromDown)) {
srcUp = BlockStateInterface.get(dest).getBlock();
srcUp = BlockStateInterface.get(x, y + 1, z).getBlock();
if (BlockStateInterface.isWater(srcUp)) {
return LADDER_UP_ONE_COST;
}
}
double hardness = MovementHelper.getMiningDurationTicks(context, toBreakPos, toBreak, true);
double hardness = MovementHelper.getMiningDurationTicks(context, x, y + 2, z, toBreak, true);
if (hardness >= COST_INF) {
return COST_INF;
}
@ -90,12 +93,11 @@ public class MovementPillar extends Movement {
if (toBreakBlock instanceof BlockLadder || toBreakBlock instanceof BlockVine) {
hardness = 0; // we won't actually need to break the ladder / vine because we're going to use it
} else {
BlockPos chkPos = src.up(3);
IBlockState check = BlockStateInterface.get(chkPos);
IBlockState check = BlockStateInterface.get(x, y + 3, z);
if (check.getBlock() instanceof BlockFalling) {
// see MovementAscend's identical check for breaking a falling block above our head
if (srcUp == null) {
srcUp = BlockStateInterface.get(dest).getBlock();
srcUp = BlockStateInterface.get(x, y + 1, z).getBlock();
}
if (!(toBreakBlock instanceof BlockFalling) || !(srcUp instanceof BlockFalling)) {
return COST_INF;
@ -120,6 +122,13 @@ public class MovementPillar extends Movement {
}
}
public static boolean hasAgainst(int x, int y, int z) {
return BlockStateInterface.get(x + 1, y, z).isBlockNormalCube() ||
BlockStateInterface.get(x - 1, y, z).isBlockNormalCube() ||
BlockStateInterface.get(x, y, z + 1).isBlockNormalCube() ||
BlockStateInterface.get(x, y, z - 1).isBlockNormalCube();
}
public static BlockPos getAgainst(BlockPos vine) {
if (BlockStateInterface.get(vine.north()).isBlockNormalCube()) {
return vine.north();