Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.