From d433cbb90bcbdf58c301c262f36aff67964eccc4 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 14:56:21 -0700 Subject: [PATCH] no more against array creation --- .../baritone/pathing/movement/Movement.java | 3 ++ .../movement/movements/MovementAscend.java | 34 +++++++------------ .../movement/movements/MovementTraverse.java | 32 +++++++---------- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index ce730b00..44c9d5a3 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -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; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index dc4476f3..5afa8243 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -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); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 6d09dee8..7a45c8bc 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -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");