Posted May 16, 20205 yr Hello all, I'm trying to find something that functions just like Item's onItemUse, but called for a left-click instead of a right click. The essential part I need is the hit vector; I need to know exactly where on the block the player has left-clicked. It's for a specific item/block combo, so I can handle it either in the item or the block. Any help would be hugely appreciated!
May 16, 20205 yr Im not exactly sure how to do what you want, but the Item#onEntitySwing is executed whenever you left click with an item. From there you might be able to use the players look vector and do some ray tracing, but this is just me guessing. Remember the method is called many times, and will continue being called while holding down left click.
May 16, 20205 yr Author I've managed to find a sort of workaround - although it doesn't work in Creative mode, so open to ideas. For anyone who finds this via google in the future, in your Item class, add a function which returns the protected Item.rayTrace function, and then in your block class, override onBlockClicked and call item.onItemUse, passing a new ItemUseContext with the BlockRayTraceResult being the output of your function. This in effect will then trigger onItemUse from your left-click action instead of your right click. (It might also be a good idea to override canPlayerBreakBlockWhileHolding and return false in your item). Note that it will only call it once when holding left-click (it'll continue to call when holding right click) The only remaining problem is onBlockClicked doesn't seem to get called if the player is in creative mode. Will update if I find a workaround
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.