Jump to content

1.19.1 - how do I add an effect to the player?


Choccy Biscuit

Recommended Posts

I am trying to add strength to the player on use, along with playing a sound.

here's the code:

public class DarksteelHornItem extends Item {
    public DarksteelHornItem(Properties properties) {
        super(properties);
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
        if(level.isClientSide() && hand == InteractionHand.MAIN_HAND) {
            level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.RAID_HORN, SoundSource.PLAYERS, 1.0F, 1.0F);
            player.addEffect(new MobEffectInstance(new MobEffect(), 5));

        }
        return super.use(level, player, hand);
    }
}

Edited by Choccy Biscuit
formatting
Link to comment
Share on other sites

1 hour ago, MFMods said:

addEffect should be run on server-side (level.isClientSide==false). playSound on client-side (isClientSIde==true).

I've changed it to this, but I get the error "'MobEffect(net.minecraft.world.effect.MobEffectCategory, int)' has protected access in 'net.minecraft.world.effect.MobEffect'"

It also returns the error on run:

"required: MobEffectCategory,int
  found:    no arguments
  reason: actual and formal argument lists differ in length"

public class DarksteelHornItem extends Item {
    public DarksteelHornItem(Properties properties) {
        super(properties);
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
        if(level.isClientSide() == true && hand == InteractionHand.MAIN_HAND) {
            level.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.RAID_HORN,           SoundSource.PLAYERS, 1.0F, 1.0F);
        if(level.isClientSide() == false && hand == InteractionHand.MAIN_HAND){
            player.addEffect(new MobEffectInstance(new MobEffect(),5));
            }
        player.getCooldowns().addCooldown(this,400);
        }
        return super.use(level, player, hand);
    }
}

Edited by Choccy Biscuit
detail
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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