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

Hello, I've been trying to make an item so that when you hold it in your hand it gives you blindness.

But, when I have the code set up like this (in the class of that item):

@Override
    public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5)
    {
        super.onUpdate(stack, world, entity, par4, par5);
        if (entity instanceof EntityPlayer)
        {
            EntityPlayer player = (EntityPlayer) entity;
            ItemStack equipped = player.getCurrentEquippedItem();
            if (equipped == stack)
            {
                player.addPotionEffect(new PotionEffect(Potion.blindness.id, 1, 3));
            }
        }

It only gives me this in-game:

KItTP0z.png

And the only effect it gives me is that I am unable to sprint...

 

Can someone help me?

The second parameter is in ticks I believe. Try something higher like 20 (which should correspond to ~1s).

player.addPotionEffect(new PotionEffect(Potion.blindness.id, 20, 3));//1 replaces with 20

I'm not sure, but it might be because in this line:

player.addPotionEffect(new PotionEffect(Potion.blindness.id, 1, 3));

In the second parameter you wrote 1. The second parameter is for the duration, so you wrote it gives the player a blindness effect for one second, which probably isn't even long enough to show the actual blindness effect. Again I'm not completely sure, but hopefully this helps!

  • Author

The second parameter is in ticks I believe. Try something higher like 20 (which should correspond to ~1s).

player.addPotionEffect(new PotionEffect(Potion.blindness.id, 20, 3));//1 replaces with 20

Thanks, that did it :)

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.