Posted August 19, 20223 yr On regular singleplayer I use function like this to check if player is holding down control key. @OnlyIn(Dist.CLIENT) public static boolean isHoldingControl() { return InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_CONTROL) || InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_RIGHT_CONTROL); } However, on multiplayer it throws an error, because this is a client-side function and the Minecraft class is also client-side (if I understand correctly). How can I make a function that would work for DEDICATED_SERVER as well? I guess I have to pass in a player as an argument, but I can't figure out how to check weather control is held or not. Thanks. Edited March 2, 20232 yr by RInventor7
August 19, 20223 yr You should use a KeyMapping for that, then check in ClientTickEvent KeyMapping#isDown and send the state of the KeyMapping via a custom network packet to the server. To avoid sending a Packet each tick, you should send the Packet only if the KeyMapping got pressed or released (the state changed).
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.