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 baritone.api.utils.BetterBlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.List;
/** /**
* @author Brady * @author Brady
* @since 10/8/2018 * @since 10/8/2018
@ -58,10 +56,4 @@ public interface IMovement {
BetterBlockPos getDest(); BetterBlockPos getDest();
BlockPos getDirection(); 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; toWalkIntoCached = null;
} }
@Override public List<BlockPos> toBreak(BlockStateInterface bsi) {
public List<BlockPos> toBreak() {
if (toBreakCached != null) { if (toBreakCached != null) {
return toBreakCached; return toBreakCached;
} }
List<BlockPos> result = new ArrayList<>(); List<BlockPos> result = new ArrayList<>();
for (BetterBlockPos positionToBreak : positionsToBreak) { for (BetterBlockPos positionToBreak : positionsToBreak) {
if (!MovementHelper.canWalkThrough(ctx, positionToBreak)) { if (!MovementHelper.canWalkThrough(bsi, positionToBreak.x, positionToBreak.y, positionToBreak.z)) {
result.add(positionToBreak); result.add(positionToBreak);
} }
} }
@ -259,21 +258,19 @@ public abstract class Movement implements IMovement, MovementHelper {
return result; return result;
} }
@Override public List<BlockPos> toPlace(BlockStateInterface bsi) {
public List<BlockPos> toPlace() {
if (toPlaceCached != null) { if (toPlaceCached != null) {
return toPlaceCached; return toPlaceCached;
} }
List<BlockPos> result = new ArrayList<>(); 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); result.add(positionToPlace);
} }
toPlaceCached = result; toPlaceCached = result;
return result; return result;
} }
@Override public List<BlockPos> toWalkInto(BlockStateInterface bsi) { // overridden by movementdiagonal
public List<BlockPos> toWalkInto() { // overridden by movementdiagonal
if (toWalkIntoCached == null) { if (toWalkIntoCached == null) {
toWalkIntoCached = new ArrayList<>(); toWalkIntoCached = new ArrayList<>();
} }

View File

@ -25,6 +25,7 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement; import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.MovementState; import baritone.pathing.movement.MovementState;
import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -158,13 +159,13 @@ public class MovementDiagonal extends Movement {
} }
@Override @Override
public List<BlockPos> toBreak() { public List<BlockPos> toBreak(BlockStateInterface bsi) {
if (toBreakCached != null) { if (toBreakCached != null) {
return toBreakCached; return toBreakCached;
} }
List<BlockPos> result = new ArrayList<>(); List<BlockPos> result = new ArrayList<>();
for (int i = 4; i < 6; i++) { 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]); result.add(positionsToBreak[i]);
} }
} }
@ -173,13 +174,13 @@ public class MovementDiagonal extends Movement {
} }
@Override @Override
public List<BlockPos> toWalkInto() { public List<BlockPos> toWalkInto(BlockStateInterface bsi) {
if (toWalkIntoCached == null) { if (toWalkIntoCached == null) {
toWalkIntoCached = new ArrayList<>(); toWalkIntoCached = new ArrayList<>();
} }
List<BlockPos> result = new ArrayList<>(); List<BlockPos> result = new ArrayList<>();
for (int i = 0; i < 4; i++) { 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]); result.add(positionsToBreak[i]);
} }
} }

View File

@ -30,6 +30,7 @@ import baritone.api.utils.input.Input;
import baritone.behavior.PathingBehavior; import baritone.behavior.PathingBehavior;
import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.AbstractNodeCostSearch;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.pathing.movement.movements.*; import baritone.pathing.movement.movements.*;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
@ -186,22 +187,23 @@ public class PathExecutor implements IPathExecutor, Helper {
} }
}*/ }*/
//long start = System.nanoTime() / 1000000L; //long start = System.nanoTime() / 1000000L;
BlockStateInterface bsi = new BlockStateInterface(ctx);
for (int i = pathPosition - 10; i < pathPosition + 10; i++) { for (int i = pathPosition - 10; i < pathPosition + 10; i++) {
if (i < 0 || i >= path.movements().size()) { if (i < 0 || i >= path.movements().size()) {
continue; continue;
} }
IMovement m = path.movements().get(i); Movement m = (Movement) path.movements().get(i);
HashSet<BlockPos> prevBreak = new HashSet<>(m.toBreak()); HashSet<BlockPos> prevBreak = new HashSet<>(m.toBreak(bsi));
HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace()); HashSet<BlockPos> prevPlace = new HashSet<>(m.toPlace(bsi));
HashSet<BlockPos> prevWalkInto = new HashSet<>(m.toWalkInto()); HashSet<BlockPos> prevWalkInto = new HashSet<>(m.toWalkInto(bsi));
m.resetBlockCache(); m.resetBlockCache();
if (!prevBreak.equals(new HashSet<>(m.toBreak()))) { if (!prevBreak.equals(new HashSet<>(m.toBreak(bsi)))) {
recalcBP = true; recalcBP = true;
} }
if (!prevPlace.equals(new HashSet<>(m.toPlace()))) { if (!prevPlace.equals(new HashSet<>(m.toPlace(bsi)))) {
recalcBP = true; recalcBP = true;
} }
if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto()))) { if (!prevWalkInto.equals(new HashSet<>(m.toWalkInto(bsi)))) {
recalcBP = true; recalcBP = true;
} }
} }
@ -210,9 +212,10 @@ public class PathExecutor implements IPathExecutor, Helper {
HashSet<BlockPos> newPlace = new HashSet<>(); HashSet<BlockPos> newPlace = new HashSet<>();
HashSet<BlockPos> newWalkInto = new HashSet<>(); HashSet<BlockPos> newWalkInto = new HashSet<>();
for (int i = pathPosition; i < path.movements().size(); i++) { for (int i = pathPosition; i < path.movements().size(); i++) {
newBreak.addAll(path.movements().get(i).toBreak()); Movement movement = (Movement) path.movements().get(i);
newPlace.addAll(path.movements().get(i).toPlace()); newBreak.addAll(movement.toBreak(bsi));
newWalkInto.addAll(path.movements().get(i).toWalkInto()); newPlace.addAll(movement.toPlace(bsi));
newWalkInto.addAll(movement.toWalkInto(bsi));
} }
toBreak = newBreak; toBreak = newBreak;
toPlace = newPlace; toPlace = newPlace;