Jump to content

Recommended Posts

Posted

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);
        }
    }
}
Posted
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.

Posted

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

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



×
×
  • Create New...

Important Information

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