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

I have a feeling this is a really simple thing to do and probably a dumb question, but I have been searching for a while and not really found what I am looking for.

 

What I want to do is, detect when the player selects an item (scrolls to it, or presses the hotbar number). I have attempted to check the player's currently equipped item and compare it to the previously equipped item (as in the last held item), but I couldn't find a method for previously equipped items.

 

I did attempt a LivingUpdateEvent, to check and store the held item, but it didn't seem like the most practical way to do it, so I was wondering if anyone could advise me on a better way to detect when the player changes their held item.

Comparing current to previous is the only option. Any other way would require either ASM or quite some replacements to vanilla inventory system.

 

As to storin previous values:

You need to implements IExtendedEntityProperties, use PlayerTickEvent (note: pick one event.phase, otherwise event is ran twice), make comprasion to previous stack and then refresh.

 

You will probably have to save two fields:

player.inventory.currentItem to check if "wheel" slot is same as before. - if it changed from prev pick, item changed.

player.inventory.getCurrentItem() compare if previous ItemStack is same as new one (from current tick).

 

I fortog you can just "==", no need to save currentItem.

 

Links:

IEEP tutorial:

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-1-7-2-1-6-4-eventhandler-and

1.7.10 is no longer supported by forge, you are on your own.

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.