Posted July 10, 201510 yr Hey, i'm simply trying to figure out how to detect a specific item in a players inventory, then run specific actions such as potion effects if its there, which would run under a server tick event. I just can't seem to figure out how to actually detect the item itself. From what I've read, I should use if(player.inventory.hasItem(ItemRegenerationStone)) but that doesnt seem to work. Any help would be much appreciated.
July 10, 201510 yr Is that your own Item? If so: Use Item#onUpdate() - it runs always when item is in inventory. If that is not your: Don't use server tick. You want PlayerTickEvent. then: event.player.inventory and interate through itemstack. Then e.g : if(stack.getItem() == Items.stick) Note that tick events have 2 phases - pick one. event.phase. 1.7.10 is no longer supported by forge, you are on your own.
July 10, 201510 yr Author Where/how would i use Item#onUpdate? I would imagine somehow like the following: @SubscribeEvent public void onUpdate(LivingUpdateEvent event) { //seteffects } but how do I put in the Item# part and how would I specify the item in question?
July 10, 201510 yr Author Okay, I'm starting to feel like a pest but I can't get this to work. At this point I am able to at least launch Minecraft and load/make worlds, but when I put the item in my inventory, the game crashes. Here is my code: import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class ItemRegenerationStone extends Item { EntityPlayer player = Minecraft.getMinecraft().thePlayer; @Override public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag) { player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 100, 1)); } } I feel like I'm doing something horribly wrong in there but I can't figure out what.\ Thanks for the help.
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.