Jump to content

Recommended Posts

Posted

I am currently working on a mod that adds Touch Screen support to Minecraft (and any other mod, really). I am developing in 1.6.4 using Forge. Actually, my mod is finished, outside of the fact that it doesn't work because of the useless Forge MouseEvent.

 

The only thing required for my mod to work as intended is for me to be able to read in all MouseEvents and input, interpret it, and pass it along (or not) to Minecraft. I originally planned to register for MouseEvents, make sure no clicks happened on any buttons I care about, etc, and then pass in modified input values with something like:

 

mouseEvent.setX(int x), mouseEvent.setY(int y), etc.

 

However, MouseEvents only have getters, not setters. OK, I thought. I'll just use the getters, interpret it, cancel the mouse event, and make a new one, using values I want! Well, that doesn't work either.

 

Minecraft makes several references to lwjgl.Mouse to get its .x, .y .dX, .dY, etc directly, rather than going through MouseEvent. So, even if I cancel all mouse events, the mouse motion, clicks, drags, still cause player motion!!! You just can't left or right click in game. That's not very useful.

 

I propose an edit to Forge and the Base, in which we overload lwjgl.Mouse, and add getters and setters to it, and replace all lwjgl.Mouse calls in Minecraft and Forge Base Code with this subclassed lwjgl.Mouse. It would fix my problems, and add more control for future modders using MinecraftForge. Since the goal of my project is to add universal touchscreen support to Minecraft and its mods, a base edit is out of the question, and this is the only way. I have the code ready to go, but not the authority to add it to Forge. If there is a better place or way to handle this, I'm open to it as well.

Posted

So, you're wanting us to replace {from a quick search} over 100 instances in the MC code to our wrapper, Not to mention the fact that Mouse is a static class, NOT a Object we can override.

I've seen touch screen done before, pretty sure MC has support for it natvly.

However, what you COULD do, is reflectivly set things, or write a coremod that override the lwjgl classes.

Not to mention the MouseEvent is designed as a PASSIVE event. Just because it has a reference to those values doesn't mean changing those values would actually do anything.

But I fail to see the reason you're needing to do this precisely?

I advise you do a bit of research get your hands into exactly whats going on. Rahter then what you THINK is going on.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

MC has a 'touchscreen mode' but feel free to turn that on and see what it gets you: Only support for clicking menu buttons; you still need mouse and keyboard to play the game.

 

I'm not familiar with coremods, considering this is my first mod. Perhaps since you know so much, you can set me straight, I thought that anything I wrote that didn't use the Forge API was considered a huge foul and would break compatibility. Hence my coming to this forum, suggesting that the MouseEvent actually cancel mouse input to the display, as the MouseEvent.isCancelled(boolean) method seemed to imply. If you have any great sources I would absolutely read them, I'm a very capable developer, and am not afraid to get my hands dirty. Just keep in mind, my goal is to make my mod usable with others, so anything that breaks compatibility is a no go for my project.

Posted

I never advocate breaking compatibility, however, CoreMods are a construct in FML to allow modders to do specialized edits to the internal MC code HOPEFULLY keeping the best compatibility {unless you do something retarded}

However the more I look into it the more I se that core mods arnt needed.

Also, canceling the vent prevents Minecaft from processing it. And just moves on to the next Mouse event.

How is that confusing? Also all of our sources are open so you can easily verify for yourself what it does.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Well, if you feel core mods aren't necessary, I'd happily take your advice, as I've been reading your source for three days now, and haven't found or thought of a way to avoid MC source edits (which now I understand can be accomplished with core mod, thank you for that clarification). I've read several places where coremods are frowned upon, and it must be what you are insinuating, that it's not necessary.

 

I have registered for MouseEvents, and RenderOverlayEvents, I draw my overlay of controls, and on MouseEvents, I try to detect if my buttons are being clicked or not, among other things. Before all this runs, I set mc.inGameFocus to false to free the mouse to click anywhere but mc.displayWidth /2 and mc.displayHeight/2, but any time a click occurs, the mouse cursor is moved to screen center and nothing registers, as expected. Interestingly enough, if you click and drag quickly, you can change your view substantially from the player perspective. I attribute this to the lwjgl.Mouse calls in the MC code that I have read into substantially.

 

If you feel a core mod is not necessary, what classes should I be looking into using, or reading into? Are there any projects or tutorials I should be looking at to avoid a core mod?

Posted

So, what EXACTLY are you trying to do? Be as thorough as possible, Screen shots, annotations all good.

You should ALWAYS be as through as possible when thinking through ideas. Base edits are a LAST resort, if you're just intercepting some mouse clicks, then it's easy to do.

Remember, how 3D games work.

The mouse is ALWAYS in the center of the screen when looking in the world. If it moves, then the camera adjusts around it to bring it back into the center.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

I can't seem to attach files or embed code using the forum, so here is a dropbox link to my source: https://www.dropbox.com/s/i9qjb7jav64f3dw/touchcraft.zip

 

I am trying to capture the mouse clicks and coordinates to pass into my mod class, which checks if the clicks and coordinates coincide with any on screen inputs that I have drawn. If the answer is true for any of these, they trigger a method that will use a Robot to virtually press the keys or move the mouse. This isn't working, however, and it seems to be because Minecraft is calling up the lwjgl.Mouse for raw input rather than using the MouseEvents that I am cancelling after verifying that they can be used. I wish that I could properly embed code, but I will post some raw code to try and demonstrate the process.

 

/* This is the relevant code in my InputOverlay class, which is called up in my basemod after setting everything up with proxies and whatnot

@ForgeSubscribe(priority = EventPriority.NORMAL)

public void onMouseEvent(MouseEvent event) {

//free the mouse! this is step one

//something is resetting the mouse pos though to window center

mc.setIngameNotInFocus();

 

// Determine where click or touch occurred and if input needs consumed

 

if (isMouseEventConsumed(event)) {

event.setCanceled(true);

} else return;

}

 

@ForgeSubscribe

private boolean isMouseEventConsumed(MouseEvent event) {

boolean result = false;

 

for (int i = 0; i < inputs.size(); i++) {

if (inputs.get(i).consumes(event)) {

result = true;

}

}

return result;

}

 

/* here is my joystick class, a subclass of my input class, to demonstrate how I am handling the event

package touchcraft;

 

import java.awt.event.KeyEvent;

 

import net.minecraftforge.client.event.MouseEvent;

 

public class Joystick extends Input implements Drawable {

 

boolean keyDown[] = new boolean[4];

 

public Joystick(int x, int y, float r) {

super(x, y, r);

for(int i = 0; i < keyDown.length; i++) {

keyDown = false;

}

// TODO Auto-generated constructor stub

}

 

/*

    * The goal is to have an analogue joystick map the wasd keys in MC

    * There are 8 options, each 45 degrees wide radially

    * 8 way dpad

    * w,a,s,d,wa,wd,as,ds

    */

private final double JOYSTICK_ANGLE_SCALAR = 1.5;  // scalar is for dual inputs: 1-2

private final int W = 90, A = 180, S = 270, D = 0; // Angles for keys

private final int keyCode[] = {KeyEvent.VK_W, KeyEvent.VK_A, KeyEvent.VK_S, KeyEvent.VK_D}; //int codes for wasd

 

public void joystickEvent(int x, int y) {

    //calculate the angle for motion vector

        double theta = Math.atan2(y - originY, x - originX);

        theta *= 180 / Math.PI;

 

        if(theta < ( W + (W * JOYSTICK_ANGLE_SCALAR)) && theta > (W - (45 * JOYSTICK_ANGLE_SCALAR)))

        {

            Input.keyDown(keyCode[0]);

            keyDown[0] = true;

        }

        else if(keyDown[0]) Input.keyUp(keyCode[0]);

       

        if (theta < (S + S * JOYSTICK_ANGLE_SCALAR) && theta > (S - 45 * JOYSTICK_ANGLE_SCALAR))

        {

        Input.keyDown(keyCode[1]);

        keyDown[1] = true;

        }

        else if(keyDown[1]) Input.keyUp(keyCode[1]);

       

        if(theta < ( A + (A * JOYSTICK_ANGLE_SCALAR)) && theta > (A - (45 * JOYSTICK_ANGLE_SCALAR)))

        {

        Input.keyDown(keyCode[2]);

        keyDown[2] = true;

        }

        else if(keyDown[2]) Input.keyUp(keyCode[2]);

       

        if(theta < ( D + (D * JOYSTICK_ANGLE_SCALAR)) && theta > (D - (45 * JOYSTICK_ANGLE_SCALAR)))

        {

        Input.keyDown(keyCode[3]);

        keyDown[3] = true;

        }

        else if(keyDown[3]) Input.keyUp(keyCode[3]);

    }

 

public boolean consumes(MouseEvent event) {

if((event.x - originX)*(event.x - originX) + (event.y - originY)*(event.y - originY) < radius * radius && event.buttonstate)

{

joystickEvent(event.x, event.y);

return true;

} else return false;

}

 

public void draw() {

super.draw();

}

}

 

My goal was to cancel the mouse events and create new ones with the 'fake' values that I wanted Minecraft to actually act on. I want to intercept Mouse input to convert it into keyboard and mouse key presses to replace the traditional keyboard and mouse input methods with my on screen ones. If you download the source zip from my dropbox, you can see exactly what I'm talking about. Keep in mind, nothing will work unless you enable Touch Screen mode in your Minecraft settings however.

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Post logs as described in the FAQ, there might be a clue in there what is going on.
    • The registered recipe name doesn't need to be the name of the item, so name one ruby_from_block and one ruby_from_nugs or something like that.   Without seeing code/project files, that's the best guess I have.
    • Whenever I launch Minecraft Forge (With or without any mods installed, yes, I've checked my mods folder, it is empty. I also tried Curseforge's app.) above the version 1.18.2 (Versions 1.18.2 and below work fine), the game crashes before opening and shows error code 1. I have no clue what it could be, I've tried many different options on my own, but any suggestion helps.
    • Hello support, I would like to tell you that I recently had troubles with getting into forge in Minecraft. I wanted to play with my friend a modpack in the game in version 1.20.1 when I downloaded it it crashed so we I started deleting some unnecessary mods to maybe lower the pressure if my PC is not good enough to run the modpack. But I went to delete every mod and installed a hole new version of forge with no mods installed or anything with it it still crashed. I found some help on the forms telling to download java 17 and install it on my windows so I did that and still couldn’t play because it crashes  The log files and everything I could find to help this problem is here : https://pastebin.com/9rWpANcW Hope your help arrives quickly
    • I'm testing a modpack for a server, and everything is fine, until I update the Aether mod from version "aether-1.20.1-1.4.2-neoforge" to version "aether-1.20.1-1.5.1-neoforge" now on the server it gives the error: Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode but in the game it says something different (scroll down) [21Nov2024 15:58:50.673] [main/WARN] [net.minecraft.server.Main/]: Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode 2002java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Failed to load registries due to above errors 2003at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[?:?] 2004at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073) ~[?:?] 2005at net.minecraft.server.Main.main(Main.java:195) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2006at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] 2007at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] 2008at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] 2009at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] 2010at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:111) ~[fmlloader-1.20.1-47.3.12.jar%2369!/:?] 2011at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.serverService(CommonLaunchHandler.java:103) ~[fmlloader-1.20.1-47.3.12.jar%2369!/:?] 2012at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$makeService$0(CommonServerLaunchHandler.java:27) ~[fmlloader-1.20.1-47.3.12.jar%2369!/:?] 2013at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.9.jar%2355!/:?] 2014at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.9.jar%2355!/:?] 2015at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.9.jar%2355!/:?] 2016at cpw.mods.modlauncher.Launcher.run(Launcher.java:108) ~[modlauncher-10.0.9.jar%2355!/:?] 2017at cpw.mods.modlauncher.Launcher.main(Launcher.java:78) ~[modlauncher-10.0.9.jar%2355!/:?] 2018at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.9.jar%2355!/:?] 2019at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.9.jar%2355!/:?] 2020at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] 2021Caused by: java.lang.IllegalStateException: Failed to load registries due to above errors 2022at net.minecraft.resources.RegistryDataLoader.m_247207_(RegistryDataLoader.java:77) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2023at net.minecraft.server.WorldLoader.m_246152_(WorldLoader.java:54) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2024at net.minecraft.server.WorldLoader.m_245736_(WorldLoader.java:58) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2025at net.minecraft.server.WorldLoader.m_214362_(WorldLoader.java:31) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2026at net.minecraft.server.Main.lambda$main$2(Main.java:167) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2027at net.minecraft.Util.m_214652_(Util.java:777) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2028at net.minecraft.Util.m_214679_(Util.java:772) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2029at net.minecraft.server.Main.main(Main.java:166) ~[server-1.20.1-20230612.114412-srg.jar%23535!/:?] 2030... 15 more   AND THE ERROR THAT THE GAME SAY WENT I WANT TO PLAY IN SOLO (local): Time: 2024-11-21 16:16:37 Description: mouseClicked event handler java.lang.IllegalStateException: Failed to load registries due to above errors     at net.minecraft.resources.RegistryDataLoader.m_247207_(RegistryDataLoader.java:77) ~[client-1.20.1-20230612.114412-srg.jar%23652!/:?] {re:mixin,pl:connector_pre_launch:A,re:classloading,pl:mixin:APP:bclib.mixins.common.json:RegistryDataLoaderMixin from mod bclib,pl:mixin:APP:lithostitched.mixins.json:common.RegistryDataLoaderMixin from mod lithostitched,pl:mixin:APP:zeta.mixins.json:RegistryDataLoaderMixin from mod zeta,pl:mixin:APP:fabric-registry-sync-v0.mixins.json:RegistryLoaderMixin from mod fabric_registry_sync_v0,pl:mixin:APP:together.mixins.common.json:RegistryDataLoaderMixin from mod bclib,pl:mixin:APP:connectormod.mixins.json:registries.RegistryDataLoaderMixin from mod connectormod,pl:mixin:A,pl:connector_pre_launch:A} at net.minecraft.server.WorldLoader.m_246152_(WorldLoader.java:54) ~[client-1.20.1-20230612.114412-srg.jar%23652!/:?] {re:mixin,pl:connector_pre_launch:A,re:classloading,pl:mixin:APP:together.mixins.common.json:WorldLoaderMixin from mod bclib,pl:mixin:A,pl:connector_pre_launch:A}     at net.minecraft.server.WorldLoader.m_245736_(WorldLoader.java:58) ~[client-1.20.1-20230612.114412-srg.jar%23652!/:?] {re:mixin,pl:connector_pre_launch:A,re:classloading,pl:mixin:APP:together.mixins.common.json:WorldLoaderMixin from mod bclib,pl:mixin:A,pl:connector_pre_launch:A}     at net.minecraft.server.WorldLoader.m_214362_(WorldLoader.java:31) ~[client-1.20.1-20230612.114412-srg.jar%23652!/:?] {re:mixin,pl:connector_pre_launch:A,re:classloading,pl:mixin:APP:together.mixins.common.json:WorldLoaderMixin from mod bclib,pl:mixin:A,pl:connector_pre_launch:A}     at net.minecraft.client.gui.screens.worldselection.CreateWorldScreen.m_232896_(CreateWorldScreen.java:125) ~[client-1.20.1-20230612.114412-srg.jar%23652!/:?] {re:mixin,pl:accesstransformer:B,pl:connector_pre_launch:A,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:modernfix-common.mixins.json:perf.dedicated_reload_executor.CreateWorldScreenMixin from mod modernfix,pl:mixin:APP:modernfix-forge.mixins.json:bugfix.extra_experimental_screen.CreateWorldScreenMixin from mod modernfix,pl:mixin:APP:cumulus_menus.mixins.json:client.accessor.CreateWorldScreenAccessor from mod cumulus_menus,pl:mixin:APP:mediumcore.mixins.json:client.CreateWorldScreenMixin from mod mediumcore,pl:mixin:APP:aether.mixins.json:client.CreateWorldScreenMixin from mod aether,pl:mixin:APP:together.mixins.client.json:CreateWorldScreen_Mixin from mod bclib,pl:mixin:APP:fancymenu.mixins.json:client.MixinCreateWorldScreen from mod fancymenu,pl:mixin:A,pl:connector_pre_launch:A,pl:runtimedistcleaner:A}        
  • Topics

×
×
  • Create New...

Important Information

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