Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Trying to open a gui with a keybind click.
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
FireIsH0t

Trying to open a gui with a keybind click.

By FireIsH0t, December 16, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

FireIsH0t    1

FireIsH0t

FireIsH0t    1

  • Stone Miner
  • FireIsH0t
  • Members
  • 1
  • 56 posts
Posted December 16, 2018

When I click "g" on my keyboard it doesn't open my gui which is what I want.

 

GuiCosmetics class:

public class GuiCosmetics extends GuiScreen
{
    // Images
    private final ResourceLocation BACKGROUND = new ResourceLocation(ModReference.MOD_ID,"textures/gui/cosmetics/bg.png");

    @Override
    public void initGui() {
        super.initGui();
    }

    @Override
    protected void actionPerformed(GuiButton button) throws IOException {
        super.actionPerformed(button);
    }

    @Override
    public void updateScreen() {
        super.updateScreen();
    }

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        super.drawScreen(mouseX, mouseY, partialTicks);

        // Draw Background
        this.drawBackground();
    }

    @Override
    public void handleKeyboardInput() throws IOException {
        super.handleKeyboardInput();
    }

    private void drawBackground()
    {
        ArsenalUtils.drawBackground(0, 0, BACKGROUND, this.width, this.height);
    }

}

 

ClientEventSubsriber Class:
 

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event)
{
    if (!FMLClientHandler.instance().isGUIOpen(GuiCosmetics.class)) {
        int key = Keyboard.getEventKey();
        boolean isDown = Keyboard.getEventKeyState();
        AbstractClientPlayer playerMP = Minecraft.getMinecraft().player;

        if (isDown && key == Keyboard.KEY_G)
        {
            playerMP.openGui(ArsenalMod.instance, ModReference.GUI_COSMETICS, playerMP.world, (int) playerMP.posX, (int) playerMP.posY, (int) playerMP.posZ);
        }
    }
}
  • Quote

Share this post


Link to post
Share on other sites

V0idWa1k3r    386

V0idWa1k3r

V0idWa1k3r    386

  • World Shaper
  • V0idWa1k3r
  • Members
  • 386
  • 1773 posts
Posted December 16, 2018
11 minutes ago, FireIsH0t said:

InputEvent.KeyInputEvent

Don't use the KeyInputEvent, use the basic client tick event.

 

12 minutes ago, FireIsH0t said:

!FMLClientHandler.instance().isGUIOpen(GuiCosmetics.class)

Why are you checking it like this? You are on the client anyway, just check Minecraft.currentScreen directly.

 

13 minutes ago, FireIsH0t said:

int key = Keyboard.getEventKey(); boolean isDown = Keyboard.getEventKeyState();

13 minutes ago, FireIsH0t said:

if (isDown && key == Keyboard.KEY_G)

Why are you doing this? Minecraft has a built-in system for creating key bindings, it's called KeyBindings. Use it.

 

14 minutes ago, FireIsH0t said:

AbstractClientPlayer playerMP

This is me nitpicking but AbstractClientPlayer != EntityPlayerMP. They belong to different logical sides.

 

14 minutes ago, FireIsH0t said:

playerMP.openGui(ArsenalMod.instance, ModReference.GUI_COSMETICS, playerMP.world, (int) playerMP.posX, (int) playerMP.posY, (int) playerMP.posZ);

AFAIK you can't do this on the client. If you want to open a GUI on the client either open it directly by calling Minecraft#displayGuiScreen or if you need a gui/container pair then you need to send a packet to the server.

  • Quote

Share this post


Link to post
Share on other sites

FireIsH0t    1

FireIsH0t

FireIsH0t    1

  • Stone Miner
  • FireIsH0t
  • Members
  • 1
  • 56 posts
Posted December 16, 2018

Could you explain keybinds?

  • Quote

Share this post


Link to post
Share on other sites

V0idWa1k3r    386

V0idWa1k3r

V0idWa1k3r    386

  • World Shaper
  • V0idWa1k3r
  • Members
  • 386
  • 1773 posts
Posted December 16, 2018

KeyBinding is a way of registering and detecting key presses in minecraft. As a side effect it also makes your key rebindable.

To start you would need to construct a new instance of KeyBinding. Use the forge provided constructor.

Then you need to register the keybinding using ClientRegistry.registerKeyBinding.

Finally you can use KeyBinding#isPressed to detect whether the keybinding was pressed or KeyBinding#isKeyDown to detect whether the key is currently pressed.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Memory Heap Thingy!

      By diesieben07 · Posted 2 minutes ago

      That's not what this thread is about... Make your own thread and post logs.
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 20 minutes ago

      It gets stuck on that part and doesn’t change
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 21 minutes ago

      Wym  
    • RaphGamingz
      ScreenGui does nothing

      By RaphGamingz · Posted 1 hour ago

      any errors?
    • RaphGamingz
      Game crashing when the block is activated

      By RaphGamingz · Posted 1 hour ago

      then you    your not assigning a value to the tileEntity try in the constructor tileEntity = world.getTileEntity(pos);
  • Topics

    • Mizinov
      7
      Memory Heap Thingy!

      By Mizinov
      Started August 24

    • Jaffaaaaa
      2
      ScreenGui does nothing

      By Jaffaaaaa
      Started Wednesday at 07:03 PM

    • jun2040
      5
      Game crashing when the block is activated

      By jun2040
      Started 17 hours ago

    • Merthew
      5
      [1.12.2] Multiple Structure Generation

      By Merthew
      Started November 7, 2018

    • Professional Derp
      16
      Server frequently crashes

      By Professional Derp
      Started 10 hours ago

  • Who's Online (See full list)

    • Krevik
    • diesieben07
    • GttiqwT
    • ZigTheHedge
    • ewew
    • jun2040
    • gudie73
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Trying to open a gui with a keybind click.
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community