Jump to content

How to check if player is holding control on multiplayer? [1.18.2] [SOLVED]


RInventor7

Recommended Posts

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 by RInventor7
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

  • RInventor7 changed the title to How to check if player is holding control on multiplayer? [1.18.2] [SOLVED]

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.