Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.