LeeCrafts Posted May 27, 2022 Posted May 27, 2022 (edited) I want to give a player a status effect whenever it presses a certain key. This was my first attempt: @SubscribeEvent public static void pressCKey(InputEvent.KeyInputEvent event) { LocalPlayer localPlayer = Minecraft.getInstance().player; if (localPlayer != null && event.getKey() == 67 && event.getAction() == GLFW.GLFW_PRESS) { if (localPlayer.getActiveEffectsMap() != null) localPlayer.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 1000)); } } I quickly realized this didn't work because it was adding the effect to the client-side player (LocalPlayer), and not the server-side player. I then searched through some older forums and found out that I would need to send a packet to the server whenever a key is pressed. There was a vanilla packet called ServerboundKeyPacket, but it confused me when I saw its constructor. I am unsure if this packet is the right one to use because it apparently does not consider which player pressed the key. Should I just use a custom packet instead? Edited May 28, 2022 by LeeCrafts Quote
Luis_ST Posted May 27, 2022 Posted May 27, 2022 On 5/27/2022 at 5:50 PM, LeeCrafts said: Should I just use a custom packet instead? Expand yes you should, you can take a look at this 1 Quote
Recommended Posts
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.