Posted May 27, 20223 yr 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, 20223 yr by LeeCrafts
May 27, 20223 yr 10 minutes ago, LeeCrafts said: Should I just use a custom packet instead? yes you should, you can take a look at this
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.