Posted November 2, 201510 yr 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.
November 3, 201510 yr 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.