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

So, after getting my custom inventory to work, I find it a tad bit annoying not having the ability to close it with my custom key ®. I have tried sending a packet to close the container (which I believe would tell the client to close the gui also), but the KeyInputEvent is not called while in a gui.

 

Here is my key handler class:

http://pastebin.com/jA9eTDub

 

And my Packet to close the container:

http://pastebin.com/uNNQyzVp

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

  • Author

Thank you for that, so, I put that in the keyTyped method in my GUI class. The only problem seems to be that, it will close and re-open. I find this to be that the KeyInputEvent gets called multiple times per press. Is there a way to counter this?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

KeyInputEvent fires both when the key is pressed and when the key is released; Keyboard#getEventKeyState() will be true if it was pressed, and false if it was released, or you can use the ClientTickEvent as diesieben suggests.

 

And yes, you can put the closing logic in your Gui's #keyTyped method if you want, or in the key handling section. I like to put it in my Gui so that the key doesn't close other screens (you can prevent that by checking the current screen's type, but it's easier to just put it in your Gui).

  • Author

@diesieben07 Basically, I close the screen in my gui because KeyInputEvent doesn't fire in a gui (I don't know if that is normal, but that's what I found).

 

@coolAlias Thank you! I now check if the custom key is down, and if the current container is not my own before sending the packet to open the gui. Here's an example for those experiencing something similar:

 

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

if(kb == keys[CUSTOM_INV].getKeyCode() && isDown && !(player.openContainer instanceof YourContainer)) {
System.out.println(player.openContainer);

if(player.openContainer instanceof YourContainer) {
	//Unused		
}else {
        PacketHandler.network.sendToServer(new PacketOpenGui(CUSTOM_INV));
	System.out.println("Packet was sent");
}
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

  • Author

That's what I did. I posted the fix to the code that was conflicting (reopening the gui after closing it). When I'd attempt to close the gui, I never checked in my KeyHandler if the key was down. So, when the key was released, it would send the packet to reopen the gui. Thus, constantly reopening it after closing it.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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.