slowpath rendering

This commit is contained in:
Leijurv 2018-08-05 18:53:11 -04:00
parent e7c27e04ac
commit 98f94f0a81
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 89 additions and 20 deletions

View File

@ -4,11 +4,15 @@ import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.ChatEvent;
import baritone.bot.event.events.RenderEvent;
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.BlockStateInterface;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.BufferBuilder;
@ -16,6 +20,8 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import org.lwjgl.opengl.GL11;
@ -138,10 +144,25 @@ public class PathingBehavior extends Behavior {
public void onRenderPass(RenderEvent event) {
//System.out.println("Render passing");
//System.out.println(event.getPartialTicks());
drawPath(player(), event.getPartialTicks(), Color.RED);
IPath path = getPath();
float partialTicks = event.getPartialTicks();
if (path != null) {
drawPath(path, player(), partialTicks, Color.RED);
}
if (AbstractNodeCostSearch.currentlyRunning != null) {
IPath p = AbstractNodeCostSearch.currentlyRunning.bestPathSoFar();
if (p != null) {
drawPath(p, player(), partialTicks, Color.BLUE);
IPath mr = AbstractNodeCostSearch.currentlyRunning.pathToMostRecentNodeConsidered();
if (mr != null) {
drawPath(mr, player(), partialTicks, Color.CYAN);
drawSelectionBox(player(), mr.getDest(), partialTicks, Color.CYAN);
}
}
}
}
public void drawPath(EntityPlayerSP player, float partialTicks, Color color) {
public void drawPath(IPath path, EntityPlayerSP player, float partialTicks, Color color) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
@ -150,22 +171,21 @@ public class PathingBehavior extends Behavior {
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
IPath path = getPath();
if (path != null) {
List<BlockPos> positions = path.positions();
for (int i = 0; i < positions.size() - 1; i++) {
BlockPos a = positions.get(i);
BlockPos b = positions.get(i + 1);
double x1 = a.getX();
double y1 = a.getY();
double z1 = a.getZ();
double x2 = b.getX();
double y2 = b.getY();
double z2 = b.getZ();
drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks);
}
List<BlockPos> positions = path.positions();
for (int i = 0; i < positions.size() - 1; i++) {
BlockPos a = positions.get(i);
BlockPos b = positions.get(i + 1);
double x1 = a.getX();
double y1 = a.getY();
double z1 = a.getZ();
double x2 = b.getX();
double y2 = b.getY();
double z2 = b.getZ();
drawLine(player, x1, y1, z1, x2, y2, z2, partialTicks);
}
//GlStateManager.color(0.0f, 0.0f, 0.0f, 0.4f);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
@ -187,5 +207,54 @@ public class PathingBehavior extends Behavior {
tessellator.draw();
}
public static void drawSelectionBox(EntityPlayer player, BlockPos blockpos, 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.4F);
GL11.glLineWidth(5.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
float f = 0.002F;
//BlockPos blockpos = movingObjectPositionIn.getBlockPos();
IBlockState state = BlockStateInterface.get(blockpos);
Block block = state.getBlock();
if (block.equals(Blocks.AIR)) {
block = Blocks.DIRT;
}
//block.setBlockBoundsBasedOnState(Minecraft.getMinecraft().world, blockpos);
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialTicks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialTicks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialTicks;
AxisAlignedBB toDraw = block.getSelectedBoundingBox(state, Minecraft.getMinecraft().world, blockpos).expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D).offset(-d0, -d1, -d2);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldrenderer = tessellator.getBuffer();
worldrenderer.begin(3, DefaultVertexFormats.POSITION);
worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
tessellator.draw();
worldrenderer.begin(3, DefaultVertexFormats.POSITION);
worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
tessellator.draw();
worldrenderer.begin(1, DefaultVertexFormats.POSITION);
worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
worldrenderer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
tessellator.draw();
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
}

View File

@ -39,19 +39,19 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
}
currentlyRunning = this;
long startTime = System.currentTimeMillis();
long timeoutTime = startTime + /*(Baritone.slowPath ? 40000 : */4000/*)*/;
boolean slowPath=true;
long timeoutTime = startTime + (slowPath ? 40000 :4000);
long lastPrintout = 0;
int numNodes = 0;
ToolSet ts = new ToolSet();
int numEmptyChunk = 0;
while (!openSet.isEmpty() && numEmptyChunk < 50 && System.currentTimeMillis() < timeoutTime) {
/*if (Baritone.slowPath) {
if (slowPath) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(AStarPathFinder.class.getName()).log(Level.SEVERE, null, ex);
}
}*/
}
PathNode currentNode = openSet.removeLowest();
currentNode.isOpen = false;
mostRecentConsidered = currentNode;