0
\$\begingroup\$

I'm trying to make an eyedropper tool (one where it picks up the color the tool is being pointed at) for a Minecraft mod that uses Forge on IntelliJ IDEA. I already have the item/tool ready and able to be crafted, but I'm not sure how to build it so it can pick up pixel color, whether it's possible without Javascript, or if it would be possible to build it as of now considering it's in a game software rather than within a browser.

This is the closest I've come to with research on how I can build it with Java, but import net.java.swing.application.* was an issue for which I'm not sure the reason.

import java.text.*;
import java.util.List;
import java.awt.*;
import javax.swing.*;


public class PickupColor extends SingleFrameApplication { // "Cannot resolve symbol 'SingleFrameApplication'"
    public JButton eyedropper, quit;
    public JComponent colormap;
    public JFrame rootFrame;
    public Image background_image;
    public Robot robot;
    public Dimension screen_size;
    public Container contentPane;
    public JComponent button_panel;
    public JPanel image_panel;
    public JPanel control_panel;
    public JPanel color_panel;
    public ColorLabel selected_color; // "Cannot resolve symbol 'ColorLabel'"
    public ColorLabel color_rich, color_pale,
            color_bright, color_dark; // // "Cannot resolve symbol 'ColorLabel'"
    public Font color_font;

    /* init code */
    public void init(JFrame rootFrame,
                     Container contentPane, List args) {
        try {
            this.rootFrame = rootFrame;
            this.contentPane = contentPane;
            this.color_font = new Font("Monospaced",Font.PLAIN,14);

            // take a screenshot
            screen_size = Toolkit.getDefaultToolkit().getScreenSize();
            Rectangle rect = new Rectangle(0,0,
                    (int)screen_size.getWidth(),
                    (int)screen_size.getHeight());
            this.robot = new Robot();
            background_image = robot.createScreenCapture(rect);

            super.init(rootFrame,contentPane,args); // "Cannot resolve method 'init(JFrame, Container, List)'"

        } catch (Exception ex) {
            p(ex.toString()); // "Cannot resolve method 'p' in 'PickupColor'"
        }
}

The errors listed above are most likely because of that one import I am unable to include.

The plan for the tool is as follows:

  • The eyedropper tool is in the right hand of the player, and similar to mods like Chisels and Bits (here is the GitHub too), it would pick up the pixels of the block that's being pointed at with the tool
  • The one specific pixel being pointed at is zoomed in on and displays the hex value of that pixel above
  • The player can right-click it to save that color temporarily for other functions
\$\endgroup\$
5
  • \$\begingroup\$ What have you tried? \$\endgroup\$ Nov 28, 2022 at 15:35
  • \$\begingroup\$ @user253751 I just made an edit to add what I included so far, and the errors I am getting. \$\endgroup\$
    – leguchi
    Nov 28, 2022 at 15:44
  • \$\begingroup\$ Are you trying to make one where you click somewhere on your computer screen? \$\endgroup\$ Nov 28, 2022 at 15:45
  • \$\begingroup\$ @user253751 part of it does include clicking, yes. Others include hovering. \$\endgroup\$
    – leguchi
    Nov 28, 2022 at 15:46
  • \$\begingroup\$ I've never looked at the codebase and am fairly unfamiliar with Minecraft so take this with a pinch of salt but ... I'd be very surprised if minecraft is using Swing for its UI. In game development, it's not uncommon for the graphics card to handle all the rendering and display it without the CPU ever being aware of exactly what's on screen. Game capture software (or a thousand other things running windowed rather than full screen) can cause the graphics to be sent back to the CPU, but it's not a given. \$\endgroup\$
    – Basic
    Nov 28, 2022 at 16:49

0

You must log in to answer this question.

Browse other questions tagged .