diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 9ff8102d..6c8099f9 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -33,6 +33,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; +import baritone.utils.schematic.AirSchematic; import baritone.utils.schematic.Schematic; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -94,6 +95,14 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro return true; } + public void clearArea(BlockPos corner1, BlockPos corner2) { + BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); + int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; + int heightY = Math.abs(corner1.getY() - corner2.getY()) + 1; + int lengthZ = Math.abs(corner1.getZ() - corner2.getZ()) + 1; + build("clear area", new AirSchematic(widthX, heightY, lengthZ), origin); + } + private static ISchematic parse(NBTTagCompound schematic) { return new Schematic(schematic); } @@ -273,7 +282,7 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro // this will work as is, but it'll be trashy // need to iterate over incorrectPositions and see which ones we can "correct" from our current standing position - + baritone.getInputOverrideHandler().clearAllKeys(); BuilderCalculationContext bcc = new BuilderCalculationContext(); if (!recalc(bcc)) { logDirect("Done building"); diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 97d58162..baa0ae7b 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -35,7 +35,6 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.Moves; import baritone.process.CustomGoalProcess; import baritone.utils.pathing.SegmentedCalculator; -import baritone.utils.schematic.AirSchematic; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ChunkProviderClient; @@ -336,11 +335,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } } - BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); - int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; - int heightY = Math.abs(corner1.getY() - corner2.getY()) + 1; - int lengthZ = Math.abs(corner1.getZ() - corner2.getZ()) + 1; - baritone.getBuilderProcess().build("clear area", new AirSchematic(widthX, heightY, lengthZ), origin); + baritone.getBuilderProcess().clearArea(corner1, corner2); return true; } if (msg.equals("reset")) { diff --git a/src/main/java/baritone/utils/GuiClickMeme.java b/src/main/java/baritone/utils/GuiClickMeme.java index 1db794ba..4bd878e1 100644 --- a/src/main/java/baritone/utils/GuiClickMeme.java +++ b/src/main/java/baritone/utils/GuiClickMeme.java @@ -17,22 +17,23 @@ package baritone.utils; +import baritone.Baritone; import baritone.api.BaritoneAPI; import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalTwoBlocks; +import baritone.api.utils.BetterBlockPos; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import org.lwjgl.BufferUtils; import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.Display; import org.lwjgl.util.glu.GLU; import java.awt.*; -import java.io.IOException; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.Collections; @@ -48,7 +49,8 @@ public class GuiClickMeme extends GuiScreen { private final FloatBuffer TO_SCREEN_BUFFER = BufferUtils.createFloatBuffer(3); private final FloatBuffer TO_WORLD_BUFFER = BufferUtils.createFloatBuffer(3); - private BlockPos meme; + private BlockPos clickStart; + private BlockPos currentMouseOver; @Override public boolean doesGuiPauseGame() { @@ -65,19 +67,40 @@ public class GuiClickMeme extends GuiScreen { Vec3d viewerPos = new Vec3d(mc.getRenderManager().viewerPosX, mc.getRenderManager().viewerPosY, mc.getRenderManager().viewerPosZ); RayTraceResult result = mc.world.rayTraceBlocks(near.add(viewerPos), far.add(viewerPos), false, false, true); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) { - meme = result.getBlockPos(); + currentMouseOver = result.getBlockPos(); } } + } @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); + protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { + System.out.println("Mouse released"); if (mouseButton == 0) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalTwoBlocks(meme)); + if (clickStart != null && !clickStart.equals(currentMouseOver)) { + ((Baritone) BaritoneAPI.getProvider().getPrimaryBaritone()).getBuilderProcess().clearArea(clickStart, currentMouseOver); + clickStart = null; + } else { + + + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalTwoBlocks(currentMouseOver)); + } } else if (mouseButton == 1) { - BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(meme.up())); + BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver.up())); } + clickStart = null; + } + + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + System.out.println("Mouse clicked"); + clickStart = currentMouseOver; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + System.out.println("Click move"); } public void onRender(float partialTicks) { @@ -85,11 +108,30 @@ public class GuiClickMeme extends GuiScreen { GlStateManager.getFloat(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear()); GlStateManager.glGetInteger(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear()); - if (meme != null) { + if (currentMouseOver != null) { Entity e = mc.getRenderViewEntity(); // drawSingleSelectionBox WHEN? - PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(meme), Color.CYAN); + PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(currentMouseOver), Color.CYAN); + if (clickStart != null && !clickStart.equals(currentMouseOver)) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.color(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F); + GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); + GlStateManager.disableTexture2D(); + GlStateManager.depthMask(false); + GlStateManager.disableDepth(); + BetterBlockPos a = new BetterBlockPos(currentMouseOver); + BetterBlockPos b = new BetterBlockPos(clickStart); + PathRenderer.drawAABB(new AxisAlignedBB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1)); + GlStateManager.enableDepth(); + + GlStateManager.depthMask(true); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } } + + } public Vec3d toWorld(double x, double y, double z) { diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index c0af870e..807523e2 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -211,7 +211,7 @@ public final class PathRenderer implements Helper { GlStateManager.disableDepth(); } - float expand = 0.002F; + //BlockPos blockpos = movingObjectPositionIn.getBlockPos(); BlockStateInterface bsi = new BlockStateInterface(BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()); // TODO this assumes same dimension between primary baritone and render view? is this safe? positions.forEach(pos -> { @@ -222,31 +222,7 @@ public final class PathRenderer implements Helper { } else { toDraw = state.getSelectedBoundingBox(player.world, pos); } - toDraw = toDraw.expand(expand, expand, expand).offset(-mc.getRenderManager().viewerPosX, -mc.getRenderManager().viewerPosY, -mc.getRenderManager().viewerPosZ); - BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); - BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - TESSELLATOR.draw(); - BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); - BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - TESSELLATOR.draw(); - BUFFER.begin(GL_LINES, DefaultVertexFormats.POSITION); - BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); - BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); - TESSELLATOR.draw(); + drawAABB(toDraw); }); if (Baritone.settings().renderSelectionBoxesIgnoreDepth.get()) { @@ -258,6 +234,35 @@ public final class PathRenderer implements Helper { GlStateManager.disableBlend(); } + public static void drawAABB(AxisAlignedBB aabb) { + float expand = 0.002F; + AxisAlignedBB toDraw = aabb.expand(expand, expand, expand).offset(-mc.getRenderManager().viewerPosX, -mc.getRenderManager().viewerPosY, -mc.getRenderManager().viewerPosZ); + BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); + BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); + TESSELLATOR.draw(); + BUFFER.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); + BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); + TESSELLATOR.draw(); + BUFFER.begin(GL_LINES, DefaultVertexFormats.POSITION); + BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex(); + BUFFER.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex(); + TESSELLATOR.draw(); + } + public static void drawDankLitGoalBox(Entity player, Goal goal, float partialTicks, Color color) { double renderPosX = mc.getRenderManager().viewerPosX; double renderPosY = mc.getRenderManager().viewerPosY;