instead of casting to BetterBlockPos at runtime, let the compiler verify that

This commit is contained in:
Leijurv 2018-09-09 09:22:35 -07:00
parent dce51d856b
commit 760f68cb05
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
11 changed files with 33 additions and 23 deletions

View File

@ -109,7 +109,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
if (movementToGetToNeighbor == null) { if (movementToGetToNeighbor == null) {
continue; continue;
} }
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); BetterBlockPos dest = movementToGetToNeighbor.getDest();
int chunkX = currentNodePos.x >> 4; int chunkX = currentNodePos.x >> 4;
int chunkZ = currentNodePos.z >> 4; int chunkZ = currentNodePos.z >> 4;
if (dest.x >> 4 != chunkX || dest.z >> 4 != chunkZ) { if (dest.x >> 4 != chunkX || dest.z >> 4 != chunkZ) {

View File

@ -22,6 +22,7 @@ import baritone.behavior.impl.LookBehavior;
import baritone.behavior.impl.LookBehaviorUtils; import baritone.behavior.impl.LookBehaviorUtils;
import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.utils.*; import baritone.utils.*;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
@ -39,9 +40,9 @@ public abstract class Movement implements Helper, MovementHelper {
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING); private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
protected final BlockPos src; protected final BetterBlockPos src;
protected final BlockPos dest; protected final BetterBlockPos dest;
/** /**
* The positions that need to be broken before this movement can ensue * The positions that need to be broken before this movement can ensue
@ -57,14 +58,14 @@ public abstract class Movement implements Helper, MovementHelper {
private Double cost; private Double cost;
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos toPlace) { protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak, BlockPos toPlace) {
this.src = src; this.src = src;
this.dest = dest; this.dest = dest;
this.positionsToBreak = toBreak; this.positionsToBreak = toBreak;
this.positionToPlace = toPlace; this.positionToPlace = toPlace;
} }
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) { protected Movement(BetterBlockPos src, BetterBlockPos dest, BlockPos[] toBreak) {
this(src, dest, toBreak, null); this(src, dest, toBreak, null);
} }
@ -185,11 +186,11 @@ public abstract class Movement implements Helper, MovementHelper {
&& currentState.getStatus() != MovementStatus.WAITING); && currentState.getStatus() != MovementStatus.WAITING);
} }
public BlockPos getSrc() { public BetterBlockPos getSrc() {
return src; return src;
} }
public BlockPos getDest() { public BetterBlockPos getDest() {
return dest; return dest;
} }

View File

@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.pathing.movement.movements.MovementDescend; import baritone.pathing.movement.movements.MovementDescend;
import baritone.pathing.movement.movements.MovementFall; import baritone.pathing.movement.movements.MovementFall;
import baritone.utils.*; import baritone.utils.*;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -401,7 +402,7 @@ public interface MovementHelper extends ActionCosts, Helper {
)).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); )).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
} }
static Movement generateMovementFallOrDescend(BlockPos pos, BlockPos dest, CalculationContext calcContext) { static Movement generateMovementFallOrDescend(BetterBlockPos pos, BetterBlockPos dest, CalculationContext calcContext) {
// A // A
//SA //SA
// A // A
@ -423,7 +424,7 @@ public interface MovementHelper extends ActionCosts, Helper {
// we're clear for a fall 2 // we're clear for a fall 2
// let's see how far we can fall // let's see how far we can fall
for (int fallHeight = 3; true; fallHeight++) { for (int fallHeight = 3; true; fallHeight++) {
BlockPos onto = dest.down(fallHeight); BetterBlockPos onto = dest.down(fallHeight);
if (onto.getY() < 0) { if (onto.getY() < 0) {
// when pathing in the end, where you could plausibly fall into the void // when pathing in the end, where you could plausibly fall into the void
// this check prevents it from getting the block at y=-1 and crashing // this check prevents it from getting the block at y=-1 and crashing

View File

@ -26,6 +26,7 @@ import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.Utils; import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -41,7 +42,7 @@ public class MovementAscend extends Movement {
private int ticksWithoutPlacement = 0; private int ticksWithoutPlacement = 0;
public MovementAscend(BlockPos src, BlockPos dest) { public MovementAscend(BetterBlockPos src, BetterBlockPos dest) {
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down()); super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down());
} }
@ -155,8 +156,8 @@ public class MovementAscend extends Movement {
if (player().isSneaking()) { if (player().isSneaking()) {
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
} }
if (ticksWithoutPlacement > 20) { if (ticksWithoutPlacement > 10) {
// After 20 ticks without placement, we might be standing in the way, move back // After 10 ticks without placement, we might be standing in the way, move back
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true); state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
} }
} else { } else {

View File

@ -24,13 +24,14 @@ import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
public class MovementDescend extends Movement { public class MovementDescend extends Movement {
public MovementDescend(BlockPos start, BlockPos end) { public MovementDescend(BetterBlockPos start, BetterBlockPos end) {
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down()); super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down());
} }

View File

@ -23,6 +23,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockMagma; import net.minecraft.block.BlockMagma;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -37,16 +38,16 @@ public class MovementDiagonal extends Movement {
private static final double SQRT_2 = Math.sqrt(2); private static final double SQRT_2 = Math.sqrt(2);
public MovementDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) { public MovementDiagonal(BetterBlockPos start, EnumFacing dir1, EnumFacing dir2) {
this(start, start.offset(dir1), start.offset(dir2), 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()}); // 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 MovementDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) { private MovementDiagonal(BetterBlockPos start, BetterBlockPos dir1, BetterBlockPos dir2, EnumFacing drr2) {
this(start, dir1.offset(drr2), dir1, dir2); this(start, dir1.offset(drr2), dir1, dir2);
} }
public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) { private MovementDiagonal(BetterBlockPos start, BetterBlockPos end, BetterBlockPos dir1, BetterBlockPos dir2) {
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}); super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()});
} }

View File

@ -22,6 +22,7 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -31,7 +32,7 @@ public class MovementDownward extends Movement {
private int numTicks = 0; private int numTicks = 0;
public MovementDownward(BlockPos start, BlockPos end) { public MovementDownward(BetterBlockPos start, BetterBlockPos end) {
super(start, end, new BlockPos[]{end}); super(start, end, new BlockPos[]{end});
} }

View File

@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState;
import baritone.pathing.movement.MovementState.MovementStatus; import baritone.pathing.movement.MovementState.MovementStatus;
import baritone.pathing.movement.MovementState.MovementTarget; import baritone.pathing.movement.MovementState.MovementTarget;
import baritone.utils.*; import baritone.utils.*;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -41,7 +42,7 @@ public class MovementFall extends Movement {
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET); private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET); private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
public MovementFall(BlockPos src, BlockPos dest) { public MovementFall(BetterBlockPos src, BetterBlockPos dest) {
super(src, dest, MovementFall.buildPositionsToBreak(src, dest)); super(src, dest, MovementFall.buildPositionsToBreak(src, dest));
} }

View File

@ -24,6 +24,7 @@ import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -34,14 +35,14 @@ public class MovementParkour extends Movement {
final EnumFacing direction; final EnumFacing direction;
final int dist; final int dist;
private MovementParkour(BlockPos src, int dist, EnumFacing dir) { private MovementParkour(BetterBlockPos src, int dist, EnumFacing dir) {
super(src, src.offset(dir, dist), new BlockPos[]{}); super(src, src.offset(dir, dist), new BlockPos[]{});
this.direction = dir; this.direction = dir;
this.dist = dist; this.dist = dist;
super.override(costFromJumpDistance(dist)); super.override(costFromJumpDistance(dist));
} }
public static MovementParkour calculate(BlockPos src, EnumFacing dir) { public static MovementParkour calculate(BetterBlockPos src, EnumFacing dir) {
if (!Baritone.settings().allowParkour.get()) { if (!Baritone.settings().allowParkour.get()) {
return null; return null;
} }

View File

@ -25,6 +25,7 @@ import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.Rotation; import baritone.utils.Rotation;
import baritone.utils.Utils; import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -33,7 +34,7 @@ import net.minecraft.util.math.BlockPos;
public class MovementPillar extends Movement { public class MovementPillar extends Movement {
private int numTicks = 0; private int numTicks = 0;
public MovementPillar(BlockPos start, BlockPos end) { public MovementPillar(BetterBlockPos start, BetterBlockPos end) {
super(start, end, new BlockPos[]{start.up(2)}, start); super(start, end, new BlockPos[]{start.up(2)}, start);
} }
@ -169,7 +170,7 @@ public class MovementPillar extends Movement {
state.setInput(InputOverrideHandler.Input.SNEAK, true); state.setInput(InputOverrideHandler.Input.SNEAK, true);
// Otherwise jump // Otherwise jump
if (numTicks > 40) { if (numTicks > 20) {
double diffX = player().posX - (dest.getX() + 0.5); double diffX = player().posX - (dest.getX() + 0.5);
double diffZ = player().posZ - (dest.getZ() + 0.5); double diffZ = player().posZ - (dest.getZ() + 0.5);
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ); double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);

View File

@ -25,6 +25,7 @@ import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.InputOverrideHandler; import baritone.utils.InputOverrideHandler;
import baritone.utils.Utils; import baritone.utils.Utils;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -42,7 +43,7 @@ public class MovementTraverse extends Movement {
*/ */
private boolean wasTheBridgeBlockAlwaysThere = true; private boolean wasTheBridgeBlockAlwaysThere = true;
public MovementTraverse(BlockPos from, BlockPos to) { public MovementTraverse(BetterBlockPos from, BetterBlockPos to) {
super(from, to, new BlockPos[]{to.up(), to}, to.down()); super(from, to, new BlockPos[]{to.up(), to}, to.down());
} }