Jump to content

Recommended Posts

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?

Posted

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

Posted

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!

Posted

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.