How to prevent the switching of items inside the hotbar in vanilla minecraft [1.12.2]? [duplicate]

Is there a set of commands I could use which would allow for me to prevent a player from switching items? So if their "selectedItem" slot is 1, they can't switch the slot to 2.


No.

Not much more to say here, there's just no way to do it, except for writing a custom mod for both client and server.

I recommend instead thinking about what you want to really do. For example, maybe it could work to just move the item in the hotbar with the selected slot. Or just give the player 9 identical items. Or make whatever you're doing not dependent on the selected slot. Or …