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.

Featured Replies

Posted

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!

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.

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

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.