no more against array creation

This commit is contained in:
Leijurv 2018-08-28 14:56:21 -07:00
parent a33b515871
commit d433cbb90b
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 29 additions and 40 deletions

View File

@ -28,6 +28,7 @@ import baritone.utils.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
@ -40,6 +41,8 @@ import static baritone.utils.InputOverrideHandler.Input;
public abstract class Movement implements Helper, MovementHelper {
protected static final EnumFacing[] HORIZONTALS = {EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST};
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
protected final BlockPos src;

View File

@ -39,29 +39,10 @@ import java.util.Objects;
public class MovementAscend extends Movement {
private BlockPos[] against = new BlockPos[3];
private int ticksWithoutPlacement = 0;
public MovementAscend(BlockPos src, BlockPos dest) {
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down());
BlockPos placementLocation = positionToPlace; // dest.down()
int i = 0;
if (!placementLocation.north().equals(src))
against[i++] = placementLocation.north();
if (!placementLocation.south().equals(src))
against[i++] = placementLocation.south();
if (!placementLocation.east().equals(src))
against[i++] = placementLocation.east();
if (!placementLocation.west().equals(src))
against[i] = placementLocation.west();
// 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
// Counterpoint to the above TODO ^ you should move then pillar instead of ascend
}
@Override
@ -80,7 +61,14 @@ public class MovementAscend extends Movement {
if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) {
return COST_INF;
}
for (BlockPos against1 : against) {
// 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
// Counterpoint to the above TODO ^ you should move then pillar instead of ascend
for (int i = 0; i < 4; i++) {
BlockPos against1 = positionToPlace.offset(HORIZONTALS[i]);
if (against1.equals(src)) {
continue;
}
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context);
}
@ -136,7 +124,11 @@ public class MovementAscend extends Movement {
}
if (!MovementHelper.canWalkOn(positionToPlace)) {
for (BlockPos anAgainst : against) {
for (int i = 0; i < 4; i++) {
BlockPos anAgainst = positionToPlace.offset(HORIZONTALS[i]);
if (anAgainst.equals(src)) {
continue;
}
if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) {
if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block
return state.setStatus(MovementStatus.UNREACHABLE);

View File

@ -37,8 +37,6 @@ import java.util.Objects;
public class MovementTraverse extends Movement {
private BlockPos[] against = new BlockPos[3];
/**
* Did we have to place a bridge block or was it always there
*/
@ -46,21 +44,6 @@ public class MovementTraverse extends Movement {
public MovementTraverse(BlockPos from, BlockPos to) {
super(from, to, new BlockPos[]{to.up(), to}, to.down());
int i = 0;
if (!to.north().equals(from))
against[i++] = to.north().down();
if (!to.south().equals(from))
against[i++] = to.south().down();
if (!to.east().equals(from))
against[i++] = to.east().down();
if (!to.west().equals(from))
against[i] = to.west().down();
//note: do NOT add ability to place against .down().down()
}
@Override
@ -114,7 +97,13 @@ public class MovementTraverse extends Movement {
return COST_INF;
}
double WC = throughWater ? WALK_ONE_IN_WATER_COST : WALK_ONE_BLOCK_COST;
for (BlockPos against1 : against) {
for (int i = 0; i < 4; i++) {
BlockPos against1 = dest.offset(HORIZONTALS[i]);
if (against1.equals(src)) {
continue;
}
against1 = against1.down();
// TODO isBlockNormalCube isn't the best check for whether or not we can place a block against it. e.g. glass isn't normalCube but we can place against it
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
return WC + context.placeBlockCost() + getTotalHardnessOfBlocksToBreak(context);
}
@ -206,7 +195,12 @@ public class MovementTraverse extends Movement {
return state;
} else {
wasTheBridgeBlockAlwaysThere = false;
for (BlockPos against1 : against) {
for (int i = 0; i < 4; i++) {
BlockPos against1 = dest.offset(HORIZONTALS[i]);
if (against1.equals(src)) {
continue;
}
against1 = against1.down();
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
if (!MovementHelper.throwaway(true)) { // get ready to place a throwaway block
displayChatMessageRaw("bb pls get me some blocks. dirt or cobble");