| 47 | import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; |
| 48 | |
| 49 | public class GuiClick extends Screen implements Helper { |
| 50 | |
| 51 | private Matrix4f projectionViewMatrix; |
| 52 | |
| 53 | private BlockPos clickStart; |
| 54 | private BlockPos currentMouseOver; |
| 55 | |
| 56 | public GuiClick() { |
| 57 | super(Component.literal("CLICK")); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean isPauseScreen() { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void render(GuiGraphics stack, int mouseX, int mouseY, float partialTicks) { |
| 67 | double mx = mc.mouseHandler.xpos(); |
| 68 | double my = mc.mouseHandler.ypos(); |
| 69 | |
| 70 | my = mc.getWindow().getScreenHeight() - my; |
| 71 | my *= mc.getWindow().getHeight() / (double) mc.getWindow().getScreenHeight(); |
| 72 | mx *= mc.getWindow().getWidth() / (double) mc.getWindow().getScreenWidth(); |
| 73 | Vec3 near = toWorld(mx, my, 0); |
| 74 | Vec3 far = toWorld(mx, my, 1); // "Use 0.945 that's what stack overflow says" - leijurv |
| 75 | |
| 76 | if (near != null && far != null) { |
| 77 | Vec3 viewerPos = new Vec3(PathRenderer.posX(), PathRenderer.posY(), PathRenderer.posZ()); |
| 78 | LocalPlayer player = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().player(); |
| 79 | HitResult result = player.level().clip(new ClipContext(near.add(viewerPos), far.add(viewerPos), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)); |
| 80 | if (result != null && result.getType() == HitResult.Type.BLOCK) { |
| 81 | currentMouseOver = ((BlockHitResult) result).getBlockPos(); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { |
| 88 | if (currentMouseOver != null) { //Catch this, or else a click into void will result in a crash |
| 89 | if (mouseButton == 0) { |
| 90 | if (clickStart != null && !clickStart.equals(currentMouseOver)) { |
| 91 | BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().removeAllSelections(); |
| 92 | BaritoneAPI.getProvider().getPrimaryBaritone().getSelectionManager().addSelection(BetterBlockPos.from(clickStart), BetterBlockPos.from(currentMouseOver)); |
| 93 | MutableComponent component = Component.literal("Selection made! For usage: " + Baritone.settings().prefix.value + "help sel"); |
| 94 | component.setStyle(component.getStyle() |
| 95 | .withColor(ChatFormatting.WHITE) |
| 96 | .withClickEvent(new ClickEvent.RunCommand( |
| 97 | FORCE_COMMAND_PREFIX + "help sel" |
| 98 | ))); |
| 99 | Helper.HELPER.logDirect(component); |
| 100 | clickStart = null; |
| 101 | } else { |
| 102 | BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver)); |
| 103 | } |
| 104 | } else if (mouseButton == 1) { |
| 105 | BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess().setGoalAndPath(new GoalBlock(currentMouseOver.above())); |
| 106 | } |
nothing calls this directly
no outgoing calls
no test coverage detected