From 2ba0e6ada673e7952aa1fd650646a1e27a55a070 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 25 Nov 2018 22:19:04 -0800 Subject: [PATCH] don't create a new bsi hundreds of times a tick maybe? --- .../api/pathing/movement/IMovement.java | 8 ------- .../baritone/pathing/movement/Movement.java | 13 ++++------- .../movement/movements/MovementDiagonal.java | 9 ++++---- .../baritone/pathing/path/PathExecutor.java | 23 +++++++++++-------- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/api/java/baritone/api/pathing/movement/IMovement.java b/src/api/java/baritone/api/pathing/movement/IMovement.java index 7b3eca5f..c9b9ea4b 100644 --- a/src/api/java/baritone/api/pathing/movement/IMovement.java +++ b/src/api/java/baritone/api/pathing/movement/IMovement.java @@ -20,8 +20,6 @@ package baritone.api.pathing.movement; import baritone.api.utils.BetterBlockPos; import net.minecraft.util.math.BlockPos; -import java.util.List; - /** * @author Brady * @since 10/8/2018 @@ -58,10 +56,4 @@ public interface IMovement { BetterBlockPos getDest(); BlockPos getDirection(); - - List toBreak(); - - List toPlace(); - - List toWalkInto(); } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index a3e841c6..f0f20648 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -244,14 +244,13 @@ public abstract class Movement implements IMovement, MovementHelper { toWalkIntoCached = null; } - @Override - public List toBreak() { + public List toBreak(BlockStateInterface bsi) { if (toBreakCached != null) { return toBreakCached; } List result = new ArrayList<>(); for (BetterBlockPos positionToBreak : positionsToBreak) { - if (!MovementHelper.canWalkThrough(ctx, positionToBreak)) { + if (!MovementHelper.canWalkThrough(bsi, positionToBreak.x, positionToBreak.y, positionToBreak.z)) { result.add(positionToBreak); } } @@ -259,21 +258,19 @@ public abstract class Movement implements IMovement, MovementHelper { return result; } - @Override - public List toPlace() { + public List toPlace(BlockStateInterface bsi) { if (toPlaceCached != null) { return toPlaceCached; } List result = new ArrayList<>(); - if (positionToPlace != null && !MovementHelper.canWalkOn(ctx, positionToPlace)) { + if (positionToPlace != null && !MovementHelper.canWalkOn(bsi, positionToPlace.x, positionToPlace.y, positionToPlace.z)) { result.add(positionToPlace); } toPlaceCached = result; return result; } - @Override - public List toWalkInto() { // overridden by movementdiagonal + public List toWalkInto(BlockStateInterface bsi) { // overridden by movementdiagonal if (toWalkIntoCached == null) { toWalkIntoCached = new ArrayList<>(); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 4a098380..49385273 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -25,6 +25,7 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; +import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -158,13 +159,13 @@ public class MovementDiagonal extends Movement { } @Override - public List toBreak() { + public List toBreak(BlockStateInterface bsi) { if (toBreakCached != null) { return toBreakCached; } List result = new ArrayList<>(); for (int i = 4; i < 6; i++) { - if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(bsi, positionsToBreak[i].x, positionsToBreak[i].y, positionsToBreak[i].z)) { result.add(positionsToBreak[i]); } } @@ -173,13 +174,13 @@ public class MovementDiagonal extends Movement { } @Override - public List toWalkInto() { + public List toWalkInto(BlockStateInterface bsi) { if (toWalkIntoCached == null) { toWalkIntoCached = new ArrayList<>(); } List result = new ArrayList<>(); for (int i = 0; i < 4; i++) { - if (!MovementHelper.canWalkThrough(ctx, positionsToBreak[i])) { + if (!MovementHelper.canWalkThrough(bsi, positionsToBreak[i].x, positionsToBreak[i].y, positionsToBreak[i].z)) { result.add(positionsToBreak[i]); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 171dd769..b17cd281 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -30,6 +30,7 @@ import baritone.api.utils.input.Input; import baritone.behavior.PathingBehavior; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; +import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.movements.*; import baritone.utils.BlockStateInterface; @@ -186,22 +187,23 @@ public class PathExecutor implements IPathExecutor, Helper { } }*/ //long start = System.nanoTime() / 1000000L; + BlockStateInterface bsi = new BlockStateInterface(ctx); for (int i = pathPosition - 10; i < pathPosition + 10; i++) { if (i < 0 || i >= path.movements().size()) { continue; } - IMovement m = path.movements().get(i); - HashSet prevBreak = new HashSet<>(m.toBreak()); - HashSet prevPlace = new HashSet<>(m.toPlace()); - HashSet prevWalkInto = new HashSet<>(m.toWalkInto()); + Movement m = (Movement) path.movements().get(i); + HashSet prevBreak = new HashSet<>(m.toBreak(bsi)); + HashSet prevPlace = new HashSet<>(m.toPlace(bsi)); + HashSet prevWalkInto = new HashSet<>(m.toWalkInto(bsi)); m.resetBlockCache(); - if (!prevBreak.equals(new HashSet<>(m.toBreak()))) { + if (!prevBreak.equals(new HashSet<>(m.toBreak(bsi)))) { recalcBP = true; } - if (!prevPlace.equals(new HashSet<>(m.toPlace()))) { + if (!prevPlace.equals(new HashSet<>(m.toPlace(bsi)))) { recalcBP = true; } - if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto()))) { + if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto(bsi)))) { recalcBP = true; } } @@ -210,9 +212,10 @@ public class PathExecutor implements IPathExecutor, Helper { HashSet newPlace = new HashSet<>(); HashSet newWalkInto = new HashSet<>(); for (int i = pathPosition; i < path.movements().size(); i++) { - newBreak.addAll(path.movements().get(i).toBreak()); - newPlace.addAll(path.movements().get(i).toPlace()); - newWalkInto.addAll(path.movements().get(i).toWalkInto()); + Movement movement = (Movement) path.movements().get(i); + newBreak.addAll(movement.toBreak(bsi)); + newPlace.addAll(movement.toPlace(bsi)); + newWalkInto.addAll(movement.toWalkInto(bsi)); } toBreak = newBreak; toPlace = newPlace;