How to disable off-hand

Started by Phase360 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to disable off-hand

so I am making a mod that have guns and will be multiplayer and i want off hand not to work so how can i do that please help me i want a blue print so it can you tell me 

please help me

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I made something like this…
Sat, 11/11/2023 - 16:05

I made something like this to prevent buckets from being used in the off-hand, for elaborate reasons that aren't really worth mentioning. 

The basic idea is that you make a procedure which, on player update tick, checks if the item in their offhand is the desired item. (The item that shouldn't be in their offhand.) If it is, set 1 of the item in their offhand in the player's inventory, (Using the 'set (item) in player inventory' function), and then set air in the player's off hand. As long as your items are non-stackable, you don't have to worry about the number of items in their hand.

Since the procedure triggers every tick, attempting to set an item in the offhand will immediately trigger the procedure. In most cases, the game won't even register the keypress before returning the item to the player's inventory. Do be sure to test this though, it's very easy to create a duplication bug by accident.