don't create a new bsi hundreds of times a tick maybe?

This commit is contained in:
Leijurv 2018-11-25 22:19:04 -08:00
parent 943b75455b
commit 2ba0e6ada6
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 23 additions and 30 deletions

View File

@ -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<BlockPos> toBreak();
List<BlockPos> toPlace();
List<BlockPos> toWalkInto();
}

View File

@ -244,14 +244,13 @@ public abstract class Movement implements IMovement, MovementHelper {
toWalkIntoCached = null;
}
@Override
public List<BlockPos> toBreak() {
public List<BlockPos> toBreak(BlockStateInterface bsi) {
if (toBreakCached != null) {
return toBreakCached;
}
List<BlockPos> 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<BlockPos> toPlace() {
public List<BlockPos> toPlace(BlockStateInterface bsi) {
if (toPlaceCached != null) {
return toPlaceCached;
}
List<BlockPos> 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<BlockPos> toWalkInto() { // overridden by movementdiagonal
public List<BlockPos> toWalkInto(BlockStateInterface bsi) { // overridden by movementdiagonal
if (toWalkIntoCached == null) {
toWalkIntoCached = new ArrayList<>();
}

View File

@ -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<BlockPos> toBreak() {
public List<BlockPos> toBreak(BlockStateInterface bsi) {
if (toBreakCached != null) {
return toBreakCached;
}
List<BlockPos> 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<BlockPos> toWalkInto() {
public List<BlockPos> toWalkInto(BlockStateInterface bsi) {
if (toWalkIntoCached == null) {
toWalkIntoCached = new ArrayList<>();
}
List<BlockPos> 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]);
}
}

View File

@ -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<BlockPos> prevBreak = new HashSet<>(m.toBreak());
HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace());
HashSet<BlockPos> prevWalkInto = new HashSet<>(m.toWalkInto());
Movement m = (Movement) path.movements().get(i);
HashSet<BlockPos> prevBreak = new HashSet<>(m.toBreak(bsi));
HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace(bsi));
HashSet<BlockPos> 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<BlockPos> newPlace = new HashSet<>();
HashSet<BlockPos> 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;