From 6860521403c741133cbb092879ab55c8cb1f572c Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 15 Aug 2018 17:53:42 -0700 Subject: [PATCH] dank goal render --- src/main/java/baritone/bot/Settings.java | 1 + .../bot/behavior/impl/PathingBehavior.java | 30 ++++----- .../java/baritone/bot/utils/PathRenderer.java | 62 ++++++++++++++++++- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/main/java/baritone/bot/Settings.java b/src/main/java/baritone/bot/Settings.java index 3f03ee53..9e68df8b 100644 --- a/src/main/java/baritone/bot/Settings.java +++ b/src/main/java/baritone/bot/Settings.java @@ -45,6 +45,7 @@ public class Settings { Item.getItemFromBlock(Blocks.COBBLESTONE), Item.getItemFromBlock(Blocks.NETHERRACK) )); + public Setting renderGoal = new Setting<>(true); public final Map> byName; public final List> allSettings; diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 0c27f8a2..00153053 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -25,6 +25,7 @@ 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.path.IPath; import baritone.bot.pathing.path.PathExecutor; import baritone.bot.utils.PathRenderer; @@ -198,19 +199,13 @@ public class PathingBehavior extends Behavior { } } }); - /* - isThereAnythingInProgress = false; - if (!currentPath.goal.isInGoal(currentPath.end)) { - if (talkAboutIt) { - Out.gui("I couldn't get all the way to " + goal + ", but I'm going to get as close as I can. " + currentPath.numNodes + " nodes considered", Out.Mode.Standard); - } - planAhead(); - } else if (talkAboutIt) { - Out.gui(, Out.Mode.Debug); - } - */ if (talkAboutIt && current != null && current.getPath() != null) { - displayChatMessageRaw("Finished finding a path from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + if (goal.isInGoal(current.getPath().getDest())) { + displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + } else { + displayChatMessageRaw("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + + } } synchronized (pathCalcLock) { isPathCalcInProgress = false; @@ -240,14 +235,19 @@ public class PathingBehavior extends Behavior { @Override public void onRenderPass(RenderEvent event) { - if (!Baritone.settings().renderPath.get()) { - return; - } // System.out.println("Render passing"); // System.out.println(event.getPartialTicks()); float partialTicks = event.getPartialTicks(); + if (goal instanceof GoalBlock && Baritone.settings().renderGoal.value) { + PathRenderer.drawLitDankGoalBox(player(), ((GoalBlock) goal).getGoalPos(), partialTicks, Color.GREEN); + } + if (!Baritone.settings().renderPath.get()) { + return; + } + long start = System.nanoTime(); + PathExecutor current = this.current; // this should prevent most race conditions? PathExecutor next = this.next; // like, now it's not possible for current!=null to be true, then suddenly false because of another thread // TODO is this enough, or do we need to acquire a lock here? diff --git a/src/main/java/baritone/bot/utils/PathRenderer.java b/src/main/java/baritone/bot/utils/PathRenderer.java index dccd736e..92d55b91 100644 --- a/src/main/java/baritone/bot/utils/PathRenderer.java +++ b/src/main/java/baritone/bot/utils/PathRenderer.java @@ -58,8 +58,8 @@ public final class PathRenderer implements Helper { List positions = path.positions(); int next; Tessellator tessellator = Tessellator.getInstance(); - fadeStart+=startIndex; - fadeEnd+=startIndex; + fadeStart += startIndex; + fadeEnd += startIndex; for (int i = startIndex; i < positions.size() - 1; i = next) { BlockPos start = positions.get(i); @@ -86,7 +86,7 @@ public final class PathRenderer implements Helper { if (i > fadeEnd) { break; } - alpha = 0.4F * (1.0F - (float)(i - fadeStart) / (float)(fadeEnd - fadeStart)); + alpha = 0.4F * (1.0F - (float) (i - fadeStart) / (float) (fadeEnd - fadeStart)); } GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], alpha); } @@ -159,6 +159,62 @@ public final class PathRenderer implements Helper { TESSELLATOR.draw(); }); + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + + public static void drawLitDankGoalBox(EntityPlayer player, BlockPos goal, float partialTicks, Color color) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.color(color.getColorComponents(null)[0], color.getColorComponents(null)[1], color.getColorComponents(null)[2], 0.6F); + GlStateManager.glLineWidth(5.0F); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + float expand = 0.002F; + double renderPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks; + double renderPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks; + double renderPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks; + + double minX = goal.getX() + 0.002 - renderPosX; + double maxX = goal.getX() + 1 - 0.002 - renderPosX; + double minZ = goal.getZ() + 0.002 - renderPosZ; + double maxZ = goal.getZ() + 1 - 0.002 - renderPosZ; + double y = Math.sin((System.currentTimeMillis() % 2000L) / 2000F * Math.PI * 2); + double y1 = 1 + y + goal.getY() - renderPosY; + double y2 = 1 - y + goal.getY() - renderPosY; + double minY = goal.getY() - renderPosY; + double maxY = minY + 2; + + + BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); + BUFFER.pos(minX, y1, minZ).endVertex(); + BUFFER.pos(maxX, y1, minZ).endVertex(); + BUFFER.pos(maxX, y1, maxZ).endVertex(); + BUFFER.pos(minX, y1, maxZ).endVertex(); + BUFFER.pos(minX, y1, minZ).endVertex(); + TESSELLATOR.draw(); + + BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); + BUFFER.pos(minX, y2, minZ).endVertex(); + BUFFER.pos(maxX, y2, minZ).endVertex(); + BUFFER.pos(maxX, y2, maxZ).endVertex(); + BUFFER.pos(minX, y2, maxZ).endVertex(); + BUFFER.pos(minX, y2, minZ).endVertex(); + TESSELLATOR.draw(); + + BUFFER.begin(GL_LINES, DefaultVertexFormats.POSITION); + BUFFER.pos(minX, minY, minZ).endVertex(); + BUFFER.pos(minX, maxY, minZ).endVertex(); + BUFFER.pos(maxX, minY, minZ).endVertex(); + BUFFER.pos(maxX, maxY, minZ).endVertex(); + BUFFER.pos(maxX, minY, maxZ).endVertex(); + BUFFER.pos(maxX, maxY, maxZ).endVertex(); + BUFFER.pos(minX, minY, maxZ).endVertex(); + BUFFER.pos(minX, maxY, maxZ).endVertex(); + TESSELLATOR.draw(); + + GlStateManager.depthMask(true); GlStateManager.enableTexture2D(); GlStateManager.disableBlend();