Posted August 16, 20214 yr 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 August 17, 20214 yr by Bowtruckle_HD
August 16, 20214 yr 23 minutes ago, Bowtruckle_HD said: how to make a Player invisible first. also the armor?
August 16, 20214 yr Author ok and can you tell me how to cancel it only when a player presses a button? Like do I have to use capabillities?
August 16, 20214 yr Author I think that I can figure this out myself, only one thing, which event do I use to get when a player presses a key?
August 16, 20214 yr it's a little more complicated than you think, becuase KeyBindings are client side: create a custom KeyBinding and register it in FMLClientSetupEvent use TickEvent.ClientTickEvent to check if the KeyBinding is pressed (Note: TickEvents fired twice, check this with TickEvent.phase) if the KeyBinding is pressed, set Capability value to true (on client) 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
August 16, 20214 yr 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?
August 17, 20214 yr 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
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.