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

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.

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.

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

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

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.