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

Hello, I'm fairly new to modding and I was trying to make a player invisible, when he presses the key "g". I set up the KeyboardKeypressed event, its probably not the right way, because you cant change the keybind, but i wanted to learn , how to make a Player invisible first. Sadly I cant seem to get the Player from the event. Could anyone give me a rough explanation, on what to do and where to start? I dont just want the code, but some explanation too, so I can learn from it. I posted my Code down below, but it is not much. Thx in Advance

 

@SubscribeEvent public void onPlayerRender (GuiScreenEvent.KeyboardKeyPressedEvent event) { if(event.getKeyCode() == 71) { } }

Edited by Bowtruckle_HD

it's a little more complicated than you think, becuase KeyBindings are client side:

  1. create a custom KeyBinding and register it in FMLClientSetupEvent
  2. use TickEvent.ClientTickEvent to check if the KeyBinding is pressed (Note: TickEvents fired twice, check this with TickEvent.phase)
  3. if the KeyBinding is pressed, set Capability value to true (on client)
  4. get Capability value in RenderPlayerEvent.Pre and cancele it if the value is true

I have no idea whether you have to sync the capability to all clients because the RenderPlayerEvent has no Java doc, so its not clear when and how the event is fired

  • Author
2 hours ago, Luis_ST said:

cancele RenderPlayerEvent.Pre

Ok, I got it working, but there are still the particles at my feet and the shadow of the player. Any Events I can turn it off with?

  • Author
4 hours ago, diesieben07 said:

You definitely would have to sync the capability. Both pressing a key as well as rendering is entirely client side. So when the key is pressed you need to send a packet to the server, the server updates the capability and syncs the change to all clients.

It is actually not very straightforward to do this. It would be best to just apply the invisibility effect to the player.

Ok, thank you both very much, I did apply the invisibility effect and it works well now. I'm gonna mark this post as solved now

  • Bowtruckle_HD changed the title to [Solved](1.16.5)How to get the Player who pressed a key?

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.