Started by
Phase360
on
Topic category: Help with Minecraft modding (Java Edition)
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
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.