From 2cbf8fff9bdf2f55f9356f3b9c6b0c72aeccd8e2 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 6 Aug 2018 16:09:28 -0700 Subject: [PATCH] render improvements --- .../baritone/bot/behavior/impl/PathingBehavior.java | 5 +++++ .../java/baritone/bot/pathing/movement/Movement.java | 11 +++++++++++ .../java/baritone/bot/pathing/path/PathExecutor.java | 9 ++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index a83794c9..018fbfe7 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -134,9 +134,11 @@ public class PathingBehavior extends Behavior { //System.out.println("Render passing"); //System.out.println(event.getPartialTicks()); float partialTicks = event.getPartialTicks(); + long start = System.currentTimeMillis(); // Render the current path, if there is one getPath().ifPresent(path -> drawPath(path, player(), partialTicks, Color.RED)); + long split = System.currentTimeMillis(); getPath().ifPresent(path -> { for (BlockPos pos : path.getBlocksToBreak()) { drawSelectionBox(player(), pos, partialTicks, Color.RED); @@ -156,6 +158,9 @@ public class PathingBehavior extends Behavior { }); }); }); + long end = System.currentTimeMillis(); + if (end - start > 0) + System.out.println("Frame took " + (split - start) + " " + (end - split)); } public void drawPath(IPath path, EntityPlayerSP player, float partialTicks, Color color) { diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index fb478cb4..2854a025 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -187,23 +187,34 @@ public abstract class Movement implements Helper, MovementHelper { return state; } + public ArrayList toBreakCached = null; + public ArrayList toPlaceCached = null; + public ArrayList toBreak() { + if (toBreakCached != null) { + return toBreakCached; + } ArrayList result = new ArrayList<>(); for (BlockPos positionsToBreak1 : positionsToBreak) { if (!MovementHelper.canWalkThrough(positionsToBreak1, BlockStateInterface.get(positionsToBreak1))) { result.add(positionsToBreak1); } } + toBreakCached = result; return result; } public ArrayList toPlace() { + if (toPlaceCached != null) { + return toPlaceCached; + } ArrayList result = new ArrayList<>(); for (BlockPos positionsToPlace1 : positionsToPlace) { if (!MovementHelper.canWalkOn(positionsToPlace1)) { result.add(positionsToPlace1); } } + toPlaceCached = result; return result; } } diff --git a/src/main/java/baritone/bot/pathing/path/PathExecutor.java b/src/main/java/baritone/bot/pathing/path/PathExecutor.java index 087e53f6..6b41cf2c 100644 --- a/src/main/java/baritone/bot/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/bot/pathing/path/PathExecutor.java @@ -35,7 +35,7 @@ public class PathExecutor extends Behavior { @Override public void onTick(TickEvent event) { - if(event.getType() == TickEvent.Type.OUT) { + if (event.getType() == TickEvent.Type.OUT) { return; } if (pathPosition >= path.length()) { @@ -48,6 +48,7 @@ public class PathExecutor extends Behavior { BlockPos whereAmI = playerFeet(); if (pathPosition == path.length() - 1) { System.out.println("On last path position -- done!"); + pathPosition++; return; } if (!whereShouldIBe.equals(whereAmI)) { @@ -116,6 +117,12 @@ public class PathExecutor extends Behavior { } } }*/ + for (int i = pathPosition - 10; i < pathPosition + 10; i++) { + if (i >= 0 && i < path.movements().size()) { + path.movements().get(i).toBreakCached = null; + path.movements().get(i).toPlaceCached = null; + } + } Movement movement = path.movements().get(pathPosition); if (movement.recalculateCost() >= ActionCosts.COST_INF) { System.out.println("Something has changed in the world and this movement has become impossible. Cancelling.");