Working clicking goals

This commit is contained in:
Brady 2019-02-26 21:41:08 -06:00
parent 3de02cbf21
commit c474cdb1f8
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 42 additions and 17 deletions

View File

@ -408,10 +408,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return true; return true;
} }
if (msg.equals("click")) { if (msg.equals("click")) {
mc.addScheduledTask(() -> { new Thread(() -> {
mc.displayGuiScreen(new GuiClickMeme()); try {
}); Thread.sleep(100);
logDirect("click owo"); mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiClickMeme()));
} catch (Exception ignored) {}
}).start();
logDirect("aight dude");
return true; return true;
} }
if (msg.startsWith("thisway") || msg.startsWith("forward")) { if (msg.startsWith("thisway") || msg.startsWith("forward")) {

View File

@ -18,28 +18,37 @@
package baritone.utils; package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.GoalBlock;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import org.lwjgl.util.glu.GLU; import org.lwjgl.util.glu.GLU;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.Collections;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
public class GuiClickMeme extends GuiScreen { public class GuiClickMeme extends GuiScreen {
// My name is Brady and I grant Leijurv permission to use this pasted code
private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16); private final FloatBuffer MODELVIEW = BufferUtils.createFloatBuffer(16);
private final FloatBuffer PROJECTION = BufferUtils.createFloatBuffer(16); private final FloatBuffer PROJECTION = BufferUtils.createFloatBuffer(16);
private final IntBuffer VIEWPORT = BufferUtils.createIntBuffer(16); private final IntBuffer VIEWPORT = BufferUtils.createIntBuffer(16);
private final FloatBuffer TO_SCREEN_BUFFER = BufferUtils.createFloatBuffer(3); private final FloatBuffer TO_SCREEN_BUFFER = BufferUtils.createFloatBuffer(3);
private final FloatBuffer TO_WORLD_BUFFER = BufferUtils.createFloatBuffer(3); private final FloatBuffer TO_WORLD_BUFFER = BufferUtils.createFloatBuffer(3);
private Vec3d meme;
private BlockPos meme;
@Override @Override
public boolean doesGuiPauseGame() { public boolean doesGuiPauseGame() {
@ -48,21 +57,32 @@ public class GuiClickMeme extends GuiScreen {
@Override @Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) { public void drawScreen(int mouseX, int mouseY, float partialTicks) {
System.out.println("Screen " + mouseX + " " + mouseY); int mx = Mouse.getX();
System.out.println(toWorld(mouseX, mouseY, 0)); int my = Mouse.getY();
System.out.println(toWorld(mouseX, mouseY, 0.1)); Vec3d near = toWorld(mx, my, 0);
System.out.println(toWorld(mouseX, mouseY, 1)); Vec3d far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - Leijurv
System.out.println(VIEWPORT.get(3) + " " + Display.getHeight()); if (near != null && far != null) {
meme = toWorld(mouseX, Display.getHeight() - mouseY, 0); Vec3d viewerPos = new Vec3d(mc.getRenderManager().viewerPosX, mc.getRenderManager().viewerPosY, mc.getRenderManager().viewerPosZ);
System.out.println(toScreen(mc.player.posX + 1, mc.player.posY, mc.player.posZ)); RayTraceResult result = mc.world.rayTraceBlocks(near.add(viewerPos), far.add(viewerPos), false, false, true);
System.out.println(toScreen(1, 0, 0)); if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
meme = result.getBlockPos();
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if (mouseButton == 0) {
BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoal(new GoalBlock(meme));
}
} }
public void onRender(float partialTicks) { public void onRender(float partialTicks) {
System.out.println("on render");
GlStateManager.getFloat(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear()); GlStateManager.getFloat(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear());
GlStateManager.getFloat(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear()); GlStateManager.getFloat(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear());
GlStateManager.glGetInteger(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear()); GlStateManager.glGetInteger(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear());
if (meme != null) { if (meme != null) {
Entity e = mc.getRenderViewEntity(); Entity e = mc.getRenderViewEntity();
GlStateManager.enableBlend(); GlStateManager.enableBlend();
@ -71,8 +91,10 @@ public class GuiClickMeme extends GuiScreen {
GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get()); GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.get());
GlStateManager.disableTexture2D(); GlStateManager.disableTexture2D();
GlStateManager.depthMask(false); GlStateManager.depthMask(false);
PathRenderer.drawLine(e, e.posX + 1, e.posY, e.posZ, e.posX + meme.x + 1, e.posY + meme.y, e.posZ + meme.z, partialTicks);
Tessellator.getInstance().draw(); // drawSingleSelectionBox WHEN?
PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(meme), partialTicks, Color.CYAN);
GlStateManager.depthMask(true); GlStateManager.depthMask(true);
GlStateManager.enableTexture2D(); GlStateManager.enableTexture2D();
GlStateManager.disableBlend(); GlStateManager.disableBlend();