Jump to content

xoombie

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by xoombie

  1. Finally cracked it. In case useful to anyone else, in the client you have to manually clear the headless state: MyClassConstructor() { // .... DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { initRobot(); }); } void initRobot() { System.setProperty("java.awt.headless", "false"); try { this.robot = new Robot(); } catch (AWTException e){ e.printStackTrace(); } PointerInfo pointerInfo = MouseInfo.getPointerInfo(); // you can now use all the usual Robot class methods }
  2. Developing a mod with 1.15.2, am getting java.awt.HeadlessException from PointerInfo pointerInfo = MouseInfo.getPointerInfo(); Have been looking at this excellent example: motecraft, although it is out of date, so for 1.15.2 am using the following: DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> { initRobot(); }); void initRobot() { try { this.robot = new Robot(); } catch (AWTException e){ e.printStackTrace(); } PointerInfo pointerInfo = MouseInfo.getPointerInfo(); DisplayMode mode = pointerInfo.getDevice().getDisplayMode(); int width = mode.getWidth(); int height = mode.getHeight(); this.displayPixels = height < width ? height : width; } Have tried many, many variations, but no way to avoid the exception. Can anyone indicate whether the Minecraft 1.15.2 client is headless? Or is there something obvious I've missed. Any info greatly appreciated.
  3. On 1.15.2 - 31.2.0 mod runs fine, but (as anticipated) appears as a cheat on multiplayer, due to the way movement is coded. The mod is effectively a driver for custom hardware that enables more natural navigation than a mouse/trackpad. Is there a way to test something like this with a server, without getting an immediate 30-day ban? And are there any coding tricks that can be used to deliberately *avoid* cheating, eg, work out permitted movement per tick, or something like that. Any info greatly appreciated. In the thirty seconds or so the device worked on mc.hypixel.net, it worked perfectly!
  4. Got it working. Thanks for clearing up some confusion for this noob. In case anyone else finds it useful, the SRG names are the cryptic kind, eg func_189810_i The dev environment will also accept human-friendly MCP names as ObfuscationReflectionHelper arguments, eg updateAutoJump The runtime-only environment (ie, during normal use) only works if ObfuscationReflectionHelper has SRG name arguments. My working code now looks like: this.updateAutoJump = ObfuscationReflectionHelper.findMethod(ClientPlayerEntity.class, "func_189810_i", // func_189810_i = updateAutoJump float.class, float.class); this.mouseButtonSimulate = ObfuscationReflectionHelper.findMethod(MouseHelper.class, "func_198023_a", // func_198023_a = mouseButtonCallback long.class, int.class, int.class, int.class); Useful links: MCP, environments and naming Tool for looking up SRG names
  5. On 1.15.2 - 31.2.0 mod runs fine in dev environment, but fails at the first of the following lines during common_setup event phase. If the first line is omitted, it fails on the second, indicating a general problem with symbol lookup in the runtime only environment: this.updateAutoJump = ObfuscationReflectionHelper.findMethod(ClientPlayerEntity.class, "updateAutoJump", float.class, float.class); this.mouseButtonSimulate = ObfuscationReflectionHelper.findMethod(MouseHelper.class, "mouseButtonCallback", long.class, int.class, int.class, int.class); The relevant part of build.gradle: minecraft { [...] mappings channel: 'snapshot', version: '20201216-1.15.1' //mappings channel: 'snapshot', version: '20200514-1.15.1' // also doesn't work [...] } Has anyone else encountered this problem? Have researched for a day now, and just cannot see why the SRG names are not being consistently handled by ObfuscationReflectionHelper Any help greatly appreciated
  6. Was a noob mistake. The coordinates used by GLFW for cursor positioning are display pixels, whereas mc renders to a multiple. What worked was: double s = mc.getMainWindow().getGuiScaleFactor(); mc.currentScreen.mouseClicked(x/s, y/s, 0); // 0 is code for left button MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseClickedEvent.Pre(mc.currentScreen, x/s, y/s, 0)); // share event with any mouse handlers (optional) Hope this helps anyone doing something similar
  7. On 1.15.2, trying to simulate mouse clicks for a mod for a custom hardware input device. Mouse pointer movement works fine, using GLFW.glfwSetCursorPos() However, none of extensive attempts to simulate a mouse click has worked so far. One way is to use java.awt.Robot, but the mod sees itself in a headless environment, where Robot cannot function. (it appears others have successfully used this, but perhaps on old mc versions? is 1.15.2 fundamentally different in this respect?). Other attempts include: MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseClickedEvent.Pre(screen, x, y, GLFW.GLFW_MOUSE_BUTTON_1)); Because these mouse clicks are for GUIs, not the main game (click events in the game itself can be simulated by activating a keybinding). Many many hours lost through this so far, any ideas greatly appreciated. Am new to Minecraft modding, although very familiar with java.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.