Jump to content

How to execute the equivalent of left click,right click, jump etc. in java code


Recommended Posts

Posted (edited)

So basically I am attempting to make a mod that will allow you to use controllers for Minecraft (following the console version of Minecraft control's scheme)

I have this code, not tested yet, which you might aswell take a look at my current work and see if anything here is wrong (such as yaw needing the numbers in reversed etc.)

 

I can also make a github repo if that is easier to read than just code in plain text.

 

I am currently missing the following which I had no luck finding how to do online: (I added comments for most of my methods showing what they do in Minecraft code just incase I should change something)

  •  Left click
  • Right click
  • Jump 
  • Esc key button
  • (Optionally) Add a pointer that can be moved with the joysticks for buttons and allow using a button like X to {pick up/place item} in slots or click buttons in menus
    private ControllerButtons oldButtons;

    int scrollTime;

    int dropTime;

    public void update(IControlPlayer player) {

        if(oldButtons == null) {
            oldButtons = controller.getButtons();
        }


        if(!handler.isGuiOpen()) {
            //Equivalent to (Minecraft.getMinecraft().thePlayer.moveForward = controller.getAxes().getVERTICAL_LEFT_STICKER().getValue();)
            player.moveForward(controller.getAxes().getVERTICAL_LEFT_STICKER().getValue()); // -1 is down, 1 is up, 0 is stateless

            //Equivalent to (Minecraft.getMinecraft().thePlayer.moveStrafing = controller.getAxes().getHORIZONTAL_LEFT_STICKER().getValue();)
            player.moveStrafing(controller.getAxes().getHORIZONTAL_LEFT_STICKER().getValue()); // -1 IS DOWN, 1 IS UP, 0 IS STATELESS

            //Equivalent to (Minecraft.getMinecraft().thePlayer.rotationPitch += controller.getAxes().getVERTICAL_RIGHT_STICKER().getValue();)
            player.addRotationYaw(controller.getAxes().getHORIZONTAL_RIGHT_STICKER().getValue()); // -1 IS DOWN, 1 IS UP, 0 IS STATELESS

            //Equivalent to (Minecraft.getMinecraft().thePlayer.rotationYaw += controller.getAxes().getHORIZONTAL_RIGHT_STICKER().getValue();)
            player.addRotationPitch(controller.getAxes().getVERTICAL_RIGHT_STICKER().getValue()); // -1 is down, 1 is up, 0 is stateless
        }

        if(controller.getAxes().getLEFT_TRIGGER().getValue() > 0.5) {
            // RIGHT CLICK EQUIVALENT
        }

        if(controller.getAxes().getRIGHT_TRIGGER().getValue() > 0.5) {
            //LEFT CLICK EQUIVALENT
        }

        if(checkToggle(controller.getButtons().getA(),oldButtons.getA())) {
            // JUMP EQUIVALENT
        }

        //Closes GUI
        if(checkToggle(controller.getButtons().getB(),oldButtons.getB())) {
            if(handler.isGuiOpen()) {
                //Equivalent to (Minecraft.getMinecraft().displayGuiScreen(null);)
                handler.closeGUI();
            }
        }

        //////////////////////////////////////////////
        // Drops item
        if((dropTime == 0 || dropTime > 30) && !handler.isGuiOpen()) {
            boolean increaseTime = false;
            if (dropTime == 0 && !controller.getButtons().getB().isState() && oldButtons.getB().isState()) {
                player.dropItem();
                increaseTime = true;
            }
            if (dropTime > 30 && controller.getButtons().getB().isState()) {
                player.dropStack();
                increaseTime = true;
            }

            if (increaseTime) {
                dropTime++;
            } else {
                dropTime = 0;
            }
        }
        //////////////////////////////////////////////

        if(checkToggle(controller.getButtons().getSTART_BUTTON(),oldButtons.getSTART_BUTTON())) {
            //Would execute what Escape does
        }

        if(checkToggle(controller.getButtons().getY(),oldButtons.getY())) {
            boolean opened = Minecraft.getMinecraft().currentScreen instanceof GuiInventory;

            if(opened) {
                //Equivalent to (Minecraft.getMinecraft().displayGuiScreen(null);)
                handler.closeGUI();
            }else{
                //Equivalent to (Minecraft.getMinecraft().displayGuiScreen(new GuiInventory(Minecraft.getMinecraft().thePlayer));)
                player.openInventory();
            }
        }

        //Basically does what TAB would do
        if(checkToggle(controller.getButtons().getEXTRA_BUTTON(),oldButtons.getEXTRA_BUTTON())) {
            handler.renderPlayerList(true);
        }else{
            handler.renderPlayerList(false);
        }


        if(checkToggle(controller.getButtons().getLEFT_STICKER(),oldButtons.getLEFT_STICKER())) {
            //Basically player.setSneaking(!player.isSneaking());
            player.toggleSneak();
        }

        //Basically does (Minecraft.getMinecraft().displayGuiScreen(new GuiChat());)
        if(checkToggle(controller.getButtons().getDPAD_UP(),oldButtons.getDPAD_UP())) {
            handler.displayChat();
        }

        if(checkToggle(controller.getButtons().getRIGHT_STICKER(),oldButtons.getRIGHT_STICKER())) {
            //Basically Minecraft.getInstance().gameSettings.thirdPersonView++;
            handler.toggle3rdPerson();
        }

        ////////////////////////////////
        //Scrolls between the hotbar
        if(controller.getButtons().getBUMPER_RIGHT().isState() && (scrollTime == 0 || scrollTime > 30)) {
            player.scrollSlot(-1);
            scrollTime++;
        }else{
            scrollTime = 0;
        }

        if(controller.getButtons().getBUMPER_LEFT().isState()  && (scrollTime == 0 || scrollTime > 30)) {
            player.scrollSlot(1);
        }else{
            scrollTime = 0;
        }
        ////////////////////////////////

        oldButtons = controller.getButtons();
    }

    private boolean checkToggle(ControllerButtonState newButton, ControllerButtonState oldState) {
        return newButton.isState() != oldState.isState();
    }

 

Edited by fernthedev
Forgot to clarify completely my issues
Posted

Ah thanks, now how do I execute, say the equivalent code left click would run or make the player jump in these events? Also the pointer that would be moved with the joystick, should I receive help here or stackoverflow? Not really sure which is the better place to ask for help on that

Posted

Amazing tips and help you've given me. So in the movement event I can call jump/sneak methods and use my move methods? Sorry for my repetition, I just need that fully clarified 

Posted
  On 5/26/2019 at 3:50 PM, diesieben07 said:

No. Did you even look at the event? It provides you with the MovementInput instance that the game uses for storing what the player should do.

Expand  

I did not check due to being away from my development workspace at the moment, however as I see it, I use the instance of the event to jump by setting a value or calling a method, no? Same for walking or do I keep my old walk method and put it in the tick method or the moveinput event?

Posted
  On 5/26/2019 at 4:06 PM, diesieben07 said:

Walking, jumping and sneaking should be handled through MovementInput.

Expand  

I was able to look into InputUpdateEvent, however it's a 1.13 only thing as I see it. Did this exist before, if so, what is it's legacy name? I can't seem to find anything similar to it in the same package.

Posted (edited)
  On 5/27/2019 at 1:00 PM, diesieben07 said:

1.8.9 came out 3 1/2 years ago. It's no longer supported by Forge. There is no reason to use it.

Update.

Expand  

There is one reason to use it, though it's not really that important anyways. It's mostly used for pvp, aka sword blocking. However have any ideas on mods that fix that problem on later versions like 1.13? Or any idea on how to achieve the same functionality without making it look somewhat fake (I know it's off topic, I might make another topic just for that)

Edited by fernthedev

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

    • Get $100 Off temu Coupon Code { ald123454 } | for new users + 30% Discount for all users You can get a $100 Off temu Coupon code using the code { ald123454 }. This temu $100 Off code is specifically for new customers and can be redeemed to receive a $100 discount on your purchase. Our exclusive temu Coupon code offers a flat $100 Off your purchase, plus an additional 30% discount. As a new temu customer, you can slash prices by up to 30% as a new temu customer using code { ald123454 }. Existing users can enjoy $100 Off their next haul with this code. But that’s not all! With our temu coupon code get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our temu codes provide extra discounts tailored just for you. Save up to 30% with these current temu Coupons { ald123454 } for February 2025. The latest temu coupon codes at here. Free temu codes $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Memorial Day Sale 75% off — { ald123454 } temu Coupon code today — { ald123454 } temu free gift code — { ald123454 } Without inviting friends or family member  Coupon code for Canada - $100 Off— { ald123454 } temu Coupon code Australia - $100 Off— { ald123454 } temu Coupon code New Zealand - $100 Off — { ald123454 } temu Coupon code Japan -$100 Off — { ald123454 } temu Coupon code Mexico - $100 Off — { ald123454 } temu Coupon code Chile - $100 Off — { ald123454 } temu Coupon code Peru - $100 Off — { ald123454 } temu Coupon code Colombia - $100 Off — { ald123454 } temu Coupon code Malaysia - $100 Off — { ald123454 } temu Coupon code the Philippines - $100 Off — { ald123454 } temu Coupon code South Korea - $100 Off — { ald123454 } Redeem Free temu Coupon Code { ald123454 }for first time user Get $100 discount on your temu order with the promo code "acr804084". You can get a discount by clicking on the item to purchase and entering this temu Coupon code $100 Off "{ ald123454 }". temu Coupon Code { ald123454 }: Get Up To $100 Off In June 2025 Are you looking for the best temu Coupon codes to get amazing discounts? Our temu Coupons are perfect for getting those extra savings you crave. We regularly test our coupon codes for temu to ensure they work flawlessly, giving you a guaranteed discount every time. temu New User Coupon { ald123454 }: Up To 75% OFF For First-Time Users Our temu first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on temu. To maximize your savings, download the temu Coupon For $100 Off { ald123454 }: Get A Flat $100 Discount On Order Value Get ready to save big with our incredible temu Coupon code for $100 Off! Our amazing temu $100 Off coupon code will give you a flat $100 discount on your order value, making your shopping experience even more rewarding. temu Coupon Code For $100 Off { ald123454 } For Both New And Existing Customers Our incredible temu Coupon code for $100 Off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100 Off code for temu will give you an additional discount! temu Coupon Bundle { ald123454 }: Flat $100 Off + Up To 30% Discount Get ready for an unbelievable deal with our temu Coupon bundle for 2025! Our temu Coupon bundles will give you a flat $100 discount and an additional $100 Off on top of it. Free temu Coupons { ald123454 }: Unlock Unlimited Savings! Get ready to unlock a world of savings with our free temu Coupons! We’ve got you covered with a wide range of temu Coupon code options that will help you maximize your shopping experience. $100 Off temu Coupons, Promo Codes + 25% Cash Back { ald123454 } Redeem temu Coupon Code { ald123454 }
    • Get $100 Off temu Coupon Code { ald123454 } | for new users + 30% Discount for all users You can get a $100 Off temu Coupon code using the code { ald123454 }. This temu $100 Off code is specifically for new customers and can be redeemed to receive a $100 discount on your purchase. Our exclusive temu Coupon code offers a flat $100 Off your purchase, plus an additional 30% discount. As a new temu customer, you can slash prices by up to 30% as a new temu customer using code { ald123454 }. Existing users can enjoy $100 Off their next haul with this code. But that’s not all! With our temu coupon code get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our temu codes provide extra discounts tailored just for you. Save up to 30% with these current temu Coupons { ald123454 } for February 2025. The latest temu coupon codes at here. Free temu codes $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Memorial Day Sale 75% off — { ald123454 } temu Coupon code today — { ald123454 } temu free gift code — { ald123454 } Without inviting friends or family member  Coupon code for Canada - $100 Off— { ald123454 } temu Coupon code Australia - $100 Off— { ald123454 } temu Coupon code New Zealand - $100 Off — { ald123454 } temu Coupon code Japan -$100 Off — { ald123454 } temu Coupon code Mexico - $100 Off — { ald123454 } temu Coupon code Chile - $100 Off — { ald123454 } temu Coupon code Peru - $100 Off — { ald123454 } temu Coupon code Colombia - $100 Off — { ald123454 } temu Coupon code Malaysia - $100 Off — { ald123454 } temu Coupon code the Philippines - $100 Off — { ald123454 } temu Coupon code South Korea - $100 Off — { ald123454 } Redeem Free temu Coupon Code { ald123454 }for first time user Get $100 discount on your temu order with the promo code "acr804084". You can get a discount by clicking on the item to purchase and entering this temu Coupon code $100 Off "{ ald123454 }". temu Coupon Code { ald123454 }: Get Up To $100 Off In June 2025 Are you looking for the best temu Coupon codes to get amazing discounts? Our temu Coupons are perfect for getting those extra savings you crave. We regularly test our coupon codes for temu to ensure they work flawlessly, giving you a guaranteed discount every time. temu New User Coupon { ald123454 }: Up To 75% OFF For First-Time Users Our temu first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on temu. To maximize your savings, download the temu Coupon For $100 Off { ald123454 }: Get A Flat $100 Discount On Order Value Get ready to save big with our incredible temu Coupon code for $100 Off! Our amazing temu $100 Off coupon code will give you a flat $100 discount on your order value, making your shopping experience even more rewarding. temu Coupon Code For $100 Off { ald123454 } For Both New And Existing Customers Our incredible temu Coupon code for $100 Off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100 Off code for temu will give you an additional discount! temu Coupon Bundle { ald123454 }: Flat $100 Off + Up To 30% Discount Get ready for an unbelievable deal with our temu Coupon bundle for 2025! Our temu Coupon bundles will give you a flat $100 discount and an additional $100 Off on top of it. Free temu Coupons { ald123454 }: Unlock Unlimited Savings! Get ready to unlock a world of savings with our free temu Coupons! We’ve got you covered with a wide range of temu Coupon code options that will help you maximize your shopping experience. $100 Off temu Coupons, Promo Codes + 25% Cash Back { ald123454 } Redeem temu Coupon Code { ald123454 }
    • Get $100 Off temu Coupon Code { ald123454 } | for new users + 30% Discount for all users You can get a $100 Off temu Coupon code using the code { ald123454 }. This temu $100 Off code is specifically for new customers and can be redeemed to receive a $100 discount on your purchase. Our exclusive temu Coupon code offers a flat $100 Off your purchase, plus an additional 30% discount. As a new temu customer, you can slash prices by up to 30% as a new temu customer using code { ald123454 }. Existing users can enjoy $100 Off their next haul with this code. But that’s not all! With our temu coupon code get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our temu codes provide extra discounts tailored just for you. Save up to 30% with these current temu Coupons { ald123454 } for February 2025. The latest temu coupon codes at here. Free temu codes $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Memorial Day Sale 75% off — { ald123454 } temu Coupon code today — { ald123454 } temu free gift code — { ald123454 } Without inviting friends or family member  Coupon code for Canada - $100 Off— { ald123454 } temu Coupon code Australia - $100 Off— { ald123454 } temu Coupon code New Zealand - $100 Off — { ald123454 } temu Coupon code Japan -$100 Off — { ald123454 } temu Coupon code Mexico - $100 Off — { ald123454 } temu Coupon code Chile - $100 Off — { ald123454 } temu Coupon code Peru - $100 Off — { ald123454 } temu Coupon code Colombia - $100 Off — { ald123454 } temu Coupon code Malaysia - $100 Off — { ald123454 } temu Coupon code the Philippines - $100 Off — { ald123454 } temu Coupon code South Korea - $100 Off — { ald123454 } Redeem Free temu Coupon Code { ald123454 }for first time user Get $100 discount on your temu order with the promo code "acr804084". You can get a discount by clicking on the item to purchase and entering this temu Coupon code $100 Off "{ ald123454 }". temu Coupon Code { ald123454 }: Get Up To $100 Off In June 2025 Are you looking for the best temu Coupon codes to get amazing discounts? Our temu Coupons are perfect for getting those extra savings you crave. We regularly test our coupon codes for temu to ensure they work flawlessly, giving you a guaranteed discount every time. temu New User Coupon { ald123454 }: Up To 75% OFF For First-Time Users Our temu first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on temu. To maximize your savings, download the temu Coupon For $100 Off { ald123454 }: Get A Flat $100 Discount On Order Value Get ready to save big with our incredible temu Coupon code for $100 Off! Our amazing temu $100 Off coupon code will give you a flat $100 discount on your order value, making your shopping experience even more rewarding. temu Coupon Code For $100 Off { ald123454 } For Both New And Existing Customers Our incredible temu Coupon code for $100 Off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100 Off code for temu will give you an additional discount! temu Coupon Bundle { ald123454 }: Flat $100 Off + Up To 30% Discount Get ready for an unbelievable deal with our temu Coupon bundle for 2025! Our temu Coupon bundles will give you a flat $100 discount and an additional $100 Off on top of it. Free temu Coupons { ald123454 }: Unlock Unlimited Savings! Get ready to unlock a world of savings with our free temu Coupons! We’ve got you covered with a wide range of temu Coupon code options that will help you maximize your shopping experience. $100 Off temu Coupons, Promo Codes + 25% Cash Back { ald123454 } Redeem temu Coupon Code { ald123454 }
    • Get $100 Off temu Coupon Code { ald123454 } | for new users + 30% Discount for all users You can get a $100 Off temu Coupon code using the code { ald123454 }. This temu $100 Off code is specifically for new customers and can be redeemed to receive a $100 discount on your purchase. Our exclusive temu Coupon code offers a flat $100 Off your purchase, plus an additional 30% discount. As a new temu customer, you can slash prices by up to 30% as a new temu customer using code { ald123454 }. Existing users can enjoy $100 Off their next haul with this code. But that’s not all! With our temu coupon code get up to 90% discount on select items and clearance sales. Whether you’re a new customer or an existing shopper, our temu codes provide extra discounts tailored just for you. Save up to 30% with these current temu Coupons { ald123454 } for February 2025. The latest temu coupon codes at here. Free temu codes $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Coupon $100 Off — { ald123454 } temu Memorial Day Sale 75% off — { ald123454 } temu Coupon code today — { ald123454 } temu free gift code — { ald123454 } Without inviting friends or family member  Coupon code for Canada - $100 Off— { ald123454 } temu Coupon code Australia - $100 Off— { ald123454 } temu Coupon code New Zealand - $100 Off — { ald123454 } temu Coupon code Japan -$100 Off — { ald123454 } temu Coupon code Mexico - $100 Off — { ald123454 } temu Coupon code Chile - $100 Off — { ald123454 } temu Coupon code Peru - $100 Off — { ald123454 } temu Coupon code Colombia - $100 Off — { ald123454 } temu Coupon code Malaysia - $100 Off — { ald123454 } temu Coupon code the Philippines - $100 Off — { ald123454 } temu Coupon code South Korea - $100 Off — { ald123454 } Redeem Free temu Coupon Code { ald123454 }for first time user Get $100 discount on your temu order with the promo code "acr804084". You can get a discount by clicking on the item to purchase and entering this temu Coupon code $100 Off "{ ald123454 }". temu Coupon Code { ald123454 }: Get Up To $100 Off In June 2025 Are you looking for the best temu Coupon codes to get amazing discounts? Our temu Coupons are perfect for getting those extra savings you crave. We regularly test our coupon codes for temu to ensure they work flawlessly, giving you a guaranteed discount every time. temu New User Coupon { ald123454 }: Up To 75% OFF For First-Time Users Our temu first-time user coupon codes are designed just for new customers, offering the biggest discounts and the best deals currently available on temu. To maximize your savings, download the temu Coupon For $100 Off { ald123454 }: Get A Flat $100 Discount On Order Value Get ready to save big with our incredible temu Coupon code for $100 Off! Our amazing temu $100 Off coupon code will give you a flat $100 discount on your order value, making your shopping experience even more rewarding. temu Coupon Code For $100 Off { ald123454 } For Both New And Existing Customers Our incredible temu Coupon code for $100 Off is here to help you save big on your purchases. Whether you’re a new user or an existing customer, our $100 Off code for temu will give you an additional discount! temu Coupon Bundle { ald123454 }: Flat $100 Off + Up To 30% Discount Get ready for an unbelievable deal with our temu Coupon bundle for 2025! Our temu Coupon bundles will give you a flat $100 discount and an additional $100 Off on top of it. Free temu Coupons { ald123454 }: Unlock Unlimited Savings! Get ready to unlock a world of savings with our free temu Coupons! We’ve got you covered with a wide range of temu Coupon code options that will help you maximize your shopping experience. $100 Off temu Coupons, Promo Codes + 25% Cash Back { ald123454 } Redeem temu Coupon Code { ald123454 }
  • Topics

×
×
  • Create New...

Important Information

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