From 3a68009194ee46930d9609947c93863a82c7d180 Mon Sep 17 00:00:00 2001
From: Leijurv <leijurv@gmail.com>
Date: Tue, 14 Aug 2018 11:25:30 -0700
Subject: [PATCH] don't allocate for up(0)

---
 .../bot/behavior/impl/PathingBehavior.java         |  4 ----
 .../java/baritone/bot/event/events/TickEvent.java  |  1 -
 .../bot/pathing/calc/AbstractNodeCostSearch.java   | 11 -----------
 .../bot/pathing/movement/MovementHelper.java       |  4 ++--
 .../pathing/movement/movements/MovementAscend.java | 14 +++++++-------
 src/main/java/baritone/bot/utils/Helper.java       |  4 +---
 src/main/java/baritone/bot/utils/ToolSet.java      |  3 +--
 .../baritone/bot/utils/pathing/BetterBlockPos.java |  2 +-
 8 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java
index 9bbbfa42..47f33f5f 100644
--- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java
+++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java
@@ -19,16 +19,12 @@ package baritone.bot.behavior.impl;
 
 import baritone.bot.Baritone;
 import baritone.bot.behavior.Behavior;
-import baritone.bot.event.events.ChatEvent;
 import baritone.bot.event.events.RenderEvent;
 import baritone.bot.event.events.TickEvent;
 import baritone.bot.pathing.calc.AStarPathFinder;
 import baritone.bot.pathing.calc.AbstractNodeCostSearch;
 import baritone.bot.pathing.calc.IPathFinder;
 import baritone.bot.pathing.goals.Goal;
-import baritone.bot.pathing.goals.GoalBlock;
-import baritone.bot.pathing.goals.GoalXZ;
-import baritone.bot.pathing.goals.GoalYLevel;
 import baritone.bot.pathing.path.IPath;
 import baritone.bot.pathing.path.PathExecutor;
 import baritone.bot.utils.PathRenderer;
diff --git a/src/main/java/baritone/bot/event/events/TickEvent.java b/src/main/java/baritone/bot/event/events/TickEvent.java
index 7cfe1c99..4fda101d 100644
--- a/src/main/java/baritone/bot/event/events/TickEvent.java
+++ b/src/main/java/baritone/bot/event/events/TickEvent.java
@@ -18,7 +18,6 @@
 package baritone.bot.event.events;
 
 import baritone.bot.event.events.type.EventState;
-import javafx.event.EventType;
 
 public final class TickEvent {
 
diff --git a/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java
index b6d9c293..a7da3477 100644
--- a/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java
+++ b/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java
@@ -88,7 +88,6 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
      *
      * @param n A node
      * @return The distance, squared
-     * @see AbstractNodeCostSearch#getDistFromStart(PathNode)
      */
     protected double getDistFromStartSq(PathNode n) {
         int xDiff = n.pos.getX() - start.getX();
@@ -97,16 +96,6 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
         return xDiff * xDiff + yDiff * yDiff + zDiff * zDiff;
     }
 
-    /**
-     * Determines the distance from the specified node to this the node.
-     *
-     * @param n A node
-     * @return The distance
-     */
-    protected double getDistFromStart(PathNode n) {
-        return Math.sqrt(getDistFromStartSq(n));
-    }
-
     /**
      * Attempts to search the {@link BlockPos} to {@link PathNode} map
      * for the node mapped to the specified pos. If no node is found,
diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java
index 427cf4cb..5a5732a3 100644
--- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java
+++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java
@@ -211,8 +211,8 @@ public interface MovementHelper extends ActionCosts, Helper {
         return false;
     }
 
-    static MovementState moveTowards(MovementState state, BlockPos pos) {
-        return state.setTarget(new MovementTarget(new Rotation(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
+    static void moveTowards(MovementState state, BlockPos pos) {
+        state.setTarget(new MovementTarget(new Rotation(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
                 Utils.getBlockPosCenter(pos),
                 new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getFirst(), mc.player.rotationPitch))
         ).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java
index a5fbc29f..b021e19f 100644
--- a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java
+++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java
@@ -114,17 +114,17 @@ public class MovementAscend extends Movement {
         }
 
         if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
-            for (int i = 0; i < against.length; i++) {
-                if (BlockStateInterface.get(against[i]).isBlockNormalCube()) {
+            for (BlockPos anAgainst : against) {
+                if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) {
                     if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block
                         return state.setStatus(MovementStatus.UNREACHABLE);
                     }
-                    double faceX = (dest.getX() + against[i].getX() + 1.0D) * 0.5D;
-                    double faceY = (dest.getY() + against[i].getY()) * 0.5D;
-                    double faceZ = (dest.getZ() + against[i].getZ() + 1.0D) * 0.5D;
+                    double faceX = (dest.getX() + anAgainst.getX() + 1.0D) * 0.5D;
+                    double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
+                    double faceZ = (dest.getZ() + anAgainst.getZ() + 1.0D) * 0.5D;
                     state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations())));
                     EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
-                    if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), against[i]) && LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionsToPlace[0])) {
+                    if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), anAgainst) && LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionsToPlace[0])) {
                         ticksWithoutPlacement++;
                         state.setInput(InputOverrideHandler.Input.SNEAK, true);
                         if (player().isSneaking()) {
@@ -134,7 +134,7 @@ public class MovementAscend extends Movement {
                             state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);//we might be standing in the way, move back
                         }
                     }
-                    System.out.println("Trying to look at " + against[i] + ", actually looking at" + LookBehaviorUtils.getSelectedBlock());
+                    System.out.println("Trying to look at " + anAgainst + ", actually looking at" + LookBehaviorUtils.getSelectedBlock());
                     return state;
                 }
             }
diff --git a/src/main/java/baritone/bot/utils/Helper.java b/src/main/java/baritone/bot/utils/Helper.java
index ffa3094d..4f2ef227 100755
--- a/src/main/java/baritone/bot/utils/Helper.java
+++ b/src/main/java/baritone/bot/utils/Helper.java
@@ -23,7 +23,6 @@ import net.minecraft.client.entity.EntityPlayerSP;
 import net.minecraft.client.gui.GuiNewChat;
 import net.minecraft.client.gui.GuiUtilRenderComponents;
 import net.minecraft.client.multiplayer.WorldClient;
-import net.minecraft.init.Blocks;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.util.math.MathHelper;
 import net.minecraft.util.math.Vec3d;
@@ -50,11 +49,10 @@ public interface Helper {
 
     default BlockPos playerFeet() {
         // TODO find a better way to deal with soul sand!!!!!
-        BlockPos feet = new BlockPos(player().posX, player().posY + 0.1251, player().posZ);
+        return new BlockPos(player().posX, player().posY + 0.1251, player().posZ);
         /*if (BlockStateInterface.get(feet).getBlock().equals(Blocks.SOUL_SAND) && player().posY > feet.getY() + 0.874999) {
             return feet.up();
         }*/
-        return feet;
     }
 
     default Vec3d playerFeetAsVec() {
diff --git a/src/main/java/baritone/bot/utils/ToolSet.java b/src/main/java/baritone/bot/utils/ToolSet.java
index 0177992f..575605d1 100644
--- a/src/main/java/baritone/bot/utils/ToolSet.java
+++ b/src/main/java/baritone/bot/utils/ToolSet.java
@@ -21,7 +21,6 @@ import net.minecraft.block.Block;
 import net.minecraft.block.state.IBlockState;
 import net.minecraft.client.Minecraft;
 import net.minecraft.client.entity.EntityPlayerSP;
-import net.minecraft.init.Items;
 import net.minecraft.item.Item;
 import net.minecraft.item.ItemAir;
 import net.minecraft.item.ItemStack;
@@ -125,7 +124,7 @@ public class ToolSet implements Helper {
      * Using the best tool on the hotbar, how long would it take to mine this block
      *
      * @param state the blockstate to be mined
-     * @param pos the blockpos to be mined
+     * @param pos   the blockpos to be mined
      * @return how long it would take in ticks
      */
     public double getStrVsBlock(IBlockState state, BlockPos pos) {
diff --git a/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java b/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java
index 6f010571..6541aad0 100644
--- a/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java
+++ b/src/main/java/baritone/bot/utils/pathing/BetterBlockPos.java
@@ -92,7 +92,7 @@ public class BetterBlockPos extends BlockPos {
     @Override
     public BlockPos up(int amt) {
         // see comment in up()
-        return new BetterBlockPos(x, y + amt, z);
+        return amt == 0 ? this : new BetterBlockPos(x, y + amt, z);
     }
 
     @Override