Posted December 13, 201212 yr I want to give a player certain abilities when a specific item is in the hotbar but cannot figure out how to detect when an item is in the hotbar... Any suggestions?
December 14, 201212 yr A quick look at EntityPlayer and InventoryPlayer showed a few things. You could iterate over the mainInventory of the player which is in InventoryPlayer. Further you could only iterate over the items in mainInventory that correspond to hotbar slots and then getItem() on it and perform your checks. Have a read: http://jd.minecraftforge.net/net/minecraft/entity/player/EntityPlayer.html http://jd.minecraftforge.net/net/minecraft/entity/player/InventoryPlayer.html http://jd.minecraftforge.net/net/minecraft/item/ItemStack.html If I helped you, thank me. If I didn't, let me know.
December 15, 201212 yr Author Ok... I feel bad asking but what method should i use to fire the if statement?
December 15, 201212 yr Well. Use the field mainInventory in InventoryPlayer and iterate over only indexes 0 to 8 as super_aardvark has said. Upon each iteration you could check to see if that item is equal to the one you want. If I helped you, thank me. If I didn't, let me know.
December 16, 201212 yr You would probably need to use a tick handler to call the if statement every tick
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.